blob: 6744c3ff28ac1abe0f8e449dc634b0741f8c06ac [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,
132 n,
133 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000134
cristyd0a94fa2010-03-12 14:18:11 +0000135 (void) setlocale(LC_ALL,"");
136 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000137 concurrent=MagickFalse;
138 duration=(-1.0);
139 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000140 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000141 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000142 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000143 {
144 option=argv[i];
145 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
146 continue;
147 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000148 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000149 if (LocaleCompare("concurrent",option+1) == 0)
150 concurrent=MagickTrue;
151 if (LocaleCompare("debug",option+1) == 0)
152 (void) SetLogEventMask(argv[++i]);
153 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000154 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000155 if (LocaleCompare("regard-warnings",option+1) == 0)
156 regard_warnings=MagickTrue;
157 }
cristy8ea926d2011-12-09 12:25:04 +0000158 if (iterations == 1)
159 {
160 status=command(image_info,argc,argv,metadata,exception);
161 if (exception->severity != UndefinedException)
162 {
163 if ((exception->severity > ErrorException) ||
164 (regard_warnings != MagickFalse))
165 status=MagickTrue;
166 CatchException(exception);
167 }
168 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
169 {
170 (void) fputs(*metadata,stdout);
171 (void) fputc('\n',stdout);
172 *metadata=DestroyString(*metadata);
173 }
174 return(status);
175 }
cristyc2e3aeb2011-12-09 11:09:38 +0000176 number_threads=GetOpenMPMaximumThreads();
cristy8ea926d2011-12-09 12:25:04 +0000177 serial=0.0;
cristyc2e3aeb2011-12-09 11:09:38 +0000178 for (n=1; n <= number_threads; n++)
179 {
180 double
cristy8ea926d2011-12-09 12:25:04 +0000181 e,
182 parallel,
cristyc2e3aeb2011-12-09 11:09:38 +0000183 user_time;
184
185 TimerInfo
186 *timer;
187
188 SetOpenMPMaximumThreads(n);
189 timer=AcquireTimerInfo();
190 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000191 {
cristyc2e3aeb2011-12-09 11:09:38 +0000192 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000193 {
cristyc2e3aeb2011-12-09 11:09:38 +0000194 if (status != MagickFalse)
195 continue;
196 if (duration > 0)
197 {
198 if (GetElapsedTime(timer) > duration)
199 continue;
200 (void) ContinueTimer(timer);
201 }
202 status=command(image_info,argc,argv,metadata,exception);
cristyceae09d2009-10-28 17:18:47 +0000203 if (exception->severity != UndefinedException)
204 {
205 if ((exception->severity > ErrorException) ||
206 (regard_warnings != MagickFalse))
207 status=MagickTrue;
208 CatchException(exception);
209 }
210 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
211 {
212 (void) fputs(*metadata,stdout);
213 (void) fputc('\n',stdout);
214 *metadata=DestroyString(*metadata);
215 }
216 }
217 }
cristyc2e3aeb2011-12-09 11:09:38 +0000218 else
219 {
220 SetOpenMPNested(1);
221#if defined(MAGICKCORE_OPENMP_SUPPORT)
222 # pragma omp parallel for shared(status)
223#endif
224 for (i=0; i < (ssize_t) iterations; i++)
225 {
226 if (status != MagickFalse)
227 continue;
228 if (duration > 0)
229 {
230 if (GetElapsedTime(timer) > duration)
231 continue;
232 (void) ContinueTimer(timer);
233 }
234 status=command(image_info,argc,argv,metadata,exception);
235#if defined(MAGICKCORE_OPENMP_SUPPORT)
236 # pragma omp critical (MagickCore_CommandGenesis)
237#endif
238 {
239 if (exception->severity != UndefinedException)
240 {
241 if ((exception->severity > ErrorException) ||
242 (regard_warnings != MagickFalse))
243 status=MagickTrue;
244 CatchException(exception);
245 }
246 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
247 {
248 (void) fputs(*metadata,stdout);
249 (void) fputc('\n',stdout);
250 *metadata=DestroyString(*metadata);
251 }
252 }
253 }
254 }
cristyc2e3aeb2011-12-09 11:09:38 +0000255 user_time=GetUserTime(timer);
cristy8ea926d2011-12-09 12:25:04 +0000256 parallel=GetElapsedTime(timer);
257 e=1.0;
258 if (n == 1)
259 serial=parallel;
260 else
261 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
262 (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000263 (void) FormatLocaleFile(stderr,
cristy91ce84d2011-12-09 23:02:25 +0000264 "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
cristy8ea926d2011-12-09 12:25:04 +0000265 (double) n,(double) iterations,(double) iterations/parallel,e,
266 user_time,(unsigned long) (parallel/60.0),(unsigned long)
267 floor(fmod(parallel,60.0)),(unsigned long)
268 (1000.0*(parallel-floor(parallel))+0.5));
cristyc2e3aeb2011-12-09 11:09:38 +0000269 timer=DestroyTimerInfo(timer);
270 }
cristy1f9e1ed2009-11-18 04:09:38 +0000271 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000272}
273
274/*
275%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276% %
277% %
278% %
cristy3ed852e2009-09-05 21:47:34 +0000279+ M o g r i f y I m a g e %
280% %
281% %
282% %
283%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284%
anthonye9c27192011-03-27 08:07:06 +0000285% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000286% image that may be part of a large list, but also handles any 'region'
287% image handling.
anthonye9c27192011-03-27 08:07:06 +0000288%
289% The image in the list may be modified in three different ways...
290%
291% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
292% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
293% * replace by a list of images (only the -separate option!)
294%
295% In each case the result is returned into the list, and a pointer to the
296% modified image (last image added if replaced by a list of images) is
297% returned.
298%
299% ASIDE: The -crop is present but restricted to non-tile single image crops
300%
301% This means if all the images are being processed (such as by
302% MogrifyImages(), next image to be processed will be as per the pointer
303% (*image)->next. Also the image list may grow as a result of some specific
304% operations but as images are never merged or deleted, it will never shrink
305% in length. Typically the list will remain the same length.
306%
307% WARNING: As the image pointed to may be replaced, the first image in the
308% list may also change. GetFirstImageInList() should be used by caller if
309% they wish return the Image pointer to the first image in list.
310%
cristy3ed852e2009-09-05 21:47:34 +0000311%
312% The format of the MogrifyImage method is:
313%
314% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
315% const char **argv,Image **image)
316%
317% A description of each parameter follows:
318%
319% o image_info: the image info..
320%
321% o argc: Specifies a pointer to an integer describing the number of
322% elements in the argument vector.
323%
324% o argv: Specifies a pointer to a text array containing the command line
325% arguments.
326%
327% o image: the image.
328%
329% o exception: return any errors or warnings in this structure.
330%
331*/
332
anthonydf8ebac2011-04-27 09:03:19 +0000333static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
334 ExceptionInfo *exception)
335{
336 char
337 key[MaxTextExtent];
338
339 ExceptionInfo
340 *sans_exception;
341
342 Image
343 *image;
344
345 ImageInfo
346 *read_info;
347
cristyfcd785b2011-11-08 01:48:33 +0000348 /*
349 Read an image into a image cache if not already present. Return the image
350 that is in the cache under that filename.
351 */
cristyb51dff52011-05-19 16:55:47 +0000352 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000353 sans_exception=AcquireExceptionInfo();
354 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
355 sans_exception=DestroyExceptionInfo(sans_exception);
356 if (image != (Image *) NULL)
357 return(image);
358 read_info=CloneImageInfo(image_info);
359 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
360 image=ReadImage(read_info,exception);
361 read_info=DestroyImageInfo(read_info);
362 if (image != (Image *) NULL)
363 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
364 return(image);
365}
366
cristy3ed852e2009-09-05 21:47:34 +0000367static MagickBooleanType IsPathWritable(const char *path)
368{
369 if (IsPathAccessible(path) == MagickFalse)
370 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000371 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000372 return(MagickFalse);
373 return(MagickTrue);
374}
375
cristybb503372010-05-27 20:51:26 +0000376static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000377{
378 if (x > y)
379 return(x);
380 return(y);
381}
382
anthonydf8ebac2011-04-27 09:03:19 +0000383static MagickBooleanType MonitorProgress(const char *text,
384 const MagickOffsetType offset,const MagickSizeType extent,
385 void *wand_unused(client_data))
386{
387 char
388 message[MaxTextExtent],
389 tag[MaxTextExtent];
390
391 const char
392 *locale_message;
393
394 register char
395 *p;
396
397 if (extent < 2)
398 return(MagickTrue);
399 (void) CopyMagickMemory(tag,text,MaxTextExtent);
400 p=strrchr(tag,'/');
401 if (p != (char *) NULL)
402 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000403 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000404 locale_message=GetLocaleMessage(message);
405 if (locale_message == message)
406 locale_message=tag;
407 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000408 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
409 locale_message,(long) offset,(unsigned long) extent,(long)
410 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000411 else
cristyb51dff52011-05-19 16:55:47 +0000412 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000413 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
414 (100L*offset/(extent-1)));
415 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000416 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000417 (void) fflush(stderr);
418 return(MagickTrue);
419}
420
cristy3884f692011-07-08 18:00:18 +0000421static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000422 const SparseColorMethod method,const char *arguments,
423 const MagickBooleanType color_from_image,ExceptionInfo *exception)
424{
anthonydf8ebac2011-04-27 09:03:19 +0000425 char
426 token[MaxTextExtent];
427
428 const char
429 *p;
430
431 double
432 *sparse_arguments;
433
anthonydf8ebac2011-04-27 09:03:19 +0000434 Image
435 *sparse_image;
436
cristy4c08aed2011-07-01 19:47:50 +0000437 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000438 color;
439
440 MagickBooleanType
441 error;
442
cristy5f09d852011-05-29 01:39:29 +0000443 register size_t
444 x;
445
446 size_t
447 number_arguments,
448 number_colors;
449
cristyf4425a72011-11-08 01:52:04 +0000450 /*
451 SparseColorOption() parses the complex -sparse-color argument into an an
452 array of floating point values then calls SparseColorImage(). Argument is
453 a complex mix of floating-point pixel coodinates, and color specifications
454 (or direct floating point numbers). The number of floats needed to
455 represent a color varies depending on the current channel setting.
456 */
anthonydf8ebac2011-04-27 09:03:19 +0000457 assert(image != (Image *) NULL);
458 assert(image->signature == MagickSignature);
459 if (image->debug != MagickFalse)
460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
461 assert(exception != (ExceptionInfo *) NULL);
462 assert(exception->signature == MagickSignature);
463 /*
464 Limit channels according to image - and add up number of color channel.
465 */
anthonydf8ebac2011-04-27 09:03:19 +0000466 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000467 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000468 number_colors++;
cristyed231572011-07-14 02:18:59 +0000469 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000470 number_colors++;
cristyed231572011-07-14 02:18:59 +0000471 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000472 number_colors++;
cristyed231572011-07-14 02:18:59 +0000473 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000474 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000475 number_colors++;
cristyed231572011-07-14 02:18:59 +0000476 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000477 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000478 number_colors++;
479
480 /*
481 Read string, to determine number of arguments needed,
482 */
483 p=arguments;
484 x=0;
485 while( *p != '\0' )
486 {
487 GetMagickToken(p,&p,token);
488 if ( token[0] == ',' ) continue;
489 if ( isalpha((int) token[0]) || token[0] == '#' ) {
490 if ( color_from_image ) {
491 (void) ThrowMagickException(exception,GetMagickModule(),
492 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
493 "Color arg given, when colors are coming from image");
494 return( (Image *)NULL);
495 }
496 x += number_colors; /* color argument */
497 }
498 else {
499 x++; /* floating point argument */
500 }
501 }
502 error=MagickTrue;
503 if ( color_from_image ) {
504 /* just the control points are being given */
505 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
506 number_arguments=(x/2)*(2+number_colors);
507 }
508 else {
509 /* control points and color values */
510 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
511 number_arguments=x;
512 }
513 if ( error ) {
514 (void) ThrowMagickException(exception,GetMagickModule(),
515 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
516 "Invalid number of Arguments");
517 return( (Image *)NULL);
518 }
519
520 /* Allocate and fill in the floating point arguments */
521 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
522 sizeof(*sparse_arguments));
523 if (sparse_arguments == (double *) NULL) {
524 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
525 "MemoryAllocationFailed","%s","SparseColorOption");
526 return( (Image *)NULL);
527 }
528 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
529 sizeof(*sparse_arguments));
530 p=arguments;
531 x=0;
532 while( *p != '\0' && x < number_arguments ) {
533 /* X coordinate */
534 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
535 if ( token[0] == '\0' ) break;
536 if ( isalpha((int) token[0]) || token[0] == '#' ) {
537 (void) ThrowMagickException(exception,GetMagickModule(),
538 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
539 "Color found, instead of X-coord");
540 error = MagickTrue;
541 break;
542 }
cristydbdd0e32011-11-04 23:29:40 +0000543 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000544 /* Y coordinate */
545 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
546 if ( token[0] == '\0' ) break;
547 if ( isalpha((int) token[0]) || token[0] == '#' ) {
548 (void) ThrowMagickException(exception,GetMagickModule(),
549 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
550 "Color found, instead of Y-coord");
551 error = MagickTrue;
552 break;
553 }
cristydbdd0e32011-11-04 23:29:40 +0000554 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000555 /* color values for this control point */
556#if 0
557 if ( (color_from_image ) {
558 /* get color from image */
559 /* HOW??? */
560 }
561 else
562#endif
563 {
564 /* color name or function given in string argument */
565 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
566 if ( token[0] == '\0' ) break;
567 if ( isalpha((int) token[0]) || token[0] == '#' ) {
568 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000569 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000570 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000571 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000572 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000573 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000574 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000575 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000576 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000577 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000578 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000579 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000580 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000581 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000582 }
583 else {
584 /* Colors given as a set of floating point values - experimental */
585 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000586 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000587 {
anthonydf8ebac2011-04-27 09:03:19 +0000588 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
589 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
590 break;
cristydbdd0e32011-11-04 23:29:40 +0000591 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000592 token[0] = ','; /* used this token - get another */
593 }
cristyed231572011-07-14 02:18:59 +0000594 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000595 {
anthonydf8ebac2011-04-27 09:03:19 +0000596 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
597 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
598 break;
cristydbdd0e32011-11-04 23:29:40 +0000599 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000600 token[0] = ','; /* used this token - get another */
601 }
cristyed231572011-07-14 02:18:59 +0000602 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000603 {
anthonydf8ebac2011-04-27 09:03:19 +0000604 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
605 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
606 break;
cristydbdd0e32011-11-04 23:29:40 +0000607 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000608 token[0] = ','; /* used this token - get another */
609 }
cristyed231572011-07-14 02:18:59 +0000610 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000611 (image->colorspace == CMYKColorspace))
612 {
anthonydf8ebac2011-04-27 09:03:19 +0000613 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
614 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
615 break;
cristydbdd0e32011-11-04 23:29:40 +0000616 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000617 token[0] = ','; /* used this token - get another */
618 }
cristyed231572011-07-14 02:18:59 +0000619 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000620 (image->matte != MagickFalse))
621 {
anthonydf8ebac2011-04-27 09:03:19 +0000622 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
623 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
624 break;
cristydbdd0e32011-11-04 23:29:40 +0000625 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000626 token[0] = ','; /* used this token - get another */
627 }
628 }
629 }
630 }
631 if ( number_arguments != x && !error ) {
632 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
633 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
634 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
635 return( (Image *)NULL);
636 }
637 if ( error )
638 return( (Image *)NULL);
639
640 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000641 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
642 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000643 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
644 return( sparse_image );
645}
646
cristy3ed852e2009-09-05 21:47:34 +0000647WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
648 const char **argv,Image **image,ExceptionInfo *exception)
649{
cristy633f0c62011-09-15 13:27:36 +0000650 CompositeOperator
651 compose;
652
anthonydf8ebac2011-04-27 09:03:19 +0000653 const char
654 *format,
655 *option;
656
cristy9ed1f812011-10-08 02:00:08 +0000657 double
658 attenuate;
659
anthonydf8ebac2011-04-27 09:03:19 +0000660 DrawInfo
661 *draw_info;
662
663 GeometryInfo
664 geometry_info;
665
cristy3ed852e2009-09-05 21:47:34 +0000666 Image
667 *region_image;
668
anthonydf8ebac2011-04-27 09:03:19 +0000669 ImageInfo
670 *mogrify_info;
671
cristyebbcfea2011-02-25 02:43:54 +0000672 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000673 status;
674
cristy4c08aed2011-07-01 19:47:50 +0000675 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000676 fill;
cristy3ed852e2009-09-05 21:47:34 +0000677
anthonydf8ebac2011-04-27 09:03:19 +0000678 MagickStatusType
679 flags;
680
cristy28474bf2011-09-11 23:32:52 +0000681 PixelInterpolateMethod
682 interpolate_method;
683
anthonydf8ebac2011-04-27 09:03:19 +0000684 QuantizeInfo
685 *quantize_info;
686
687 RectangleInfo
688 geometry,
689 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000690
cristybb503372010-05-27 20:51:26 +0000691 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000692 i;
693
694 /*
695 Initialize method variables.
696 */
697 assert(image_info != (const ImageInfo *) NULL);
698 assert(image_info->signature == MagickSignature);
699 assert(image != (Image **) NULL);
700 assert((*image)->signature == MagickSignature);
701 if ((*image)->debug != MagickFalse)
702 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
703 if (argc < 0)
704 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000705 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000706 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
707 quantize_info=AcquireQuantizeInfo(mogrify_info);
708 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000709 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000710 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000711 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000712 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000713 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000714 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000715 SetGeometry(*image,&region_geometry);
716 region_image=NewImageList();
717 /*
718 Transmogrify the image.
719 */
cristybb503372010-05-27 20:51:26 +0000720 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000721 {
anthonydf8ebac2011-04-27 09:03:19 +0000722 Image
723 *mogrify_image;
724
anthonye9c27192011-03-27 08:07:06 +0000725 ssize_t
726 count;
727
anthonydf8ebac2011-04-27 09:03:19 +0000728 option=argv[i];
729 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000730 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000731 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
732 0L);
cristycee97112010-05-28 00:44:52 +0000733 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000734 break;
cristy6b3da3a2010-06-20 02:21:46 +0000735 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000736 mogrify_image=(Image *)NULL;
737 switch (*(option+1))
738 {
739 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000740 {
anthonydf8ebac2011-04-27 09:03:19 +0000741 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000742 {
anthonydf8ebac2011-04-27 09:03:19 +0000743 /*
744 Adaptive blur image.
745 */
cristy6fccee12011-10-20 18:43:18 +0000746 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000747 flags=ParseGeometry(argv[i+1],&geometry_info);
748 if ((flags & SigmaValue) == 0)
749 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000750 if ((flags & XiValue) == 0)
751 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000752 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000753 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000754 break;
cristy3ed852e2009-09-05 21:47:34 +0000755 }
anthonydf8ebac2011-04-27 09:03:19 +0000756 if (LocaleCompare("adaptive-resize",option+1) == 0)
757 {
758 /*
759 Adaptive resize image.
760 */
cristy6fccee12011-10-20 18:43:18 +0000761 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000762 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
763 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
anthonyfd706f92012-01-19 04:22:02 +0000764 geometry.height,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000765 break;
766 }
767 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
768 {
769 /*
770 Adaptive sharpen image.
771 */
cristy6fccee12011-10-20 18:43:18 +0000772 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000773 flags=ParseGeometry(argv[i+1],&geometry_info);
774 if ((flags & SigmaValue) == 0)
775 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000776 if ((flags & XiValue) == 0)
777 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000778 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000779 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000780 break;
781 }
782 if (LocaleCompare("affine",option+1) == 0)
783 {
784 /*
785 Affine matrix.
786 */
787 if (*option == '+')
788 {
789 GetAffineMatrix(&draw_info->affine);
790 break;
791 }
792 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
793 break;
794 }
795 if (LocaleCompare("alpha",option+1) == 0)
796 {
797 AlphaChannelType
798 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000799
cristy6fccee12011-10-20 18:43:18 +0000800 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000801 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
802 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000803 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000804 break;
805 }
806 if (LocaleCompare("annotate",option+1) == 0)
807 {
808 char
809 *text,
810 geometry[MaxTextExtent];
811
812 /*
813 Annotate image.
814 */
cristy6fccee12011-10-20 18:43:18 +0000815 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000816 SetGeometryInfo(&geometry_info);
817 flags=ParseGeometry(argv[i+1],&geometry_info);
818 if ((flags & SigmaValue) == 0)
819 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000820 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
821 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000822 if (text == (char *) NULL)
823 break;
824 (void) CloneString(&draw_info->text,text);
825 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000826 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000827 geometry_info.xi,geometry_info.psi);
828 (void) CloneString(&draw_info->geometry,geometry);
829 draw_info->affine.sx=cos(DegreesToRadians(
830 fmod(geometry_info.rho,360.0)));
831 draw_info->affine.rx=sin(DegreesToRadians(
832 fmod(geometry_info.rho,360.0)));
833 draw_info->affine.ry=(-sin(DegreesToRadians(
834 fmod(geometry_info.sigma,360.0))));
835 draw_info->affine.sy=cos(DegreesToRadians(
836 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000837 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000838 break;
839 }
840 if (LocaleCompare("antialias",option+1) == 0)
841 {
842 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
843 MagickFalse;
844 draw_info->text_antialias=(*option == '-') ? MagickTrue :
845 MagickFalse;
846 break;
847 }
cristy9ed1f812011-10-08 02:00:08 +0000848 if (LocaleCompare("attenuate",option+1) == 0)
849 {
850 if (*option == '+')
851 {
852 attenuate=1.0;
853 break;
854 }
cristydbdd0e32011-11-04 23:29:40 +0000855 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000856 break;
857 }
anthonydf8ebac2011-04-27 09:03:19 +0000858 if (LocaleCompare("auto-gamma",option+1) == 0)
859 {
860 /*
861 Auto Adjust Gamma of image based on its mean
862 */
cristy6fccee12011-10-20 18:43:18 +0000863 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000864 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000865 break;
866 }
867 if (LocaleCompare("auto-level",option+1) == 0)
868 {
869 /*
870 Perfectly Normalize (max/min stretch) the image
871 */
cristy6fccee12011-10-20 18:43:18 +0000872 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000873 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000874 break;
875 }
876 if (LocaleCompare("auto-orient",option+1) == 0)
877 {
cristy6fccee12011-10-20 18:43:18 +0000878 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000879 switch ((*image)->orientation)
880 {
881 case TopRightOrientation:
882 {
883 mogrify_image=FlopImage(*image,exception);
884 break;
885 }
886 case BottomRightOrientation:
887 {
888 mogrify_image=RotateImage(*image,180.0,exception);
889 break;
890 }
891 case BottomLeftOrientation:
892 {
893 mogrify_image=FlipImage(*image,exception);
894 break;
895 }
896 case LeftTopOrientation:
897 {
898 mogrify_image=TransposeImage(*image,exception);
899 break;
900 }
901 case RightTopOrientation:
902 {
903 mogrify_image=RotateImage(*image,90.0,exception);
904 break;
905 }
906 case RightBottomOrientation:
907 {
908 mogrify_image=TransverseImage(*image,exception);
909 break;
910 }
911 case LeftBottomOrientation:
912 {
913 mogrify_image=RotateImage(*image,270.0,exception);
914 break;
915 }
916 default:
917 break;
918 }
919 if (mogrify_image != (Image *) NULL)
920 mogrify_image->orientation=TopLeftOrientation;
921 break;
922 }
923 break;
924 }
925 case 'b':
926 {
927 if (LocaleCompare("black-threshold",option+1) == 0)
928 {
929 /*
930 Black threshold image.
931 */
cristy6fccee12011-10-20 18:43:18 +0000932 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000933 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000934 break;
935 }
936 if (LocaleCompare("blue-shift",option+1) == 0)
937 {
938 /*
939 Blue shift image.
940 */
cristy6fccee12011-10-20 18:43:18 +0000941 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000942 geometry_info.rho=1.5;
943 if (*option == '-')
944 flags=ParseGeometry(argv[i+1],&geometry_info);
945 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
946 break;
947 }
948 if (LocaleCompare("blur",option+1) == 0)
949 {
950 /*
951 Gaussian blur image.
952 */
cristy6fccee12011-10-20 18:43:18 +0000953 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000954 flags=ParseGeometry(argv[i+1],&geometry_info);
955 if ((flags & SigmaValue) == 0)
956 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000957 if ((flags & XiValue) == 0)
958 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000959 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000960 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000961 break;
962 }
963 if (LocaleCompare("border",option+1) == 0)
964 {
965 /*
966 Surround image with a border of solid color.
967 */
cristy6fccee12011-10-20 18:43:18 +0000968 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000969 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
970 if ((flags & SigmaValue) == 0)
971 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000972 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000973 break;
974 }
975 if (LocaleCompare("bordercolor",option+1) == 0)
976 {
977 if (*option == '+')
978 {
cristy9950d572011-10-01 18:22:35 +0000979 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000980 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000981 break;
982 }
cristy9950d572011-10-01 18:22:35 +0000983 (void) QueryColorCompliance(argv[i+1],AllCompliance,
984 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000985 break;
986 }
987 if (LocaleCompare("box",option+1) == 0)
988 {
cristy9950d572011-10-01 18:22:35 +0000989 (void) QueryColorCompliance(argv[i+1],AllCompliance,
990 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000991 break;
992 }
993 if (LocaleCompare("brightness-contrast",option+1) == 0)
994 {
995 double
996 brightness,
997 contrast;
998
999 GeometryInfo
1000 geometry_info;
1001
1002 MagickStatusType
1003 flags;
1004
1005 /*
1006 Brightness / contrast image.
1007 */
cristy6fccee12011-10-20 18:43:18 +00001008 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001009 flags=ParseGeometry(argv[i+1],&geometry_info);
1010 brightness=geometry_info.rho;
1011 contrast=0.0;
1012 if ((flags & SigmaValue) != 0)
1013 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001014 (void) BrightnessContrastImage(*image,brightness,contrast,
1015 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001016 break;
1017 }
1018 break;
1019 }
1020 case 'c':
1021 {
1022 if (LocaleCompare("cdl",option+1) == 0)
1023 {
1024 char
1025 *color_correction_collection;
1026
1027 /*
1028 Color correct with a color decision list.
1029 */
cristy6fccee12011-10-20 18:43:18 +00001030 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001031 color_correction_collection=FileToString(argv[i+1],~0,exception);
1032 if (color_correction_collection == (char *) NULL)
1033 break;
cristy1bfa9f02011-08-11 02:35:43 +00001034 (void) ColorDecisionListImage(*image,color_correction_collection,
1035 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001036 break;
1037 }
anthonydf8ebac2011-04-27 09:03:19 +00001038 if (LocaleCompare("charcoal",option+1) == 0)
1039 {
1040 /*
1041 Charcoal image.
1042 */
cristy6fccee12011-10-20 18:43:18 +00001043 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001044 flags=ParseGeometry(argv[i+1],&geometry_info);
1045 if ((flags & SigmaValue) == 0)
1046 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001047 if ((flags & XiValue) == 0)
1048 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001049 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001050 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001051 break;
1052 }
1053 if (LocaleCompare("chop",option+1) == 0)
1054 {
1055 /*
1056 Chop the image.
1057 */
cristy6fccee12011-10-20 18:43:18 +00001058 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001059 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1060 mogrify_image=ChopImage(*image,&geometry,exception);
1061 break;
1062 }
1063 if (LocaleCompare("clamp",option+1) == 0)
1064 {
1065 /*
1066 Clamp image.
1067 */
cristy6fccee12011-10-20 18:43:18 +00001068 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001069 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001070 break;
1071 }
1072 if (LocaleCompare("clip",option+1) == 0)
1073 {
cristy6fccee12011-10-20 18:43:18 +00001074 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001075 if (*option == '+')
1076 {
cristy10a6c612012-01-29 21:41:05 +00001077 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001078 break;
1079 }
cristy018f07f2011-09-04 21:15:19 +00001080 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001081 break;
1082 }
1083 if (LocaleCompare("clip-mask",option+1) == 0)
1084 {
1085 CacheView
1086 *mask_view;
1087
1088 Image
1089 *mask_image;
1090
cristy4c08aed2011-07-01 19:47:50 +00001091 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001092 *restrict q;
1093
1094 register ssize_t
1095 x;
1096
1097 ssize_t
1098 y;
1099
cristy6fccee12011-10-20 18:43:18 +00001100 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001101 if (*option == '+')
1102 {
1103 /*
1104 Remove a mask.
1105 */
cristy018f07f2011-09-04 21:15:19 +00001106 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001107 break;
1108 }
1109 /*
1110 Set the image mask.
1111 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1112 */
1113 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1114 if (mask_image == (Image *) NULL)
1115 break;
cristy574cc262011-08-05 01:23:58 +00001116 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001117 return(MagickFalse);
1118 mask_view=AcquireCacheView(mask_image);
1119 for (y=0; y < (ssize_t) mask_image->rows; y++)
1120 {
1121 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1122 exception);
cristyacd2ed22011-08-30 01:44:23 +00001123 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001124 break;
1125 for (x=0; x < (ssize_t) mask_image->columns; x++)
1126 {
1127 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001128 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1129 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1130 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1131 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001132 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001133 }
1134 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1135 break;
1136 }
1137 mask_view=DestroyCacheView(mask_view);
1138 mask_image->matte=MagickTrue;
cristy10a6c612012-01-29 21:41:05 +00001139 (void) SetImageMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001140 break;
1141 }
1142 if (LocaleCompare("clip-path",option+1) == 0)
1143 {
cristy6fccee12011-10-20 18:43:18 +00001144 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001145 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001146 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001147 break;
1148 }
1149 if (LocaleCompare("colorize",option+1) == 0)
1150 {
1151 /*
1152 Colorize the image.
1153 */
cristy6fccee12011-10-20 18:43:18 +00001154 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001155 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001156 break;
1157 }
1158 if (LocaleCompare("color-matrix",option+1) == 0)
1159 {
1160 KernelInfo
1161 *kernel;
1162
cristy6fccee12011-10-20 18:43:18 +00001163 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001164 kernel=AcquireKernelInfo(argv[i+1]);
1165 if (kernel == (KernelInfo *) NULL)
1166 break;
anthonyfd706f92012-01-19 04:22:02 +00001167 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001168 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1169 kernel=DestroyKernelInfo(kernel);
1170 break;
1171 }
1172 if (LocaleCompare("colors",option+1) == 0)
1173 {
1174 /*
1175 Reduce the number of colors in the image.
1176 */
cristy6fccee12011-10-20 18:43:18 +00001177 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001178 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1179 if (quantize_info->number_colors == 0)
1180 break;
1181 if (((*image)->storage_class == DirectClass) ||
1182 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001183 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001184 else
cristy018f07f2011-09-04 21:15:19 +00001185 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001186 break;
1187 }
1188 if (LocaleCompare("colorspace",option+1) == 0)
1189 {
1190 ColorspaceType
1191 colorspace;
1192
cristy6fccee12011-10-20 18:43:18 +00001193 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001194 if (*option == '+')
1195 {
cristye941a752011-10-15 01:52:48 +00001196 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001197 break;
1198 }
1199 colorspace=(ColorspaceType) ParseCommandOption(
1200 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001201 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001202 break;
1203 }
cristy633f0c62011-09-15 13:27:36 +00001204 if (LocaleCompare("compose",option+1) == 0)
1205 {
cristy6fccee12011-10-20 18:43:18 +00001206 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001207 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1208 MagickFalse,argv[i+1]);
1209 break;
1210 }
anthonydf8ebac2011-04-27 09:03:19 +00001211 if (LocaleCompare("contrast",option+1) == 0)
1212 {
cristy6fccee12011-10-20 18:43:18 +00001213 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001214 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001215 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001216 break;
1217 }
1218 if (LocaleCompare("contrast-stretch",option+1) == 0)
1219 {
1220 double
1221 black_point,
1222 white_point;
1223
1224 MagickStatusType
1225 flags;
1226
1227 /*
1228 Contrast stretch image.
1229 */
cristy6fccee12011-10-20 18:43:18 +00001230 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001231 flags=ParseGeometry(argv[i+1],&geometry_info);
1232 black_point=geometry_info.rho;
1233 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1234 black_point;
1235 if ((flags & PercentValue) != 0)
1236 {
1237 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1238 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1239 }
1240 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1241 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001242 (void) ContrastStretchImage(*image,black_point,white_point,
1243 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001244 break;
1245 }
1246 if (LocaleCompare("convolve",option+1) == 0)
1247 {
anthonydf8ebac2011-04-27 09:03:19 +00001248 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001249 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001250
cristy6fccee12011-10-20 18:43:18 +00001251 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001252 kernel_info=AcquireKernelInfo(argv[i+1]);
1253 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001254 break;
cristy0a922382011-07-16 15:30:34 +00001255 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001256 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001257 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001258 break;
1259 }
1260 if (LocaleCompare("crop",option+1) == 0)
1261 {
1262 /*
1263 Crop a image to a smaller size
1264 */
cristy6fccee12011-10-20 18:43:18 +00001265 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001266 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001267 break;
1268 }
1269 if (LocaleCompare("cycle",option+1) == 0)
1270 {
1271 /*
1272 Cycle an image colormap.
1273 */
cristy6fccee12011-10-20 18:43:18 +00001274 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001275 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1276 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001277 break;
1278 }
1279 break;
1280 }
1281 case 'd':
1282 {
1283 if (LocaleCompare("decipher",option+1) == 0)
1284 {
1285 StringInfo
1286 *passkey;
1287
1288 /*
1289 Decipher pixels.
1290 */
cristy6fccee12011-10-20 18:43:18 +00001291 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001292 passkey=FileToStringInfo(argv[i+1],~0,exception);
1293 if (passkey != (StringInfo *) NULL)
1294 {
1295 (void) PasskeyDecipherImage(*image,passkey,exception);
1296 passkey=DestroyStringInfo(passkey);
1297 }
1298 break;
1299 }
1300 if (LocaleCompare("density",option+1) == 0)
1301 {
1302 /*
1303 Set image density.
1304 */
1305 (void) CloneString(&draw_info->density,argv[i+1]);
1306 break;
1307 }
1308 if (LocaleCompare("depth",option+1) == 0)
1309 {
cristy6fccee12011-10-20 18:43:18 +00001310 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001311 if (*option == '+')
1312 {
cristy8a11cb12011-10-19 23:53:34 +00001313 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001314 break;
1315 }
cristy8a11cb12011-10-19 23:53:34 +00001316 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1317 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001318 break;
1319 }
1320 if (LocaleCompare("deskew",option+1) == 0)
1321 {
1322 double
1323 threshold;
1324
1325 /*
1326 Straighten the image.
1327 */
cristy6fccee12011-10-20 18:43:18 +00001328 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001329 if (*option == '+')
1330 threshold=40.0*QuantumRange/100.0;
1331 else
cristy9b34e302011-11-05 02:15:45 +00001332 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1333 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001334 mogrify_image=DeskewImage(*image,threshold,exception);
1335 break;
1336 }
1337 if (LocaleCompare("despeckle",option+1) == 0)
1338 {
1339 /*
1340 Reduce the speckles within an image.
1341 */
cristy6fccee12011-10-20 18:43:18 +00001342 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001343 mogrify_image=DespeckleImage(*image,exception);
1344 break;
1345 }
1346 if (LocaleCompare("display",option+1) == 0)
1347 {
1348 (void) CloneString(&draw_info->server_name,argv[i+1]);
1349 break;
1350 }
1351 if (LocaleCompare("distort",option+1) == 0)
1352 {
1353 char
1354 *args,
1355 token[MaxTextExtent];
1356
1357 const char
1358 *p;
1359
1360 DistortImageMethod
1361 method;
1362
1363 double
1364 *arguments;
1365
1366 register ssize_t
1367 x;
1368
1369 size_t
1370 number_arguments;
1371
1372 /*
1373 Distort image.
1374 */
cristy6fccee12011-10-20 18:43:18 +00001375 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001376 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1377 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001378 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001379 {
anthonydf8ebac2011-04-27 09:03:19 +00001380 double
1381 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001382
1383 /*
1384 Special Case - Argument is actually a resize geometry!
1385 Convert that to an appropriate distortion argument array.
1386 */
anthonydf8ebac2011-04-27 09:03:19 +00001387 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001388 exception);
1389 resize_args[0]=(double) geometry.width;
1390 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001391 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001392 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001393 break;
1394 }
cristy018f07f2011-09-04 21:15:19 +00001395 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1396 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001397 if (args == (char *) NULL)
1398 break;
1399 p=(char *) args;
1400 for (x=0; *p != '\0'; x++)
1401 {
1402 GetMagickToken(p,&p,token);
1403 if (*token == ',')
1404 GetMagickToken(p,&p,token);
1405 }
1406 number_arguments=(size_t) x;
1407 arguments=(double *) AcquireQuantumMemory(number_arguments,
1408 sizeof(*arguments));
1409 if (arguments == (double *) NULL)
1410 ThrowWandFatalException(ResourceLimitFatalError,
1411 "MemoryAllocationFailed",(*image)->filename);
1412 (void) ResetMagickMemory(arguments,0,number_arguments*
1413 sizeof(*arguments));
1414 p=(char *) args;
1415 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1416 {
1417 GetMagickToken(p,&p,token);
1418 if (*token == ',')
1419 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001420 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001421 }
1422 args=DestroyString(args);
1423 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1424 (*option == '+') ? MagickTrue : MagickFalse,exception);
1425 arguments=(double *) RelinquishMagickMemory(arguments);
1426 break;
1427 }
1428 if (LocaleCompare("dither",option+1) == 0)
1429 {
1430 if (*option == '+')
1431 {
1432 quantize_info->dither=MagickFalse;
1433 break;
1434 }
1435 quantize_info->dither=MagickTrue;
1436 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1437 MagickDitherOptions,MagickFalse,argv[i+1]);
1438 if (quantize_info->dither_method == NoDitherMethod)
1439 quantize_info->dither=MagickFalse;
1440 break;
1441 }
1442 if (LocaleCompare("draw",option+1) == 0)
1443 {
1444 /*
1445 Draw image.
1446 */
cristy6fccee12011-10-20 18:43:18 +00001447 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001448 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001449 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001450 break;
1451 }
1452 break;
1453 }
1454 case 'e':
1455 {
1456 if (LocaleCompare("edge",option+1) == 0)
1457 {
1458 /*
1459 Enhance edges in the image.
1460 */
cristy6fccee12011-10-20 18:43:18 +00001461 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001462 flags=ParseGeometry(argv[i+1],&geometry_info);
1463 if ((flags & SigmaValue) == 0)
1464 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001465 mogrify_image=EdgeImage(*image,geometry_info.rho,
1466 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001467 break;
1468 }
1469 if (LocaleCompare("emboss",option+1) == 0)
1470 {
1471 /*
cristyd89705a2012-01-20 02:52:24 +00001472 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001473 */
cristy6fccee12011-10-20 18:43:18 +00001474 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001475 flags=ParseGeometry(argv[i+1],&geometry_info);
1476 if ((flags & SigmaValue) == 0)
1477 geometry_info.sigma=1.0;
1478 mogrify_image=EmbossImage(*image,geometry_info.rho,
1479 geometry_info.sigma,exception);
1480 break;
1481 }
1482 if (LocaleCompare("encipher",option+1) == 0)
1483 {
1484 StringInfo
1485 *passkey;
1486
1487 /*
1488 Encipher pixels.
1489 */
cristy6fccee12011-10-20 18:43:18 +00001490 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001491 passkey=FileToStringInfo(argv[i+1],~0,exception);
1492 if (passkey != (StringInfo *) NULL)
1493 {
1494 (void) PasskeyEncipherImage(*image,passkey,exception);
1495 passkey=DestroyStringInfo(passkey);
1496 }
1497 break;
1498 }
1499 if (LocaleCompare("encoding",option+1) == 0)
1500 {
1501 (void) CloneString(&draw_info->encoding,argv[i+1]);
1502 break;
1503 }
1504 if (LocaleCompare("enhance",option+1) == 0)
1505 {
1506 /*
1507 Enhance image.
1508 */
cristy6fccee12011-10-20 18:43:18 +00001509 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001510 mogrify_image=EnhanceImage(*image,exception);
1511 break;
1512 }
1513 if (LocaleCompare("equalize",option+1) == 0)
1514 {
1515 /*
1516 Equalize image.
1517 */
cristy6fccee12011-10-20 18:43:18 +00001518 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001519 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001520 break;
1521 }
1522 if (LocaleCompare("evaluate",option+1) == 0)
1523 {
1524 double
1525 constant;
1526
1527 MagickEvaluateOperator
1528 op;
1529
cristy6fccee12011-10-20 18:43:18 +00001530 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001531 op=(MagickEvaluateOperator) ParseCommandOption(
1532 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001533 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1534 1.0);
cristyd42d9952011-07-08 14:21:50 +00001535 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001536 break;
1537 }
1538 if (LocaleCompare("extent",option+1) == 0)
1539 {
1540 /*
1541 Set the image extent.
1542 */
cristy6fccee12011-10-20 18:43:18 +00001543 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001544 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1545 if (geometry.width == 0)
1546 geometry.width=(*image)->columns;
1547 if (geometry.height == 0)
1548 geometry.height=(*image)->rows;
1549 mogrify_image=ExtentImage(*image,&geometry,exception);
1550 break;
1551 }
1552 break;
1553 }
1554 case 'f':
1555 {
1556 if (LocaleCompare("family",option+1) == 0)
1557 {
1558 if (*option == '+')
1559 {
1560 if (draw_info->family != (char *) NULL)
1561 draw_info->family=DestroyString(draw_info->family);
1562 break;
1563 }
1564 (void) CloneString(&draw_info->family,argv[i+1]);
1565 break;
1566 }
1567 if (LocaleCompare("features",option+1) == 0)
1568 {
1569 if (*option == '+')
1570 {
1571 (void) DeleteImageArtifact(*image,"identify:features");
1572 break;
1573 }
1574 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1575 break;
1576 }
1577 if (LocaleCompare("fill",option+1) == 0)
1578 {
1579 ExceptionInfo
1580 *sans;
1581
anthonyfd706f92012-01-19 04:22:02 +00001582 PixelInfo
1583 color;
1584
cristy4c08aed2011-07-01 19:47:50 +00001585 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001586 if (*option == '+')
1587 {
cristy269c9412011-10-13 23:41:15 +00001588 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001589 exception);
anthonyfd706f92012-01-19 04:22:02 +00001590 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001591 if (draw_info->fill_pattern != (Image *) NULL)
1592 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1593 break;
1594 }
1595 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001596 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001597 sans=DestroyExceptionInfo(sans);
1598 if (status == MagickFalse)
1599 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1600 exception);
anthonyfd706f92012-01-19 04:22:02 +00001601 else
1602 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001603 break;
1604 }
1605 if (LocaleCompare("flip",option+1) == 0)
1606 {
1607 /*
1608 Flip image scanlines.
1609 */
cristy6fccee12011-10-20 18:43:18 +00001610 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001611 mogrify_image=FlipImage(*image,exception);
1612 break;
1613 }
anthonydf8ebac2011-04-27 09:03:19 +00001614 if (LocaleCompare("floodfill",option+1) == 0)
1615 {
cristy4c08aed2011-07-01 19:47:50 +00001616 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001617 target;
1618
1619 /*
1620 Floodfill image.
1621 */
cristy6fccee12011-10-20 18:43:18 +00001622 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001623 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001624 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001625 exception);
cristyd42d9952011-07-08 14:21:50 +00001626 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001627 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001628 break;
1629 }
anthony3d2f4862011-05-01 13:48:16 +00001630 if (LocaleCompare("flop",option+1) == 0)
1631 {
1632 /*
1633 Flop image scanlines.
1634 */
cristy6fccee12011-10-20 18:43:18 +00001635 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001636 mogrify_image=FlopImage(*image,exception);
1637 break;
1638 }
anthonydf8ebac2011-04-27 09:03:19 +00001639 if (LocaleCompare("font",option+1) == 0)
1640 {
1641 if (*option == '+')
1642 {
1643 if (draw_info->font != (char *) NULL)
1644 draw_info->font=DestroyString(draw_info->font);
1645 break;
1646 }
1647 (void) CloneString(&draw_info->font,argv[i+1]);
1648 break;
1649 }
1650 if (LocaleCompare("format",option+1) == 0)
1651 {
1652 format=argv[i+1];
1653 break;
1654 }
1655 if (LocaleCompare("frame",option+1) == 0)
1656 {
1657 FrameInfo
1658 frame_info;
1659
1660 /*
1661 Surround image with an ornamental border.
1662 */
cristy6fccee12011-10-20 18:43:18 +00001663 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001664 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1665 frame_info.width=geometry.width;
1666 frame_info.height=geometry.height;
1667 if ((flags & HeightValue) == 0)
1668 frame_info.height=geometry.width;
1669 frame_info.outer_bevel=geometry.x;
1670 frame_info.inner_bevel=geometry.y;
1671 frame_info.x=(ssize_t) frame_info.width;
1672 frame_info.y=(ssize_t) frame_info.height;
1673 frame_info.width=(*image)->columns+2*frame_info.width;
1674 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001675 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001676 break;
1677 }
1678 if (LocaleCompare("function",option+1) == 0)
1679 {
1680 char
1681 *arguments,
1682 token[MaxTextExtent];
1683
1684 const char
1685 *p;
1686
1687 double
1688 *parameters;
1689
1690 MagickFunction
1691 function;
1692
1693 register ssize_t
1694 x;
1695
1696 size_t
1697 number_parameters;
1698
1699 /*
1700 Function Modify Image Values
1701 */
cristy6fccee12011-10-20 18:43:18 +00001702 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001703 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1704 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001705 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1706 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001707 if (arguments == (char *) NULL)
1708 break;
1709 p=(char *) arguments;
1710 for (x=0; *p != '\0'; x++)
1711 {
1712 GetMagickToken(p,&p,token);
1713 if (*token == ',')
1714 GetMagickToken(p,&p,token);
1715 }
1716 number_parameters=(size_t) x;
1717 parameters=(double *) AcquireQuantumMemory(number_parameters,
1718 sizeof(*parameters));
1719 if (parameters == (double *) NULL)
1720 ThrowWandFatalException(ResourceLimitFatalError,
1721 "MemoryAllocationFailed",(*image)->filename);
1722 (void) ResetMagickMemory(parameters,0,number_parameters*
1723 sizeof(*parameters));
1724 p=(char *) arguments;
1725 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1726 {
1727 GetMagickToken(p,&p,token);
1728 if (*token == ',')
1729 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001730 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001731 }
1732 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001733 (void) FunctionImage(*image,function,number_parameters,parameters,
1734 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001735 parameters=(double *) RelinquishMagickMemory(parameters);
1736 break;
1737 }
1738 break;
1739 }
1740 case 'g':
1741 {
1742 if (LocaleCompare("gamma",option+1) == 0)
1743 {
1744 /*
1745 Gamma image.
1746 */
cristy6fccee12011-10-20 18:43:18 +00001747 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001748 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001749 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001750 else
cristydbdd0e32011-11-04 23:29:40 +00001751 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001752 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001753 break;
1754 }
1755 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1756 (LocaleCompare("gaussian",option+1) == 0))
1757 {
1758 /*
1759 Gaussian blur image.
1760 */
cristy6fccee12011-10-20 18:43:18 +00001761 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001762 flags=ParseGeometry(argv[i+1],&geometry_info);
1763 if ((flags & SigmaValue) == 0)
1764 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001765 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001766 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001767 break;
1768 }
1769 if (LocaleCompare("geometry",option+1) == 0)
1770 {
1771 /*
1772 Record Image offset, Resize last image.
1773 */
cristy6fccee12011-10-20 18:43:18 +00001774 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001775 if (*option == '+')
1776 {
1777 if ((*image)->geometry != (char *) NULL)
1778 (*image)->geometry=DestroyString((*image)->geometry);
1779 break;
1780 }
1781 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1782 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1783 (void) CloneString(&(*image)->geometry,argv[i+1]);
1784 else
1785 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1786 (*image)->filter,(*image)->blur,exception);
1787 break;
1788 }
1789 if (LocaleCompare("gravity",option+1) == 0)
1790 {
1791 if (*option == '+')
1792 {
1793 draw_info->gravity=UndefinedGravity;
1794 break;
1795 }
1796 draw_info->gravity=(GravityType) ParseCommandOption(
1797 MagickGravityOptions,MagickFalse,argv[i+1]);
1798 break;
1799 }
1800 break;
1801 }
1802 case 'h':
1803 {
1804 if (LocaleCompare("highlight-color",option+1) == 0)
1805 {
1806 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1807 break;
1808 }
1809 break;
1810 }
1811 case 'i':
1812 {
1813 if (LocaleCompare("identify",option+1) == 0)
1814 {
1815 char
1816 *text;
1817
cristy6fccee12011-10-20 18:43:18 +00001818 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001819 if (format == (char *) NULL)
1820 {
cristya4037272011-08-28 15:11:39 +00001821 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1822 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001823 break;
1824 }
cristy018f07f2011-09-04 21:15:19 +00001825 text=InterpretImageProperties(mogrify_info,*image,format,
1826 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001827 if (text == (char *) NULL)
1828 break;
1829 (void) fputs(text,stdout);
1830 (void) fputc('\n',stdout);
1831 text=DestroyString(text);
1832 break;
1833 }
1834 if (LocaleCompare("implode",option+1) == 0)
1835 {
1836 /*
1837 Implode image.
1838 */
cristy6fccee12011-10-20 18:43:18 +00001839 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001840 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001841 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1842 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001843 break;
1844 }
1845 if (LocaleCompare("interline-spacing",option+1) == 0)
1846 {
1847 if (*option == '+')
1848 (void) ParseGeometry("0",&geometry_info);
1849 else
1850 (void) ParseGeometry(argv[i+1],&geometry_info);
1851 draw_info->interline_spacing=geometry_info.rho;
1852 break;
1853 }
cristy28474bf2011-09-11 23:32:52 +00001854 if (LocaleCompare("interpolate",option+1) == 0)
1855 {
1856 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1857 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1858 break;
1859 }
anthonydf8ebac2011-04-27 09:03:19 +00001860 if (LocaleCompare("interword-spacing",option+1) == 0)
1861 {
1862 if (*option == '+')
1863 (void) ParseGeometry("0",&geometry_info);
1864 else
1865 (void) ParseGeometry(argv[i+1],&geometry_info);
1866 draw_info->interword_spacing=geometry_info.rho;
1867 break;
1868 }
anthonyfd706f92012-01-19 04:22:02 +00001869 if (LocaleCompare("interpolative-resize",option+1) == 0)
1870 {
1871 /*
1872 Interpolative resize image.
1873 */
1874 (void) SyncImageSettings(mogrify_info,*image,exception);
1875 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1876 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1877 geometry.height,interpolate_method,exception);
1878 break;
1879 }
anthonydf8ebac2011-04-27 09:03:19 +00001880 break;
1881 }
1882 case 'k':
1883 {
1884 if (LocaleCompare("kerning",option+1) == 0)
1885 {
1886 if (*option == '+')
1887 (void) ParseGeometry("0",&geometry_info);
1888 else
1889 (void) ParseGeometry(argv[i+1],&geometry_info);
1890 draw_info->kerning=geometry_info.rho;
1891 break;
1892 }
1893 break;
1894 }
1895 case 'l':
1896 {
1897 if (LocaleCompare("lat",option+1) == 0)
1898 {
1899 /*
1900 Local adaptive threshold image.
1901 */
cristy6fccee12011-10-20 18:43:18 +00001902 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001903 flags=ParseGeometry(argv[i+1],&geometry_info);
1904 if ((flags & PercentValue) != 0)
1905 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1906 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001907 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001908 geometry_info.xi,exception);
1909 break;
1910 }
1911 if (LocaleCompare("level",option+1) == 0)
1912 {
1913 MagickRealType
1914 black_point,
1915 gamma,
1916 white_point;
1917
1918 MagickStatusType
1919 flags;
1920
1921 /*
1922 Parse levels.
1923 */
cristy6fccee12011-10-20 18:43:18 +00001924 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001925 flags=ParseGeometry(argv[i+1],&geometry_info);
1926 black_point=geometry_info.rho;
1927 white_point=(MagickRealType) QuantumRange;
1928 if ((flags & SigmaValue) != 0)
1929 white_point=geometry_info.sigma;
1930 gamma=1.0;
1931 if ((flags & XiValue) != 0)
1932 gamma=geometry_info.xi;
1933 if ((flags & PercentValue) != 0)
1934 {
1935 black_point*=(MagickRealType) (QuantumRange/100.0);
1936 white_point*=(MagickRealType) (QuantumRange/100.0);
1937 }
1938 if ((flags & SigmaValue) == 0)
1939 white_point=(MagickRealType) QuantumRange-black_point;
1940 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001941 (void) LevelizeImage(*image,black_point,white_point,gamma,
1942 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001943 else
cristy01e9afd2011-08-10 17:38:41 +00001944 (void) LevelImage(*image,black_point,white_point,gamma,
1945 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001946 break;
1947 }
1948 if (LocaleCompare("level-colors",option+1) == 0)
1949 {
1950 char
1951 token[MaxTextExtent];
1952
1953 const char
1954 *p;
1955
cristy4c08aed2011-07-01 19:47:50 +00001956 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001957 black_point,
1958 white_point;
1959
1960 p=(const char *) argv[i+1];
1961 GetMagickToken(p,&p,token); /* get black point color */
1962 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001963 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001964 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001965 else
cristy269c9412011-10-13 23:41:15 +00001966 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001967 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001968 if (isalpha((int) token[0]) || (token[0] == '#'))
1969 GetMagickToken(p,&p,token);
1970 if (*token == '\0')
1971 white_point=black_point; /* set everything to that color */
1972 else
1973 {
1974 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1975 GetMagickToken(p,&p,token); /* Get white point color. */
1976 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001977 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001978 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001979 else
cristy269c9412011-10-13 23:41:15 +00001980 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001981 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001982 }
cristy490408a2011-07-07 14:42:05 +00001983 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001984 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001985 break;
1986 }
1987 if (LocaleCompare("linear-stretch",option+1) == 0)
1988 {
1989 double
1990 black_point,
1991 white_point;
1992
1993 MagickStatusType
1994 flags;
1995
cristy6fccee12011-10-20 18:43:18 +00001996 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001997 flags=ParseGeometry(argv[i+1],&geometry_info);
1998 black_point=geometry_info.rho;
1999 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2000 if ((flags & SigmaValue) != 0)
2001 white_point=geometry_info.sigma;
2002 if ((flags & PercentValue) != 0)
2003 {
2004 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2005 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2006 }
2007 if ((flags & SigmaValue) == 0)
2008 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2009 black_point;
cristy33bd5152011-08-24 01:42:24 +00002010 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002011 break;
2012 }
anthonydf8ebac2011-04-27 09:03:19 +00002013 if (LocaleCompare("liquid-rescale",option+1) == 0)
2014 {
2015 /*
2016 Liquid rescale image.
2017 */
cristy6fccee12011-10-20 18:43:18 +00002018 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002019 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2020 if ((flags & XValue) == 0)
2021 geometry.x=1;
2022 if ((flags & YValue) == 0)
2023 geometry.y=0;
2024 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2025 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2026 break;
2027 }
2028 if (LocaleCompare("lowlight-color",option+1) == 0)
2029 {
2030 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2031 break;
2032 }
2033 break;
2034 }
2035 case 'm':
2036 {
2037 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002038 {
cristy3ed852e2009-09-05 21:47:34 +00002039 Image
anthonydf8ebac2011-04-27 09:03:19 +00002040 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002041
anthonydf8ebac2011-04-27 09:03:19 +00002042 /*
2043 Transform image colors to match this set of colors.
2044 */
cristy6fccee12011-10-20 18:43:18 +00002045 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002046 if (*option == '+')
2047 break;
2048 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2049 if (remap_image == (Image *) NULL)
2050 break;
cristy018f07f2011-09-04 21:15:19 +00002051 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002052 remap_image=DestroyImage(remap_image);
2053 break;
2054 }
2055 if (LocaleCompare("mask",option+1) == 0)
2056 {
2057 Image
2058 *mask;
2059
cristy6fccee12011-10-20 18:43:18 +00002060 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002061 if (*option == '+')
2062 {
2063 /*
2064 Remove a mask.
2065 */
cristy018f07f2011-09-04 21:15:19 +00002066 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002067 break;
2068 }
2069 /*
2070 Set the image mask.
2071 */
2072 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2073 if (mask == (Image *) NULL)
2074 break;
cristy018f07f2011-09-04 21:15:19 +00002075 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002076 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002077 break;
2078 }
2079 if (LocaleCompare("matte",option+1) == 0)
2080 {
2081 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002082 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002083 break;
2084 }
2085 if (LocaleCompare("median",option+1) == 0)
2086 {
2087 /*
2088 Median filter image.
2089 */
cristy6fccee12011-10-20 18:43:18 +00002090 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002091 flags=ParseGeometry(argv[i+1],&geometry_info);
2092 if ((flags & SigmaValue) == 0)
2093 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002094 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002095 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002096 break;
2097 }
2098 if (LocaleCompare("mode",option+1) == 0)
2099 {
2100 /*
2101 Mode image.
2102 */
cristy6fccee12011-10-20 18:43:18 +00002103 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002104 flags=ParseGeometry(argv[i+1],&geometry_info);
2105 if ((flags & SigmaValue) == 0)
2106 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002107 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002108 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002109 break;
2110 }
2111 if (LocaleCompare("modulate",option+1) == 0)
2112 {
cristy6fccee12011-10-20 18:43:18 +00002113 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002114 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002115 break;
2116 }
2117 if (LocaleCompare("monitor",option+1) == 0)
2118 {
2119 if (*option == '+')
2120 {
2121 (void) SetImageProgressMonitor(*image,
2122 (MagickProgressMonitor) NULL,(void *) NULL);
2123 break;
2124 }
2125 (void) SetImageProgressMonitor(*image,MonitorProgress,
2126 (void *) NULL);
2127 break;
2128 }
2129 if (LocaleCompare("monochrome",option+1) == 0)
2130 {
cristy6fccee12011-10-20 18:43:18 +00002131 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002132 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002133 break;
2134 }
2135 if (LocaleCompare("morphology",option+1) == 0)
2136 {
2137 char
2138 token[MaxTextExtent];
2139
2140 const char
2141 *p;
2142
2143 KernelInfo
2144 *kernel;
2145
2146 MorphologyMethod
2147 method;
2148
2149 ssize_t
2150 iterations;
2151
2152 /*
2153 Morphological Image Operation
2154 */
cristy6fccee12011-10-20 18:43:18 +00002155 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002156 p=argv[i+1];
2157 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002158 method=(MorphologyMethod) ParseCommandOption(
2159 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002160 iterations=1L;
2161 GetMagickToken(p,&p,token);
2162 if ((*p == ':') || (*p == ','))
2163 GetMagickToken(p,&p,token);
2164 if ((*p != '\0'))
2165 iterations=(ssize_t) StringToLong(p);
2166 kernel=AcquireKernelInfo(argv[i+2]);
2167 if (kernel == (KernelInfo *) NULL)
2168 {
2169 (void) ThrowMagickException(exception,GetMagickModule(),
2170 OptionError,"UnabletoParseKernel","morphology");
2171 status=MagickFalse;
2172 break;
2173 }
cristyf4ad9df2011-07-08 16:49:03 +00002174 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2175 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002176 kernel=DestroyKernelInfo(kernel);
2177 break;
2178 }
2179 if (LocaleCompare("motion-blur",option+1) == 0)
2180 {
2181 /*
2182 Motion blur image.
2183 */
cristy6fccee12011-10-20 18:43:18 +00002184 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002185 flags=ParseGeometry(argv[i+1],&geometry_info);
2186 if ((flags & SigmaValue) == 0)
2187 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002188 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002189 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002190 break;
2191 }
2192 break;
2193 }
2194 case 'n':
2195 {
2196 if (LocaleCompare("negate",option+1) == 0)
2197 {
cristy6fccee12011-10-20 18:43:18 +00002198 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002199 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002200 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002201 break;
2202 }
2203 if (LocaleCompare("noise",option+1) == 0)
2204 {
cristy6fccee12011-10-20 18:43:18 +00002205 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002206 if (*option == '-')
2207 {
cristyf36cbcb2011-09-07 13:28:22 +00002208 flags=ParseGeometry(argv[i+1],&geometry_info);
2209 if ((flags & SigmaValue) == 0)
2210 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002211 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002212 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002213 }
2214 else
2215 {
2216 NoiseType
2217 noise;
2218
2219 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2220 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002221 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002222 }
2223 break;
2224 }
2225 if (LocaleCompare("normalize",option+1) == 0)
2226 {
cristy6fccee12011-10-20 18:43:18 +00002227 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002228 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002229 break;
2230 }
2231 break;
2232 }
2233 case 'o':
2234 {
2235 if (LocaleCompare("opaque",option+1) == 0)
2236 {
cristy4c08aed2011-07-01 19:47:50 +00002237 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002238 target;
2239
cristy6fccee12011-10-20 18:43:18 +00002240 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002241 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002242 exception);
cristyd42d9952011-07-08 14:21:50 +00002243 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002244 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002245 break;
2246 }
2247 if (LocaleCompare("ordered-dither",option+1) == 0)
2248 {
cristy6fccee12011-10-20 18:43:18 +00002249 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002250 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002251 break;
2252 }
2253 break;
2254 }
2255 case 'p':
2256 {
2257 if (LocaleCompare("paint",option+1) == 0)
2258 {
cristy6fccee12011-10-20 18:43:18 +00002259 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002260 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002261 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2262 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002263 break;
2264 }
anthonydf8ebac2011-04-27 09:03:19 +00002265 if (LocaleCompare("pointsize",option+1) == 0)
2266 {
2267 if (*option == '+')
2268 (void) ParseGeometry("12",&geometry_info);
2269 else
2270 (void) ParseGeometry(argv[i+1],&geometry_info);
2271 draw_info->pointsize=geometry_info.rho;
2272 break;
2273 }
2274 if (LocaleCompare("polaroid",option+1) == 0)
2275 {
cristye9e3d382011-12-14 01:50:13 +00002276 const char
2277 *caption;
2278
anthonydf8ebac2011-04-27 09:03:19 +00002279 double
2280 angle;
2281
2282 RandomInfo
2283 *random_info;
2284
2285 /*
2286 Simulate a Polaroid picture.
2287 */
cristy6fccee12011-10-20 18:43:18 +00002288 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002289 random_info=AcquireRandomInfo();
2290 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2291 random_info=DestroyRandomInfo(random_info);
2292 if (*option == '-')
2293 {
2294 SetGeometryInfo(&geometry_info);
2295 flags=ParseGeometry(argv[i+1],&geometry_info);
2296 angle=geometry_info.rho;
2297 }
cristye9e3d382011-12-14 01:50:13 +00002298 caption=GetImageProperty(*image,"caption",exception);
2299 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002300 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002301 break;
2302 }
2303 if (LocaleCompare("posterize",option+1) == 0)
2304 {
2305 /*
2306 Posterize image.
2307 */
cristy6fccee12011-10-20 18:43:18 +00002308 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002309 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002310 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002311 break;
2312 }
2313 if (LocaleCompare("preview",option+1) == 0)
2314 {
2315 PreviewType
2316 preview_type;
2317
2318 /*
2319 Preview image.
2320 */
cristy6fccee12011-10-20 18:43:18 +00002321 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002322 if (*option == '+')
2323 preview_type=UndefinedPreview;
2324 else
cristy28474bf2011-09-11 23:32:52 +00002325 preview_type=(PreviewType) ParseCommandOption(
2326 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002327 mogrify_image=PreviewImage(*image,preview_type,exception);
2328 break;
2329 }
2330 if (LocaleCompare("profile",option+1) == 0)
2331 {
2332 const char
2333 *name;
2334
2335 const StringInfo
2336 *profile;
2337
2338 Image
2339 *profile_image;
2340
2341 ImageInfo
2342 *profile_info;
2343
cristy6fccee12011-10-20 18:43:18 +00002344 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002345 if (*option == '+')
2346 {
2347 /*
2348 Remove a profile from the image.
2349 */
2350 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002351 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002352 break;
2353 }
2354 /*
2355 Associate a profile with the image.
2356 */
2357 profile_info=CloneImageInfo(mogrify_info);
2358 profile=GetImageProfile(*image,"iptc");
2359 if (profile != (StringInfo *) NULL)
2360 profile_info->profile=(void *) CloneStringInfo(profile);
2361 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2362 profile_info=DestroyImageInfo(profile_info);
2363 if (profile_image == (Image *) NULL)
2364 {
2365 StringInfo
2366 *profile;
2367
2368 profile_info=CloneImageInfo(mogrify_info);
2369 (void) CopyMagickString(profile_info->filename,argv[i+1],
2370 MaxTextExtent);
2371 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2372 if (profile != (StringInfo *) NULL)
2373 {
2374 (void) ProfileImage(*image,profile_info->magick,
2375 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002376 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002377 profile=DestroyStringInfo(profile);
2378 }
2379 profile_info=DestroyImageInfo(profile_info);
2380 break;
2381 }
2382 ResetImageProfileIterator(profile_image);
2383 name=GetNextImageProfile(profile_image);
2384 while (name != (const char *) NULL)
2385 {
2386 profile=GetImageProfile(profile_image,name);
2387 if (profile != (StringInfo *) NULL)
2388 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002389 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002390 name=GetNextImageProfile(profile_image);
2391 }
2392 profile_image=DestroyImage(profile_image);
2393 break;
2394 }
2395 break;
2396 }
2397 case 'q':
2398 {
2399 if (LocaleCompare("quantize",option+1) == 0)
2400 {
2401 if (*option == '+')
2402 {
2403 quantize_info->colorspace=UndefinedColorspace;
2404 break;
2405 }
2406 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2407 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2408 break;
2409 }
2410 break;
2411 }
2412 case 'r':
2413 {
2414 if (LocaleCompare("radial-blur",option+1) == 0)
2415 {
2416 /*
2417 Radial blur image.
2418 */
cristy6fccee12011-10-20 18:43:18 +00002419 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002420 flags=ParseGeometry(argv[i+1],&geometry_info);
2421 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2422 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002423 break;
2424 }
2425 if (LocaleCompare("raise",option+1) == 0)
2426 {
2427 /*
2428 Surround image with a raise of solid color.
2429 */
2430 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2431 if ((flags & SigmaValue) == 0)
2432 geometry.height=geometry.width;
2433 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002434 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002435 break;
2436 }
2437 if (LocaleCompare("random-threshold",option+1) == 0)
2438 {
2439 /*
2440 Threshold image.
2441 */
cristy6fccee12011-10-20 18:43:18 +00002442 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002443 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002444 break;
2445 }
anthonydf8ebac2011-04-27 09:03:19 +00002446 if (LocaleCompare("region",option+1) == 0)
2447 {
cristy6fccee12011-10-20 18:43:18 +00002448 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002449 if (region_image != (Image *) NULL)
2450 {
2451 /*
2452 Composite region.
2453 */
2454 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002455 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002456 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002457 *image=DestroyImage(*image);
2458 *image=region_image;
2459 region_image = (Image *) NULL;
2460 }
2461 if (*option == '+')
2462 break;
2463 /*
2464 Apply transformations to a selected region of the image.
2465 */
cristy3ed852e2009-09-05 21:47:34 +00002466 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2467 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002468 mogrify_image=CropImage(*image,&region_geometry,exception);
2469 if (mogrify_image == (Image *) NULL)
2470 break;
2471 region_image=(*image);
2472 *image=mogrify_image;
2473 mogrify_image=(Image *) NULL;
2474 break;
cristy3ed852e2009-09-05 21:47:34 +00002475 }
anthonydf8ebac2011-04-27 09:03:19 +00002476 if (LocaleCompare("render",option+1) == 0)
2477 {
cristy6fccee12011-10-20 18:43:18 +00002478 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002479 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2480 break;
2481 }
2482 if (LocaleCompare("remap",option+1) == 0)
2483 {
2484 Image
2485 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002486
anthonydf8ebac2011-04-27 09:03:19 +00002487 /*
2488 Transform image colors to match this set of colors.
2489 */
cristy6fccee12011-10-20 18:43:18 +00002490 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002491 if (*option == '+')
2492 break;
2493 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2494 if (remap_image == (Image *) NULL)
2495 break;
cristy018f07f2011-09-04 21:15:19 +00002496 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002497 remap_image=DestroyImage(remap_image);
2498 break;
2499 }
2500 if (LocaleCompare("repage",option+1) == 0)
2501 {
2502 if (*option == '+')
2503 {
2504 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2505 break;
2506 }
2507 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002508 break;
2509 }
2510 if (LocaleCompare("resample",option+1) == 0)
2511 {
2512 /*
2513 Resample image.
2514 */
cristy6fccee12011-10-20 18:43:18 +00002515 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002516 flags=ParseGeometry(argv[i+1],&geometry_info);
2517 if ((flags & SigmaValue) == 0)
2518 geometry_info.sigma=geometry_info.rho;
2519 mogrify_image=ResampleImage(*image,geometry_info.rho,
2520 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2521 break;
2522 }
2523 if (LocaleCompare("resize",option+1) == 0)
2524 {
2525 /*
2526 Resize image.
2527 */
cristy6fccee12011-10-20 18:43:18 +00002528 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002529 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2530 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2531 (*image)->filter,(*image)->blur,exception);
2532 break;
2533 }
2534 if (LocaleCompare("roll",option+1) == 0)
2535 {
2536 /*
2537 Roll image.
2538 */
cristy6fccee12011-10-20 18:43:18 +00002539 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002540 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2541 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2542 break;
2543 }
2544 if (LocaleCompare("rotate",option+1) == 0)
2545 {
2546 char
2547 *geometry;
2548
2549 /*
2550 Check for conditional image rotation.
2551 */
cristy6fccee12011-10-20 18:43:18 +00002552 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002553 if (strchr(argv[i+1],'>') != (char *) NULL)
2554 if ((*image)->columns <= (*image)->rows)
2555 break;
2556 if (strchr(argv[i+1],'<') != (char *) NULL)
2557 if ((*image)->columns >= (*image)->rows)
2558 break;
2559 /*
2560 Rotate image.
2561 */
2562 geometry=ConstantString(argv[i+1]);
2563 (void) SubstituteString(&geometry,">","");
2564 (void) SubstituteString(&geometry,"<","");
2565 (void) ParseGeometry(geometry,&geometry_info);
2566 geometry=DestroyString(geometry);
2567 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2568 break;
2569 }
2570 break;
2571 }
2572 case 's':
2573 {
2574 if (LocaleCompare("sample",option+1) == 0)
2575 {
2576 /*
2577 Sample image with pixel replication.
2578 */
cristy6fccee12011-10-20 18:43:18 +00002579 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002580 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2581 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2582 exception);
2583 break;
2584 }
2585 if (LocaleCompare("scale",option+1) == 0)
2586 {
2587 /*
2588 Resize image.
2589 */
cristy6fccee12011-10-20 18:43:18 +00002590 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002591 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2592 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2593 exception);
2594 break;
2595 }
2596 if (LocaleCompare("selective-blur",option+1) == 0)
2597 {
2598 /*
2599 Selectively blur pixels within a contrast threshold.
2600 */
cristy6fccee12011-10-20 18:43:18 +00002601 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002602 flags=ParseGeometry(argv[i+1],&geometry_info);
2603 if ((flags & PercentValue) != 0)
2604 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002605 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002606 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002607 break;
2608 }
2609 if (LocaleCompare("separate",option+1) == 0)
2610 {
2611 /*
2612 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002613 */
cristy6fccee12011-10-20 18:43:18 +00002614 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002615 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002616 break;
2617 }
2618 if (LocaleCompare("sepia-tone",option+1) == 0)
2619 {
2620 double
2621 threshold;
2622
2623 /*
2624 Sepia-tone image.
2625 */
cristy6fccee12011-10-20 18:43:18 +00002626 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002627 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2628 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002629 mogrify_image=SepiaToneImage(*image,threshold,exception);
2630 break;
2631 }
2632 if (LocaleCompare("segment",option+1) == 0)
2633 {
2634 /*
2635 Segment image.
2636 */
cristy6fccee12011-10-20 18:43:18 +00002637 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002638 flags=ParseGeometry(argv[i+1],&geometry_info);
2639 if ((flags & SigmaValue) == 0)
2640 geometry_info.sigma=1.0;
2641 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002642 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2643 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002644 break;
2645 }
2646 if (LocaleCompare("set",option+1) == 0)
2647 {
2648 char
2649 *value;
2650
2651 /*
2652 Set image option.
2653 */
2654 if (*option == '+')
2655 {
2656 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2657 (void) DeleteImageRegistry(argv[i+1]+9);
2658 else
2659 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2660 {
2661 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2662 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2663 }
2664 else
2665 (void) DeleteImageProperty(*image,argv[i+1]);
2666 break;
2667 }
cristy018f07f2011-09-04 21:15:19 +00002668 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2669 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002670 if (value == (char *) NULL)
2671 break;
2672 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2673 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2674 exception);
2675 else
2676 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2677 {
2678 (void) SetImageOption(image_info,argv[i+1]+7,value);
2679 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2680 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2681 }
2682 else
cristyd15e6592011-10-15 00:13:06 +00002683 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002684 value=DestroyString(value);
2685 break;
2686 }
2687 if (LocaleCompare("shade",option+1) == 0)
2688 {
2689 /*
2690 Shade image.
2691 */
cristy6fccee12011-10-20 18:43:18 +00002692 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002693 flags=ParseGeometry(argv[i+1],&geometry_info);
2694 if ((flags & SigmaValue) == 0)
2695 geometry_info.sigma=1.0;
2696 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2697 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2698 break;
2699 }
2700 if (LocaleCompare("shadow",option+1) == 0)
2701 {
2702 /*
2703 Shadow image.
2704 */
cristy6fccee12011-10-20 18:43:18 +00002705 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002706 flags=ParseGeometry(argv[i+1],&geometry_info);
2707 if ((flags & SigmaValue) == 0)
2708 geometry_info.sigma=1.0;
2709 if ((flags & XiValue) == 0)
2710 geometry_info.xi=4.0;
2711 if ((flags & PsiValue) == 0)
2712 geometry_info.psi=4.0;
2713 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002714 geometry_info.sigma,(*image)->bias,(ssize_t)
2715 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2716 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002717 break;
2718 }
2719 if (LocaleCompare("sharpen",option+1) == 0)
2720 {
2721 /*
2722 Sharpen image.
2723 */
cristy6fccee12011-10-20 18:43:18 +00002724 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002725 flags=ParseGeometry(argv[i+1],&geometry_info);
2726 if ((flags & SigmaValue) == 0)
2727 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002728 if ((flags & XiValue) == 0)
2729 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002730 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002731 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002732 break;
2733 }
2734 if (LocaleCompare("shave",option+1) == 0)
2735 {
2736 /*
2737 Shave the image edges.
2738 */
cristy6fccee12011-10-20 18:43:18 +00002739 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002740 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2741 mogrify_image=ShaveImage(*image,&geometry,exception);
2742 break;
2743 }
2744 if (LocaleCompare("shear",option+1) == 0)
2745 {
2746 /*
2747 Shear image.
2748 */
cristy6fccee12011-10-20 18:43:18 +00002749 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002750 flags=ParseGeometry(argv[i+1],&geometry_info);
2751 if ((flags & SigmaValue) == 0)
2752 geometry_info.sigma=geometry_info.rho;
2753 mogrify_image=ShearImage(*image,geometry_info.rho,
2754 geometry_info.sigma,exception);
2755 break;
2756 }
2757 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2758 {
2759 /*
2760 Sigmoidal non-linearity contrast control.
2761 */
cristy6fccee12011-10-20 18:43:18 +00002762 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002763 flags=ParseGeometry(argv[i+1],&geometry_info);
2764 if ((flags & SigmaValue) == 0)
2765 geometry_info.sigma=(double) QuantumRange/2.0;
2766 if ((flags & PercentValue) != 0)
2767 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2768 100.0;
cristy9ee60942011-07-06 14:54:38 +00002769 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002770 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2771 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002772 break;
2773 }
2774 if (LocaleCompare("sketch",option+1) == 0)
2775 {
2776 /*
2777 Sketch image.
2778 */
cristy6fccee12011-10-20 18:43:18 +00002779 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002780 flags=ParseGeometry(argv[i+1],&geometry_info);
2781 if ((flags & SigmaValue) == 0)
2782 geometry_info.sigma=1.0;
2783 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002784 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002785 break;
2786 }
2787 if (LocaleCompare("solarize",option+1) == 0)
2788 {
2789 double
2790 threshold;
2791
cristy6fccee12011-10-20 18:43:18 +00002792 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002793 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2794 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002795 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002796 break;
2797 }
2798 if (LocaleCompare("sparse-color",option+1) == 0)
2799 {
2800 SparseColorMethod
2801 method;
2802
2803 char
2804 *arguments;
2805
2806 /*
2807 Sparse Color Interpolated Gradient
2808 */
cristy6fccee12011-10-20 18:43:18 +00002809 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002810 method=(SparseColorMethod) ParseCommandOption(
2811 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002812 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2813 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002814 if (arguments == (char *) NULL)
2815 break;
cristy3884f692011-07-08 18:00:18 +00002816 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002817 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2818 arguments=DestroyString(arguments);
2819 break;
2820 }
2821 if (LocaleCompare("splice",option+1) == 0)
2822 {
2823 /*
2824 Splice a solid color into the image.
2825 */
cristy6fccee12011-10-20 18:43:18 +00002826 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002827 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2828 mogrify_image=SpliceImage(*image,&geometry,exception);
2829 break;
2830 }
2831 if (LocaleCompare("spread",option+1) == 0)
2832 {
2833 /*
2834 Spread an image.
2835 */
cristy6fccee12011-10-20 18:43:18 +00002836 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002837 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002838 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002839 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002840 break;
2841 }
2842 if (LocaleCompare("statistic",option+1) == 0)
2843 {
2844 StatisticType
2845 type;
2846
cristy6fccee12011-10-20 18:43:18 +00002847 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002848 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2849 MagickFalse,argv[i+1]);
2850 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002851 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2852 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002853 break;
2854 }
2855 if (LocaleCompare("stretch",option+1) == 0)
2856 {
2857 if (*option == '+')
2858 {
2859 draw_info->stretch=UndefinedStretch;
2860 break;
2861 }
2862 draw_info->stretch=(StretchType) ParseCommandOption(
2863 MagickStretchOptions,MagickFalse,argv[i+1]);
2864 break;
2865 }
2866 if (LocaleCompare("strip",option+1) == 0)
2867 {
2868 /*
2869 Strip image of profiles and comments.
2870 */
cristy6fccee12011-10-20 18:43:18 +00002871 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002872 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002873 break;
2874 }
2875 if (LocaleCompare("stroke",option+1) == 0)
2876 {
2877 ExceptionInfo
2878 *sans;
2879
anthonyfd706f92012-01-19 04:22:02 +00002880 PixelInfo
2881 color;
2882
anthonydf8ebac2011-04-27 09:03:19 +00002883 if (*option == '+')
2884 {
cristy9950d572011-10-01 18:22:35 +00002885 (void) QueryColorCompliance("none",AllCompliance,
2886 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002887 if (draw_info->stroke_pattern != (Image *) NULL)
2888 draw_info->stroke_pattern=DestroyImage(
2889 draw_info->stroke_pattern);
2890 break;
2891 }
2892 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00002893 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002894 sans=DestroyExceptionInfo(sans);
2895 if (status == MagickFalse)
2896 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2897 exception);
anthonyfd706f92012-01-19 04:22:02 +00002898 else
2899 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00002900 break;
2901 }
2902 if (LocaleCompare("strokewidth",option+1) == 0)
2903 {
cristy9b34e302011-11-05 02:15:45 +00002904 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002905 break;
2906 }
2907 if (LocaleCompare("style",option+1) == 0)
2908 {
2909 if (*option == '+')
2910 {
2911 draw_info->style=UndefinedStyle;
2912 break;
2913 }
2914 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2915 MagickFalse,argv[i+1]);
2916 break;
2917 }
2918 if (LocaleCompare("swirl",option+1) == 0)
2919 {
2920 /*
2921 Swirl image.
2922 */
cristy6fccee12011-10-20 18:43:18 +00002923 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002924 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002925 mogrify_image=SwirlImage(*image,geometry_info.rho,
2926 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002927 break;
2928 }
2929 break;
2930 }
2931 case 't':
2932 {
2933 if (LocaleCompare("threshold",option+1) == 0)
2934 {
2935 double
2936 threshold;
2937
2938 /*
2939 Threshold image.
2940 */
cristy6fccee12011-10-20 18:43:18 +00002941 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002942 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002943 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002944 else
cristy9b34e302011-11-05 02:15:45 +00002945 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2946 1.0);
cristye941a752011-10-15 01:52:48 +00002947 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002948 break;
2949 }
2950 if (LocaleCompare("thumbnail",option+1) == 0)
2951 {
2952 /*
2953 Thumbnail image.
2954 */
cristy6fccee12011-10-20 18:43:18 +00002955 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002956 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2957 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2958 exception);
2959 break;
2960 }
2961 if (LocaleCompare("tile",option+1) == 0)
2962 {
2963 if (*option == '+')
2964 {
2965 if (draw_info->fill_pattern != (Image *) NULL)
2966 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2967 break;
2968 }
2969 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2970 exception);
2971 break;
2972 }
2973 if (LocaleCompare("tint",option+1) == 0)
2974 {
2975 /*
2976 Tint the image.
2977 */
cristy6fccee12011-10-20 18:43:18 +00002978 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002979 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002980 break;
2981 }
2982 if (LocaleCompare("transform",option+1) == 0)
2983 {
2984 /*
2985 Affine transform image.
2986 */
cristy6fccee12011-10-20 18:43:18 +00002987 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002988 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2989 exception);
2990 break;
2991 }
2992 if (LocaleCompare("transparent",option+1) == 0)
2993 {
cristy4c08aed2011-07-01 19:47:50 +00002994 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002995 target;
2996
cristy6fccee12011-10-20 18:43:18 +00002997 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002998 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002999 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003000 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003001 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003002 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003003 break;
3004 }
3005 if (LocaleCompare("transpose",option+1) == 0)
3006 {
3007 /*
3008 Transpose image scanlines.
3009 */
cristy6fccee12011-10-20 18:43:18 +00003010 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003011 mogrify_image=TransposeImage(*image,exception);
3012 break;
3013 }
3014 if (LocaleCompare("transverse",option+1) == 0)
3015 {
3016 /*
3017 Transverse image scanlines.
3018 */
cristy6fccee12011-10-20 18:43:18 +00003019 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003020 mogrify_image=TransverseImage(*image,exception);
3021 break;
3022 }
3023 if (LocaleCompare("treedepth",option+1) == 0)
3024 {
3025 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3026 break;
3027 }
3028 if (LocaleCompare("trim",option+1) == 0)
3029 {
3030 /*
3031 Trim image.
3032 */
cristy6fccee12011-10-20 18:43:18 +00003033 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003034 mogrify_image=TrimImage(*image,exception);
3035 break;
3036 }
3037 if (LocaleCompare("type",option+1) == 0)
3038 {
3039 ImageType
3040 type;
3041
cristy6fccee12011-10-20 18:43:18 +00003042 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003043 if (*option == '+')
3044 type=UndefinedType;
3045 else
3046 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3047 argv[i+1]);
3048 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003049 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003050 break;
3051 }
3052 break;
3053 }
3054 case 'u':
3055 {
3056 if (LocaleCompare("undercolor",option+1) == 0)
3057 {
cristy9950d572011-10-01 18:22:35 +00003058 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3059 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003060 break;
3061 }
3062 if (LocaleCompare("unique",option+1) == 0)
3063 {
3064 if (*option == '+')
3065 {
3066 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3067 break;
3068 }
3069 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3070 (void) SetImageArtifact(*image,"verbose","true");
3071 break;
3072 }
3073 if (LocaleCompare("unique-colors",option+1) == 0)
3074 {
3075 /*
3076 Unique image colors.
3077 */
cristy6fccee12011-10-20 18:43:18 +00003078 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003079 mogrify_image=UniqueImageColors(*image,exception);
3080 break;
3081 }
3082 if (LocaleCompare("unsharp",option+1) == 0)
3083 {
3084 /*
3085 Unsharp mask image.
3086 */
cristy6fccee12011-10-20 18:43:18 +00003087 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003088 flags=ParseGeometry(argv[i+1],&geometry_info);
3089 if ((flags & SigmaValue) == 0)
3090 geometry_info.sigma=1.0;
3091 if ((flags & XiValue) == 0)
3092 geometry_info.xi=1.0;
3093 if ((flags & PsiValue) == 0)
3094 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003095 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3096 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003097 break;
3098 }
3099 break;
3100 }
3101 case 'v':
3102 {
3103 if (LocaleCompare("verbose",option+1) == 0)
3104 {
3105 (void) SetImageArtifact(*image,option+1,
3106 *option == '+' ? "false" : "true");
3107 break;
3108 }
3109 if (LocaleCompare("vignette",option+1) == 0)
3110 {
3111 /*
3112 Vignette image.
3113 */
cristy6fccee12011-10-20 18:43:18 +00003114 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003115 flags=ParseGeometry(argv[i+1],&geometry_info);
3116 if ((flags & SigmaValue) == 0)
3117 geometry_info.sigma=1.0;
3118 if ((flags & XiValue) == 0)
3119 geometry_info.xi=0.1*(*image)->columns;
3120 if ((flags & PsiValue) == 0)
3121 geometry_info.psi=0.1*(*image)->rows;
3122 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003123 geometry_info.sigma,(*image)->bias,(ssize_t)
3124 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3125 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003126 break;
3127 }
3128 if (LocaleCompare("virtual-pixel",option+1) == 0)
3129 {
3130 if (*option == '+')
3131 {
3132 (void) SetImageVirtualPixelMethod(*image,
3133 UndefinedVirtualPixelMethod);
3134 break;
3135 }
3136 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3137 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3138 argv[i+1]));
3139 break;
3140 }
3141 break;
3142 }
3143 case 'w':
3144 {
3145 if (LocaleCompare("wave",option+1) == 0)
3146 {
3147 /*
3148 Wave image.
3149 */
cristy6fccee12011-10-20 18:43:18 +00003150 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003151 flags=ParseGeometry(argv[i+1],&geometry_info);
3152 if ((flags & SigmaValue) == 0)
3153 geometry_info.sigma=1.0;
3154 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003155 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003156 break;
3157 }
3158 if (LocaleCompare("weight",option+1) == 0)
3159 {
3160 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3161 if (LocaleCompare(argv[i+1],"all") == 0)
3162 draw_info->weight=0;
3163 if (LocaleCompare(argv[i+1],"bold") == 0)
3164 draw_info->weight=700;
3165 if (LocaleCompare(argv[i+1],"bolder") == 0)
3166 if (draw_info->weight <= 800)
3167 draw_info->weight+=100;
3168 if (LocaleCompare(argv[i+1],"lighter") == 0)
3169 if (draw_info->weight >= 100)
3170 draw_info->weight-=100;
3171 if (LocaleCompare(argv[i+1],"normal") == 0)
3172 draw_info->weight=400;
3173 break;
3174 }
3175 if (LocaleCompare("white-threshold",option+1) == 0)
3176 {
3177 /*
3178 White threshold image.
3179 */
cristy6fccee12011-10-20 18:43:18 +00003180 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003181 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003182 break;
3183 }
3184 break;
3185 }
3186 default:
3187 break;
3188 }
3189 /*
3190 Replace current image with any image that was generated
3191 */
3192 if (mogrify_image != (Image *) NULL)
3193 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003194 i+=count;
3195 }
3196 if (region_image != (Image *) NULL)
3197 {
anthonydf8ebac2011-04-27 09:03:19 +00003198 /*
3199 Composite transformed region onto image.
3200 */
cristy6fccee12011-10-20 18:43:18 +00003201 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003202 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003203 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003204 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003205 *image=DestroyImage(*image);
3206 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003207 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003208 }
3209 /*
3210 Free resources.
3211 */
anthonydf8ebac2011-04-27 09:03:19 +00003212 quantize_info=DestroyQuantizeInfo(quantize_info);
3213 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003214 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003215 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003216 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003217}
3218
3219/*
3220%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3221% %
3222% %
3223% %
cristy5063d812010-10-19 16:28:10 +00003224+ 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 +00003225% %
3226% %
3227% %
3228%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3229%
3230% MogrifyImageCommand() transforms an image or a sequence of images. These
3231% transforms include image scaling, image rotation, color reduction, and
3232% others. The transmogrified image overwrites the original image.
3233%
3234% The format of the MogrifyImageCommand method is:
3235%
3236% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3237% const char **argv,char **metadata,ExceptionInfo *exception)
3238%
3239% A description of each parameter follows:
3240%
3241% o image_info: the image info.
3242%
3243% o argc: the number of elements in the argument vector.
3244%
3245% o argv: A text array containing the command line arguments.
3246%
3247% o metadata: any metadata is returned here.
3248%
3249% o exception: return any errors or warnings in this structure.
3250%
3251*/
3252
3253static MagickBooleanType MogrifyUsage(void)
3254{
3255 static const char
3256 *miscellaneous[]=
3257 {
3258 "-debug events display copious debugging information",
3259 "-help print program options",
3260 "-list type print a list of supported option arguments",
3261 "-log format format of debugging information",
3262 "-version print version information",
3263 (char *) NULL
3264 },
3265 *operators[]=
3266 {
3267 "-adaptive-blur geometry",
3268 " adaptively blur pixels; decrease effect near edges",
3269 "-adaptive-resize geometry",
3270 " adaptively resize image using 'mesh' interpolation",
3271 "-adaptive-sharpen geometry",
3272 " adaptively sharpen pixels; increase effect near edges",
3273 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3274 " transparent, extract, background, or shape",
3275 "-annotate geometry text",
3276 " annotate the image with text",
3277 "-auto-gamma automagically adjust gamma level of image",
3278 "-auto-level automagically adjust color levels of image",
3279 "-auto-orient automagically orient (rotate) image",
3280 "-bench iterations measure performance",
3281 "-black-threshold value",
3282 " force all pixels below the threshold into black",
3283 "-blue-shift simulate a scene at nighttime in the moonlight",
3284 "-blur geometry reduce image noise and reduce detail levels",
3285 "-border geometry surround image with a border of color",
3286 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003287 "-brightness-contrast geometry",
3288 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003289 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003290 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003291 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003292 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003293 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003294 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003295 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003296 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003297 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003298 "-contrast enhance or reduce the image contrast",
3299 "-contrast-stretch geometry",
3300 " improve contrast by `stretching' the intensity range",
3301 "-convolve coefficients",
3302 " apply a convolution kernel to the image",
3303 "-cycle amount cycle the image colormap",
3304 "-decipher filename convert cipher pixels to plain pixels",
3305 "-deskew threshold straighten an image",
3306 "-despeckle reduce the speckles within an image",
3307 "-distort method args",
3308 " distort images according to given method ad args",
3309 "-draw string annotate the image with a graphic primitive",
3310 "-edge radius apply a filter to detect edges in the image",
3311 "-encipher filename convert plain pixels to cipher pixels",
3312 "-emboss radius emboss an image",
3313 "-enhance apply a digital filter to enhance a noisy image",
3314 "-equalize perform histogram equalization to an image",
3315 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003316 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003317 "-extent geometry set the image size",
3318 "-extract geometry extract area from image",
3319 "-fft implements the discrete Fourier transform (DFT)",
3320 "-flip flip image vertically",
3321 "-floodfill geometry color",
3322 " floodfill the image with color",
3323 "-flop flop image horizontally",
3324 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003325 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003326 " apply function over image values",
3327 "-gamma value level of gamma correction",
3328 "-gaussian-blur geometry",
3329 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003330 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003331 "-identify identify the format and characteristics of the image",
3332 "-ift implements the inverse discrete Fourier transform (DFT)",
3333 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003334 "-interpolative-resize geometry",
3335 " resize image using interpolation",
cristy3ed852e2009-09-05 21:47:34 +00003336 "-lat geometry local adaptive thresholding",
3337 "-layers method optimize, merge, or compare image layers",
3338 "-level value adjust the level of image contrast",
3339 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003340 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003341 "-linear-stretch geometry",
3342 " improve contrast by `stretching with saturation'",
3343 "-liquid-rescale geometry",
3344 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003345 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003346 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003347 "-modulate value vary the brightness, saturation, and hue",
3348 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003349 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003350 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003351 "-motion-blur geometry",
3352 " simulate motion blur",
3353 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003354 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003355 "-normalize transform image to span the full range of colors",
3356 "-opaque color change this color to the fill color",
3357 "-ordered-dither NxN",
3358 " add a noise pattern to the image with specific",
3359 " amplitudes",
3360 "-paint radius simulate an oil painting",
3361 "-polaroid angle simulate a Polaroid picture",
3362 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003363 "-profile filename add, delete, or apply an image profile",
3364 "-quantize colorspace reduce colors in this colorspace",
3365 "-radial-blur angle radial blur the image",
3366 "-raise value lighten/darken image edges to create a 3-D effect",
3367 "-random-threshold low,high",
3368 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-region geometry apply options to a portion of the image",
3370 "-render render vector graphics",
3371 "-repage geometry size and location of an image canvas",
3372 "-resample geometry change the resolution of an image",
3373 "-resize geometry resize the image",
3374 "-roll geometry roll an image vertically or horizontally",
3375 "-rotate degrees apply Paeth rotation to the image",
3376 "-sample geometry scale image with pixel sampling",
3377 "-scale geometry scale the image",
3378 "-segment values segment an image",
3379 "-selective-blur geometry",
3380 " selectively blur pixels within a contrast threshold",
3381 "-sepia-tone threshold",
3382 " simulate a sepia-toned photo",
3383 "-set property value set an image property",
3384 "-shade degrees shade the image using a distant light source",
3385 "-shadow geometry simulate an image shadow",
3386 "-sharpen geometry sharpen the image",
3387 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003388 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003389 "-sigmoidal-contrast geometry",
3390 " increase the contrast without saturating highlights or shadows",
3391 "-sketch geometry simulate a pencil sketch",
3392 "-solarize threshold negate all pixels above the threshold level",
3393 "-sparse-color method args",
3394 " fill in a image based on a few color points",
3395 "-splice geometry splice the background color into the image",
3396 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003397 "-statistic type radius",
3398 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003399 "-strip strip image of all profiles and comments",
3400 "-swirl degrees swirl image pixels about the center",
3401 "-threshold value threshold the image",
3402 "-thumbnail geometry create a thumbnail of the image",
3403 "-tile filename tile image when filling a graphic primitive",
3404 "-tint value tint the image with the fill color",
3405 "-transform affine transform image",
3406 "-transparent color make this color transparent within the image",
3407 "-transpose flip image vertically and rotate 90 degrees",
3408 "-transverse flop image horizontally and rotate 270 degrees",
3409 "-trim trim image edges",
3410 "-type type image type",
3411 "-unique-colors discard all but one of any pixel color",
3412 "-unsharp geometry sharpen the image",
3413 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003414 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003415 "-white-threshold value",
3416 " force all pixels above the threshold into white",
3417 (char *) NULL
3418 },
3419 *sequence_operators[]=
3420 {
cristy4285d782011-02-09 20:12:28 +00003421 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003422 "-clut apply a color lookup table to the image",
3423 "-coalesce merge a sequence of images",
3424 "-combine combine a sequence of images",
3425 "-composite composite image",
3426 "-crop geometry cut out a rectangular region of the image",
3427 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003428 "-evaluate-sequence operator",
3429 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003430 "-flatten flatten a sequence of images",
3431 "-fx expression apply mathematical expression to an image channel(s)",
3432 "-hald-clut apply a Hald color lookup table to the image",
3433 "-morph value morph an image sequence",
3434 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003435 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003436 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003437 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003438 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003439 "-write filename write images to this file",
3440 (char *) NULL
3441 },
3442 *settings[]=
3443 {
3444 "-adjoin join images into a single multi-image file",
3445 "-affine matrix affine transform matrix",
3446 "-alpha option activate, deactivate, reset, or set the alpha channel",
3447 "-antialias remove pixel-aliasing",
3448 "-authenticate password",
3449 " decipher image with this password",
3450 "-attenuate value lessen (or intensify) when adding noise to an image",
3451 "-background color background color",
3452 "-bias value add bias when convolving an image",
3453 "-black-point-compensation",
3454 " use black point compensation",
3455 "-blue-primary point chromaticity blue primary point",
3456 "-bordercolor color border color",
3457 "-caption string assign a caption to an image",
3458 "-channel type apply option to select image channels",
3459 "-colors value preferred number of colors in the image",
3460 "-colorspace type alternate image colorspace",
3461 "-comment string annotate image with comment",
3462 "-compose operator set image composite operator",
3463 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003464 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003465 " define one or more image format options",
3466 "-delay value display the next image after pausing",
3467 "-density geometry horizontal and vertical density of the image",
3468 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003469 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003470 "-display server get image or font from this X server",
3471 "-dispose method layer disposal method",
3472 "-dither method apply error diffusion to image",
3473 "-encoding type text encoding type",
3474 "-endian type endianness (MSB or LSB) of the image",
3475 "-family name render text with this font family",
3476 "-fill color color to use when filling a graphic primitive",
3477 "-filter type use this filter when resizing an image",
3478 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003479 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003480 "-fuzz distance colors within this distance are considered equal",
3481 "-gravity type horizontal and vertical text placement",
3482 "-green-primary point chromaticity green primary point",
3483 "-intent type type of rendering intent when managing the image color",
3484 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003485 "-interline-spacing value",
3486 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003487 "-interpolate method pixel color interpolation method",
3488 "-interword-spacing value",
3489 " set the space between two words",
3490 "-kerning value set the space between two letters",
3491 "-label string assign a label to an image",
3492 "-limit type value pixel cache resource limit",
3493 "-loop iterations add Netscape loop extension to your GIF animation",
3494 "-mask filename associate a mask with the image",
3495 "-mattecolor color frame color",
3496 "-monitor monitor progress",
3497 "-orient type image orientation",
3498 "-page geometry size and location of an image canvas (setting)",
3499 "-ping efficiently determine image attributes",
3500 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003501 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003502 "-preview type image preview type",
3503 "-quality value JPEG/MIFF/PNG compression level",
3504 "-quiet suppress all warning messages",
3505 "-red-primary point chromaticity red primary point",
3506 "-regard-warnings pay attention to warning messages",
3507 "-remap filename transform image colors to match this set of colors",
3508 "-respect-parentheses settings remain in effect until parenthesis boundary",
3509 "-sampling-factor geometry",
3510 " horizontal and vertical sampling factor",
3511 "-scene value image scene number",
3512 "-seed value seed a new sequence of pseudo-random numbers",
3513 "-size geometry width and height of image",
3514 "-stretch type render text with this font stretch",
3515 "-stroke color graphic primitive stroke color",
3516 "-strokewidth value graphic primitive stroke width",
3517 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003518 "-synchronize synchronize image to storage device",
3519 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003520 "-texture filename name of texture to tile onto the image background",
3521 "-tile-offset geometry",
3522 " tile offset",
3523 "-treedepth value color tree depth",
3524 "-transparent-color color",
3525 " transparent color",
3526 "-undercolor color annotation bounding box color",
3527 "-units type the units of image resolution",
3528 "-verbose print detailed information about the image",
3529 "-view FlashPix viewing transforms",
3530 "-virtual-pixel method",
3531 " virtual pixel access method",
3532 "-weight type render text with this font weight",
3533 "-white-point point chromaticity white point",
3534 (char *) NULL
3535 },
3536 *stack_operators[]=
3537 {
anthonyb69c4b32011-03-23 04:37:44 +00003538 "-delete indexes delete the image from the image sequence",
3539 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003540 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003541 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003542 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003543 "-swap indexes swap two images in the image sequence",
3544 (char *) NULL
3545 };
3546
3547 const char
3548 **p;
3549
cristybb503372010-05-27 20:51:26 +00003550 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003551 (void) printf("Copyright: %s\n",GetMagickCopyright());
3552 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003553 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3554 GetClientName());
3555 (void) printf("\nImage Settings:\n");
3556 for (p=settings; *p != (char *) NULL; p++)
3557 (void) printf(" %s\n",*p);
3558 (void) printf("\nImage Operators:\n");
3559 for (p=operators; *p != (char *) NULL; p++)
3560 (void) printf(" %s\n",*p);
3561 (void) printf("\nImage Sequence Operators:\n");
3562 for (p=sequence_operators; *p != (char *) NULL; p++)
3563 (void) printf(" %s\n",*p);
3564 (void) printf("\nImage Stack Operators:\n");
3565 for (p=stack_operators; *p != (char *) NULL; p++)
3566 (void) printf(" %s\n",*p);
3567 (void) printf("\nMiscellaneous Options:\n");
3568 for (p=miscellaneous; *p != (char *) NULL; p++)
3569 (void) printf(" %s\n",*p);
3570 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003571 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003572 (void) printf(
3573 "number. To specify a particular image format, precede the filename\n");
3574 (void) printf(
3575 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3576 (void) printf(
3577 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3578 (void) printf("'-' for standard input or output.\n");
3579 return(MagickFalse);
3580}
3581
3582WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3583 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3584{
3585#define DestroyMogrify() \
3586{ \
3587 if (format != (char *) NULL) \
3588 format=DestroyString(format); \
3589 if (path != (char *) NULL) \
3590 path=DestroyString(path); \
3591 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003592 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003593 argv[i]=DestroyString(argv[i]); \
3594 argv=(char **) RelinquishMagickMemory(argv); \
3595}
3596#define ThrowMogrifyException(asperity,tag,option) \
3597{ \
3598 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3599 option); \
3600 DestroyMogrify(); \
3601 return(MagickFalse); \
3602}
3603#define ThrowMogrifyInvalidArgumentException(option,argument) \
3604{ \
3605 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3606 "InvalidArgument","`%s': %s",argument,option); \
3607 DestroyMogrify(); \
3608 return(MagickFalse); \
3609}
3610
3611 char
3612 *format,
3613 *option,
3614 *path;
3615
3616 Image
3617 *image;
3618
3619 ImageStack
3620 image_stack[MaxImageStackDepth+1];
3621
cristy3ed852e2009-09-05 21:47:34 +00003622 MagickBooleanType
3623 global_colormap;
3624
3625 MagickBooleanType
3626 fire,
cristyebbcfea2011-02-25 02:43:54 +00003627 pend,
3628 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003629
3630 MagickStatusType
3631 status;
3632
cristyebbcfea2011-02-25 02:43:54 +00003633 register ssize_t
3634 i;
3635
3636 ssize_t
3637 j,
3638 k;
3639
cristy3ed852e2009-09-05 21:47:34 +00003640 /*
3641 Set defaults.
3642 */
3643 assert(image_info != (ImageInfo *) NULL);
3644 assert(image_info->signature == MagickSignature);
3645 if (image_info->debug != MagickFalse)
3646 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3647 assert(exception != (ExceptionInfo *) NULL);
3648 if (argc == 2)
3649 {
3650 option=argv[1];
3651 if ((LocaleCompare("version",option+1) == 0) ||
3652 (LocaleCompare("-version",option+1) == 0))
3653 {
cristyb51dff52011-05-19 16:55:47 +00003654 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003655 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003656 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3657 GetMagickCopyright());
3658 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3659 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003660 return(MagickFalse);
3661 }
3662 }
3663 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003664 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003665 format=(char *) NULL;
3666 path=(char *) NULL;
3667 global_colormap=MagickFalse;
3668 k=0;
3669 j=1;
3670 NewImageStack();
3671 option=(char *) NULL;
3672 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003673 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003674 status=MagickTrue;
3675 /*
3676 Parse command line.
3677 */
3678 ReadCommandlLine(argc,&argv);
3679 status=ExpandFilenames(&argc,&argv);
3680 if (status == MagickFalse)
3681 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3682 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003683 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003684 {
3685 option=argv[i];
3686 if (LocaleCompare(option,"(") == 0)
3687 {
3688 FireImageStack(MagickFalse,MagickTrue,pend);
3689 if (k == MaxImageStackDepth)
3690 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3691 option);
3692 PushImageStack();
3693 continue;
3694 }
3695 if (LocaleCompare(option,")") == 0)
3696 {
3697 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3698 if (k == 0)
3699 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3700 PopImageStack();
3701 continue;
3702 }
cristy042ee782011-04-22 18:48:30 +00003703 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003704 {
3705 char
3706 backup_filename[MaxTextExtent],
3707 *filename;
3708
3709 Image
3710 *images;
3711
3712 /*
3713 Option is a file name: begin by reading image from specified file.
3714 */
3715 FireImageStack(MagickFalse,MagickFalse,pend);
3716 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003717 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003718 filename=argv[++i];
3719 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3720 images=ReadImages(image_info,exception);
3721 status&=(images != (Image *) NULL) &&
3722 (exception->severity < ErrorException);
3723 if (images == (Image *) NULL)
3724 continue;
cristydaa76602010-06-30 13:05:11 +00003725 if (format != (char *) NULL)
3726 (void) CopyMagickString(images->filename,images->magick_filename,
3727 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003728 if (path != (char *) NULL)
3729 {
3730 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003731 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003732 path,*DirectorySeparator,filename);
3733 }
3734 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003735 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003736 AppendImageStack(images);
3737 FinalizeImageSettings(image_info,image,MagickFalse);
3738 if (global_colormap != MagickFalse)
3739 {
3740 QuantizeInfo
3741 *quantize_info;
3742
3743 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003744 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003745 quantize_info=DestroyQuantizeInfo(quantize_info);
3746 }
3747 *backup_filename='\0';
3748 if ((LocaleCompare(image->filename,"-") != 0) &&
3749 (IsPathWritable(image->filename) != MagickFalse))
3750 {
cristybb503372010-05-27 20:51:26 +00003751 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003752 i;
3753
3754 /*
3755 Rename image file as backup.
3756 */
3757 (void) CopyMagickString(backup_filename,image->filename,
3758 MaxTextExtent);
3759 for (i=0; i < 6; i++)
3760 {
3761 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3762 if (IsPathAccessible(backup_filename) == MagickFalse)
3763 break;
3764 }
3765 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003766 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003767 *backup_filename='\0';
3768 }
3769 /*
3770 Write transmogrified image to disk.
3771 */
3772 image_info->synchronize=MagickTrue;
3773 status&=WriteImages(image_info,image,image->filename,exception);
3774 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003775 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003776 RemoveAllImageStack();
3777 continue;
3778 }
3779 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3780 switch (*(option+1))
3781 {
3782 case 'a':
3783 {
3784 if (LocaleCompare("adaptive-blur",option+1) == 0)
3785 {
3786 i++;
cristybb503372010-05-27 20:51:26 +00003787 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003788 ThrowMogrifyException(OptionError,"MissingArgument",option);
3789 if (IsGeometry(argv[i]) == MagickFalse)
3790 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3791 break;
3792 }
3793 if (LocaleCompare("adaptive-resize",option+1) == 0)
3794 {
3795 i++;
cristybb503372010-05-27 20:51:26 +00003796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003797 ThrowMogrifyException(OptionError,"MissingArgument",option);
3798 if (IsGeometry(argv[i]) == MagickFalse)
3799 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3800 break;
3801 }
3802 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3803 {
3804 i++;
cristybb503372010-05-27 20:51:26 +00003805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003806 ThrowMogrifyException(OptionError,"MissingArgument",option);
3807 if (IsGeometry(argv[i]) == MagickFalse)
3808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3809 break;
3810 }
3811 if (LocaleCompare("affine",option+1) == 0)
3812 {
3813 if (*option == '+')
3814 break;
3815 i++;
cristybb503372010-05-27 20:51:26 +00003816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003817 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003818 break;
3819 }
3820 if (LocaleCompare("alpha",option+1) == 0)
3821 {
cristybb503372010-05-27 20:51:26 +00003822 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003823 type;
3824
3825 if (*option == '+')
3826 break;
3827 i++;
cristybb503372010-05-27 20:51:26 +00003828 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003829 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003830 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003831 if (type < 0)
3832 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3833 argv[i]);
3834 break;
3835 }
3836 if (LocaleCompare("annotate",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);
3843 if (IsGeometry(argv[i]) == MagickFalse)
3844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003846 ThrowMogrifyException(OptionError,"MissingArgument",option);
3847 i++;
3848 break;
3849 }
3850 if (LocaleCompare("antialias",option+1) == 0)
3851 break;
3852 if (LocaleCompare("append",option+1) == 0)
3853 break;
3854 if (LocaleCompare("attenuate",option+1) == 0)
3855 {
3856 if (*option == '+')
3857 break;
3858 i++;
cristybb503372010-05-27 20:51:26 +00003859 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003860 ThrowMogrifyException(OptionError,"MissingArgument",option);
3861 if (IsGeometry(argv[i]) == MagickFalse)
3862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3863 break;
3864 }
3865 if (LocaleCompare("authenticate",option+1) == 0)
3866 {
3867 if (*option == '+')
3868 break;
3869 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 break;
3873 }
3874 if (LocaleCompare("auto-gamma",option+1) == 0)
3875 break;
3876 if (LocaleCompare("auto-level",option+1) == 0)
3877 break;
3878 if (LocaleCompare("auto-orient",option+1) == 0)
3879 break;
3880 if (LocaleCompare("average",option+1) == 0)
3881 break;
3882 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3883 }
3884 case 'b':
3885 {
3886 if (LocaleCompare("background",option+1) == 0)
3887 {
3888 if (*option == '+')
3889 break;
3890 i++;
cristybb503372010-05-27 20:51:26 +00003891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003892 ThrowMogrifyException(OptionError,"MissingArgument",option);
3893 break;
3894 }
3895 if (LocaleCompare("bias",option+1) == 0)
3896 {
3897 if (*option == '+')
3898 break;
3899 i++;
cristybb503372010-05-27 20:51:26 +00003900 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003901 ThrowMogrifyException(OptionError,"MissingArgument",option);
3902 if (IsGeometry(argv[i]) == MagickFalse)
3903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3904 break;
3905 }
3906 if (LocaleCompare("black-point-compensation",option+1) == 0)
3907 break;
3908 if (LocaleCompare("black-threshold",option+1) == 0)
3909 {
3910 if (*option == '+')
3911 break;
3912 i++;
cristybb503372010-05-27 20:51:26 +00003913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003914 ThrowMogrifyException(OptionError,"MissingArgument",option);
3915 if (IsGeometry(argv[i]) == MagickFalse)
3916 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3917 break;
3918 }
3919 if (LocaleCompare("blue-primary",option+1) == 0)
3920 {
3921 if (*option == '+')
3922 break;
3923 i++;
cristybb503372010-05-27 20:51:26 +00003924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003925 ThrowMogrifyException(OptionError,"MissingArgument",option);
3926 if (IsGeometry(argv[i]) == MagickFalse)
3927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3928 break;
3929 }
3930 if (LocaleCompare("blue-shift",option+1) == 0)
3931 {
3932 i++;
cristybb503372010-05-27 20:51:26 +00003933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003934 ThrowMogrifyException(OptionError,"MissingArgument",option);
3935 if (IsGeometry(argv[i]) == MagickFalse)
3936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3937 break;
3938 }
3939 if (LocaleCompare("blur",option+1) == 0)
3940 {
3941 i++;
cristybb503372010-05-27 20:51:26 +00003942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003943 ThrowMogrifyException(OptionError,"MissingArgument",option);
3944 if (IsGeometry(argv[i]) == MagickFalse)
3945 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3946 break;
3947 }
3948 if (LocaleCompare("border",option+1) == 0)
3949 {
3950 if (*option == '+')
3951 break;
3952 i++;
cristybb503372010-05-27 20:51:26 +00003953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003954 ThrowMogrifyException(OptionError,"MissingArgument",option);
3955 if (IsGeometry(argv[i]) == MagickFalse)
3956 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3957 break;
3958 }
3959 if (LocaleCompare("bordercolor",option+1) == 0)
3960 {
3961 if (*option == '+')
3962 break;
3963 i++;
cristybb503372010-05-27 20:51:26 +00003964 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003965 ThrowMogrifyException(OptionError,"MissingArgument",option);
3966 break;
3967 }
3968 if (LocaleCompare("box",option+1) == 0)
3969 {
3970 if (*option == '+')
3971 break;
3972 i++;
cristybb503372010-05-27 20:51:26 +00003973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003974 ThrowMogrifyException(OptionError,"MissingArgument",option);
3975 break;
3976 }
cristya28d6b82010-01-11 20:03:47 +00003977 if (LocaleCompare("brightness-contrast",option+1) == 0)
3978 {
3979 i++;
cristybb503372010-05-27 20:51:26 +00003980 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003981 ThrowMogrifyException(OptionError,"MissingArgument",option);
3982 if (IsGeometry(argv[i]) == MagickFalse)
3983 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3984 break;
3985 }
cristy3ed852e2009-09-05 21:47:34 +00003986 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3987 }
3988 case 'c':
3989 {
3990 if (LocaleCompare("cache",option+1) == 0)
3991 {
3992 if (*option == '+')
3993 break;
3994 i++;
cristybb503372010-05-27 20:51:26 +00003995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003996 ThrowMogrifyException(OptionError,"MissingArgument",option);
3997 if (IsGeometry(argv[i]) == MagickFalse)
3998 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3999 break;
4000 }
4001 if (LocaleCompare("caption",option+1) == 0)
4002 {
4003 if (*option == '+')
4004 break;
4005 i++;
cristybb503372010-05-27 20:51:26 +00004006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004007 ThrowMogrifyException(OptionError,"MissingArgument",option);
4008 break;
4009 }
4010 if (LocaleCompare("channel",option+1) == 0)
4011 {
cristybb503372010-05-27 20:51:26 +00004012 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004013 channel;
4014
4015 if (*option == '+')
4016 break;
4017 i++;
cristybb503372010-05-27 20:51:26 +00004018 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004019 ThrowMogrifyException(OptionError,"MissingArgument",option);
4020 channel=ParseChannelOption(argv[i]);
4021 if (channel < 0)
4022 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4023 argv[i]);
4024 break;
4025 }
4026 if (LocaleCompare("cdl",option+1) == 0)
4027 {
4028 if (*option == '+')
4029 break;
4030 i++;
cristybb503372010-05-27 20:51:26 +00004031 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004032 ThrowMogrifyException(OptionError,"MissingArgument",option);
4033 break;
4034 }
4035 if (LocaleCompare("charcoal",option+1) == 0)
4036 {
4037 if (*option == '+')
4038 break;
4039 i++;
cristybb503372010-05-27 20:51:26 +00004040 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004041 ThrowMogrifyException(OptionError,"MissingArgument",option);
4042 if (IsGeometry(argv[i]) == MagickFalse)
4043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4044 break;
4045 }
4046 if (LocaleCompare("chop",option+1) == 0)
4047 {
4048 if (*option == '+')
4049 break;
4050 i++;
cristybb503372010-05-27 20:51:26 +00004051 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004052 ThrowMogrifyException(OptionError,"MissingArgument",option);
4053 if (IsGeometry(argv[i]) == MagickFalse)
4054 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4055 break;
4056 }
cristy1eb45dd2009-09-25 16:38:06 +00004057 if (LocaleCompare("clamp",option+1) == 0)
4058 break;
4059 if (LocaleCompare("clip",option+1) == 0)
4060 break;
cristy3ed852e2009-09-05 21:47:34 +00004061 if (LocaleCompare("clip-mask",option+1) == 0)
4062 {
4063 if (*option == '+')
4064 break;
4065 i++;
cristybb503372010-05-27 20:51:26 +00004066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004067 ThrowMogrifyException(OptionError,"MissingArgument",option);
4068 break;
4069 }
4070 if (LocaleCompare("clut",option+1) == 0)
4071 break;
4072 if (LocaleCompare("coalesce",option+1) == 0)
4073 break;
4074 if (LocaleCompare("colorize",option+1) == 0)
4075 {
4076 if (*option == '+')
4077 break;
4078 i++;
cristybb503372010-05-27 20:51:26 +00004079 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004080 ThrowMogrifyException(OptionError,"MissingArgument",option);
4081 if (IsGeometry(argv[i]) == MagickFalse)
4082 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4083 break;
4084 }
cristye6365592010-04-02 17:31:23 +00004085 if (LocaleCompare("color-matrix",option+1) == 0)
4086 {
cristyb6bd4ad2010-08-08 01:12:27 +00004087 KernelInfo
4088 *kernel_info;
4089
cristye6365592010-04-02 17:31:23 +00004090 if (*option == '+')
4091 break;
4092 i++;
cristybb503372010-05-27 20:51:26 +00004093 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004094 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004095 kernel_info=AcquireKernelInfo(argv[i]);
4096 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004097 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004098 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004099 break;
4100 }
cristy3ed852e2009-09-05 21:47:34 +00004101 if (LocaleCompare("colors",option+1) == 0)
4102 {
4103 if (*option == '+')
4104 break;
4105 i++;
cristybb503372010-05-27 20:51:26 +00004106 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004107 ThrowMogrifyException(OptionError,"MissingArgument",option);
4108 if (IsGeometry(argv[i]) == MagickFalse)
4109 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4110 break;
4111 }
4112 if (LocaleCompare("colorspace",option+1) == 0)
4113 {
cristybb503372010-05-27 20:51:26 +00004114 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004115 colorspace;
4116
4117 if (*option == '+')
4118 break;
4119 i++;
cristybb503372010-05-27 20:51:26 +00004120 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004121 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004122 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004123 argv[i]);
4124 if (colorspace < 0)
4125 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4126 argv[i]);
4127 break;
4128 }
4129 if (LocaleCompare("combine",option+1) == 0)
4130 break;
4131 if (LocaleCompare("comment",option+1) == 0)
4132 {
4133 if (*option == '+')
4134 break;
4135 i++;
cristybb503372010-05-27 20:51:26 +00004136 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004137 ThrowMogrifyException(OptionError,"MissingArgument",option);
4138 break;
4139 }
4140 if (LocaleCompare("composite",option+1) == 0)
4141 break;
4142 if (LocaleCompare("compress",option+1) == 0)
4143 {
cristybb503372010-05-27 20:51:26 +00004144 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004145 compress;
4146
4147 if (*option == '+')
4148 break;
4149 i++;
cristybb503372010-05-27 20:51:26 +00004150 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004151 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004152 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004153 argv[i]);
4154 if (compress < 0)
4155 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4156 argv[i]);
4157 break;
4158 }
cristy22879752009-10-25 23:55:40 +00004159 if (LocaleCompare("concurrent",option+1) == 0)
4160 break;
cristy3ed852e2009-09-05 21:47:34 +00004161 if (LocaleCompare("contrast",option+1) == 0)
4162 break;
4163 if (LocaleCompare("contrast-stretch",option+1) == 0)
4164 {
4165 i++;
cristybb503372010-05-27 20:51:26 +00004166 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004167 ThrowMogrifyException(OptionError,"MissingArgument",option);
4168 if (IsGeometry(argv[i]) == MagickFalse)
4169 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4170 break;
4171 }
4172 if (LocaleCompare("convolve",option+1) == 0)
4173 {
cristyb6bd4ad2010-08-08 01:12:27 +00004174 KernelInfo
4175 *kernel_info;
4176
cristy3ed852e2009-09-05 21:47:34 +00004177 if (*option == '+')
4178 break;
4179 i++;
cristybb503372010-05-27 20:51:26 +00004180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004181 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004182 kernel_info=AcquireKernelInfo(argv[i]);
4183 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004184 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004185 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004186 break;
4187 }
4188 if (LocaleCompare("crop",option+1) == 0)
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);
4195 if (IsGeometry(argv[i]) == MagickFalse)
4196 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4197 break;
4198 }
4199 if (LocaleCompare("cycle",option+1) == 0)
4200 {
4201 if (*option == '+')
4202 break;
4203 i++;
cristybb503372010-05-27 20:51:26 +00004204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004205 ThrowMogrifyException(OptionError,"MissingArgument",option);
4206 if (IsGeometry(argv[i]) == MagickFalse)
4207 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4208 break;
4209 }
4210 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4211 }
4212 case 'd':
4213 {
4214 if (LocaleCompare("decipher",option+1) == 0)
4215 {
4216 if (*option == '+')
4217 break;
4218 i++;
cristybb503372010-05-27 20:51:26 +00004219 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004220 ThrowMogrifyException(OptionError,"MissingArgument",option);
4221 break;
4222 }
4223 if (LocaleCompare("deconstruct",option+1) == 0)
4224 break;
4225 if (LocaleCompare("debug",option+1) == 0)
4226 {
cristybb503372010-05-27 20:51:26 +00004227 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004228 event;
4229
4230 if (*option == '+')
4231 break;
4232 i++;
cristybb503372010-05-27 20:51:26 +00004233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004234 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004235 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004236 if (event < 0)
4237 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4238 argv[i]);
4239 (void) SetLogEventMask(argv[i]);
4240 break;
4241 }
4242 if (LocaleCompare("define",option+1) == 0)
4243 {
4244 i++;
cristybb503372010-05-27 20:51:26 +00004245 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004246 ThrowMogrifyException(OptionError,"MissingArgument",option);
4247 if (*option == '+')
4248 {
4249 const char
4250 *define;
4251
4252 define=GetImageOption(image_info,argv[i]);
4253 if (define == (const char *) NULL)
4254 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4255 break;
4256 }
4257 break;
4258 }
4259 if (LocaleCompare("delay",option+1) == 0)
4260 {
4261 if (*option == '+')
4262 break;
4263 i++;
cristybb503372010-05-27 20:51:26 +00004264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004265 ThrowMogrifyException(OptionError,"MissingArgument",option);
4266 if (IsGeometry(argv[i]) == MagickFalse)
4267 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4268 break;
4269 }
cristyecb10ff2011-03-22 13:14:03 +00004270 if (LocaleCompare("delete",option+1) == 0)
4271 {
4272 if (*option == '+')
4273 break;
4274 i++;
4275 if (i == (ssize_t) (argc-1))
4276 ThrowMogrifyException(OptionError,"MissingArgument",option);
4277 if (IsGeometry(argv[i]) == MagickFalse)
4278 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4279 break;
4280 }
cristy3ed852e2009-09-05 21:47:34 +00004281 if (LocaleCompare("density",option+1) == 0)
4282 {
4283 if (*option == '+')
4284 break;
4285 i++;
cristybb503372010-05-27 20:51:26 +00004286 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004287 ThrowMogrifyException(OptionError,"MissingArgument",option);
4288 if (IsGeometry(argv[i]) == MagickFalse)
4289 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4290 break;
4291 }
4292 if (LocaleCompare("depth",option+1) == 0)
4293 {
4294 if (*option == '+')
4295 break;
4296 i++;
cristybb503372010-05-27 20:51:26 +00004297 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004298 ThrowMogrifyException(OptionError,"MissingArgument",option);
4299 if (IsGeometry(argv[i]) == MagickFalse)
4300 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4301 break;
4302 }
4303 if (LocaleCompare("deskew",option+1) == 0)
4304 {
4305 if (*option == '+')
4306 break;
4307 i++;
cristybb503372010-05-27 20:51:26 +00004308 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004309 ThrowMogrifyException(OptionError,"MissingArgument",option);
4310 if (IsGeometry(argv[i]) == MagickFalse)
4311 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4312 break;
4313 }
4314 if (LocaleCompare("despeckle",option+1) == 0)
4315 break;
4316 if (LocaleCompare("dft",option+1) == 0)
4317 break;
cristyc9b12952010-03-28 01:12:28 +00004318 if (LocaleCompare("direction",option+1) == 0)
4319 {
cristybb503372010-05-27 20:51:26 +00004320 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004321 direction;
4322
4323 if (*option == '+')
4324 break;
4325 i++;
cristybb503372010-05-27 20:51:26 +00004326 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004327 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004328 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004329 argv[i]);
4330 if (direction < 0)
4331 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4332 argv[i]);
4333 break;
4334 }
cristy3ed852e2009-09-05 21:47:34 +00004335 if (LocaleCompare("display",option+1) == 0)
4336 {
4337 if (*option == '+')
4338 break;
4339 i++;
cristybb503372010-05-27 20:51:26 +00004340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004341 ThrowMogrifyException(OptionError,"MissingArgument",option);
4342 break;
4343 }
4344 if (LocaleCompare("dispose",option+1) == 0)
4345 {
cristybb503372010-05-27 20:51:26 +00004346 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004347 dispose;
4348
4349 if (*option == '+')
4350 break;
4351 i++;
cristybb503372010-05-27 20:51:26 +00004352 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004353 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004354 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004355 if (dispose < 0)
4356 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4357 argv[i]);
4358 break;
4359 }
4360 if (LocaleCompare("distort",option+1) == 0)
4361 {
cristybb503372010-05-27 20:51:26 +00004362 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004363 op;
4364
4365 i++;
cristybb503372010-05-27 20:51:26 +00004366 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004367 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004368 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004369 if (op < 0)
4370 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4371 argv[i]);
4372 i++;
cristybb503372010-05-27 20:51:26 +00004373 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004374 ThrowMogrifyException(OptionError,"MissingArgument",option);
4375 break;
4376 }
4377 if (LocaleCompare("dither",option+1) == 0)
4378 {
cristybb503372010-05-27 20:51:26 +00004379 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004380 method;
4381
4382 if (*option == '+')
4383 break;
4384 i++;
cristybb503372010-05-27 20:51:26 +00004385 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004386 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004387 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004388 if (method < 0)
4389 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4390 argv[i]);
4391 break;
4392 }
4393 if (LocaleCompare("draw",option+1) == 0)
4394 {
4395 if (*option == '+')
4396 break;
4397 i++;
cristybb503372010-05-27 20:51:26 +00004398 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004399 ThrowMogrifyException(OptionError,"MissingArgument",option);
4400 break;
4401 }
cristyecb10ff2011-03-22 13:14:03 +00004402 if (LocaleCompare("duplicate",option+1) == 0)
4403 {
4404 if (*option == '+')
4405 break;
4406 i++;
4407 if (i == (ssize_t) (argc-1))
4408 ThrowMogrifyException(OptionError,"MissingArgument",option);
4409 if (IsGeometry(argv[i]) == MagickFalse)
4410 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4411 break;
4412 }
cristy22879752009-10-25 23:55:40 +00004413 if (LocaleCompare("duration",option+1) == 0)
4414 {
4415 if (*option == '+')
4416 break;
4417 i++;
cristybb503372010-05-27 20:51:26 +00004418 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004419 ThrowMogrifyException(OptionError,"MissingArgument",option);
4420 if (IsGeometry(argv[i]) == MagickFalse)
4421 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4422 break;
4423 }
cristy3ed852e2009-09-05 21:47:34 +00004424 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4425 }
4426 case 'e':
4427 {
4428 if (LocaleCompare("edge",option+1) == 0)
4429 {
4430 if (*option == '+')
4431 break;
4432 i++;
cristybb503372010-05-27 20:51:26 +00004433 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004434 ThrowMogrifyException(OptionError,"MissingArgument",option);
4435 if (IsGeometry(argv[i]) == MagickFalse)
4436 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4437 break;
4438 }
4439 if (LocaleCompare("emboss",option+1) == 0)
4440 {
4441 if (*option == '+')
4442 break;
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
4446 if (IsGeometry(argv[i]) == MagickFalse)
4447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4448 break;
4449 }
4450 if (LocaleCompare("encipher",option+1) == 0)
4451 {
4452 if (*option == '+')
4453 break;
4454 i++;
cristybb503372010-05-27 20:51:26 +00004455 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004456 ThrowMogrifyException(OptionError,"MissingArgument",option);
4457 break;
4458 }
4459 if (LocaleCompare("encoding",option+1) == 0)
4460 {
4461 if (*option == '+')
4462 break;
4463 i++;
cristybb503372010-05-27 20:51:26 +00004464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004465 ThrowMogrifyException(OptionError,"MissingArgument",option);
4466 break;
4467 }
4468 if (LocaleCompare("endian",option+1) == 0)
4469 {
cristybb503372010-05-27 20:51:26 +00004470 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004471 endian;
4472
4473 if (*option == '+')
4474 break;
4475 i++;
cristybb503372010-05-27 20:51:26 +00004476 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004477 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004478 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004479 if (endian < 0)
4480 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4481 argv[i]);
4482 break;
4483 }
4484 if (LocaleCompare("enhance",option+1) == 0)
4485 break;
4486 if (LocaleCompare("equalize",option+1) == 0)
4487 break;
4488 if (LocaleCompare("evaluate",option+1) == 0)
4489 {
cristybb503372010-05-27 20:51:26 +00004490 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004491 op;
4492
4493 if (*option == '+')
4494 break;
4495 i++;
cristybb503372010-05-27 20:51:26 +00004496 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004497 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004498 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004499 if (op < 0)
4500 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4501 argv[i]);
4502 i++;
cristybb503372010-05-27 20:51:26 +00004503 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004504 ThrowMogrifyException(OptionError,"MissingArgument",option);
4505 if (IsGeometry(argv[i]) == MagickFalse)
4506 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4507 break;
4508 }
cristyd18ae7c2010-03-07 17:39:52 +00004509 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4510 {
cristybb503372010-05-27 20:51:26 +00004511 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004512 op;
4513
4514 if (*option == '+')
4515 break;
4516 i++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004519 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004520 if (op < 0)
4521 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4522 argv[i]);
4523 break;
4524 }
cristy3ed852e2009-09-05 21:47:34 +00004525 if (LocaleCompare("extent",option+1) == 0)
4526 {
4527 if (*option == '+')
4528 break;
4529 i++;
cristybb503372010-05-27 20:51:26 +00004530 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004531 ThrowMogrifyException(OptionError,"MissingArgument",option);
4532 if (IsGeometry(argv[i]) == MagickFalse)
4533 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4534 break;
4535 }
4536 if (LocaleCompare("extract",option+1) == 0)
4537 {
4538 if (*option == '+')
4539 break;
4540 i++;
cristybb503372010-05-27 20:51:26 +00004541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004542 ThrowMogrifyException(OptionError,"MissingArgument",option);
4543 if (IsGeometry(argv[i]) == MagickFalse)
4544 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4545 break;
4546 }
4547 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4548 }
4549 case 'f':
4550 {
4551 if (LocaleCompare("family",option+1) == 0)
4552 {
4553 if (*option == '+')
4554 break;
4555 i++;
cristybb503372010-05-27 20:51:26 +00004556 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004557 ThrowMogrifyException(OptionError,"MissingArgument",option);
4558 break;
4559 }
4560 if (LocaleCompare("fill",option+1) == 0)
4561 {
4562 if (*option == '+')
4563 break;
4564 i++;
cristybb503372010-05-27 20:51:26 +00004565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004566 ThrowMogrifyException(OptionError,"MissingArgument",option);
4567 break;
4568 }
4569 if (LocaleCompare("filter",option+1) == 0)
4570 {
cristybb503372010-05-27 20:51:26 +00004571 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004572 filter;
4573
4574 if (*option == '+')
4575 break;
4576 i++;
cristybb503372010-05-27 20:51:26 +00004577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004578 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004579 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004580 if (filter < 0)
4581 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4582 argv[i]);
4583 break;
4584 }
4585 if (LocaleCompare("flatten",option+1) == 0)
4586 break;
4587 if (LocaleCompare("flip",option+1) == 0)
4588 break;
4589 if (LocaleCompare("flop",option+1) == 0)
4590 break;
4591 if (LocaleCompare("floodfill",option+1) == 0)
4592 {
4593 if (*option == '+')
4594 break;
4595 i++;
cristybb503372010-05-27 20:51:26 +00004596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004597 ThrowMogrifyException(OptionError,"MissingArgument",option);
4598 if (IsGeometry(argv[i]) == MagickFalse)
4599 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4600 i++;
cristybb503372010-05-27 20:51:26 +00004601 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004602 ThrowMogrifyException(OptionError,"MissingArgument",option);
4603 break;
4604 }
4605 if (LocaleCompare("font",option+1) == 0)
4606 {
4607 if (*option == '+')
4608 break;
4609 i++;
cristybb503372010-05-27 20:51:26 +00004610 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004611 ThrowMogrifyException(OptionError,"MissingArgument",option);
4612 break;
4613 }
4614 if (LocaleCompare("format",option+1) == 0)
4615 {
4616 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4617 (void) CloneString(&format,(char *) NULL);
4618 if (*option == '+')
4619 break;
4620 i++;
cristybb503372010-05-27 20:51:26 +00004621 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004622 ThrowMogrifyException(OptionError,"MissingArgument",option);
4623 (void) CloneString(&format,argv[i]);
4624 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4625 (void) ConcatenateMagickString(image_info->filename,":",
4626 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004627 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004628 if (*image_info->magick == '\0')
4629 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4630 format);
4631 break;
4632 }
4633 if (LocaleCompare("frame",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 if (IsGeometry(argv[i]) == MagickFalse)
4641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4642 break;
4643 }
4644 if (LocaleCompare("function",option+1) == 0)
4645 {
cristybb503372010-05-27 20:51:26 +00004646 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004647 op;
4648
4649 if (*option == '+')
4650 break;
4651 i++;
cristybb503372010-05-27 20:51:26 +00004652 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004653 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004654 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004655 if (op < 0)
4656 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4657 i++;
cristybb503372010-05-27 20:51:26 +00004658 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004659 ThrowMogrifyException(OptionError,"MissingArgument",option);
4660 break;
4661 }
4662 if (LocaleCompare("fuzz",option+1) == 0)
4663 {
4664 if (*option == '+')
4665 break;
4666 i++;
cristybb503372010-05-27 20:51:26 +00004667 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004668 ThrowMogrifyException(OptionError,"MissingArgument",option);
4669 if (IsGeometry(argv[i]) == MagickFalse)
4670 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4671 break;
4672 }
4673 if (LocaleCompare("fx",option+1) == 0)
4674 {
4675 if (*option == '+')
4676 break;
4677 i++;
cristybb503372010-05-27 20:51:26 +00004678 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004679 ThrowMogrifyException(OptionError,"MissingArgument",option);
4680 break;
4681 }
4682 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4683 }
4684 case 'g':
4685 {
4686 if (LocaleCompare("gamma",option+1) == 0)
4687 {
4688 i++;
cristybb503372010-05-27 20:51:26 +00004689 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004690 ThrowMogrifyException(OptionError,"MissingArgument",option);
4691 if (IsGeometry(argv[i]) == MagickFalse)
4692 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4693 break;
4694 }
4695 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4696 (LocaleCompare("gaussian",option+1) == 0))
4697 {
4698 i++;
cristybb503372010-05-27 20:51:26 +00004699 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004700 ThrowMogrifyException(OptionError,"MissingArgument",option);
4701 if (IsGeometry(argv[i]) == MagickFalse)
4702 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4703 break;
4704 }
4705 if (LocaleCompare("geometry",option+1) == 0)
4706 {
4707 if (*option == '+')
4708 break;
4709 i++;
cristybb503372010-05-27 20:51:26 +00004710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004711 ThrowMogrifyException(OptionError,"MissingArgument",option);
4712 if (IsGeometry(argv[i]) == MagickFalse)
4713 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4714 break;
4715 }
4716 if (LocaleCompare("gravity",option+1) == 0)
4717 {
cristybb503372010-05-27 20:51:26 +00004718 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004719 gravity;
4720
4721 if (*option == '+')
4722 break;
4723 i++;
cristybb503372010-05-27 20:51:26 +00004724 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004725 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004726 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004727 if (gravity < 0)
4728 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4729 argv[i]);
4730 break;
4731 }
4732 if (LocaleCompare("green-primary",option+1) == 0)
4733 {
4734 if (*option == '+')
4735 break;
4736 i++;
cristybb503372010-05-27 20:51:26 +00004737 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004738 ThrowMogrifyException(OptionError,"MissingArgument",option);
4739 if (IsGeometry(argv[i]) == MagickFalse)
4740 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4741 break;
4742 }
4743 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4744 }
4745 case 'h':
4746 {
4747 if (LocaleCompare("hald-clut",option+1) == 0)
4748 break;
4749 if ((LocaleCompare("help",option+1) == 0) ||
4750 (LocaleCompare("-help",option+1) == 0))
4751 return(MogrifyUsage());
4752 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4753 }
4754 case 'i':
4755 {
4756 if (LocaleCompare("identify",option+1) == 0)
4757 break;
4758 if (LocaleCompare("idft",option+1) == 0)
4759 break;
4760 if (LocaleCompare("implode",option+1) == 0)
4761 {
4762 if (*option == '+')
4763 break;
4764 i++;
cristybb503372010-05-27 20:51:26 +00004765 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004766 ThrowMogrifyException(OptionError,"MissingArgument",option);
4767 if (IsGeometry(argv[i]) == MagickFalse)
4768 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4769 break;
4770 }
4771 if (LocaleCompare("intent",option+1) == 0)
4772 {
cristybb503372010-05-27 20:51:26 +00004773 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004774 intent;
4775
4776 if (*option == '+')
4777 break;
4778 i++;
cristybb503372010-05-27 20:51:26 +00004779 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004780 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004781 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004782 if (intent < 0)
4783 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4784 argv[i]);
4785 break;
4786 }
4787 if (LocaleCompare("interlace",option+1) == 0)
4788 {
cristybb503372010-05-27 20:51:26 +00004789 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004790 interlace;
4791
4792 if (*option == '+')
4793 break;
4794 i++;
cristybb503372010-05-27 20:51:26 +00004795 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004796 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004797 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004798 argv[i]);
4799 if (interlace < 0)
4800 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4801 argv[i]);
4802 break;
4803 }
cristyb32b90a2009-09-07 21:45:48 +00004804 if (LocaleCompare("interline-spacing",option+1) == 0)
4805 {
4806 if (*option == '+')
4807 break;
4808 i++;
cristybb503372010-05-27 20:51:26 +00004809 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004810 ThrowMogrifyException(OptionError,"MissingArgument",option);
4811 if (IsGeometry(argv[i]) == MagickFalse)
4812 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4813 break;
4814 }
cristy3ed852e2009-09-05 21:47:34 +00004815 if (LocaleCompare("interpolate",option+1) == 0)
4816 {
cristybb503372010-05-27 20:51:26 +00004817 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004818 interpolate;
4819
4820 if (*option == '+')
4821 break;
4822 i++;
cristybb503372010-05-27 20:51:26 +00004823 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004824 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004825 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004826 argv[i]);
4827 if (interpolate < 0)
4828 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4829 argv[i]);
4830 break;
4831 }
4832 if (LocaleCompare("interword-spacing",option+1) == 0)
4833 {
4834 if (*option == '+')
4835 break;
4836 i++;
cristybb503372010-05-27 20:51:26 +00004837 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004838 ThrowMogrifyException(OptionError,"MissingArgument",option);
4839 if (IsGeometry(argv[i]) == MagickFalse)
4840 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4841 break;
4842 }
4843 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4844 }
4845 case 'k':
4846 {
4847 if (LocaleCompare("kerning",option+1) == 0)
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);
4854 if (IsGeometry(argv[i]) == MagickFalse)
4855 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4856 break;
4857 }
4858 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4859 }
4860 case 'l':
4861 {
4862 if (LocaleCompare("label",option+1) == 0)
4863 {
4864 if (*option == '+')
4865 break;
4866 i++;
cristybb503372010-05-27 20:51:26 +00004867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004868 ThrowMogrifyException(OptionError,"MissingArgument",option);
4869 break;
4870 }
4871 if (LocaleCompare("lat",option+1) == 0)
4872 {
4873 if (*option == '+')
4874 break;
4875 i++;
cristybb503372010-05-27 20:51:26 +00004876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004877 ThrowMogrifyException(OptionError,"MissingArgument",option);
4878 if (IsGeometry(argv[i]) == MagickFalse)
4879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4880 }
4881 if (LocaleCompare("layers",option+1) == 0)
4882 {
cristybb503372010-05-27 20:51:26 +00004883 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004884 type;
4885
4886 if (*option == '+')
4887 break;
4888 i++;
cristybb503372010-05-27 20:51:26 +00004889 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004890 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004891 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004892 if (type < 0)
4893 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4894 argv[i]);
4895 break;
4896 }
4897 if (LocaleCompare("level",option+1) == 0)
4898 {
4899 i++;
cristybb503372010-05-27 20:51:26 +00004900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004901 ThrowMogrifyException(OptionError,"MissingArgument",option);
4902 if (IsGeometry(argv[i]) == MagickFalse)
4903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4904 break;
4905 }
4906 if (LocaleCompare("level-colors",option+1) == 0)
4907 {
4908 i++;
cristybb503372010-05-27 20:51:26 +00004909 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004910 ThrowMogrifyException(OptionError,"MissingArgument",option);
4911 break;
4912 }
cristy3ed852e2009-09-05 21:47:34 +00004913 if (LocaleCompare("limit",option+1) == 0)
4914 {
4915 char
4916 *p;
4917
4918 double
4919 value;
4920
cristybb503372010-05-27 20:51:26 +00004921 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004922 resource;
4923
4924 if (*option == '+')
4925 break;
4926 i++;
cristybb503372010-05-27 20:51:26 +00004927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004928 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004929 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004930 argv[i]);
4931 if (resource < 0)
4932 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4933 argv[i]);
4934 i++;
cristybb503372010-05-27 20:51:26 +00004935 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004936 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004937 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004938 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004939 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4941 break;
4942 }
4943 if (LocaleCompare("liquid-rescale",option+1) == 0)
4944 {
4945 i++;
cristybb503372010-05-27 20:51:26 +00004946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004947 ThrowMogrifyException(OptionError,"MissingArgument",option);
4948 if (IsGeometry(argv[i]) == MagickFalse)
4949 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4950 break;
4951 }
4952 if (LocaleCompare("list",option+1) == 0)
4953 {
cristybb503372010-05-27 20:51:26 +00004954 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004955 list;
4956
4957 if (*option == '+')
4958 break;
4959 i++;
cristybb503372010-05-27 20:51:26 +00004960 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004961 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004962 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004963 if (list < 0)
4964 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004965 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004966 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004967 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004968 }
4969 if (LocaleCompare("log",option+1) == 0)
4970 {
4971 if (*option == '+')
4972 break;
4973 i++;
cristybb503372010-05-27 20:51:26 +00004974 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004975 (strchr(argv[i],'%') == (char *) NULL))
4976 ThrowMogrifyException(OptionError,"MissingArgument",option);
4977 break;
4978 }
4979 if (LocaleCompare("loop",option+1) == 0)
4980 {
4981 if (*option == '+')
4982 break;
4983 i++;
cristybb503372010-05-27 20:51:26 +00004984 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004985 ThrowMogrifyException(OptionError,"MissingArgument",option);
4986 if (IsGeometry(argv[i]) == MagickFalse)
4987 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4988 break;
4989 }
4990 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4991 }
4992 case 'm':
4993 {
4994 if (LocaleCompare("map",option+1) == 0)
4995 {
4996 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
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);
5002 break;
5003 }
5004 if (LocaleCompare("mask",option+1) == 0)
5005 {
5006 if (*option == '+')
5007 break;
5008 i++;
cristybb503372010-05-27 20:51:26 +00005009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005010 ThrowMogrifyException(OptionError,"MissingArgument",option);
5011 break;
5012 }
5013 if (LocaleCompare("matte",option+1) == 0)
5014 break;
5015 if (LocaleCompare("mattecolor",option+1) == 0)
5016 {
5017 if (*option == '+')
5018 break;
5019 i++;
cristybb503372010-05-27 20:51:26 +00005020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005021 ThrowMogrifyException(OptionError,"MissingArgument",option);
5022 break;
5023 }
cristyf40785b2010-03-06 02:27:27 +00005024 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005025 break;
cristyf40785b2010-03-06 02:27:27 +00005026 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005027 break;
cristy3ed852e2009-09-05 21:47:34 +00005028 if (LocaleCompare("modulate",option+1) == 0)
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);
5035 if (IsGeometry(argv[i]) == MagickFalse)
5036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5037 break;
5038 }
5039 if (LocaleCompare("median",option+1) == 0)
5040 {
5041 if (*option == '+')
5042 break;
5043 i++;
cristybb503372010-05-27 20:51:26 +00005044 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005045 ThrowMogrifyException(OptionError,"MissingArgument",option);
5046 if (IsGeometry(argv[i]) == MagickFalse)
5047 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5048 break;
5049 }
cristy69ec32d2011-02-27 23:57:09 +00005050 if (LocaleCompare("mode",option+1) == 0)
5051 {
5052 if (*option == '+')
5053 break;
5054 i++;
5055 if (i == (ssize_t) argc)
5056 ThrowMogrifyException(OptionError,"MissingArgument",option);
5057 if (IsGeometry(argv[i]) == MagickFalse)
5058 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5059 break;
5060 }
cristy3ed852e2009-09-05 21:47:34 +00005061 if (LocaleCompare("monitor",option+1) == 0)
5062 break;
5063 if (LocaleCompare("monochrome",option+1) == 0)
5064 break;
5065 if (LocaleCompare("morph",option+1) == 0)
5066 {
5067 if (*option == '+')
5068 break;
5069 i++;
cristybb503372010-05-27 20:51:26 +00005070 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005071 ThrowMogrifyException(OptionError,"MissingArgument",option);
5072 if (IsGeometry(argv[i]) == MagickFalse)
5073 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5074 break;
5075 }
anthony29188a82010-01-22 10:12:34 +00005076 if (LocaleCompare("morphology",option+1) == 0)
5077 {
anthony29188a82010-01-22 10:12:34 +00005078 char
5079 token[MaxTextExtent];
5080
cristyb6bd4ad2010-08-08 01:12:27 +00005081 KernelInfo
5082 *kernel_info;
5083
5084 ssize_t
5085 op;
5086
anthony29188a82010-01-22 10:12:34 +00005087 i++;
cristybb503372010-05-27 20:51:26 +00005088 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005089 ThrowMogrifyException(OptionError,"MissingArgument",option);
5090 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005091 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005092 if (op < 0)
5093 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005094 token);
anthony29188a82010-01-22 10:12:34 +00005095 i++;
cristybb503372010-05-27 20:51:26 +00005096 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005097 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005098 kernel_info=AcquireKernelInfo(argv[i]);
5099 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005100 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005101 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005102 break;
5103 }
cristy3ed852e2009-09-05 21:47:34 +00005104 if (LocaleCompare("mosaic",option+1) == 0)
5105 break;
5106 if (LocaleCompare("motion-blur",option+1) == 0)
5107 {
5108 if (*option == '+')
5109 break;
5110 i++;
cristybb503372010-05-27 20:51:26 +00005111 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005112 ThrowMogrifyException(OptionError,"MissingArgument",option);
5113 if (IsGeometry(argv[i]) == MagickFalse)
5114 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5115 break;
5116 }
5117 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5118 }
5119 case 'n':
5120 {
5121 if (LocaleCompare("negate",option+1) == 0)
5122 break;
5123 if (LocaleCompare("noise",option+1) == 0)
5124 {
5125 i++;
cristybb503372010-05-27 20:51:26 +00005126 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005127 ThrowMogrifyException(OptionError,"MissingArgument",option);
5128 if (*option == '+')
5129 {
cristybb503372010-05-27 20:51:26 +00005130 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005131 noise;
5132
cristy042ee782011-04-22 18:48:30 +00005133 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005134 if (noise < 0)
5135 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5136 argv[i]);
5137 break;
5138 }
5139 if (IsGeometry(argv[i]) == MagickFalse)
5140 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5141 break;
5142 }
5143 if (LocaleCompare("noop",option+1) == 0)
5144 break;
5145 if (LocaleCompare("normalize",option+1) == 0)
5146 break;
5147 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5148 }
5149 case 'o':
5150 {
5151 if (LocaleCompare("opaque",option+1) == 0)
5152 {
cristy3ed852e2009-09-05 21:47:34 +00005153 i++;
cristybb503372010-05-27 20:51:26 +00005154 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005155 ThrowMogrifyException(OptionError,"MissingArgument",option);
5156 break;
5157 }
5158 if (LocaleCompare("ordered-dither",option+1) == 0)
5159 {
5160 if (*option == '+')
5161 break;
5162 i++;
cristybb503372010-05-27 20:51:26 +00005163 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005164 ThrowMogrifyException(OptionError,"MissingArgument",option);
5165 break;
5166 }
5167 if (LocaleCompare("orient",option+1) == 0)
5168 {
cristybb503372010-05-27 20:51:26 +00005169 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005170 orientation;
5171
5172 orientation=UndefinedOrientation;
5173 if (*option == '+')
5174 break;
5175 i++;
cristybb503372010-05-27 20:51:26 +00005176 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005177 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005178 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005179 argv[i]);
5180 if (orientation < 0)
5181 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5182 argv[i]);
5183 break;
5184 }
5185 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5186 }
5187 case 'p':
5188 {
5189 if (LocaleCompare("page",option+1) == 0)
5190 {
5191 if (*option == '+')
5192 break;
5193 i++;
cristybb503372010-05-27 20:51:26 +00005194 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005195 ThrowMogrifyException(OptionError,"MissingArgument",option);
5196 break;
5197 }
5198 if (LocaleCompare("paint",option+1) == 0)
5199 {
5200 if (*option == '+')
5201 break;
5202 i++;
cristybb503372010-05-27 20:51:26 +00005203 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005204 ThrowMogrifyException(OptionError,"MissingArgument",option);
5205 if (IsGeometry(argv[i]) == MagickFalse)
5206 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5207 break;
5208 }
5209 if (LocaleCompare("path",option+1) == 0)
5210 {
5211 (void) CloneString(&path,(char *) NULL);
5212 if (*option == '+')
5213 break;
5214 i++;
cristybb503372010-05-27 20:51:26 +00005215 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005216 ThrowMogrifyException(OptionError,"MissingArgument",option);
5217 (void) CloneString(&path,argv[i]);
5218 break;
5219 }
5220 if (LocaleCompare("pointsize",option+1) == 0)
5221 {
5222 if (*option == '+')
5223 break;
5224 i++;
cristybb503372010-05-27 20:51:26 +00005225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005226 ThrowMogrifyException(OptionError,"MissingArgument",option);
5227 if (IsGeometry(argv[i]) == MagickFalse)
5228 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5229 break;
5230 }
5231 if (LocaleCompare("polaroid",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 if (IsGeometry(argv[i]) == MagickFalse)
5239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5240 break;
5241 }
5242 if (LocaleCompare("posterize",option+1) == 0)
5243 {
5244 if (*option == '+')
5245 break;
5246 i++;
cristybb503372010-05-27 20:51:26 +00005247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005248 ThrowMogrifyException(OptionError,"MissingArgument",option);
5249 if (IsGeometry(argv[i]) == MagickFalse)
5250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5251 break;
5252 }
cristye7f51092010-01-17 00:39:37 +00005253 if (LocaleCompare("precision",option+1) == 0)
5254 {
5255 if (*option == '+')
5256 break;
5257 i++;
cristybb503372010-05-27 20:51:26 +00005258 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005259 ThrowMogrifyException(OptionError,"MissingArgument",option);
5260 if (IsGeometry(argv[i]) == MagickFalse)
5261 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5262 break;
5263 }
cristy3ed852e2009-09-05 21:47:34 +00005264 if (LocaleCompare("print",option+1) == 0)
5265 {
5266 if (*option == '+')
5267 break;
5268 i++;
cristybb503372010-05-27 20:51:26 +00005269 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005270 ThrowMogrifyException(OptionError,"MissingArgument",option);
5271 break;
5272 }
5273 if (LocaleCompare("process",option+1) == 0)
5274 {
5275 if (*option == '+')
5276 break;
5277 i++;
cristybb503372010-05-27 20:51:26 +00005278 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005279 ThrowMogrifyException(OptionError,"MissingArgument",option);
5280 break;
5281 }
5282 if (LocaleCompare("profile",option+1) == 0)
5283 {
5284 i++;
cristybb503372010-05-27 20:51:26 +00005285 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005286 ThrowMogrifyException(OptionError,"MissingArgument",option);
5287 break;
5288 }
5289 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5290 }
5291 case 'q':
5292 {
5293 if (LocaleCompare("quality",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("quantize",option+1) == 0)
5305 {
cristybb503372010-05-27 20:51:26 +00005306 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005307 colorspace;
5308
5309 if (*option == '+')
5310 break;
5311 i++;
cristybb503372010-05-27 20:51:26 +00005312 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005313 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005314 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005315 argv[i]);
5316 if (colorspace < 0)
5317 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5318 argv[i]);
5319 break;
5320 }
5321 if (LocaleCompare("quiet",option+1) == 0)
5322 break;
5323 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5324 }
5325 case 'r':
5326 {
5327 if (LocaleCompare("radial-blur",option+1) == 0)
5328 {
5329 i++;
cristybb503372010-05-27 20:51:26 +00005330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 if (IsGeometry(argv[i]) == MagickFalse)
5333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5334 break;
5335 }
5336 if (LocaleCompare("raise",option+1) == 0)
5337 {
5338 i++;
cristybb503372010-05-27 20:51:26 +00005339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005340 ThrowMogrifyException(OptionError,"MissingArgument",option);
5341 if (IsGeometry(argv[i]) == MagickFalse)
5342 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5343 break;
5344 }
5345 if (LocaleCompare("random-threshold",option+1) == 0)
5346 {
5347 if (*option == '+')
5348 break;
5349 i++;
cristybb503372010-05-27 20:51:26 +00005350 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005351 ThrowMogrifyException(OptionError,"MissingArgument",option);
5352 if (IsGeometry(argv[i]) == MagickFalse)
5353 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5354 break;
5355 }
5356 if (LocaleCompare("red-primary",option+1) == 0)
5357 {
5358 if (*option == '+')
5359 break;
5360 i++;
cristybb503372010-05-27 20:51:26 +00005361 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005362 ThrowMogrifyException(OptionError,"MissingArgument",option);
5363 if (IsGeometry(argv[i]) == MagickFalse)
5364 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5365 }
cristy9f2083a2010-04-22 19:48:05 +00005366 if (LocaleCompare("regard-warnings",option+1) == 0)
5367 break;
cristy3ed852e2009-09-05 21:47:34 +00005368 if (LocaleCompare("region",option+1) == 0)
5369 {
5370 if (*option == '+')
5371 break;
5372 i++;
cristybb503372010-05-27 20:51:26 +00005373 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005374 ThrowMogrifyException(OptionError,"MissingArgument",option);
5375 if (IsGeometry(argv[i]) == MagickFalse)
5376 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5377 break;
5378 }
cristyf0c78232010-03-15 12:53:40 +00005379 if (LocaleCompare("remap",option+1) == 0)
5380 {
5381 if (*option == '+')
5382 break;
5383 i++;
cristybb503372010-05-27 20:51:26 +00005384 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005385 ThrowMogrifyException(OptionError,"MissingArgument",option);
5386 break;
5387 }
cristy3ed852e2009-09-05 21:47:34 +00005388 if (LocaleCompare("render",option+1) == 0)
5389 break;
5390 if (LocaleCompare("repage",option+1) == 0)
5391 {
5392 if (*option == '+')
5393 break;
5394 i++;
cristybb503372010-05-27 20:51:26 +00005395 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005396 ThrowMogrifyException(OptionError,"MissingArgument",option);
5397 if (IsGeometry(argv[i]) == MagickFalse)
5398 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5399 break;
5400 }
5401 if (LocaleCompare("resample",option+1) == 0)
5402 {
5403 if (*option == '+')
5404 break;
5405 i++;
cristybb503372010-05-27 20:51:26 +00005406 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005407 ThrowMogrifyException(OptionError,"MissingArgument",option);
5408 if (IsGeometry(argv[i]) == MagickFalse)
5409 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5410 break;
5411 }
5412 if (LocaleCompare("resize",option+1) == 0)
5413 {
5414 if (*option == '+')
5415 break;
5416 i++;
cristybb503372010-05-27 20:51:26 +00005417 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005418 ThrowMogrifyException(OptionError,"MissingArgument",option);
5419 if (IsGeometry(argv[i]) == MagickFalse)
5420 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5421 break;
5422 }
cristyebbcfea2011-02-25 02:43:54 +00005423 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5424 {
5425 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5426 break;
5427 }
cristy3ed852e2009-09-05 21:47:34 +00005428 if (LocaleCompare("reverse",option+1) == 0)
5429 break;
5430 if (LocaleCompare("roll",option+1) == 0)
5431 {
5432 if (*option == '+')
5433 break;
5434 i++;
cristybb503372010-05-27 20:51:26 +00005435 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005436 ThrowMogrifyException(OptionError,"MissingArgument",option);
5437 if (IsGeometry(argv[i]) == MagickFalse)
5438 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5439 break;
5440 }
5441 if (LocaleCompare("rotate",option+1) == 0)
5442 {
5443 i++;
cristybb503372010-05-27 20:51:26 +00005444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005445 ThrowMogrifyException(OptionError,"MissingArgument",option);
5446 if (IsGeometry(argv[i]) == MagickFalse)
5447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5448 break;
5449 }
5450 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5451 }
5452 case 's':
5453 {
5454 if (LocaleCompare("sample",option+1) == 0)
5455 {
5456 if (*option == '+')
5457 break;
5458 i++;
cristybb503372010-05-27 20:51:26 +00005459 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005460 ThrowMogrifyException(OptionError,"MissingArgument",option);
5461 if (IsGeometry(argv[i]) == MagickFalse)
5462 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5463 break;
5464 }
5465 if (LocaleCompare("sampling-factor",option+1) == 0)
5466 {
5467 if (*option == '+')
5468 break;
5469 i++;
cristybb503372010-05-27 20:51:26 +00005470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005471 ThrowMogrifyException(OptionError,"MissingArgument",option);
5472 if (IsGeometry(argv[i]) == MagickFalse)
5473 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5474 break;
5475 }
5476 if (LocaleCompare("scale",option+1) == 0)
5477 {
5478 if (*option == '+')
5479 break;
5480 i++;
cristybb503372010-05-27 20:51:26 +00005481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005482 ThrowMogrifyException(OptionError,"MissingArgument",option);
5483 if (IsGeometry(argv[i]) == MagickFalse)
5484 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5485 break;
5486 }
5487 if (LocaleCompare("scene",option+1) == 0)
5488 {
5489 if (*option == '+')
5490 break;
5491 i++;
cristybb503372010-05-27 20:51:26 +00005492 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005493 ThrowMogrifyException(OptionError,"MissingArgument",option);
5494 if (IsGeometry(argv[i]) == MagickFalse)
5495 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5496 break;
5497 }
5498 if (LocaleCompare("seed",option+1) == 0)
5499 {
5500 if (*option == '+')
5501 break;
5502 i++;
cristybb503372010-05-27 20:51:26 +00005503 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005504 ThrowMogrifyException(OptionError,"MissingArgument",option);
5505 if (IsGeometry(argv[i]) == MagickFalse)
5506 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5507 break;
5508 }
5509 if (LocaleCompare("segment",option+1) == 0)
5510 {
5511 if (*option == '+')
5512 break;
5513 i++;
cristybb503372010-05-27 20:51:26 +00005514 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005515 ThrowMogrifyException(OptionError,"MissingArgument",option);
5516 if (IsGeometry(argv[i]) == MagickFalse)
5517 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5518 break;
5519 }
5520 if (LocaleCompare("selective-blur",option+1) == 0)
5521 {
5522 i++;
cristybb503372010-05-27 20:51:26 +00005523 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005524 ThrowMogrifyException(OptionError,"MissingArgument",option);
5525 if (IsGeometry(argv[i]) == MagickFalse)
5526 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5527 break;
5528 }
5529 if (LocaleCompare("separate",option+1) == 0)
5530 break;
5531 if (LocaleCompare("sepia-tone",option+1) == 0)
5532 {
5533 if (*option == '+')
5534 break;
5535 i++;
cristybb503372010-05-27 20:51:26 +00005536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005537 ThrowMogrifyException(OptionError,"MissingArgument",option);
5538 if (IsGeometry(argv[i]) == MagickFalse)
5539 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5540 break;
5541 }
5542 if (LocaleCompare("set",option+1) == 0)
5543 {
5544 i++;
cristybb503372010-05-27 20:51:26 +00005545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 if (*option == '+')
5548 break;
5549 i++;
cristybb503372010-05-27 20:51:26 +00005550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005551 ThrowMogrifyException(OptionError,"MissingArgument",option);
5552 break;
5553 }
5554 if (LocaleCompare("shade",option+1) == 0)
5555 {
5556 i++;
cristybb503372010-05-27 20:51:26 +00005557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005558 ThrowMogrifyException(OptionError,"MissingArgument",option);
5559 if (IsGeometry(argv[i]) == MagickFalse)
5560 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5561 break;
5562 }
5563 if (LocaleCompare("shadow",option+1) == 0)
5564 {
5565 if (*option == '+')
5566 break;
5567 i++;
cristybb503372010-05-27 20:51:26 +00005568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005569 ThrowMogrifyException(OptionError,"MissingArgument",option);
5570 if (IsGeometry(argv[i]) == MagickFalse)
5571 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5572 break;
5573 }
5574 if (LocaleCompare("sharpen",option+1) == 0)
5575 {
5576 i++;
cristybb503372010-05-27 20:51:26 +00005577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005578 ThrowMogrifyException(OptionError,"MissingArgument",option);
5579 if (IsGeometry(argv[i]) == MagickFalse)
5580 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5581 break;
5582 }
5583 if (LocaleCompare("shave",option+1) == 0)
5584 {
5585 if (*option == '+')
5586 break;
5587 i++;
cristybb503372010-05-27 20:51:26 +00005588 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005589 ThrowMogrifyException(OptionError,"MissingArgument",option);
5590 if (IsGeometry(argv[i]) == MagickFalse)
5591 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5592 break;
5593 }
5594 if (LocaleCompare("shear",option+1) == 0)
5595 {
5596 i++;
cristybb503372010-05-27 20:51:26 +00005597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005598 ThrowMogrifyException(OptionError,"MissingArgument",option);
5599 if (IsGeometry(argv[i]) == MagickFalse)
5600 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5601 break;
5602 }
5603 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5604 {
5605 i++;
cristybb503372010-05-27 20:51:26 +00005606 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 if (IsGeometry(argv[i]) == MagickFalse)
5609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5610 break;
5611 }
5612 if (LocaleCompare("size",option+1) == 0)
5613 {
5614 if (*option == '+')
5615 break;
5616 i++;
cristybb503372010-05-27 20:51:26 +00005617 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005618 ThrowMogrifyException(OptionError,"MissingArgument",option);
5619 if (IsGeometry(argv[i]) == MagickFalse)
5620 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5621 break;
5622 }
5623 if (LocaleCompare("sketch",option+1) == 0)
5624 {
5625 if (*option == '+')
5626 break;
5627 i++;
cristybb503372010-05-27 20:51:26 +00005628 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005629 ThrowMogrifyException(OptionError,"MissingArgument",option);
5630 if (IsGeometry(argv[i]) == MagickFalse)
5631 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5632 break;
5633 }
cristy4285d782011-02-09 20:12:28 +00005634 if (LocaleCompare("smush",option+1) == 0)
5635 {
cristy4285d782011-02-09 20:12:28 +00005636 i++;
5637 if (i == (ssize_t) argc)
5638 ThrowMogrifyException(OptionError,"MissingArgument",option);
5639 if (IsGeometry(argv[i]) == MagickFalse)
5640 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005641 i++;
5642 break;
5643 }
cristy3ed852e2009-09-05 21:47:34 +00005644 if (LocaleCompare("solarize",option+1) == 0)
5645 {
5646 if (*option == '+')
5647 break;
5648 i++;
cristybb503372010-05-27 20:51:26 +00005649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005650 ThrowMogrifyException(OptionError,"MissingArgument",option);
5651 if (IsGeometry(argv[i]) == MagickFalse)
5652 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5653 break;
5654 }
5655 if (LocaleCompare("sparse-color",option+1) == 0)
5656 {
cristybb503372010-05-27 20:51:26 +00005657 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005658 op;
5659
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);
cristy042ee782011-04-22 18:48:30 +00005663 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005664 if (op < 0)
5665 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5666 argv[i]);
5667 i++;
cristybb503372010-05-27 20:51:26 +00005668 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005669 ThrowMogrifyException(OptionError,"MissingArgument",option);
5670 break;
5671 }
5672 if (LocaleCompare("spread",option+1) == 0)
5673 {
5674 if (*option == '+')
5675 break;
5676 i++;
cristybb503372010-05-27 20:51:26 +00005677 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005678 ThrowMogrifyException(OptionError,"MissingArgument",option);
5679 if (IsGeometry(argv[i]) == MagickFalse)
5680 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5681 break;
5682 }
cristy0834d642011-03-18 18:26:08 +00005683 if (LocaleCompare("statistic",option+1) == 0)
5684 {
5685 ssize_t
5686 op;
5687
5688 if (*option == '+')
5689 break;
5690 i++;
5691 if (i == (ssize_t) argc)
5692 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005693 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005694 if (op < 0)
5695 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5696 argv[i]);
5697 i++;
5698 if (i == (ssize_t) (argc-1))
5699 ThrowMogrifyException(OptionError,"MissingArgument",option);
5700 if (IsGeometry(argv[i]) == MagickFalse)
5701 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5702 break;
5703 }
cristy3ed852e2009-09-05 21:47:34 +00005704 if (LocaleCompare("stretch",option+1) == 0)
5705 {
cristybb503372010-05-27 20:51:26 +00005706 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005707 stretch;
5708
5709 if (*option == '+')
5710 break;
5711 i++;
cristybb503372010-05-27 20:51:26 +00005712 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005713 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005714 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005715 if (stretch < 0)
5716 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5717 argv[i]);
5718 break;
5719 }
5720 if (LocaleCompare("strip",option+1) == 0)
5721 break;
5722 if (LocaleCompare("stroke",option+1) == 0)
5723 {
5724 if (*option == '+')
5725 break;
5726 i++;
cristybb503372010-05-27 20:51:26 +00005727 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005728 ThrowMogrifyException(OptionError,"MissingArgument",option);
5729 break;
5730 }
5731 if (LocaleCompare("strokewidth",option+1) == 0)
5732 {
5733 if (*option == '+')
5734 break;
5735 i++;
cristybb503372010-05-27 20:51:26 +00005736 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005737 ThrowMogrifyException(OptionError,"MissingArgument",option);
5738 if (IsGeometry(argv[i]) == MagickFalse)
5739 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5740 break;
5741 }
5742 if (LocaleCompare("style",option+1) == 0)
5743 {
cristybb503372010-05-27 20:51:26 +00005744 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005745 style;
5746
5747 if (*option == '+')
5748 break;
5749 i++;
cristybb503372010-05-27 20:51:26 +00005750 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005751 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005752 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005753 if (style < 0)
5754 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5755 argv[i]);
5756 break;
5757 }
cristyecb10ff2011-03-22 13:14:03 +00005758 if (LocaleCompare("swap",option+1) == 0)
5759 {
5760 if (*option == '+')
5761 break;
5762 i++;
5763 if (i == (ssize_t) (argc-1))
5764 ThrowMogrifyException(OptionError,"MissingArgument",option);
5765 if (IsGeometry(argv[i]) == MagickFalse)
5766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5767 break;
5768 }
cristy3ed852e2009-09-05 21:47:34 +00005769 if (LocaleCompare("swirl",option+1) == 0)
5770 {
5771 if (*option == '+')
5772 break;
5773 i++;
cristybb503372010-05-27 20:51:26 +00005774 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005775 ThrowMogrifyException(OptionError,"MissingArgument",option);
5776 if (IsGeometry(argv[i]) == MagickFalse)
5777 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5778 break;
5779 }
cristyd9a29192010-10-16 16:49:53 +00005780 if (LocaleCompare("synchronize",option+1) == 0)
5781 break;
cristy3ed852e2009-09-05 21:47:34 +00005782 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5783 }
5784 case 't':
5785 {
5786 if (LocaleCompare("taint",option+1) == 0)
5787 break;
5788 if (LocaleCompare("texture",option+1) == 0)
5789 {
5790 if (*option == '+')
5791 break;
5792 i++;
cristybb503372010-05-27 20:51:26 +00005793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005794 ThrowMogrifyException(OptionError,"MissingArgument",option);
5795 break;
5796 }
5797 if (LocaleCompare("tile",option+1) == 0)
5798 {
5799 if (*option == '+')
5800 break;
5801 i++;
cristybb503372010-05-27 20:51:26 +00005802 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005803 ThrowMogrifyException(OptionError,"MissingArgument",option);
5804 break;
5805 }
5806 if (LocaleCompare("tile-offset",option+1) == 0)
5807 {
5808 if (*option == '+')
5809 break;
5810 i++;
cristybb503372010-05-27 20:51:26 +00005811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005812 ThrowMogrifyException(OptionError,"MissingArgument",option);
5813 if (IsGeometry(argv[i]) == MagickFalse)
5814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5815 break;
5816 }
5817 if (LocaleCompare("tint",option+1) == 0)
5818 {
5819 if (*option == '+')
5820 break;
5821 i++;
cristybb503372010-05-27 20:51:26 +00005822 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005823 ThrowMogrifyException(OptionError,"MissingArgument",option);
5824 if (IsGeometry(argv[i]) == MagickFalse)
5825 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5826 break;
5827 }
5828 if (LocaleCompare("transform",option+1) == 0)
5829 break;
5830 if (LocaleCompare("transpose",option+1) == 0)
5831 break;
5832 if (LocaleCompare("transverse",option+1) == 0)
5833 break;
5834 if (LocaleCompare("threshold",option+1) == 0)
5835 {
5836 if (*option == '+')
5837 break;
5838 i++;
cristybb503372010-05-27 20:51:26 +00005839 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005840 ThrowMogrifyException(OptionError,"MissingArgument",option);
5841 if (IsGeometry(argv[i]) == MagickFalse)
5842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5843 break;
5844 }
5845 if (LocaleCompare("thumbnail",option+1) == 0)
5846 {
5847 if (*option == '+')
5848 break;
5849 i++;
cristybb503372010-05-27 20:51:26 +00005850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005851 ThrowMogrifyException(OptionError,"MissingArgument",option);
5852 if (IsGeometry(argv[i]) == MagickFalse)
5853 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5854 break;
5855 }
5856 if (LocaleCompare("transparent",option+1) == 0)
5857 {
5858 i++;
cristybb503372010-05-27 20:51:26 +00005859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005860 ThrowMogrifyException(OptionError,"MissingArgument",option);
5861 break;
5862 }
5863 if (LocaleCompare("transparent-color",option+1) == 0)
5864 {
5865 if (*option == '+')
5866 break;
5867 i++;
cristybb503372010-05-27 20:51:26 +00005868 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005869 ThrowMogrifyException(OptionError,"MissingArgument",option);
5870 break;
5871 }
5872 if (LocaleCompare("treedepth",option+1) == 0)
5873 {
5874 if (*option == '+')
5875 break;
5876 i++;
cristybb503372010-05-27 20:51:26 +00005877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005878 ThrowMogrifyException(OptionError,"MissingArgument",option);
5879 if (IsGeometry(argv[i]) == MagickFalse)
5880 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5881 break;
5882 }
5883 if (LocaleCompare("trim",option+1) == 0)
5884 break;
5885 if (LocaleCompare("type",option+1) == 0)
5886 {
cristybb503372010-05-27 20:51:26 +00005887 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005888 type;
5889
5890 if (*option == '+')
5891 break;
5892 i++;
cristybb503372010-05-27 20:51:26 +00005893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005894 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005895 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005896 if (type < 0)
5897 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5898 argv[i]);
5899 break;
5900 }
5901 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5902 }
5903 case 'u':
5904 {
5905 if (LocaleCompare("undercolor",option+1) == 0)
5906 {
5907 if (*option == '+')
5908 break;
5909 i++;
cristybb503372010-05-27 20:51:26 +00005910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005911 ThrowMogrifyException(OptionError,"MissingArgument",option);
5912 break;
5913 }
5914 if (LocaleCompare("unique-colors",option+1) == 0)
5915 break;
5916 if (LocaleCompare("units",option+1) == 0)
5917 {
cristybb503372010-05-27 20:51:26 +00005918 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005919 units;
5920
5921 if (*option == '+')
5922 break;
5923 i++;
cristybb503372010-05-27 20:51:26 +00005924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005925 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005926 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005927 argv[i]);
5928 if (units < 0)
5929 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5930 argv[i]);
5931 break;
5932 }
5933 if (LocaleCompare("unsharp",option+1) == 0)
5934 {
5935 i++;
cristybb503372010-05-27 20:51:26 +00005936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005937 ThrowMogrifyException(OptionError,"MissingArgument",option);
5938 if (IsGeometry(argv[i]) == MagickFalse)
5939 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5940 break;
5941 }
5942 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5943 }
5944 case 'v':
5945 {
5946 if (LocaleCompare("verbose",option+1) == 0)
5947 {
5948 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5949 break;
5950 }
5951 if ((LocaleCompare("version",option+1) == 0) ||
5952 (LocaleCompare("-version",option+1) == 0))
5953 {
cristyb51dff52011-05-19 16:55:47 +00005954 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005955 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005956 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5957 GetMagickCopyright());
5958 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5959 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005960 break;
5961 }
5962 if (LocaleCompare("view",option+1) == 0)
5963 {
5964 if (*option == '+')
5965 break;
5966 i++;
cristybb503372010-05-27 20:51:26 +00005967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005968 ThrowMogrifyException(OptionError,"MissingArgument",option);
5969 break;
5970 }
5971 if (LocaleCompare("vignette",option+1) == 0)
5972 {
5973 if (*option == '+')
5974 break;
5975 i++;
cristybb503372010-05-27 20:51:26 +00005976 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005977 ThrowMogrifyException(OptionError,"MissingArgument",option);
5978 if (IsGeometry(argv[i]) == MagickFalse)
5979 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5980 break;
5981 }
5982 if (LocaleCompare("virtual-pixel",option+1) == 0)
5983 {
cristybb503372010-05-27 20:51:26 +00005984 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005985 method;
5986
5987 if (*option == '+')
5988 break;
5989 i++;
cristybb503372010-05-27 20:51:26 +00005990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005991 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005992 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005993 argv[i]);
5994 if (method < 0)
5995 ThrowMogrifyException(OptionError,
5996 "UnrecognizedVirtualPixelMethod",argv[i]);
5997 break;
5998 }
5999 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6000 }
6001 case 'w':
6002 {
6003 if (LocaleCompare("wave",option+1) == 0)
6004 {
6005 i++;
cristybb503372010-05-27 20:51:26 +00006006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006007 ThrowMogrifyException(OptionError,"MissingArgument",option);
6008 if (IsGeometry(argv[i]) == MagickFalse)
6009 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6010 break;
6011 }
6012 if (LocaleCompare("weight",option+1) == 0)
6013 {
6014 if (*option == '+')
6015 break;
6016 i++;
cristybb503372010-05-27 20:51:26 +00006017 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006018 ThrowMogrifyException(OptionError,"MissingArgument",option);
6019 break;
6020 }
6021 if (LocaleCompare("white-point",option+1) == 0)
6022 {
6023 if (*option == '+')
6024 break;
6025 i++;
cristybb503372010-05-27 20:51:26 +00006026 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006027 ThrowMogrifyException(OptionError,"MissingArgument",option);
6028 if (IsGeometry(argv[i]) == MagickFalse)
6029 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6030 break;
6031 }
6032 if (LocaleCompare("white-threshold",option+1) == 0)
6033 {
6034 if (*option == '+')
6035 break;
6036 i++;
cristybb503372010-05-27 20:51:26 +00006037 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006038 ThrowMogrifyException(OptionError,"MissingArgument",option);
6039 if (IsGeometry(argv[i]) == MagickFalse)
6040 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6041 break;
6042 }
6043 if (LocaleCompare("write",option+1) == 0)
6044 {
6045 i++;
cristybb503372010-05-27 20:51:26 +00006046 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006047 ThrowMogrifyException(OptionError,"MissingArgument",option);
6048 break;
6049 }
6050 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6051 }
6052 case '?':
6053 break;
6054 default:
6055 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6056 }
cristy042ee782011-04-22 18:48:30 +00006057 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6058 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006059 if (fire != MagickFalse)
6060 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6061 }
6062 if (k != 0)
6063 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006064 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006065 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6066 DestroyMogrify();
6067 return(status != 0 ? MagickTrue : MagickFalse);
6068}
6069
6070/*
6071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6072% %
6073% %
6074% %
6075+ M o g r i f y I m a g e I n f o %
6076% %
6077% %
6078% %
6079%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6080%
6081% MogrifyImageInfo() applies image processing settings to the image as
6082% prescribed by command line options.
6083%
6084% The format of the MogrifyImageInfo method is:
6085%
6086% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6087% const char **argv,ExceptionInfo *exception)
6088%
6089% A description of each parameter follows:
6090%
6091% o image_info: the image info..
6092%
6093% o argc: Specifies a pointer to an integer describing the number of
6094% elements in the argument vector.
6095%
6096% o argv: Specifies a pointer to a text array containing the command line
6097% arguments.
6098%
6099% o exception: return any errors or warnings in this structure.
6100%
6101*/
6102WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6103 const int argc,const char **argv,ExceptionInfo *exception)
6104{
6105 const char
6106 *option;
6107
6108 GeometryInfo
6109 geometry_info;
6110
cristybb503372010-05-27 20:51:26 +00006111 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006112 count;
6113
cristybb503372010-05-27 20:51:26 +00006114 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006115 i;
6116
6117 /*
6118 Initialize method variables.
6119 */
6120 assert(image_info != (ImageInfo *) NULL);
6121 assert(image_info->signature == MagickSignature);
6122 if (image_info->debug != MagickFalse)
6123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6124 image_info->filename);
6125 if (argc < 0)
6126 return(MagickTrue);
6127 /*
6128 Set the image settings.
6129 */
cristybb503372010-05-27 20:51:26 +00006130 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006131 {
6132 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006133 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006134 continue;
cristy042ee782011-04-22 18:48:30 +00006135 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006136 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006137 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006138 break;
6139 switch (*(option+1))
6140 {
6141 case 'a':
6142 {
6143 if (LocaleCompare("adjoin",option+1) == 0)
6144 {
6145 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6146 break;
6147 }
6148 if (LocaleCompare("antialias",option+1) == 0)
6149 {
6150 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6151 break;
6152 }
cristy3ed852e2009-09-05 21:47:34 +00006153 if (LocaleCompare("authenticate",option+1) == 0)
6154 {
6155 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006156 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006157 else
anthony1afdc7a2011-10-05 11:54:28 +00006158 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006159 break;
6160 }
6161 break;
6162 }
6163 case 'b':
6164 {
6165 if (LocaleCompare("background",option+1) == 0)
6166 {
6167 if (*option == '+')
6168 {
6169 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006170 (void) QueryColorCompliance(MogrifyBackgroundColor,
6171 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006172 break;
6173 }
6174 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006175 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6176 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006177 break;
6178 }
6179 if (LocaleCompare("bias",option+1) == 0)
6180 {
6181 if (*option == '+')
6182 {
6183 (void) SetImageOption(image_info,option+1,"0.0");
6184 break;
6185 }
6186 (void) SetImageOption(image_info,option+1,argv[i+1]);
6187 break;
6188 }
6189 if (LocaleCompare("black-point-compensation",option+1) == 0)
6190 {
6191 if (*option == '+')
6192 {
6193 (void) SetImageOption(image_info,option+1,"false");
6194 break;
6195 }
6196 (void) SetImageOption(image_info,option+1,"true");
6197 break;
6198 }
6199 if (LocaleCompare("blue-primary",option+1) == 0)
6200 {
6201 if (*option == '+')
6202 {
6203 (void) SetImageOption(image_info,option+1,"0.0");
6204 break;
6205 }
6206 (void) SetImageOption(image_info,option+1,argv[i+1]);
6207 break;
6208 }
6209 if (LocaleCompare("bordercolor",option+1) == 0)
6210 {
6211 if (*option == '+')
6212 {
6213 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006214 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006215 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006216 break;
6217 }
cristy9950d572011-10-01 18:22:35 +00006218 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6219 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006220 (void) SetImageOption(image_info,option+1,argv[i+1]);
6221 break;
6222 }
6223 if (LocaleCompare("box",option+1) == 0)
6224 {
6225 if (*option == '+')
6226 {
6227 (void) SetImageOption(image_info,"undercolor","none");
6228 break;
6229 }
6230 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6231 break;
6232 }
6233 break;
6234 }
6235 case 'c':
6236 {
6237 if (LocaleCompare("cache",option+1) == 0)
6238 {
6239 MagickSizeType
6240 limit;
6241
6242 limit=MagickResourceInfinity;
6243 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006244 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6245 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006246 (void) SetMagickResourceLimit(MemoryResource,limit);
6247 (void) SetMagickResourceLimit(MapResource,2*limit);
6248 break;
6249 }
6250 if (LocaleCompare("caption",option+1) == 0)
6251 {
6252 if (*option == '+')
6253 {
6254 (void) DeleteImageOption(image_info,option+1);
6255 break;
6256 }
6257 (void) SetImageOption(image_info,option+1,argv[i+1]);
6258 break;
6259 }
6260 if (LocaleCompare("channel",option+1) == 0)
6261 {
6262 if (*option == '+')
6263 {
6264 image_info->channel=DefaultChannels;
6265 break;
6266 }
6267 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6268 break;
6269 }
cristy3ed852e2009-09-05 21:47:34 +00006270 if (LocaleCompare("colorspace",option+1) == 0)
6271 {
6272 if (*option == '+')
6273 {
6274 image_info->colorspace=UndefinedColorspace;
6275 (void) SetImageOption(image_info,option+1,"undefined");
6276 break;
6277 }
cristy042ee782011-04-22 18:48:30 +00006278 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006279 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6280 (void) SetImageOption(image_info,option+1,argv[i+1]);
6281 break;
6282 }
cristy3ed852e2009-09-05 21:47:34 +00006283 if (LocaleCompare("comment",option+1) == 0)
6284 {
6285 if (*option == '+')
6286 {
6287 (void) DeleteImageOption(image_info,option+1);
6288 break;
6289 }
6290 (void) SetImageOption(image_info,option+1,argv[i+1]);
6291 break;
6292 }
6293 if (LocaleCompare("compose",option+1) == 0)
6294 {
6295 if (*option == '+')
6296 {
6297 (void) SetImageOption(image_info,option+1,"undefined");
6298 break;
6299 }
6300 (void) SetImageOption(image_info,option+1,argv[i+1]);
6301 break;
6302 }
6303 if (LocaleCompare("compress",option+1) == 0)
6304 {
6305 if (*option == '+')
6306 {
6307 image_info->compression=UndefinedCompression;
6308 (void) SetImageOption(image_info,option+1,"undefined");
6309 break;
6310 }
cristy042ee782011-04-22 18:48:30 +00006311 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006312 MagickCompressOptions,MagickFalse,argv[i+1]);
6313 (void) SetImageOption(image_info,option+1,argv[i+1]);
6314 break;
6315 }
6316 break;
6317 }
6318 case 'd':
6319 {
6320 if (LocaleCompare("debug",option+1) == 0)
6321 {
6322 if (*option == '+')
6323 (void) SetLogEventMask("none");
6324 else
6325 (void) SetLogEventMask(argv[i+1]);
6326 image_info->debug=IsEventLogging();
6327 break;
6328 }
6329 if (LocaleCompare("define",option+1) == 0)
6330 {
6331 if (*option == '+')
6332 {
6333 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6334 (void) DeleteImageRegistry(argv[i+1]+9);
6335 else
6336 (void) DeleteImageOption(image_info,argv[i+1]);
6337 break;
6338 }
6339 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6340 {
6341 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6342 exception);
6343 break;
6344 }
6345 (void) DefineImageOption(image_info,argv[i+1]);
6346 break;
6347 }
6348 if (LocaleCompare("delay",option+1) == 0)
6349 {
6350 if (*option == '+')
6351 {
6352 (void) SetImageOption(image_info,option+1,"0");
6353 break;
6354 }
6355 (void) SetImageOption(image_info,option+1,argv[i+1]);
6356 break;
6357 }
6358 if (LocaleCompare("density",option+1) == 0)
6359 {
6360 /*
6361 Set image density.
6362 */
6363 if (*option == '+')
6364 {
6365 if (image_info->density != (char *) NULL)
6366 image_info->density=DestroyString(image_info->density);
6367 (void) SetImageOption(image_info,option+1,"72");
6368 break;
6369 }
6370 (void) CloneString(&image_info->density,argv[i+1]);
6371 (void) SetImageOption(image_info,option+1,argv[i+1]);
6372 break;
6373 }
6374 if (LocaleCompare("depth",option+1) == 0)
6375 {
6376 if (*option == '+')
6377 {
6378 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6379 break;
6380 }
cristye27293e2009-12-18 02:53:20 +00006381 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006382 break;
6383 }
cristyc9b12952010-03-28 01:12:28 +00006384 if (LocaleCompare("direction",option+1) == 0)
6385 {
6386 if (*option == '+')
6387 {
6388 (void) SetImageOption(image_info,option+1,"undefined");
6389 break;
6390 }
6391 (void) SetImageOption(image_info,option+1,argv[i+1]);
6392 break;
6393 }
cristy3ed852e2009-09-05 21:47:34 +00006394 if (LocaleCompare("display",option+1) == 0)
6395 {
6396 if (*option == '+')
6397 {
6398 if (image_info->server_name != (char *) NULL)
6399 image_info->server_name=DestroyString(
6400 image_info->server_name);
6401 break;
6402 }
6403 (void) CloneString(&image_info->server_name,argv[i+1]);
6404 break;
6405 }
6406 if (LocaleCompare("dispose",option+1) == 0)
6407 {
6408 if (*option == '+')
6409 {
6410 (void) SetImageOption(image_info,option+1,"undefined");
6411 break;
6412 }
6413 (void) SetImageOption(image_info,option+1,argv[i+1]);
6414 break;
6415 }
6416 if (LocaleCompare("dither",option+1) == 0)
6417 {
6418 if (*option == '+')
6419 {
6420 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006421 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006422 break;
6423 }
6424 (void) SetImageOption(image_info,option+1,argv[i+1]);
6425 image_info->dither=MagickTrue;
6426 break;
6427 }
6428 break;
6429 }
6430 case 'e':
6431 {
6432 if (LocaleCompare("encoding",option+1) == 0)
6433 {
6434 if (*option == '+')
6435 {
6436 (void) SetImageOption(image_info,option+1,"undefined");
6437 break;
6438 }
6439 (void) SetImageOption(image_info,option+1,argv[i+1]);
6440 break;
6441 }
6442 if (LocaleCompare("endian",option+1) == 0)
6443 {
6444 if (*option == '+')
6445 {
6446 image_info->endian=UndefinedEndian;
6447 (void) SetImageOption(image_info,option+1,"undefined");
6448 break;
6449 }
cristy042ee782011-04-22 18:48:30 +00006450 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006451 MagickEndianOptions,MagickFalse,argv[i+1]);
6452 (void) SetImageOption(image_info,option+1,argv[i+1]);
6453 break;
6454 }
6455 if (LocaleCompare("extract",option+1) == 0)
6456 {
6457 /*
6458 Set image extract geometry.
6459 */
6460 if (*option == '+')
6461 {
6462 if (image_info->extract != (char *) NULL)
6463 image_info->extract=DestroyString(image_info->extract);
6464 break;
6465 }
6466 (void) CloneString(&image_info->extract,argv[i+1]);
6467 break;
6468 }
6469 break;
6470 }
6471 case 'f':
6472 {
6473 if (LocaleCompare("fill",option+1) == 0)
6474 {
6475 if (*option == '+')
6476 {
6477 (void) SetImageOption(image_info,option+1,"none");
6478 break;
6479 }
6480 (void) SetImageOption(image_info,option+1,argv[i+1]);
6481 break;
6482 }
6483 if (LocaleCompare("filter",option+1) == 0)
6484 {
6485 if (*option == '+')
6486 {
6487 (void) SetImageOption(image_info,option+1,"undefined");
6488 break;
6489 }
6490 (void) SetImageOption(image_info,option+1,argv[i+1]);
6491 break;
6492 }
6493 if (LocaleCompare("font",option+1) == 0)
6494 {
6495 if (*option == '+')
6496 {
6497 if (image_info->font != (char *) NULL)
6498 image_info->font=DestroyString(image_info->font);
6499 break;
6500 }
6501 (void) CloneString(&image_info->font,argv[i+1]);
6502 break;
6503 }
6504 if (LocaleCompare("format",option+1) == 0)
6505 {
6506 register const char
6507 *q;
6508
6509 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006510 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006511 image_info->ping=MagickFalse;
6512 (void) SetImageOption(image_info,option+1,argv[i+1]);
6513 break;
6514 }
6515 if (LocaleCompare("fuzz",option+1) == 0)
6516 {
6517 if (*option == '+')
6518 {
6519 image_info->fuzz=0.0;
6520 (void) SetImageOption(image_info,option+1,"0");
6521 break;
6522 }
cristydbdd0e32011-11-04 23:29:40 +00006523 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6524 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006525 (void) SetImageOption(image_info,option+1,argv[i+1]);
6526 break;
6527 }
6528 break;
6529 }
6530 case 'g':
6531 {
6532 if (LocaleCompare("gravity",option+1) == 0)
6533 {
6534 if (*option == '+')
6535 {
6536 (void) SetImageOption(image_info,option+1,"undefined");
6537 break;
6538 }
6539 (void) SetImageOption(image_info,option+1,argv[i+1]);
6540 break;
6541 }
6542 if (LocaleCompare("green-primary",option+1) == 0)
6543 {
6544 if (*option == '+')
6545 {
6546 (void) SetImageOption(image_info,option+1,"0.0");
6547 break;
6548 }
6549 (void) SetImageOption(image_info,option+1,argv[i+1]);
6550 break;
6551 }
6552 break;
6553 }
6554 case 'i':
6555 {
6556 if (LocaleCompare("intent",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("interlace",option+1) == 0)
6567 {
6568 if (*option == '+')
6569 {
6570 image_info->interlace=UndefinedInterlace;
6571 (void) SetImageOption(image_info,option+1,"undefined");
6572 break;
6573 }
cristy042ee782011-04-22 18:48:30 +00006574 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006575 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6576 (void) SetImageOption(image_info,option+1,argv[i+1]);
6577 break;
6578 }
cristyb32b90a2009-09-07 21:45:48 +00006579 if (LocaleCompare("interline-spacing",option+1) == 0)
6580 {
6581 if (*option == '+')
6582 {
6583 (void) SetImageOption(image_info,option+1,"undefined");
6584 break;
6585 }
6586 (void) SetImageOption(image_info,option+1,argv[i+1]);
6587 break;
6588 }
cristy3ed852e2009-09-05 21:47:34 +00006589 if (LocaleCompare("interpolate",option+1) == 0)
6590 {
6591 if (*option == '+')
6592 {
6593 (void) SetImageOption(image_info,option+1,"undefined");
6594 break;
6595 }
6596 (void) SetImageOption(image_info,option+1,argv[i+1]);
6597 break;
6598 }
6599 if (LocaleCompare("interword-spacing",option+1) == 0)
6600 {
6601 if (*option == '+')
6602 {
6603 (void) SetImageOption(image_info,option+1,"undefined");
6604 break;
6605 }
6606 (void) SetImageOption(image_info,option+1,argv[i+1]);
6607 break;
6608 }
6609 break;
6610 }
6611 case 'k':
6612 {
6613 if (LocaleCompare("kerning",option+1) == 0)
6614 {
6615 if (*option == '+')
6616 {
6617 (void) SetImageOption(image_info,option+1,"undefined");
6618 break;
6619 }
6620 (void) SetImageOption(image_info,option+1,argv[i+1]);
6621 break;
6622 }
6623 break;
6624 }
6625 case 'l':
6626 {
6627 if (LocaleCompare("label",option+1) == 0)
6628 {
6629 if (*option == '+')
6630 {
6631 (void) DeleteImageOption(image_info,option+1);
6632 break;
6633 }
6634 (void) SetImageOption(image_info,option+1,argv[i+1]);
6635 break;
6636 }
6637 if (LocaleCompare("limit",option+1) == 0)
6638 {
6639 MagickSizeType
6640 limit;
6641
6642 ResourceType
6643 type;
6644
6645 if (*option == '+')
6646 break;
cristy042ee782011-04-22 18:48:30 +00006647 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006648 MagickFalse,argv[i+1]);
6649 limit=MagickResourceInfinity;
6650 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006651 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006652 (void) SetMagickResourceLimit(type,limit);
6653 break;
6654 }
6655 if (LocaleCompare("list",option+1) == 0)
6656 {
cristybb503372010-05-27 20:51:26 +00006657 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006658 list;
6659
6660 /*
6661 Display configuration list.
6662 */
cristy042ee782011-04-22 18:48:30 +00006663 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006664 switch (list)
6665 {
6666 case MagickCoderOptions:
6667 {
6668 (void) ListCoderInfo((FILE *) NULL,exception);
6669 break;
6670 }
6671 case MagickColorOptions:
6672 {
6673 (void) ListColorInfo((FILE *) NULL,exception);
6674 break;
6675 }
6676 case MagickConfigureOptions:
6677 {
6678 (void) ListConfigureInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickDelegateOptions:
6682 {
6683 (void) ListDelegateInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickFontOptions:
6687 {
6688 (void) ListTypeInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickFormatOptions:
6692 {
6693 (void) ListMagickInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickLocaleOptions:
6697 {
6698 (void) ListLocaleInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickLogOptions:
6702 {
6703 (void) ListLogInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickMagicOptions:
6707 {
6708 (void) ListMagicInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickMimeOptions:
6712 {
6713 (void) ListMimeInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickModuleOptions:
6717 {
6718 (void) ListModuleInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickPolicyOptions:
6722 {
6723 (void) ListPolicyInfo((FILE *) NULL,exception);
6724 break;
6725 }
6726 case MagickResourceOptions:
6727 {
6728 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6729 break;
6730 }
6731 case MagickThresholdOptions:
6732 {
6733 (void) ListThresholdMaps((FILE *) NULL,exception);
6734 break;
6735 }
6736 default:
6737 {
cristy042ee782011-04-22 18:48:30 +00006738 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006739 exception);
6740 break;
6741 }
6742 }
cristyaeb2cbc2010-05-07 13:28:58 +00006743 break;
cristy3ed852e2009-09-05 21:47:34 +00006744 }
6745 if (LocaleCompare("log",option+1) == 0)
6746 {
6747 if (*option == '+')
6748 break;
6749 (void) SetLogFormat(argv[i+1]);
6750 break;
6751 }
6752 if (LocaleCompare("loop",option+1) == 0)
6753 {
6754 if (*option == '+')
6755 {
6756 (void) SetImageOption(image_info,option+1,"0");
6757 break;
6758 }
6759 (void) SetImageOption(image_info,option+1,argv[i+1]);
6760 break;
6761 }
6762 break;
6763 }
6764 case 'm':
6765 {
6766 if (LocaleCompare("matte",option+1) == 0)
6767 {
6768 if (*option == '+')
6769 {
6770 (void) SetImageOption(image_info,option+1,"false");
6771 break;
6772 }
6773 (void) SetImageOption(image_info,option+1,"true");
6774 break;
6775 }
6776 if (LocaleCompare("mattecolor",option+1) == 0)
6777 {
6778 if (*option == '+')
6779 {
6780 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006781 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006782 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006783 break;
6784 }
6785 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006786 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6787 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006788 break;
6789 }
6790 if (LocaleCompare("monitor",option+1) == 0)
6791 {
6792 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6793 (void *) NULL);
6794 break;
6795 }
6796 if (LocaleCompare("monochrome",option+1) == 0)
6797 {
6798 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6799 break;
6800 }
6801 break;
6802 }
6803 case 'o':
6804 {
6805 if (LocaleCompare("orient",option+1) == 0)
6806 {
6807 if (*option == '+')
6808 {
6809 image_info->orientation=UndefinedOrientation;
6810 (void) SetImageOption(image_info,option+1,"undefined");
6811 break;
6812 }
cristy042ee782011-04-22 18:48:30 +00006813 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006814 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006815 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006816 break;
6817 }
6818 }
6819 case 'p':
6820 {
6821 if (LocaleCompare("page",option+1) == 0)
6822 {
6823 char
6824 *canonical_page,
6825 page[MaxTextExtent];
6826
6827 const char
6828 *image_option;
6829
6830 MagickStatusType
6831 flags;
6832
6833 RectangleInfo
6834 geometry;
6835
6836 if (*option == '+')
6837 {
6838 (void) DeleteImageOption(image_info,option+1);
6839 (void) CloneString(&image_info->page,(char *) NULL);
6840 break;
6841 }
6842 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6843 image_option=GetImageOption(image_info,"page");
6844 if (image_option != (const char *) NULL)
6845 flags=ParseAbsoluteGeometry(image_option,&geometry);
6846 canonical_page=GetPageGeometry(argv[i+1]);
6847 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6848 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006849 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006850 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006851 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006852 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006853 (unsigned long) geometry.width,(unsigned long) geometry.height,
6854 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006855 (void) SetImageOption(image_info,option+1,page);
6856 (void) CloneString(&image_info->page,page);
6857 break;
6858 }
cristy3ed852e2009-09-05 21:47:34 +00006859 if (LocaleCompare("ping",option+1) == 0)
6860 {
6861 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6862 break;
6863 }
6864 if (LocaleCompare("pointsize",option+1) == 0)
6865 {
6866 if (*option == '+')
6867 geometry_info.rho=0.0;
6868 else
6869 (void) ParseGeometry(argv[i+1],&geometry_info);
6870 image_info->pointsize=geometry_info.rho;
6871 break;
6872 }
cristye7f51092010-01-17 00:39:37 +00006873 if (LocaleCompare("precision",option+1) == 0)
6874 {
cristybf2766a2010-01-17 03:33:23 +00006875 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006876 break;
6877 }
cristy3ed852e2009-09-05 21:47:34 +00006878 if (LocaleCompare("preview",option+1) == 0)
6879 {
6880 /*
6881 Preview image.
6882 */
6883 if (*option == '+')
6884 {
6885 image_info->preview_type=UndefinedPreview;
6886 break;
6887 }
cristy042ee782011-04-22 18:48:30 +00006888 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006889 MagickPreviewOptions,MagickFalse,argv[i+1]);
6890 break;
6891 }
6892 break;
6893 }
6894 case 'q':
6895 {
6896 if (LocaleCompare("quality",option+1) == 0)
6897 {
6898 /*
6899 Set image compression quality.
6900 */
6901 if (*option == '+')
6902 {
6903 image_info->quality=UndefinedCompressionQuality;
6904 (void) SetImageOption(image_info,option+1,"0");
6905 break;
6906 }
cristye27293e2009-12-18 02:53:20 +00006907 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006908 (void) SetImageOption(image_info,option+1,argv[i+1]);
6909 break;
6910 }
6911 if (LocaleCompare("quiet",option+1) == 0)
6912 {
6913 static WarningHandler
6914 warning_handler = (WarningHandler) NULL;
6915
6916 if (*option == '+')
6917 {
6918 /*
6919 Restore error or warning messages.
6920 */
6921 warning_handler=SetWarningHandler(warning_handler);
6922 break;
6923 }
6924 /*
6925 Suppress error or warning messages.
6926 */
6927 warning_handler=SetWarningHandler((WarningHandler) NULL);
6928 break;
6929 }
6930 break;
6931 }
6932 case 'r':
6933 {
6934 if (LocaleCompare("red-primary",option+1) == 0)
6935 {
6936 if (*option == '+')
6937 {
6938 (void) SetImageOption(image_info,option+1,"0.0");
6939 break;
6940 }
6941 (void) SetImageOption(image_info,option+1,argv[i+1]);
6942 break;
6943 }
6944 break;
6945 }
6946 case 's':
6947 {
6948 if (LocaleCompare("sampling-factor",option+1) == 0)
6949 {
6950 /*
6951 Set image sampling factor.
6952 */
6953 if (*option == '+')
6954 {
6955 if (image_info->sampling_factor != (char *) NULL)
6956 image_info->sampling_factor=DestroyString(
6957 image_info->sampling_factor);
6958 break;
6959 }
6960 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6961 break;
6962 }
6963 if (LocaleCompare("scene",option+1) == 0)
6964 {
6965 /*
6966 Set image scene.
6967 */
6968 if (*option == '+')
6969 {
6970 image_info->scene=0;
6971 (void) SetImageOption(image_info,option+1,"0");
6972 break;
6973 }
cristye27293e2009-12-18 02:53:20 +00006974 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006975 (void) SetImageOption(image_info,option+1,argv[i+1]);
6976 break;
6977 }
6978 if (LocaleCompare("seed",option+1) == 0)
6979 {
cristybb503372010-05-27 20:51:26 +00006980 size_t
cristy3ed852e2009-09-05 21:47:34 +00006981 seed;
6982
6983 if (*option == '+')
6984 {
cristybb503372010-05-27 20:51:26 +00006985 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006986 SeedPseudoRandomGenerator(seed);
6987 break;
6988 }
cristye27293e2009-12-18 02:53:20 +00006989 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006990 SeedPseudoRandomGenerator(seed);
6991 break;
6992 }
6993 if (LocaleCompare("size",option+1) == 0)
6994 {
6995 if (*option == '+')
6996 {
6997 if (image_info->size != (char *) NULL)
6998 image_info->size=DestroyString(image_info->size);
6999 break;
7000 }
7001 (void) CloneString(&image_info->size,argv[i+1]);
7002 break;
7003 }
7004 if (LocaleCompare("stroke",option+1) == 0)
7005 {
7006 if (*option == '+')
7007 {
7008 (void) SetImageOption(image_info,option+1,"none");
7009 break;
7010 }
7011 (void) SetImageOption(image_info,option+1,argv[i+1]);
7012 break;
7013 }
7014 if (LocaleCompare("strokewidth",option+1) == 0)
7015 {
7016 if (*option == '+')
7017 {
7018 (void) SetImageOption(image_info,option+1,"0");
7019 break;
7020 }
7021 (void) SetImageOption(image_info,option+1,argv[i+1]);
7022 break;
7023 }
cristyd9a29192010-10-16 16:49:53 +00007024 if (LocaleCompare("synchronize",option+1) == 0)
7025 {
7026 if (*option == '+')
7027 {
7028 image_info->synchronize=MagickFalse;
7029 break;
7030 }
7031 image_info->synchronize=MagickTrue;
7032 break;
7033 }
cristy3ed852e2009-09-05 21:47:34 +00007034 break;
7035 }
7036 case 't':
7037 {
7038 if (LocaleCompare("taint",option+1) == 0)
7039 {
7040 if (*option == '+')
7041 {
7042 (void) SetImageOption(image_info,option+1,"false");
7043 break;
7044 }
7045 (void) SetImageOption(image_info,option+1,"true");
7046 break;
7047 }
7048 if (LocaleCompare("texture",option+1) == 0)
7049 {
7050 if (*option == '+')
7051 {
7052 if (image_info->texture != (char *) NULL)
7053 image_info->texture=DestroyString(image_info->texture);
7054 break;
7055 }
7056 (void) CloneString(&image_info->texture,argv[i+1]);
7057 break;
7058 }
7059 if (LocaleCompare("tile-offset",option+1) == 0)
7060 {
7061 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007062 (void) SetImageOption(image_info,option+1,"0");
7063 else
7064 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007065 break;
7066 }
7067 if (LocaleCompare("transparent-color",option+1) == 0)
7068 {
7069 if (*option == '+')
7070 {
cristy9950d572011-10-01 18:22:35 +00007071 (void) QueryColorCompliance("none",AllCompliance,
7072 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007073 (void) SetImageOption(image_info,option+1,"none");
7074 break;
7075 }
cristy9950d572011-10-01 18:22:35 +00007076 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7077 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007078 (void) SetImageOption(image_info,option+1,argv[i+1]);
7079 break;
7080 }
7081 if (LocaleCompare("type",option+1) == 0)
7082 {
7083 if (*option == '+')
7084 {
cristy5f1c1ff2010-12-23 21:38:06 +00007085 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007086 (void) SetImageOption(image_info,option+1,"undefined");
7087 break;
7088 }
cristy042ee782011-04-22 18:48:30 +00007089 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007090 MagickFalse,argv[i+1]);
7091 (void) SetImageOption(image_info,option+1,argv[i+1]);
7092 break;
7093 }
7094 break;
7095 }
7096 case 'u':
7097 {
7098 if (LocaleCompare("undercolor",option+1) == 0)
7099 {
7100 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007101 (void) DeleteImageOption(image_info,option+1);
7102 else
7103 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007104 break;
7105 }
7106 if (LocaleCompare("units",option+1) == 0)
7107 {
7108 if (*option == '+')
7109 {
7110 image_info->units=UndefinedResolution;
7111 (void) SetImageOption(image_info,option+1,"undefined");
7112 break;
7113 }
cristy042ee782011-04-22 18:48:30 +00007114 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007115 MagickResolutionOptions,MagickFalse,argv[i+1]);
7116 (void) SetImageOption(image_info,option+1,argv[i+1]);
7117 break;
7118 }
7119 break;
7120 }
7121 case 'v':
7122 {
7123 if (LocaleCompare("verbose",option+1) == 0)
7124 {
7125 if (*option == '+')
7126 {
7127 image_info->verbose=MagickFalse;
7128 break;
7129 }
7130 image_info->verbose=MagickTrue;
7131 image_info->ping=MagickFalse;
7132 break;
7133 }
7134 if (LocaleCompare("view",option+1) == 0)
7135 {
7136 if (*option == '+')
7137 {
7138 if (image_info->view != (char *) NULL)
7139 image_info->view=DestroyString(image_info->view);
7140 break;
7141 }
7142 (void) CloneString(&image_info->view,argv[i+1]);
7143 break;
7144 }
7145 if (LocaleCompare("virtual-pixel",option+1) == 0)
7146 {
7147 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007148 (void) SetImageOption(image_info,option+1,"undefined");
7149 else
7150 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007151 break;
7152 }
7153 break;
7154 }
7155 case 'w':
7156 {
7157 if (LocaleCompare("white-point",option+1) == 0)
7158 {
7159 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007160 (void) SetImageOption(image_info,option+1,"0.0");
7161 else
7162 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007163 break;
7164 }
7165 break;
7166 }
7167 default:
7168 break;
7169 }
7170 i+=count;
7171 }
7172 return(MagickTrue);
7173}
7174
7175/*
7176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7177% %
7178% %
7179% %
7180+ M o g r i f y I m a g e L i s t %
7181% %
7182% %
7183% %
7184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7185%
7186% MogrifyImageList() applies any command line options that might affect the
7187% entire image list (e.g. -append, -coalesce, etc.).
7188%
7189% The format of the MogrifyImage method is:
7190%
7191% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7192% const char **argv,Image **images,ExceptionInfo *exception)
7193%
7194% A description of each parameter follows:
7195%
7196% o image_info: the image info..
7197%
7198% o argc: Specifies a pointer to an integer describing the number of
7199% elements in the argument vector.
7200%
7201% o argv: Specifies a pointer to a text array containing the command line
7202% arguments.
7203%
anthonye9c27192011-03-27 08:07:06 +00007204% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007205%
7206% o exception: return any errors or warnings in this structure.
7207%
7208*/
7209WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7210 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7211{
cristy3ed852e2009-09-05 21:47:34 +00007212 const char
7213 *option;
7214
cristy6b3da3a2010-06-20 02:21:46 +00007215 ImageInfo
7216 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007217
7218 MagickStatusType
7219 status;
7220
cristy28474bf2011-09-11 23:32:52 +00007221 PixelInterpolateMethod
7222 interpolate_method;
7223
cristy3ed852e2009-09-05 21:47:34 +00007224 QuantizeInfo
7225 *quantize_info;
7226
cristybb503372010-05-27 20:51:26 +00007227 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007228 i;
7229
cristy6b3da3a2010-06-20 02:21:46 +00007230 ssize_t
7231 count,
7232 index;
7233
cristy3ed852e2009-09-05 21:47:34 +00007234 /*
7235 Apply options to the image list.
7236 */
7237 assert(image_info != (ImageInfo *) NULL);
7238 assert(image_info->signature == MagickSignature);
7239 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007240 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007241 assert((*images)->signature == MagickSignature);
7242 if ((*images)->debug != MagickFalse)
7243 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7244 (*images)->filename);
7245 if ((argc <= 0) || (*argv == (char *) NULL))
7246 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007247 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007248 mogrify_info=CloneImageInfo(image_info);
7249 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007250 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007251 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007252 {
cristy74fe8f12009-10-03 19:09:01 +00007253 if (*images == (Image *) NULL)
7254 break;
cristy3ed852e2009-09-05 21:47:34 +00007255 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007256 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007257 continue;
cristy042ee782011-04-22 18:48:30 +00007258 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007259 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007260 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007261 break;
cristy6b3da3a2010-06-20 02:21:46 +00007262 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007263 switch (*(option+1))
7264 {
7265 case 'a':
7266 {
7267 if (LocaleCompare("affinity",option+1) == 0)
7268 {
cristy6fccee12011-10-20 18:43:18 +00007269 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007270 if (*option == '+')
7271 {
cristy018f07f2011-09-04 21:15:19 +00007272 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7273 exception);
cristy3ed852e2009-09-05 21:47:34 +00007274 break;
7275 }
7276 i++;
7277 break;
7278 }
7279 if (LocaleCompare("append",option+1) == 0)
7280 {
7281 Image
7282 *append_image;
7283
cristy6fccee12011-10-20 18:43:18 +00007284 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007285 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7286 MagickFalse,exception);
7287 if (append_image == (Image *) NULL)
7288 {
7289 status=MagickFalse;
7290 break;
7291 }
7292 *images=DestroyImageList(*images);
7293 *images=append_image;
7294 break;
7295 }
7296 if (LocaleCompare("average",option+1) == 0)
7297 {
7298 Image
7299 *average_image;
7300
cristyd18ae7c2010-03-07 17:39:52 +00007301 /*
7302 Average an image sequence (deprecated).
7303 */
cristy6fccee12011-10-20 18:43:18 +00007304 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007305 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7306 exception);
cristy3ed852e2009-09-05 21:47:34 +00007307 if (average_image == (Image *) NULL)
7308 {
7309 status=MagickFalse;
7310 break;
7311 }
7312 *images=DestroyImageList(*images);
7313 *images=average_image;
7314 break;
7315 }
7316 break;
7317 }
7318 case 'c':
7319 {
7320 if (LocaleCompare("channel",option+1) == 0)
7321 {
cristyf4ad9df2011-07-08 16:49:03 +00007322 ChannelType
7323 channel;
7324
cristy3ed852e2009-09-05 21:47:34 +00007325 if (*option == '+')
7326 {
7327 channel=DefaultChannels;
7328 break;
7329 }
7330 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00007331 SetPixelChannelMapMask(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007332 break;
7333 }
7334 if (LocaleCompare("clut",option+1) == 0)
7335 {
7336 Image
7337 *clut_image,
7338 *image;
7339
cristy6fccee12011-10-20 18:43:18 +00007340 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007341 image=RemoveFirstImageFromList(images);
7342 clut_image=RemoveFirstImageFromList(images);
7343 if (clut_image == (Image *) NULL)
7344 {
7345 status=MagickFalse;
7346 break;
7347 }
cristy28474bf2011-09-11 23:32:52 +00007348 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007349 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007350 *images=DestroyImageList(*images);
7351 *images=image;
7352 break;
7353 }
7354 if (LocaleCompare("coalesce",option+1) == 0)
7355 {
7356 Image
7357 *coalesce_image;
7358
cristy6fccee12011-10-20 18:43:18 +00007359 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007360 coalesce_image=CoalesceImages(*images,exception);
7361 if (coalesce_image == (Image *) NULL)
7362 {
7363 status=MagickFalse;
7364 break;
7365 }
7366 *images=DestroyImageList(*images);
7367 *images=coalesce_image;
7368 break;
7369 }
7370 if (LocaleCompare("combine",option+1) == 0)
7371 {
7372 Image
7373 *combine_image;
7374
cristy6fccee12011-10-20 18:43:18 +00007375 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007376 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007377 if (combine_image == (Image *) NULL)
7378 {
7379 status=MagickFalse;
7380 break;
7381 }
7382 *images=DestroyImageList(*images);
7383 *images=combine_image;
7384 break;
7385 }
7386 if (LocaleCompare("composite",option+1) == 0)
7387 {
7388 Image
7389 *mask_image,
7390 *composite_image,
7391 *image;
7392
7393 RectangleInfo
7394 geometry;
7395
cristy6fccee12011-10-20 18:43:18 +00007396 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007397 image=RemoveFirstImageFromList(images);
7398 composite_image=RemoveFirstImageFromList(images);
7399 if (composite_image == (Image *) NULL)
7400 {
7401 status=MagickFalse;
7402 break;
7403 }
7404 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007405 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007406 SetGeometry(composite_image,&geometry);
7407 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7408 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7409 &geometry);
7410 mask_image=RemoveFirstImageFromList(images);
7411 if (mask_image != (Image *) NULL)
7412 {
7413 if ((image->compose == DisplaceCompositeOp) ||
7414 (image->compose == DistortCompositeOp))
7415 {
7416 /*
7417 Merge Y displacement into X displacement image.
7418 */
7419 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007420 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007421 mask_image=DestroyImage(mask_image);
7422 }
7423 else
7424 {
7425 /*
anthony80c37752012-01-16 01:03:11 +00007426 Set a blending mask for the composition.
7427 Possible problem, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007428 */
cristy10a6c612012-01-29 21:41:05 +00007429 (void) NegateImage(mask_image,MagickFalse,exception);
7430 (void) SetImageMask(image,mask_image,exception);
7431 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00007432 }
7433 }
cristyf4ad9df2011-07-08 16:49:03 +00007434 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007435 geometry.x,geometry.y,exception);
cristy10a6c612012-01-29 21:41:05 +00007436 (void) SetImageMask(image,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00007437 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007438 *images=DestroyImageList(*images);
7439 *images=image;
7440 break;
7441 }
cristy3ed852e2009-09-05 21:47:34 +00007442 break;
7443 }
7444 case 'd':
7445 {
7446 if (LocaleCompare("deconstruct",option+1) == 0)
7447 {
7448 Image
7449 *deconstruct_image;
7450
cristy6fccee12011-10-20 18:43:18 +00007451 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007452 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007453 exception);
cristy3ed852e2009-09-05 21:47:34 +00007454 if (deconstruct_image == (Image *) NULL)
7455 {
7456 status=MagickFalse;
7457 break;
7458 }
7459 *images=DestroyImageList(*images);
7460 *images=deconstruct_image;
7461 break;
7462 }
7463 if (LocaleCompare("delete",option+1) == 0)
7464 {
7465 if (*option == '+')
7466 DeleteImages(images,"-1",exception);
7467 else
7468 DeleteImages(images,argv[i+1],exception);
7469 break;
7470 }
7471 if (LocaleCompare("dither",option+1) == 0)
7472 {
7473 if (*option == '+')
7474 {
7475 quantize_info->dither=MagickFalse;
7476 break;
7477 }
7478 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007479 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007480 MagickDitherOptions,MagickFalse,argv[i+1]);
7481 break;
7482 }
cristyecb10ff2011-03-22 13:14:03 +00007483 if (LocaleCompare("duplicate",option+1) == 0)
7484 {
cristy72988482011-03-29 16:34:38 +00007485 Image
7486 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007487
anthony2b6bcae2011-03-23 13:05:34 +00007488 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007489 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7490 else
7491 {
7492 const char
7493 *p;
7494
anthony2b6bcae2011-03-23 13:05:34 +00007495 size_t
7496 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007497
anthony2b6bcae2011-03-23 13:05:34 +00007498 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007499 p=strchr(argv[i+1],',');
7500 if (p == (const char *) NULL)
7501 duplicate_images=DuplicateImages(*images,number_duplicates,
7502 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007503 else
cristy72988482011-03-29 16:34:38 +00007504 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7505 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007506 }
7507 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007508 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007509 break;
7510 }
cristy3ed852e2009-09-05 21:47:34 +00007511 break;
7512 }
cristyd18ae7c2010-03-07 17:39:52 +00007513 case 'e':
7514 {
7515 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7516 {
7517 Image
7518 *evaluate_image;
7519
7520 MagickEvaluateOperator
7521 op;
7522
cristy6fccee12011-10-20 18:43:18 +00007523 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007524 op=(MagickEvaluateOperator) ParseCommandOption(
7525 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007526 evaluate_image=EvaluateImages(*images,op,exception);
7527 if (evaluate_image == (Image *) NULL)
7528 {
7529 status=MagickFalse;
7530 break;
7531 }
7532 *images=DestroyImageList(*images);
7533 *images=evaluate_image;
7534 break;
7535 }
7536 break;
7537 }
cristy3ed852e2009-09-05 21:47:34 +00007538 case 'f':
7539 {
cristyf0a247f2009-10-04 00:20:03 +00007540 if (LocaleCompare("fft",option+1) == 0)
7541 {
7542 Image
7543 *fourier_image;
7544
7545 /*
7546 Implements the discrete Fourier transform (DFT).
7547 */
cristy6fccee12011-10-20 18:43:18 +00007548 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007549 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7550 MagickTrue : MagickFalse,exception);
7551 if (fourier_image == (Image *) NULL)
7552 break;
7553 *images=DestroyImage(*images);
7554 *images=fourier_image;
7555 break;
7556 }
cristy3ed852e2009-09-05 21:47:34 +00007557 if (LocaleCompare("flatten",option+1) == 0)
7558 {
7559 Image
7560 *flatten_image;
7561
cristy6fccee12011-10-20 18:43:18 +00007562 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007563 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7564 if (flatten_image == (Image *) NULL)
7565 break;
7566 *images=DestroyImageList(*images);
7567 *images=flatten_image;
7568 break;
7569 }
7570 if (LocaleCompare("fx",option+1) == 0)
7571 {
7572 Image
7573 *fx_image;
7574
cristy6fccee12011-10-20 18:43:18 +00007575 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007576 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007577 if (fx_image == (Image *) NULL)
7578 {
7579 status=MagickFalse;
7580 break;
7581 }
7582 *images=DestroyImageList(*images);
7583 *images=fx_image;
7584 break;
7585 }
7586 break;
7587 }
7588 case 'h':
7589 {
7590 if (LocaleCompare("hald-clut",option+1) == 0)
7591 {
7592 Image
7593 *hald_image,
7594 *image;
7595
cristy6fccee12011-10-20 18:43:18 +00007596 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007597 image=RemoveFirstImageFromList(images);
7598 hald_image=RemoveFirstImageFromList(images);
7599 if (hald_image == (Image *) NULL)
7600 {
7601 status=MagickFalse;
7602 break;
7603 }
cristy7c0a0a42011-08-23 17:57:25 +00007604 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007605 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007606 if (*images != (Image *) NULL)
7607 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007608 *images=image;
7609 break;
7610 }
7611 break;
7612 }
7613 case 'i':
7614 {
7615 if (LocaleCompare("ift",option+1) == 0)
7616 {
7617 Image
cristy8587f882009-11-13 20:28:49 +00007618 *fourier_image,
7619 *magnitude_image,
7620 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007621
7622 /*
7623 Implements the inverse fourier discrete Fourier transform (DFT).
7624 */
cristy6fccee12011-10-20 18:43:18 +00007625 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007626 magnitude_image=RemoveFirstImageFromList(images);
7627 phase_image=RemoveFirstImageFromList(images);
7628 if (phase_image == (Image *) NULL)
7629 {
7630 status=MagickFalse;
7631 break;
7632 }
7633 fourier_image=InverseFourierTransformImage(magnitude_image,
7634 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007635 if (fourier_image == (Image *) NULL)
7636 break;
cristy0aff6ea2009-11-14 01:40:53 +00007637 if (*images != (Image *) NULL)
7638 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007639 *images=fourier_image;
7640 break;
7641 }
7642 if (LocaleCompare("insert",option+1) == 0)
7643 {
7644 Image
7645 *p,
7646 *q;
7647
7648 index=0;
7649 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007650 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007651 p=RemoveLastImageFromList(images);
7652 if (p == (Image *) NULL)
7653 {
7654 (void) ThrowMagickException(exception,GetMagickModule(),
7655 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7656 status=MagickFalse;
7657 break;
7658 }
7659 q=p;
7660 if (index == 0)
7661 PrependImageToList(images,q);
7662 else
cristybb503372010-05-27 20:51:26 +00007663 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007664 AppendImageToList(images,q);
7665 else
7666 {
7667 q=GetImageFromList(*images,index-1);
7668 if (q == (Image *) NULL)
7669 {
7670 (void) ThrowMagickException(exception,GetMagickModule(),
7671 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7672 status=MagickFalse;
7673 break;
7674 }
7675 InsertImageInList(&q,p);
7676 }
7677 *images=GetFirstImageInList(q);
7678 break;
7679 }
cristy28474bf2011-09-11 23:32:52 +00007680 if (LocaleCompare("interpolate",option+1) == 0)
7681 {
7682 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7683 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7684 break;
7685 }
cristy3ed852e2009-09-05 21:47:34 +00007686 break;
7687 }
7688 case 'l':
7689 {
7690 if (LocaleCompare("layers",option+1) == 0)
7691 {
7692 Image
7693 *layers;
7694
7695 ImageLayerMethod
7696 method;
7697
cristy6fccee12011-10-20 18:43:18 +00007698 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007699 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007700 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007701 MagickFalse,argv[i+1]);
7702 switch (method)
7703 {
7704 case CoalesceLayer:
7705 {
7706 layers=CoalesceImages(*images,exception);
7707 break;
7708 }
7709 case CompareAnyLayer:
7710 case CompareClearLayer:
7711 case CompareOverlayLayer:
7712 default:
7713 {
cristy8a9106f2011-07-05 14:39:26 +00007714 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007715 break;
7716 }
7717 case MergeLayer:
7718 case FlattenLayer:
7719 case MosaicLayer:
7720 case TrimBoundsLayer:
7721 {
7722 layers=MergeImageLayers(*images,method,exception);
7723 break;
7724 }
7725 case DisposeLayer:
7726 {
7727 layers=DisposeImages(*images,exception);
7728 break;
7729 }
7730 case OptimizeImageLayer:
7731 {
7732 layers=OptimizeImageLayers(*images,exception);
7733 break;
7734 }
7735 case OptimizePlusLayer:
7736 {
7737 layers=OptimizePlusImageLayers(*images,exception);
7738 break;
7739 }
7740 case OptimizeTransLayer:
7741 {
7742 OptimizeImageTransparency(*images,exception);
7743 break;
7744 }
7745 case RemoveDupsLayer:
7746 {
7747 RemoveDuplicateLayers(images,exception);
7748 break;
7749 }
7750 case RemoveZeroLayer:
7751 {
7752 RemoveZeroDelayLayers(images,exception);
7753 break;
7754 }
7755 case OptimizeLayer:
7756 {
7757 /*
7758 General Purpose, GIF Animation Optimizer.
7759 */
7760 layers=CoalesceImages(*images,exception);
7761 if (layers == (Image *) NULL)
7762 {
7763 status=MagickFalse;
7764 break;
7765 }
cristy3ed852e2009-09-05 21:47:34 +00007766 *images=DestroyImageList(*images);
7767 *images=layers;
7768 layers=OptimizeImageLayers(*images,exception);
7769 if (layers == (Image *) NULL)
7770 {
7771 status=MagickFalse;
7772 break;
7773 }
cristy3ed852e2009-09-05 21:47:34 +00007774 *images=DestroyImageList(*images);
7775 *images=layers;
7776 layers=(Image *) NULL;
7777 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007778 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7779 exception);
cristy3ed852e2009-09-05 21:47:34 +00007780 break;
7781 }
7782 case CompositeLayer:
7783 {
7784 CompositeOperator
7785 compose;
7786
7787 Image
7788 *source;
7789
7790 RectangleInfo
7791 geometry;
7792
7793 /*
7794 Split image sequence at the first 'NULL:' image.
7795 */
7796 source=(*images);
7797 while (source != (Image *) NULL)
7798 {
7799 source=GetNextImageInList(source);
7800 if ((source != (Image *) NULL) &&
7801 (LocaleCompare(source->magick,"NULL") == 0))
7802 break;
7803 }
7804 if (source != (Image *) NULL)
7805 {
7806 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7807 (GetNextImageInList(source) == (Image *) NULL))
7808 source=(Image *) NULL;
7809 else
7810 {
7811 /*
7812 Separate the two lists, junk the null: image.
7813 */
7814 source=SplitImageList(source->previous);
7815 DeleteImageFromList(&source);
7816 }
7817 }
7818 if (source == (Image *) NULL)
7819 {
7820 (void) ThrowMagickException(exception,GetMagickModule(),
7821 OptionError,"MissingNullSeparator","layers Composite");
7822 status=MagickFalse;
7823 break;
7824 }
7825 /*
7826 Adjust offset with gravity and virtual canvas.
7827 */
7828 SetGeometry(*images,&geometry);
7829 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7830 geometry.width=source->page.width != 0 ?
7831 source->page.width : source->columns;
7832 geometry.height=source->page.height != 0 ?
7833 source->page.height : source->rows;
7834 GravityAdjustGeometry((*images)->page.width != 0 ?
7835 (*images)->page.width : (*images)->columns,
7836 (*images)->page.height != 0 ? (*images)->page.height :
7837 (*images)->rows,(*images)->gravity,&geometry);
7838 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007839 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007840 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007841 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007842 MagickComposeOptions,MagickFalse,option);
7843 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7844 exception);
7845 source=DestroyImageList(source);
7846 break;
7847 }
7848 }
7849 if (layers == (Image *) NULL)
7850 break;
cristy3ed852e2009-09-05 21:47:34 +00007851 *images=DestroyImageList(*images);
7852 *images=layers;
7853 break;
7854 }
7855 break;
7856 }
7857 case 'm':
7858 {
7859 if (LocaleCompare("map",option+1) == 0)
7860 {
cristy6fccee12011-10-20 18:43:18 +00007861 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007862 if (*option == '+')
7863 {
cristy018f07f2011-09-04 21:15:19 +00007864 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7865 exception);
cristy3ed852e2009-09-05 21:47:34 +00007866 break;
7867 }
7868 i++;
7869 break;
7870 }
cristyf40785b2010-03-06 02:27:27 +00007871 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007872 {
7873 Image
cristyf40785b2010-03-06 02:27:27 +00007874 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007875
cristyd18ae7c2010-03-07 17:39:52 +00007876 /*
7877 Maximum image sequence (deprecated).
7878 */
cristy6fccee12011-10-20 18:43:18 +00007879 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007880 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007881 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007882 {
7883 status=MagickFalse;
7884 break;
7885 }
7886 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007887 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007888 break;
7889 }
cristyf40785b2010-03-06 02:27:27 +00007890 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007891 {
7892 Image
cristyf40785b2010-03-06 02:27:27 +00007893 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007894
cristyd18ae7c2010-03-07 17:39:52 +00007895 /*
7896 Minimum image sequence (deprecated).
7897 */
cristy6fccee12011-10-20 18:43:18 +00007898 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007899 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007900 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007901 {
7902 status=MagickFalse;
7903 break;
7904 }
7905 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007906 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007907 break;
7908 }
cristy3ed852e2009-09-05 21:47:34 +00007909 if (LocaleCompare("morph",option+1) == 0)
7910 {
7911 Image
7912 *morph_image;
7913
cristy6fccee12011-10-20 18:43:18 +00007914 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007915 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007916 exception);
7917 if (morph_image == (Image *) NULL)
7918 {
7919 status=MagickFalse;
7920 break;
7921 }
7922 *images=DestroyImageList(*images);
7923 *images=morph_image;
7924 break;
7925 }
7926 if (LocaleCompare("mosaic",option+1) == 0)
7927 {
7928 Image
7929 *mosaic_image;
7930
cristy6fccee12011-10-20 18:43:18 +00007931 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007932 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7933 if (mosaic_image == (Image *) NULL)
7934 {
7935 status=MagickFalse;
7936 break;
7937 }
7938 *images=DestroyImageList(*images);
7939 *images=mosaic_image;
7940 break;
7941 }
7942 break;
7943 }
7944 case 'p':
7945 {
7946 if (LocaleCompare("print",option+1) == 0)
7947 {
7948 char
7949 *string;
7950
cristy6fccee12011-10-20 18:43:18 +00007951 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007952 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7953 exception);
cristy3ed852e2009-09-05 21:47:34 +00007954 if (string == (char *) NULL)
7955 break;
cristyb51dff52011-05-19 16:55:47 +00007956 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007957 string=DestroyString(string);
7958 }
7959 if (LocaleCompare("process",option+1) == 0)
7960 {
7961 char
7962 **arguments;
7963
7964 int
7965 j,
7966 number_arguments;
7967
cristy6fccee12011-10-20 18:43:18 +00007968 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007969 arguments=StringToArgv(argv[i+1],&number_arguments);
7970 if (arguments == (char **) NULL)
7971 break;
7972 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7973 {
7974 char
7975 breaker,
7976 quote,
7977 *token;
7978
7979 const char
7980 *arguments;
7981
7982 int
7983 next,
7984 status;
7985
7986 size_t
7987 length;
7988
7989 TokenInfo
7990 *token_info;
7991
7992 /*
7993 Support old style syntax, filter="-option arg".
7994 */
7995 length=strlen(argv[i+1]);
7996 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00007997 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00007998 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
7999 sizeof(*token));
8000 if (token == (char *) NULL)
8001 break;
8002 next=0;
8003 arguments=argv[i+1];
8004 token_info=AcquireTokenInfo();
8005 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8006 "\"",'\0',&breaker,&next,&quote);
8007 token_info=DestroyTokenInfo(token_info);
8008 if (status == 0)
8009 {
8010 const char
8011 *argv;
8012
8013 argv=(&(arguments[next]));
8014 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8015 exception);
8016 }
8017 token=DestroyString(token);
8018 break;
8019 }
cristy91c0da22010-05-02 01:44:07 +00008020 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008021 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8022 number_arguments-2,(const char **) arguments+2,exception);
8023 for (j=0; j < number_arguments; j++)
8024 arguments[j]=DestroyString(arguments[j]);
8025 arguments=(char **) RelinquishMagickMemory(arguments);
8026 break;
8027 }
8028 break;
8029 }
8030 case 'r':
8031 {
8032 if (LocaleCompare("reverse",option+1) == 0)
8033 {
8034 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008035 break;
8036 }
8037 break;
8038 }
8039 case 's':
8040 {
cristy4285d782011-02-09 20:12:28 +00008041 if (LocaleCompare("smush",option+1) == 0)
8042 {
8043 Image
8044 *smush_image;
8045
8046 ssize_t
8047 offset;
8048
cristy6fccee12011-10-20 18:43:18 +00008049 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008050 offset=(ssize_t) StringToLong(argv[i+1]);
8051 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8052 MagickFalse,offset,exception);
8053 if (smush_image == (Image *) NULL)
8054 {
8055 status=MagickFalse;
8056 break;
8057 }
8058 *images=DestroyImageList(*images);
8059 *images=smush_image;
8060 break;
8061 }
cristy3ed852e2009-09-05 21:47:34 +00008062 if (LocaleCompare("swap",option+1) == 0)
8063 {
8064 Image
8065 *p,
8066 *q,
8067 *swap;
8068
cristybb503372010-05-27 20:51:26 +00008069 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008070 swap_index;
8071
8072 index=(-1);
8073 swap_index=(-2);
8074 if (*option != '+')
8075 {
8076 GeometryInfo
8077 geometry_info;
8078
8079 MagickStatusType
8080 flags;
8081
8082 swap_index=(-1);
8083 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008084 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008085 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008086 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008087 }
8088 p=GetImageFromList(*images,index);
8089 q=GetImageFromList(*images,swap_index);
8090 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8091 {
8092 (void) ThrowMagickException(exception,GetMagickModule(),
8093 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8094 status=MagickFalse;
8095 break;
8096 }
8097 if (p == q)
8098 break;
8099 swap=CloneImage(p,0,0,MagickTrue,exception);
8100 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8101 ReplaceImageInList(&q,swap);
8102 *images=GetFirstImageInList(q);
8103 break;
8104 }
8105 break;
8106 }
8107 case 'w':
8108 {
8109 if (LocaleCompare("write",option+1) == 0)
8110 {
cristy071dd7b2010-04-09 13:04:54 +00008111 char
cristy06609ee2010-03-17 20:21:27 +00008112 key[MaxTextExtent];
8113
cristy3ed852e2009-09-05 21:47:34 +00008114 Image
8115 *write_images;
8116
8117 ImageInfo
8118 *write_info;
8119
cristy6fccee12011-10-20 18:43:18 +00008120 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008121 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008122 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008123 write_images=(*images);
8124 if (*option == '+')
8125 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008126 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008127 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8128 write_info=DestroyImageInfo(write_info);
8129 if (*option == '+')
8130 write_images=DestroyImageList(write_images);
8131 break;
8132 }
8133 break;
8134 }
8135 default:
8136 break;
8137 }
8138 i+=count;
8139 }
8140 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008141 mogrify_info=DestroyImageInfo(mogrify_info);
8142 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008143 return(status != 0 ? MagickTrue : MagickFalse);
8144}
8145
8146/*
8147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8148% %
8149% %
8150% %
8151+ M o g r i f y I m a g e s %
8152% %
8153% %
8154% %
8155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8156%
8157% MogrifyImages() applies image processing options to a sequence of images as
8158% prescribed by command line options.
8159%
8160% The format of the MogrifyImage method is:
8161%
8162% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8163% const MagickBooleanType post,const int argc,const char **argv,
8164% Image **images,Exceptioninfo *exception)
8165%
8166% A description of each parameter follows:
8167%
8168% o image_info: the image info..
8169%
8170% o post: If true, post process image list operators otherwise pre-process.
8171%
8172% o argc: Specifies a pointer to an integer describing the number of
8173% elements in the argument vector.
8174%
8175% o argv: Specifies a pointer to a text array containing the command line
8176% arguments.
8177%
anthonye9c27192011-03-27 08:07:06 +00008178% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008179%
8180% o exception: return any errors or warnings in this structure.
8181%
8182*/
8183WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8184 const MagickBooleanType post,const int argc,const char **argv,
8185 Image **images,ExceptionInfo *exception)
8186{
8187#define MogrifyImageTag "Mogrify/Image"
8188
anthonye9c27192011-03-27 08:07:06 +00008189 MagickStatusType
8190 status;
cristy3ed852e2009-09-05 21:47:34 +00008191
cristy0e9f9c12010-02-11 03:00:47 +00008192 MagickBooleanType
8193 proceed;
8194
anthonye9c27192011-03-27 08:07:06 +00008195 size_t
8196 n;
cristy3ed852e2009-09-05 21:47:34 +00008197
cristybb503372010-05-27 20:51:26 +00008198 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008199 i;
8200
cristy3ed852e2009-09-05 21:47:34 +00008201 assert(image_info != (ImageInfo *) NULL);
8202 assert(image_info->signature == MagickSignature);
8203 if (images == (Image **) NULL)
8204 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008205 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008206 assert((*images)->signature == MagickSignature);
8207 if ((*images)->debug != MagickFalse)
8208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8209 (*images)->filename);
8210 if ((argc <= 0) || (*argv == (char *) NULL))
8211 return(MagickTrue);
8212 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8213 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008214 status=0;
anthonye9c27192011-03-27 08:07:06 +00008215
anthonyce2716b2011-04-22 09:51:34 +00008216#if 0
cristy1e604812011-05-19 18:07:50 +00008217 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8218 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008219#endif
8220
anthonye9c27192011-03-27 08:07:06 +00008221 /*
8222 Pre-process multi-image sequence operators
8223 */
cristy3ed852e2009-09-05 21:47:34 +00008224 if (post == MagickFalse)
8225 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008226 /*
8227 For each image, process simple single image operators
8228 */
8229 i=0;
8230 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008231 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008232 {
anthonyce2716b2011-04-22 09:51:34 +00008233#if 0
cristy1e604812011-05-19 18:07:50 +00008234 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8235 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008236#endif
anthonye9c27192011-03-27 08:07:06 +00008237 status&=MogrifyImage(image_info,argc,argv,images,exception);
8238 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008239 if (proceed == MagickFalse)
8240 break;
anthonye9c27192011-03-27 08:07:06 +00008241 if ( (*images)->next == (Image *) NULL )
8242 break;
8243 *images=(*images)->next;
8244 i++;
cristy3ed852e2009-09-05 21:47:34 +00008245 }
anthonye9c27192011-03-27 08:07:06 +00008246 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008247#if 0
cristy1e604812011-05-19 18:07:50 +00008248 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8249 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008250#endif
anthonye9c27192011-03-27 08:07:06 +00008251
8252 /*
8253 Post-process, multi-image sequence operators
8254 */
8255 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008256 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008257 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008258 return(status != 0 ? MagickTrue : MagickFalse);
8259}