blob: 5ce1e1675e04eda04f0bfec9c4b6354d1d36611c [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{
anthonydf8ebac2011-04-27 09:03:19 +0000650 ChannelType
651 channel;
652
cristy633f0c62011-09-15 13:27:36 +0000653 CompositeOperator
654 compose;
655
anthonydf8ebac2011-04-27 09:03:19 +0000656 const char
657 *format,
658 *option;
659
cristy9ed1f812011-10-08 02:00:08 +0000660 double
661 attenuate;
662
anthonydf8ebac2011-04-27 09:03:19 +0000663 DrawInfo
664 *draw_info;
665
666 GeometryInfo
667 geometry_info;
668
cristy3ed852e2009-09-05 21:47:34 +0000669 Image
670 *region_image;
671
anthonydf8ebac2011-04-27 09:03:19 +0000672 ImageInfo
673 *mogrify_info;
674
cristyebbcfea2011-02-25 02:43:54 +0000675 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000676 status;
677
cristy4c08aed2011-07-01 19:47:50 +0000678 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000679 fill;
cristy3ed852e2009-09-05 21:47:34 +0000680
anthonydf8ebac2011-04-27 09:03:19 +0000681 MagickStatusType
682 flags;
683
cristy28474bf2011-09-11 23:32:52 +0000684 PixelInterpolateMethod
685 interpolate_method;
686
anthonydf8ebac2011-04-27 09:03:19 +0000687 QuantizeInfo
688 *quantize_info;
689
690 RectangleInfo
691 geometry,
692 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000693
cristybb503372010-05-27 20:51:26 +0000694 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000695 i;
696
697 /*
698 Initialize method variables.
699 */
700 assert(image_info != (const ImageInfo *) NULL);
701 assert(image_info->signature == MagickSignature);
702 assert(image != (Image **) NULL);
703 assert((*image)->signature == MagickSignature);
704 if ((*image)->debug != MagickFalse)
705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
706 if (argc < 0)
707 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000708 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000709 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
710 quantize_info=AcquireQuantizeInfo(mogrify_info);
711 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000712 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000713 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000714 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000715 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000716 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000717 channel=mogrify_info->channel;
718 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000719 SetGeometry(*image,&region_geometry);
720 region_image=NewImageList();
721 /*
722 Transmogrify the image.
723 */
cristybb503372010-05-27 20:51:26 +0000724 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000725 {
anthonydf8ebac2011-04-27 09:03:19 +0000726 Image
727 *mogrify_image;
728
anthonye9c27192011-03-27 08:07:06 +0000729 ssize_t
730 count;
731
anthonydf8ebac2011-04-27 09:03:19 +0000732 option=argv[i];
733 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000734 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000735 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
736 0L);
cristycee97112010-05-28 00:44:52 +0000737 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000738 break;
cristy6b3da3a2010-06-20 02:21:46 +0000739 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000740 mogrify_image=(Image *)NULL;
741 switch (*(option+1))
742 {
743 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000744 {
anthonydf8ebac2011-04-27 09:03:19 +0000745 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000746 {
anthonydf8ebac2011-04-27 09:03:19 +0000747 /*
748 Adaptive blur image.
749 */
cristy6fccee12011-10-20 18:43:18 +0000750 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000751 flags=ParseGeometry(argv[i+1],&geometry_info);
752 if ((flags & SigmaValue) == 0)
753 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000754 if ((flags & XiValue) == 0)
755 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000756 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000757 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000758 break;
cristy3ed852e2009-09-05 21:47:34 +0000759 }
anthonydf8ebac2011-04-27 09:03:19 +0000760 if (LocaleCompare("adaptive-resize",option+1) == 0)
761 {
762 /*
763 Adaptive resize image.
764 */
cristy6fccee12011-10-20 18:43:18 +0000765 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000766 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
767 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000768 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000769 break;
770 }
771 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
772 {
773 /*
774 Adaptive sharpen image.
775 */
cristy6fccee12011-10-20 18:43:18 +0000776 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000777 flags=ParseGeometry(argv[i+1],&geometry_info);
778 if ((flags & SigmaValue) == 0)
779 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000780 if ((flags & XiValue) == 0)
781 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000782 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000783 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000784 break;
785 }
786 if (LocaleCompare("affine",option+1) == 0)
787 {
788 /*
789 Affine matrix.
790 */
791 if (*option == '+')
792 {
793 GetAffineMatrix(&draw_info->affine);
794 break;
795 }
796 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
797 break;
798 }
799 if (LocaleCompare("alpha",option+1) == 0)
800 {
801 AlphaChannelType
802 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000803
cristy6fccee12011-10-20 18:43:18 +0000804 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000805 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
806 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000807 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000808 break;
809 }
810 if (LocaleCompare("annotate",option+1) == 0)
811 {
812 char
813 *text,
814 geometry[MaxTextExtent];
815
816 /*
817 Annotate image.
818 */
cristy6fccee12011-10-20 18:43:18 +0000819 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000820 SetGeometryInfo(&geometry_info);
821 flags=ParseGeometry(argv[i+1],&geometry_info);
822 if ((flags & SigmaValue) == 0)
823 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000824 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
825 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000826 if (text == (char *) NULL)
827 break;
828 (void) CloneString(&draw_info->text,text);
829 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000830 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000831 geometry_info.xi,geometry_info.psi);
832 (void) CloneString(&draw_info->geometry,geometry);
833 draw_info->affine.sx=cos(DegreesToRadians(
834 fmod(geometry_info.rho,360.0)));
835 draw_info->affine.rx=sin(DegreesToRadians(
836 fmod(geometry_info.rho,360.0)));
837 draw_info->affine.ry=(-sin(DegreesToRadians(
838 fmod(geometry_info.sigma,360.0))));
839 draw_info->affine.sy=cos(DegreesToRadians(
840 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000841 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000842 break;
843 }
844 if (LocaleCompare("antialias",option+1) == 0)
845 {
846 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
847 MagickFalse;
848 draw_info->text_antialias=(*option == '-') ? MagickTrue :
849 MagickFalse;
850 break;
851 }
cristy9ed1f812011-10-08 02:00:08 +0000852 if (LocaleCompare("attenuate",option+1) == 0)
853 {
854 if (*option == '+')
855 {
856 attenuate=1.0;
857 break;
858 }
cristydbdd0e32011-11-04 23:29:40 +0000859 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000860 break;
861 }
anthonydf8ebac2011-04-27 09:03:19 +0000862 if (LocaleCompare("auto-gamma",option+1) == 0)
863 {
864 /*
865 Auto Adjust Gamma of image based on its mean
866 */
cristy6fccee12011-10-20 18:43:18 +0000867 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000868 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000869 break;
870 }
871 if (LocaleCompare("auto-level",option+1) == 0)
872 {
873 /*
874 Perfectly Normalize (max/min stretch) the image
875 */
cristy6fccee12011-10-20 18:43:18 +0000876 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000877 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000878 break;
879 }
880 if (LocaleCompare("auto-orient",option+1) == 0)
881 {
cristy6fccee12011-10-20 18:43:18 +0000882 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000883 switch ((*image)->orientation)
884 {
885 case TopRightOrientation:
886 {
887 mogrify_image=FlopImage(*image,exception);
888 break;
889 }
890 case BottomRightOrientation:
891 {
892 mogrify_image=RotateImage(*image,180.0,exception);
893 break;
894 }
895 case BottomLeftOrientation:
896 {
897 mogrify_image=FlipImage(*image,exception);
898 break;
899 }
900 case LeftTopOrientation:
901 {
902 mogrify_image=TransposeImage(*image,exception);
903 break;
904 }
905 case RightTopOrientation:
906 {
907 mogrify_image=RotateImage(*image,90.0,exception);
908 break;
909 }
910 case RightBottomOrientation:
911 {
912 mogrify_image=TransverseImage(*image,exception);
913 break;
914 }
915 case LeftBottomOrientation:
916 {
917 mogrify_image=RotateImage(*image,270.0,exception);
918 break;
919 }
920 default:
921 break;
922 }
923 if (mogrify_image != (Image *) NULL)
924 mogrify_image->orientation=TopLeftOrientation;
925 break;
926 }
927 break;
928 }
929 case 'b':
930 {
931 if (LocaleCompare("black-threshold",option+1) == 0)
932 {
933 /*
934 Black threshold image.
935 */
cristy6fccee12011-10-20 18:43:18 +0000936 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000937 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000938 break;
939 }
940 if (LocaleCompare("blue-shift",option+1) == 0)
941 {
942 /*
943 Blue shift image.
944 */
cristy6fccee12011-10-20 18:43:18 +0000945 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000946 geometry_info.rho=1.5;
947 if (*option == '-')
948 flags=ParseGeometry(argv[i+1],&geometry_info);
949 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
950 break;
951 }
952 if (LocaleCompare("blur",option+1) == 0)
953 {
954 /*
955 Gaussian blur image.
956 */
cristy6fccee12011-10-20 18:43:18 +0000957 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000958 flags=ParseGeometry(argv[i+1],&geometry_info);
959 if ((flags & SigmaValue) == 0)
960 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000961 if ((flags & XiValue) == 0)
962 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000963 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000964 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000965 break;
966 }
967 if (LocaleCompare("border",option+1) == 0)
968 {
969 /*
970 Surround image with a border of solid color.
971 */
cristy6fccee12011-10-20 18:43:18 +0000972 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000973 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
974 if ((flags & SigmaValue) == 0)
975 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000976 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000977 break;
978 }
979 if (LocaleCompare("bordercolor",option+1) == 0)
980 {
981 if (*option == '+')
982 {
cristy9950d572011-10-01 18:22:35 +0000983 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000984 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000985 break;
986 }
cristy9950d572011-10-01 18:22:35 +0000987 (void) QueryColorCompliance(argv[i+1],AllCompliance,
988 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000989 break;
990 }
991 if (LocaleCompare("box",option+1) == 0)
992 {
cristy9950d572011-10-01 18:22:35 +0000993 (void) QueryColorCompliance(argv[i+1],AllCompliance,
994 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000995 break;
996 }
997 if (LocaleCompare("brightness-contrast",option+1) == 0)
998 {
999 double
1000 brightness,
1001 contrast;
1002
1003 GeometryInfo
1004 geometry_info;
1005
1006 MagickStatusType
1007 flags;
1008
1009 /*
1010 Brightness / contrast image.
1011 */
cristy6fccee12011-10-20 18:43:18 +00001012 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001013 flags=ParseGeometry(argv[i+1],&geometry_info);
1014 brightness=geometry_info.rho;
1015 contrast=0.0;
1016 if ((flags & SigmaValue) != 0)
1017 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001018 (void) BrightnessContrastImage(*image,brightness,contrast,
1019 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001020 break;
1021 }
1022 break;
1023 }
1024 case 'c':
1025 {
1026 if (LocaleCompare("cdl",option+1) == 0)
1027 {
1028 char
1029 *color_correction_collection;
1030
1031 /*
1032 Color correct with a color decision list.
1033 */
cristy6fccee12011-10-20 18:43:18 +00001034 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001035 color_correction_collection=FileToString(argv[i+1],~0,exception);
1036 if (color_correction_collection == (char *) NULL)
1037 break;
cristy1bfa9f02011-08-11 02:35:43 +00001038 (void) ColorDecisionListImage(*image,color_correction_collection,
1039 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001040 break;
1041 }
1042 if (LocaleCompare("channel",option+1) == 0)
1043 {
1044 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001045 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001046 else
cristyfa806a72011-07-04 02:06:13 +00001047 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00001048 SetPixelChannelMapMask(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001049 break;
1050 }
1051 if (LocaleCompare("charcoal",option+1) == 0)
1052 {
1053 /*
1054 Charcoal image.
1055 */
cristy6fccee12011-10-20 18:43:18 +00001056 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001057 flags=ParseGeometry(argv[i+1],&geometry_info);
1058 if ((flags & SigmaValue) == 0)
1059 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001060 if ((flags & XiValue) == 0)
1061 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001062 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001063 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001064 break;
1065 }
1066 if (LocaleCompare("chop",option+1) == 0)
1067 {
1068 /*
1069 Chop the image.
1070 */
cristy6fccee12011-10-20 18:43:18 +00001071 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001072 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1073 mogrify_image=ChopImage(*image,&geometry,exception);
1074 break;
1075 }
1076 if (LocaleCompare("clamp",option+1) == 0)
1077 {
1078 /*
1079 Clamp image.
1080 */
cristy6fccee12011-10-20 18:43:18 +00001081 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001082 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001083 break;
1084 }
1085 if (LocaleCompare("clip",option+1) == 0)
1086 {
cristy6fccee12011-10-20 18:43:18 +00001087 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001088 if (*option == '+')
1089 {
cristy018f07f2011-09-04 21:15:19 +00001090 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001091 break;
1092 }
cristy018f07f2011-09-04 21:15:19 +00001093 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001094 break;
1095 }
1096 if (LocaleCompare("clip-mask",option+1) == 0)
1097 {
1098 CacheView
1099 *mask_view;
1100
1101 Image
1102 *mask_image;
1103
cristy4c08aed2011-07-01 19:47:50 +00001104 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001105 *restrict q;
1106
1107 register ssize_t
1108 x;
1109
1110 ssize_t
1111 y;
1112
cristy6fccee12011-10-20 18:43:18 +00001113 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001114 if (*option == '+')
1115 {
1116 /*
1117 Remove a mask.
1118 */
cristy018f07f2011-09-04 21:15:19 +00001119 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001120 break;
1121 }
1122 /*
1123 Set the image mask.
1124 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1125 */
1126 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1127 if (mask_image == (Image *) NULL)
1128 break;
cristy574cc262011-08-05 01:23:58 +00001129 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001130 return(MagickFalse);
1131 mask_view=AcquireCacheView(mask_image);
1132 for (y=0; y < (ssize_t) mask_image->rows; y++)
1133 {
1134 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1135 exception);
cristyacd2ed22011-08-30 01:44:23 +00001136 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001137 break;
1138 for (x=0; x < (ssize_t) mask_image->columns; x++)
1139 {
1140 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001141 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1142 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1143 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1144 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001145 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001146 }
1147 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1148 break;
1149 }
1150 mask_view=DestroyCacheView(mask_view);
1151 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001152 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001153 break;
1154 }
1155 if (LocaleCompare("clip-path",option+1) == 0)
1156 {
cristy6fccee12011-10-20 18:43:18 +00001157 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001158 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001159 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001160 break;
1161 }
1162 if (LocaleCompare("colorize",option+1) == 0)
1163 {
1164 /*
1165 Colorize the image.
1166 */
cristy6fccee12011-10-20 18:43:18 +00001167 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001168 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001169 break;
1170 }
1171 if (LocaleCompare("color-matrix",option+1) == 0)
1172 {
1173 KernelInfo
1174 *kernel;
1175
cristy6fccee12011-10-20 18:43:18 +00001176 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001177 kernel=AcquireKernelInfo(argv[i+1]);
1178 if (kernel == (KernelInfo *) NULL)
1179 break;
1180 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1181 kernel=DestroyKernelInfo(kernel);
1182 break;
1183 }
1184 if (LocaleCompare("colors",option+1) == 0)
1185 {
1186 /*
1187 Reduce the number of colors in the image.
1188 */
cristy6fccee12011-10-20 18:43:18 +00001189 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001190 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1191 if (quantize_info->number_colors == 0)
1192 break;
1193 if (((*image)->storage_class == DirectClass) ||
1194 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001195 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001196 else
cristy018f07f2011-09-04 21:15:19 +00001197 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001198 break;
1199 }
1200 if (LocaleCompare("colorspace",option+1) == 0)
1201 {
1202 ColorspaceType
1203 colorspace;
1204
cristy6fccee12011-10-20 18:43:18 +00001205 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001206 if (*option == '+')
1207 {
cristye941a752011-10-15 01:52:48 +00001208 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001209 break;
1210 }
1211 colorspace=(ColorspaceType) ParseCommandOption(
1212 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001213 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001214 break;
1215 }
cristy633f0c62011-09-15 13:27:36 +00001216 if (LocaleCompare("compose",option+1) == 0)
1217 {
cristy6fccee12011-10-20 18:43:18 +00001218 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001219 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1220 MagickFalse,argv[i+1]);
1221 break;
1222 }
anthonydf8ebac2011-04-27 09:03:19 +00001223 if (LocaleCompare("contrast",option+1) == 0)
1224 {
cristy6fccee12011-10-20 18:43:18 +00001225 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001226 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001227 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001228 break;
1229 }
1230 if (LocaleCompare("contrast-stretch",option+1) == 0)
1231 {
1232 double
1233 black_point,
1234 white_point;
1235
1236 MagickStatusType
1237 flags;
1238
1239 /*
1240 Contrast stretch image.
1241 */
cristy6fccee12011-10-20 18:43:18 +00001242 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001243 flags=ParseGeometry(argv[i+1],&geometry_info);
1244 black_point=geometry_info.rho;
1245 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1246 black_point;
1247 if ((flags & PercentValue) != 0)
1248 {
1249 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1250 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1251 }
1252 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1253 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001254 (void) ContrastStretchImage(*image,black_point,white_point,
1255 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001256 break;
1257 }
1258 if (LocaleCompare("convolve",option+1) == 0)
1259 {
anthonydf8ebac2011-04-27 09:03:19 +00001260 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001261 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001262
cristy6fccee12011-10-20 18:43:18 +00001263 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001264 kernel_info=AcquireKernelInfo(argv[i+1]);
1265 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001266 break;
cristy0a922382011-07-16 15:30:34 +00001267 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001268 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001269 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001270 break;
1271 }
1272 if (LocaleCompare("crop",option+1) == 0)
1273 {
1274 /*
1275 Crop a image to a smaller size
1276 */
cristy6fccee12011-10-20 18:43:18 +00001277 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001278 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001279 break;
1280 }
1281 if (LocaleCompare("cycle",option+1) == 0)
1282 {
1283 /*
1284 Cycle an image colormap.
1285 */
cristy6fccee12011-10-20 18:43:18 +00001286 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001287 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1288 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001289 break;
1290 }
1291 break;
1292 }
1293 case 'd':
1294 {
1295 if (LocaleCompare("decipher",option+1) == 0)
1296 {
1297 StringInfo
1298 *passkey;
1299
1300 /*
1301 Decipher pixels.
1302 */
cristy6fccee12011-10-20 18:43:18 +00001303 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001304 passkey=FileToStringInfo(argv[i+1],~0,exception);
1305 if (passkey != (StringInfo *) NULL)
1306 {
1307 (void) PasskeyDecipherImage(*image,passkey,exception);
1308 passkey=DestroyStringInfo(passkey);
1309 }
1310 break;
1311 }
1312 if (LocaleCompare("density",option+1) == 0)
1313 {
1314 /*
1315 Set image density.
1316 */
1317 (void) CloneString(&draw_info->density,argv[i+1]);
1318 break;
1319 }
1320 if (LocaleCompare("depth",option+1) == 0)
1321 {
cristy6fccee12011-10-20 18:43:18 +00001322 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001323 if (*option == '+')
1324 {
cristy8a11cb12011-10-19 23:53:34 +00001325 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001326 break;
1327 }
cristy8a11cb12011-10-19 23:53:34 +00001328 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1329 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001330 break;
1331 }
1332 if (LocaleCompare("deskew",option+1) == 0)
1333 {
1334 double
1335 threshold;
1336
1337 /*
1338 Straighten the image.
1339 */
cristy6fccee12011-10-20 18:43:18 +00001340 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001341 if (*option == '+')
1342 threshold=40.0*QuantumRange/100.0;
1343 else
cristy9b34e302011-11-05 02:15:45 +00001344 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1345 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001346 mogrify_image=DeskewImage(*image,threshold,exception);
1347 break;
1348 }
1349 if (LocaleCompare("despeckle",option+1) == 0)
1350 {
1351 /*
1352 Reduce the speckles within an image.
1353 */
cristy6fccee12011-10-20 18:43:18 +00001354 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001355 mogrify_image=DespeckleImage(*image,exception);
1356 break;
1357 }
1358 if (LocaleCompare("display",option+1) == 0)
1359 {
1360 (void) CloneString(&draw_info->server_name,argv[i+1]);
1361 break;
1362 }
1363 if (LocaleCompare("distort",option+1) == 0)
1364 {
1365 char
1366 *args,
1367 token[MaxTextExtent];
1368
1369 const char
1370 *p;
1371
1372 DistortImageMethod
1373 method;
1374
1375 double
1376 *arguments;
1377
1378 register ssize_t
1379 x;
1380
1381 size_t
1382 number_arguments;
1383
1384 /*
1385 Distort image.
1386 */
cristy6fccee12011-10-20 18:43:18 +00001387 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001388 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1389 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001390 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001391 {
anthonydf8ebac2011-04-27 09:03:19 +00001392 double
1393 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001394
1395 /*
1396 Special Case - Argument is actually a resize geometry!
1397 Convert that to an appropriate distortion argument array.
1398 */
anthonydf8ebac2011-04-27 09:03:19 +00001399 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001400 exception);
1401 resize_args[0]=(double) geometry.width;
1402 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001403 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001404 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001405 break;
1406 }
cristy018f07f2011-09-04 21:15:19 +00001407 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1408 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001409 if (args == (char *) NULL)
1410 break;
1411 p=(char *) args;
1412 for (x=0; *p != '\0'; x++)
1413 {
1414 GetMagickToken(p,&p,token);
1415 if (*token == ',')
1416 GetMagickToken(p,&p,token);
1417 }
1418 number_arguments=(size_t) x;
1419 arguments=(double *) AcquireQuantumMemory(number_arguments,
1420 sizeof(*arguments));
1421 if (arguments == (double *) NULL)
1422 ThrowWandFatalException(ResourceLimitFatalError,
1423 "MemoryAllocationFailed",(*image)->filename);
1424 (void) ResetMagickMemory(arguments,0,number_arguments*
1425 sizeof(*arguments));
1426 p=(char *) args;
1427 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1428 {
1429 GetMagickToken(p,&p,token);
1430 if (*token == ',')
1431 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001432 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001433 }
1434 args=DestroyString(args);
1435 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1436 (*option == '+') ? MagickTrue : MagickFalse,exception);
1437 arguments=(double *) RelinquishMagickMemory(arguments);
1438 break;
1439 }
1440 if (LocaleCompare("dither",option+1) == 0)
1441 {
1442 if (*option == '+')
1443 {
1444 quantize_info->dither=MagickFalse;
1445 break;
1446 }
1447 quantize_info->dither=MagickTrue;
1448 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1449 MagickDitherOptions,MagickFalse,argv[i+1]);
1450 if (quantize_info->dither_method == NoDitherMethod)
1451 quantize_info->dither=MagickFalse;
1452 break;
1453 }
1454 if (LocaleCompare("draw",option+1) == 0)
1455 {
1456 /*
1457 Draw image.
1458 */
cristy6fccee12011-10-20 18:43:18 +00001459 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001460 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001461 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001462 break;
1463 }
1464 break;
1465 }
1466 case 'e':
1467 {
1468 if (LocaleCompare("edge",option+1) == 0)
1469 {
1470 /*
1471 Enhance edges in the image.
1472 */
cristy6fccee12011-10-20 18:43:18 +00001473 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001474 flags=ParseGeometry(argv[i+1],&geometry_info);
1475 if ((flags & SigmaValue) == 0)
1476 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001477 mogrify_image=EdgeImage(*image,geometry_info.rho,
1478 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001479 break;
1480 }
1481 if (LocaleCompare("emboss",option+1) == 0)
1482 {
1483 /*
1484 Gaussian embossen image.
1485 */
cristy6fccee12011-10-20 18:43:18 +00001486 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001487 flags=ParseGeometry(argv[i+1],&geometry_info);
1488 if ((flags & SigmaValue) == 0)
1489 geometry_info.sigma=1.0;
1490 mogrify_image=EmbossImage(*image,geometry_info.rho,
1491 geometry_info.sigma,exception);
1492 break;
1493 }
1494 if (LocaleCompare("encipher",option+1) == 0)
1495 {
1496 StringInfo
1497 *passkey;
1498
1499 /*
1500 Encipher pixels.
1501 */
cristy6fccee12011-10-20 18:43:18 +00001502 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001503 passkey=FileToStringInfo(argv[i+1],~0,exception);
1504 if (passkey != (StringInfo *) NULL)
1505 {
1506 (void) PasskeyEncipherImage(*image,passkey,exception);
1507 passkey=DestroyStringInfo(passkey);
1508 }
1509 break;
1510 }
1511 if (LocaleCompare("encoding",option+1) == 0)
1512 {
1513 (void) CloneString(&draw_info->encoding,argv[i+1]);
1514 break;
1515 }
1516 if (LocaleCompare("enhance",option+1) == 0)
1517 {
1518 /*
1519 Enhance image.
1520 */
cristy6fccee12011-10-20 18:43:18 +00001521 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001522 mogrify_image=EnhanceImage(*image,exception);
1523 break;
1524 }
1525 if (LocaleCompare("equalize",option+1) == 0)
1526 {
1527 /*
1528 Equalize image.
1529 */
cristy6fccee12011-10-20 18:43:18 +00001530 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001531 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001532 break;
1533 }
1534 if (LocaleCompare("evaluate",option+1) == 0)
1535 {
1536 double
1537 constant;
1538
1539 MagickEvaluateOperator
1540 op;
1541
cristy6fccee12011-10-20 18:43:18 +00001542 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001543 op=(MagickEvaluateOperator) ParseCommandOption(
1544 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001545 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1546 1.0);
cristyd42d9952011-07-08 14:21:50 +00001547 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001548 break;
1549 }
1550 if (LocaleCompare("extent",option+1) == 0)
1551 {
1552 /*
1553 Set the image extent.
1554 */
cristy6fccee12011-10-20 18:43:18 +00001555 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001556 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1557 if (geometry.width == 0)
1558 geometry.width=(*image)->columns;
1559 if (geometry.height == 0)
1560 geometry.height=(*image)->rows;
1561 mogrify_image=ExtentImage(*image,&geometry,exception);
1562 break;
1563 }
1564 break;
1565 }
1566 case 'f':
1567 {
1568 if (LocaleCompare("family",option+1) == 0)
1569 {
1570 if (*option == '+')
1571 {
1572 if (draw_info->family != (char *) NULL)
1573 draw_info->family=DestroyString(draw_info->family);
1574 break;
1575 }
1576 (void) CloneString(&draw_info->family,argv[i+1]);
1577 break;
1578 }
1579 if (LocaleCompare("features",option+1) == 0)
1580 {
1581 if (*option == '+')
1582 {
1583 (void) DeleteImageArtifact(*image,"identify:features");
1584 break;
1585 }
1586 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1587 break;
1588 }
1589 if (LocaleCompare("fill",option+1) == 0)
1590 {
1591 ExceptionInfo
1592 *sans;
1593
cristy4c08aed2011-07-01 19:47:50 +00001594 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001595 if (*option == '+')
1596 {
cristy269c9412011-10-13 23:41:15 +00001597 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001598 exception);
1599 (void) QueryColorCompliance("none",AllCompliance,
1600 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001601 if (draw_info->fill_pattern != (Image *) NULL)
1602 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1603 break;
1604 }
1605 sans=AcquireExceptionInfo();
cristy269c9412011-10-13 23:41:15 +00001606 (void) QueryColorCompliance(argv[i+1],AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001607 sans);
1608 status=QueryColorCompliance(argv[i+1],AllCompliance,
1609 &draw_info->fill,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001610 sans=DestroyExceptionInfo(sans);
1611 if (status == MagickFalse)
1612 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1613 exception);
1614 break;
1615 }
1616 if (LocaleCompare("flip",option+1) == 0)
1617 {
1618 /*
1619 Flip image scanlines.
1620 */
cristy6fccee12011-10-20 18:43:18 +00001621 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001622 mogrify_image=FlipImage(*image,exception);
1623 break;
1624 }
anthonydf8ebac2011-04-27 09:03:19 +00001625 if (LocaleCompare("floodfill",option+1) == 0)
1626 {
cristy4c08aed2011-07-01 19:47:50 +00001627 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001628 target;
1629
1630 /*
1631 Floodfill image.
1632 */
cristy6fccee12011-10-20 18:43:18 +00001633 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001634 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001635 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001636 exception);
cristyd42d9952011-07-08 14:21:50 +00001637 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001638 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001639 break;
1640 }
anthony3d2f4862011-05-01 13:48:16 +00001641 if (LocaleCompare("flop",option+1) == 0)
1642 {
1643 /*
1644 Flop image scanlines.
1645 */
cristy6fccee12011-10-20 18:43:18 +00001646 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001647 mogrify_image=FlopImage(*image,exception);
1648 break;
1649 }
anthonydf8ebac2011-04-27 09:03:19 +00001650 if (LocaleCompare("font",option+1) == 0)
1651 {
1652 if (*option == '+')
1653 {
1654 if (draw_info->font != (char *) NULL)
1655 draw_info->font=DestroyString(draw_info->font);
1656 break;
1657 }
1658 (void) CloneString(&draw_info->font,argv[i+1]);
1659 break;
1660 }
1661 if (LocaleCompare("format",option+1) == 0)
1662 {
1663 format=argv[i+1];
1664 break;
1665 }
1666 if (LocaleCompare("frame",option+1) == 0)
1667 {
1668 FrameInfo
1669 frame_info;
1670
1671 /*
1672 Surround image with an ornamental border.
1673 */
cristy6fccee12011-10-20 18:43:18 +00001674 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001675 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1676 frame_info.width=geometry.width;
1677 frame_info.height=geometry.height;
1678 if ((flags & HeightValue) == 0)
1679 frame_info.height=geometry.width;
1680 frame_info.outer_bevel=geometry.x;
1681 frame_info.inner_bevel=geometry.y;
1682 frame_info.x=(ssize_t) frame_info.width;
1683 frame_info.y=(ssize_t) frame_info.height;
1684 frame_info.width=(*image)->columns+2*frame_info.width;
1685 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001686 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001687 break;
1688 }
1689 if (LocaleCompare("function",option+1) == 0)
1690 {
1691 char
1692 *arguments,
1693 token[MaxTextExtent];
1694
1695 const char
1696 *p;
1697
1698 double
1699 *parameters;
1700
1701 MagickFunction
1702 function;
1703
1704 register ssize_t
1705 x;
1706
1707 size_t
1708 number_parameters;
1709
1710 /*
1711 Function Modify Image Values
1712 */
cristy6fccee12011-10-20 18:43:18 +00001713 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001714 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1715 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001716 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1717 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001718 if (arguments == (char *) NULL)
1719 break;
1720 p=(char *) arguments;
1721 for (x=0; *p != '\0'; x++)
1722 {
1723 GetMagickToken(p,&p,token);
1724 if (*token == ',')
1725 GetMagickToken(p,&p,token);
1726 }
1727 number_parameters=(size_t) x;
1728 parameters=(double *) AcquireQuantumMemory(number_parameters,
1729 sizeof(*parameters));
1730 if (parameters == (double *) NULL)
1731 ThrowWandFatalException(ResourceLimitFatalError,
1732 "MemoryAllocationFailed",(*image)->filename);
1733 (void) ResetMagickMemory(parameters,0,number_parameters*
1734 sizeof(*parameters));
1735 p=(char *) arguments;
1736 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1737 {
1738 GetMagickToken(p,&p,token);
1739 if (*token == ',')
1740 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001741 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001742 }
1743 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001744 (void) FunctionImage(*image,function,number_parameters,parameters,
1745 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001746 parameters=(double *) RelinquishMagickMemory(parameters);
1747 break;
1748 }
1749 break;
1750 }
1751 case 'g':
1752 {
1753 if (LocaleCompare("gamma",option+1) == 0)
1754 {
1755 /*
1756 Gamma image.
1757 */
cristy6fccee12011-10-20 18:43:18 +00001758 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001759 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001760 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001761 else
cristydbdd0e32011-11-04 23:29:40 +00001762 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001763 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001764 break;
1765 }
1766 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1767 (LocaleCompare("gaussian",option+1) == 0))
1768 {
1769 /*
1770 Gaussian blur image.
1771 */
cristy6fccee12011-10-20 18:43:18 +00001772 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001773 flags=ParseGeometry(argv[i+1],&geometry_info);
1774 if ((flags & SigmaValue) == 0)
1775 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001776 if ((flags & XiValue) == 0)
1777 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001778 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001779 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001780 break;
1781 }
1782 if (LocaleCompare("geometry",option+1) == 0)
1783 {
1784 /*
1785 Record Image offset, Resize last image.
1786 */
cristy6fccee12011-10-20 18:43:18 +00001787 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001788 if (*option == '+')
1789 {
1790 if ((*image)->geometry != (char *) NULL)
1791 (*image)->geometry=DestroyString((*image)->geometry);
1792 break;
1793 }
1794 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1795 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1796 (void) CloneString(&(*image)->geometry,argv[i+1]);
1797 else
1798 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1799 (*image)->filter,(*image)->blur,exception);
1800 break;
1801 }
1802 if (LocaleCompare("gravity",option+1) == 0)
1803 {
1804 if (*option == '+')
1805 {
1806 draw_info->gravity=UndefinedGravity;
1807 break;
1808 }
1809 draw_info->gravity=(GravityType) ParseCommandOption(
1810 MagickGravityOptions,MagickFalse,argv[i+1]);
1811 break;
1812 }
1813 break;
1814 }
1815 case 'h':
1816 {
1817 if (LocaleCompare("highlight-color",option+1) == 0)
1818 {
1819 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1820 break;
1821 }
1822 break;
1823 }
1824 case 'i':
1825 {
1826 if (LocaleCompare("identify",option+1) == 0)
1827 {
1828 char
1829 *text;
1830
cristy6fccee12011-10-20 18:43:18 +00001831 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001832 if (format == (char *) NULL)
1833 {
cristya4037272011-08-28 15:11:39 +00001834 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1835 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001836 break;
1837 }
cristy018f07f2011-09-04 21:15:19 +00001838 text=InterpretImageProperties(mogrify_info,*image,format,
1839 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001840 if (text == (char *) NULL)
1841 break;
1842 (void) fputs(text,stdout);
1843 (void) fputc('\n',stdout);
1844 text=DestroyString(text);
1845 break;
1846 }
1847 if (LocaleCompare("implode",option+1) == 0)
1848 {
1849 /*
1850 Implode image.
1851 */
cristy6fccee12011-10-20 18:43:18 +00001852 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001853 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001854 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1855 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001856 break;
1857 }
1858 if (LocaleCompare("interline-spacing",option+1) == 0)
1859 {
1860 if (*option == '+')
1861 (void) ParseGeometry("0",&geometry_info);
1862 else
1863 (void) ParseGeometry(argv[i+1],&geometry_info);
1864 draw_info->interline_spacing=geometry_info.rho;
1865 break;
1866 }
cristy28474bf2011-09-11 23:32:52 +00001867 if (LocaleCompare("interpolate",option+1) == 0)
1868 {
1869 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1870 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1871 break;
1872 }
anthonydf8ebac2011-04-27 09:03:19 +00001873 if (LocaleCompare("interword-spacing",option+1) == 0)
1874 {
1875 if (*option == '+')
1876 (void) ParseGeometry("0",&geometry_info);
1877 else
1878 (void) ParseGeometry(argv[i+1],&geometry_info);
1879 draw_info->interword_spacing=geometry_info.rho;
1880 break;
1881 }
1882 break;
1883 }
1884 case 'k':
1885 {
1886 if (LocaleCompare("kerning",option+1) == 0)
1887 {
1888 if (*option == '+')
1889 (void) ParseGeometry("0",&geometry_info);
1890 else
1891 (void) ParseGeometry(argv[i+1],&geometry_info);
1892 draw_info->kerning=geometry_info.rho;
1893 break;
1894 }
1895 break;
1896 }
1897 case 'l':
1898 {
1899 if (LocaleCompare("lat",option+1) == 0)
1900 {
1901 /*
1902 Local adaptive threshold image.
1903 */
cristy6fccee12011-10-20 18:43:18 +00001904 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001905 flags=ParseGeometry(argv[i+1],&geometry_info);
1906 if ((flags & PercentValue) != 0)
1907 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1908 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001909 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001910 geometry_info.xi,exception);
1911 break;
1912 }
1913 if (LocaleCompare("level",option+1) == 0)
1914 {
1915 MagickRealType
1916 black_point,
1917 gamma,
1918 white_point;
1919
1920 MagickStatusType
1921 flags;
1922
1923 /*
1924 Parse levels.
1925 */
cristy6fccee12011-10-20 18:43:18 +00001926 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001927 flags=ParseGeometry(argv[i+1],&geometry_info);
1928 black_point=geometry_info.rho;
1929 white_point=(MagickRealType) QuantumRange;
1930 if ((flags & SigmaValue) != 0)
1931 white_point=geometry_info.sigma;
1932 gamma=1.0;
1933 if ((flags & XiValue) != 0)
1934 gamma=geometry_info.xi;
1935 if ((flags & PercentValue) != 0)
1936 {
1937 black_point*=(MagickRealType) (QuantumRange/100.0);
1938 white_point*=(MagickRealType) (QuantumRange/100.0);
1939 }
1940 if ((flags & SigmaValue) == 0)
1941 white_point=(MagickRealType) QuantumRange-black_point;
1942 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001943 (void) LevelizeImage(*image,black_point,white_point,gamma,
1944 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001945 else
cristy01e9afd2011-08-10 17:38:41 +00001946 (void) LevelImage(*image,black_point,white_point,gamma,
1947 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001948 break;
1949 }
1950 if (LocaleCompare("level-colors",option+1) == 0)
1951 {
1952 char
1953 token[MaxTextExtent];
1954
1955 const char
1956 *p;
1957
cristy4c08aed2011-07-01 19:47:50 +00001958 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001959 black_point,
1960 white_point;
1961
1962 p=(const char *) argv[i+1];
1963 GetMagickToken(p,&p,token); /* get black point color */
1964 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001965 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001966 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001967 else
cristy269c9412011-10-13 23:41:15 +00001968 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001969 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001970 if (isalpha((int) token[0]) || (token[0] == '#'))
1971 GetMagickToken(p,&p,token);
1972 if (*token == '\0')
1973 white_point=black_point; /* set everything to that color */
1974 else
1975 {
1976 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1977 GetMagickToken(p,&p,token); /* Get white point color. */
1978 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001979 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001980 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001981 else
cristy269c9412011-10-13 23:41:15 +00001982 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001983 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001984 }
cristy490408a2011-07-07 14:42:05 +00001985 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001986 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001987 break;
1988 }
1989 if (LocaleCompare("linear-stretch",option+1) == 0)
1990 {
1991 double
1992 black_point,
1993 white_point;
1994
1995 MagickStatusType
1996 flags;
1997
cristy6fccee12011-10-20 18:43:18 +00001998 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001999 flags=ParseGeometry(argv[i+1],&geometry_info);
2000 black_point=geometry_info.rho;
2001 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2002 if ((flags & SigmaValue) != 0)
2003 white_point=geometry_info.sigma;
2004 if ((flags & PercentValue) != 0)
2005 {
2006 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2007 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2008 }
2009 if ((flags & SigmaValue) == 0)
2010 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2011 black_point;
cristy33bd5152011-08-24 01:42:24 +00002012 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002013 break;
2014 }
2015 if (LocaleCompare("linewidth",option+1) == 0)
2016 {
cristy9b34e302011-11-05 02:15:45 +00002017 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002018 break;
2019 }
2020 if (LocaleCompare("liquid-rescale",option+1) == 0)
2021 {
2022 /*
2023 Liquid rescale image.
2024 */
cristy6fccee12011-10-20 18:43:18 +00002025 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002026 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2027 if ((flags & XValue) == 0)
2028 geometry.x=1;
2029 if ((flags & YValue) == 0)
2030 geometry.y=0;
2031 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2032 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2033 break;
2034 }
2035 if (LocaleCompare("lowlight-color",option+1) == 0)
2036 {
2037 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2038 break;
2039 }
2040 break;
2041 }
2042 case 'm':
2043 {
2044 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002045 {
cristy3ed852e2009-09-05 21:47:34 +00002046 Image
anthonydf8ebac2011-04-27 09:03:19 +00002047 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002048
anthonydf8ebac2011-04-27 09:03:19 +00002049 /*
2050 Transform image colors to match this set of colors.
2051 */
cristy6fccee12011-10-20 18:43:18 +00002052 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002053 if (*option == '+')
2054 break;
2055 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2056 if (remap_image == (Image *) NULL)
2057 break;
cristy018f07f2011-09-04 21:15:19 +00002058 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002059 remap_image=DestroyImage(remap_image);
2060 break;
2061 }
2062 if (LocaleCompare("mask",option+1) == 0)
2063 {
2064 Image
2065 *mask;
2066
cristy6fccee12011-10-20 18:43:18 +00002067 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002068 if (*option == '+')
2069 {
2070 /*
2071 Remove a mask.
2072 */
cristy018f07f2011-09-04 21:15:19 +00002073 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002074 break;
2075 }
2076 /*
2077 Set the image mask.
2078 */
2079 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2080 if (mask == (Image *) NULL)
2081 break;
cristy018f07f2011-09-04 21:15:19 +00002082 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002083 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002084 break;
2085 }
2086 if (LocaleCompare("matte",option+1) == 0)
2087 {
2088 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002089 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002090 break;
2091 }
2092 if (LocaleCompare("median",option+1) == 0)
2093 {
2094 /*
2095 Median filter image.
2096 */
cristy6fccee12011-10-20 18:43:18 +00002097 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002098 flags=ParseGeometry(argv[i+1],&geometry_info);
2099 if ((flags & SigmaValue) == 0)
2100 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002101 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002102 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002103 break;
2104 }
2105 if (LocaleCompare("mode",option+1) == 0)
2106 {
2107 /*
2108 Mode image.
2109 */
cristy6fccee12011-10-20 18:43:18 +00002110 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002111 flags=ParseGeometry(argv[i+1],&geometry_info);
2112 if ((flags & SigmaValue) == 0)
2113 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002114 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002115 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002116 break;
2117 }
2118 if (LocaleCompare("modulate",option+1) == 0)
2119 {
cristy6fccee12011-10-20 18:43:18 +00002120 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002121 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002122 break;
2123 }
2124 if (LocaleCompare("monitor",option+1) == 0)
2125 {
2126 if (*option == '+')
2127 {
2128 (void) SetImageProgressMonitor(*image,
2129 (MagickProgressMonitor) NULL,(void *) NULL);
2130 break;
2131 }
2132 (void) SetImageProgressMonitor(*image,MonitorProgress,
2133 (void *) NULL);
2134 break;
2135 }
2136 if (LocaleCompare("monochrome",option+1) == 0)
2137 {
cristy6fccee12011-10-20 18:43:18 +00002138 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002139 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002140 break;
2141 }
2142 if (LocaleCompare("morphology",option+1) == 0)
2143 {
2144 char
2145 token[MaxTextExtent];
2146
2147 const char
2148 *p;
2149
2150 KernelInfo
2151 *kernel;
2152
2153 MorphologyMethod
2154 method;
2155
2156 ssize_t
2157 iterations;
2158
2159 /*
2160 Morphological Image Operation
2161 */
cristy6fccee12011-10-20 18:43:18 +00002162 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002163 p=argv[i+1];
2164 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002165 method=(MorphologyMethod) ParseCommandOption(
2166 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002167 iterations=1L;
2168 GetMagickToken(p,&p,token);
2169 if ((*p == ':') || (*p == ','))
2170 GetMagickToken(p,&p,token);
2171 if ((*p != '\0'))
2172 iterations=(ssize_t) StringToLong(p);
2173 kernel=AcquireKernelInfo(argv[i+2]);
2174 if (kernel == (KernelInfo *) NULL)
2175 {
2176 (void) ThrowMagickException(exception,GetMagickModule(),
2177 OptionError,"UnabletoParseKernel","morphology");
2178 status=MagickFalse;
2179 break;
2180 }
cristyf4ad9df2011-07-08 16:49:03 +00002181 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2182 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002183 kernel=DestroyKernelInfo(kernel);
2184 break;
2185 }
2186 if (LocaleCompare("motion-blur",option+1) == 0)
2187 {
2188 /*
2189 Motion blur image.
2190 */
cristy6fccee12011-10-20 18:43:18 +00002191 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002192 flags=ParseGeometry(argv[i+1],&geometry_info);
2193 if ((flags & SigmaValue) == 0)
2194 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002195 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002196 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002197 break;
2198 }
2199 break;
2200 }
2201 case 'n':
2202 {
2203 if (LocaleCompare("negate",option+1) == 0)
2204 {
cristy6fccee12011-10-20 18:43:18 +00002205 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002206 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002207 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002208 break;
2209 }
2210 if (LocaleCompare("noise",option+1) == 0)
2211 {
cristy6fccee12011-10-20 18:43:18 +00002212 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002213 if (*option == '-')
2214 {
cristyf36cbcb2011-09-07 13:28:22 +00002215 flags=ParseGeometry(argv[i+1],&geometry_info);
2216 if ((flags & SigmaValue) == 0)
2217 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002218 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002219 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002220 }
2221 else
2222 {
2223 NoiseType
2224 noise;
2225
2226 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2227 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002228 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002229 }
2230 break;
2231 }
2232 if (LocaleCompare("normalize",option+1) == 0)
2233 {
cristy6fccee12011-10-20 18:43:18 +00002234 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002235 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002236 break;
2237 }
2238 break;
2239 }
2240 case 'o':
2241 {
2242 if (LocaleCompare("opaque",option+1) == 0)
2243 {
cristy4c08aed2011-07-01 19:47:50 +00002244 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002245 target;
2246
cristy6fccee12011-10-20 18:43:18 +00002247 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002248 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002249 exception);
cristyd42d9952011-07-08 14:21:50 +00002250 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002251 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002252 break;
2253 }
2254 if (LocaleCompare("ordered-dither",option+1) == 0)
2255 {
cristy6fccee12011-10-20 18:43:18 +00002256 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002257 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002258 break;
2259 }
2260 break;
2261 }
2262 case 'p':
2263 {
2264 if (LocaleCompare("paint",option+1) == 0)
2265 {
cristy6fccee12011-10-20 18:43:18 +00002266 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002267 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002268 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2269 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002270 break;
2271 }
anthonydf8ebac2011-04-27 09:03:19 +00002272 if (LocaleCompare("pointsize",option+1) == 0)
2273 {
2274 if (*option == '+')
2275 (void) ParseGeometry("12",&geometry_info);
2276 else
2277 (void) ParseGeometry(argv[i+1],&geometry_info);
2278 draw_info->pointsize=geometry_info.rho;
2279 break;
2280 }
2281 if (LocaleCompare("polaroid",option+1) == 0)
2282 {
cristye9e3d382011-12-14 01:50:13 +00002283 const char
2284 *caption;
2285
anthonydf8ebac2011-04-27 09:03:19 +00002286 double
2287 angle;
2288
2289 RandomInfo
2290 *random_info;
2291
2292 /*
2293 Simulate a Polaroid picture.
2294 */
cristy6fccee12011-10-20 18:43:18 +00002295 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002296 random_info=AcquireRandomInfo();
2297 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2298 random_info=DestroyRandomInfo(random_info);
2299 if (*option == '-')
2300 {
2301 SetGeometryInfo(&geometry_info);
2302 flags=ParseGeometry(argv[i+1],&geometry_info);
2303 angle=geometry_info.rho;
2304 }
cristye9e3d382011-12-14 01:50:13 +00002305 caption=GetImageProperty(*image,"caption",exception);
2306 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002307 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002308 break;
2309 }
2310 if (LocaleCompare("posterize",option+1) == 0)
2311 {
2312 /*
2313 Posterize image.
2314 */
cristy6fccee12011-10-20 18:43:18 +00002315 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002316 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002317 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002318 break;
2319 }
2320 if (LocaleCompare("preview",option+1) == 0)
2321 {
2322 PreviewType
2323 preview_type;
2324
2325 /*
2326 Preview image.
2327 */
cristy6fccee12011-10-20 18:43:18 +00002328 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002329 if (*option == '+')
2330 preview_type=UndefinedPreview;
2331 else
cristy28474bf2011-09-11 23:32:52 +00002332 preview_type=(PreviewType) ParseCommandOption(
2333 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002334 mogrify_image=PreviewImage(*image,preview_type,exception);
2335 break;
2336 }
2337 if (LocaleCompare("profile",option+1) == 0)
2338 {
2339 const char
2340 *name;
2341
2342 const StringInfo
2343 *profile;
2344
2345 Image
2346 *profile_image;
2347
2348 ImageInfo
2349 *profile_info;
2350
cristy6fccee12011-10-20 18:43:18 +00002351 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002352 if (*option == '+')
2353 {
2354 /*
2355 Remove a profile from the image.
2356 */
2357 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002358 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002359 break;
2360 }
2361 /*
2362 Associate a profile with the image.
2363 */
2364 profile_info=CloneImageInfo(mogrify_info);
2365 profile=GetImageProfile(*image,"iptc");
2366 if (profile != (StringInfo *) NULL)
2367 profile_info->profile=(void *) CloneStringInfo(profile);
2368 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2369 profile_info=DestroyImageInfo(profile_info);
2370 if (profile_image == (Image *) NULL)
2371 {
2372 StringInfo
2373 *profile;
2374
2375 profile_info=CloneImageInfo(mogrify_info);
2376 (void) CopyMagickString(profile_info->filename,argv[i+1],
2377 MaxTextExtent);
2378 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2379 if (profile != (StringInfo *) NULL)
2380 {
2381 (void) ProfileImage(*image,profile_info->magick,
2382 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002383 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002384 profile=DestroyStringInfo(profile);
2385 }
2386 profile_info=DestroyImageInfo(profile_info);
2387 break;
2388 }
2389 ResetImageProfileIterator(profile_image);
2390 name=GetNextImageProfile(profile_image);
2391 while (name != (const char *) NULL)
2392 {
2393 profile=GetImageProfile(profile_image,name);
2394 if (profile != (StringInfo *) NULL)
2395 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002396 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002397 name=GetNextImageProfile(profile_image);
2398 }
2399 profile_image=DestroyImage(profile_image);
2400 break;
2401 }
2402 break;
2403 }
2404 case 'q':
2405 {
2406 if (LocaleCompare("quantize",option+1) == 0)
2407 {
2408 if (*option == '+')
2409 {
2410 quantize_info->colorspace=UndefinedColorspace;
2411 break;
2412 }
2413 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2414 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2415 break;
2416 }
2417 break;
2418 }
2419 case 'r':
2420 {
2421 if (LocaleCompare("radial-blur",option+1) == 0)
2422 {
2423 /*
2424 Radial blur image.
2425 */
cristy6fccee12011-10-20 18:43:18 +00002426 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002427 flags=ParseGeometry(argv[i+1],&geometry_info);
2428 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2429 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002430 break;
2431 }
2432 if (LocaleCompare("raise",option+1) == 0)
2433 {
2434 /*
2435 Surround image with a raise of solid color.
2436 */
2437 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2438 if ((flags & SigmaValue) == 0)
2439 geometry.height=geometry.width;
2440 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002441 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002442 break;
2443 }
2444 if (LocaleCompare("random-threshold",option+1) == 0)
2445 {
2446 /*
2447 Threshold image.
2448 */
cristy6fccee12011-10-20 18:43:18 +00002449 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002450 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002451 break;
2452 }
2453 if (LocaleCompare("recolor",option+1) == 0)
2454 {
2455 KernelInfo
2456 *kernel;
2457
cristy6fccee12011-10-20 18:43:18 +00002458 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002459 kernel=AcquireKernelInfo(argv[i+1]);
2460 if (kernel == (KernelInfo *) NULL)
2461 break;
2462 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2463 kernel=DestroyKernelInfo(kernel);
2464 break;
2465 }
2466 if (LocaleCompare("region",option+1) == 0)
2467 {
cristy6fccee12011-10-20 18:43:18 +00002468 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002469 if (region_image != (Image *) NULL)
2470 {
2471 /*
2472 Composite region.
2473 */
2474 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002475 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002476 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002477 *image=DestroyImage(*image);
2478 *image=region_image;
2479 region_image = (Image *) NULL;
2480 }
2481 if (*option == '+')
2482 break;
2483 /*
2484 Apply transformations to a selected region of the image.
2485 */
cristy3ed852e2009-09-05 21:47:34 +00002486 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2487 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002488 mogrify_image=CropImage(*image,&region_geometry,exception);
2489 if (mogrify_image == (Image *) NULL)
2490 break;
2491 region_image=(*image);
2492 *image=mogrify_image;
2493 mogrify_image=(Image *) NULL;
2494 break;
cristy3ed852e2009-09-05 21:47:34 +00002495 }
anthonydf8ebac2011-04-27 09:03:19 +00002496 if (LocaleCompare("render",option+1) == 0)
2497 {
cristy6fccee12011-10-20 18:43:18 +00002498 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002499 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2500 break;
2501 }
2502 if (LocaleCompare("remap",option+1) == 0)
2503 {
2504 Image
2505 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002506
anthonydf8ebac2011-04-27 09:03:19 +00002507 /*
2508 Transform image colors to match this set of colors.
2509 */
cristy6fccee12011-10-20 18:43:18 +00002510 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002511 if (*option == '+')
2512 break;
2513 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2514 if (remap_image == (Image *) NULL)
2515 break;
cristy018f07f2011-09-04 21:15:19 +00002516 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002517 remap_image=DestroyImage(remap_image);
2518 break;
2519 }
2520 if (LocaleCompare("repage",option+1) == 0)
2521 {
2522 if (*option == '+')
2523 {
2524 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2525 break;
2526 }
2527 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002528 break;
2529 }
2530 if (LocaleCompare("resample",option+1) == 0)
2531 {
2532 /*
2533 Resample image.
2534 */
cristy6fccee12011-10-20 18:43:18 +00002535 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002536 flags=ParseGeometry(argv[i+1],&geometry_info);
2537 if ((flags & SigmaValue) == 0)
2538 geometry_info.sigma=geometry_info.rho;
2539 mogrify_image=ResampleImage(*image,geometry_info.rho,
2540 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2541 break;
2542 }
2543 if (LocaleCompare("resize",option+1) == 0)
2544 {
2545 /*
2546 Resize image.
2547 */
cristy6fccee12011-10-20 18:43:18 +00002548 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002549 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2550 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2551 (*image)->filter,(*image)->blur,exception);
2552 break;
2553 }
2554 if (LocaleCompare("roll",option+1) == 0)
2555 {
2556 /*
2557 Roll image.
2558 */
cristy6fccee12011-10-20 18:43:18 +00002559 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002560 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2561 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2562 break;
2563 }
2564 if (LocaleCompare("rotate",option+1) == 0)
2565 {
2566 char
2567 *geometry;
2568
2569 /*
2570 Check for conditional image rotation.
2571 */
cristy6fccee12011-10-20 18:43:18 +00002572 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002573 if (strchr(argv[i+1],'>') != (char *) NULL)
2574 if ((*image)->columns <= (*image)->rows)
2575 break;
2576 if (strchr(argv[i+1],'<') != (char *) NULL)
2577 if ((*image)->columns >= (*image)->rows)
2578 break;
2579 /*
2580 Rotate image.
2581 */
2582 geometry=ConstantString(argv[i+1]);
2583 (void) SubstituteString(&geometry,">","");
2584 (void) SubstituteString(&geometry,"<","");
2585 (void) ParseGeometry(geometry,&geometry_info);
2586 geometry=DestroyString(geometry);
2587 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2588 break;
2589 }
2590 break;
2591 }
2592 case 's':
2593 {
2594 if (LocaleCompare("sample",option+1) == 0)
2595 {
2596 /*
2597 Sample image with pixel replication.
2598 */
cristy6fccee12011-10-20 18:43:18 +00002599 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002600 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2601 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2602 exception);
2603 break;
2604 }
2605 if (LocaleCompare("scale",option+1) == 0)
2606 {
2607 /*
2608 Resize image.
2609 */
cristy6fccee12011-10-20 18:43:18 +00002610 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002611 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2612 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2613 exception);
2614 break;
2615 }
2616 if (LocaleCompare("selective-blur",option+1) == 0)
2617 {
2618 /*
2619 Selectively blur pixels within a contrast threshold.
2620 */
cristy6fccee12011-10-20 18:43:18 +00002621 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002622 flags=ParseGeometry(argv[i+1],&geometry_info);
2623 if ((flags & PercentValue) != 0)
2624 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002625 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002626 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002627 break;
2628 }
2629 if (LocaleCompare("separate",option+1) == 0)
2630 {
2631 /*
2632 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002633 */
cristy6fccee12011-10-20 18:43:18 +00002634 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002635 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002636 break;
2637 }
2638 if (LocaleCompare("sepia-tone",option+1) == 0)
2639 {
2640 double
2641 threshold;
2642
2643 /*
2644 Sepia-tone image.
2645 */
cristy6fccee12011-10-20 18:43:18 +00002646 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002647 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2648 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002649 mogrify_image=SepiaToneImage(*image,threshold,exception);
2650 break;
2651 }
2652 if (LocaleCompare("segment",option+1) == 0)
2653 {
2654 /*
2655 Segment image.
2656 */
cristy6fccee12011-10-20 18:43:18 +00002657 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002658 flags=ParseGeometry(argv[i+1],&geometry_info);
2659 if ((flags & SigmaValue) == 0)
2660 geometry_info.sigma=1.0;
2661 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002662 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2663 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002664 break;
2665 }
2666 if (LocaleCompare("set",option+1) == 0)
2667 {
2668 char
2669 *value;
2670
2671 /*
2672 Set image option.
2673 */
2674 if (*option == '+')
2675 {
2676 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2677 (void) DeleteImageRegistry(argv[i+1]+9);
2678 else
2679 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2680 {
2681 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2682 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2683 }
2684 else
2685 (void) DeleteImageProperty(*image,argv[i+1]);
2686 break;
2687 }
cristy018f07f2011-09-04 21:15:19 +00002688 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2689 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002690 if (value == (char *) NULL)
2691 break;
2692 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2693 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2694 exception);
2695 else
2696 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2697 {
2698 (void) SetImageOption(image_info,argv[i+1]+7,value);
2699 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2700 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2701 }
2702 else
cristyd15e6592011-10-15 00:13:06 +00002703 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002704 value=DestroyString(value);
2705 break;
2706 }
2707 if (LocaleCompare("shade",option+1) == 0)
2708 {
2709 /*
2710 Shade image.
2711 */
cristy6fccee12011-10-20 18:43:18 +00002712 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002713 flags=ParseGeometry(argv[i+1],&geometry_info);
2714 if ((flags & SigmaValue) == 0)
2715 geometry_info.sigma=1.0;
2716 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2717 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2718 break;
2719 }
2720 if (LocaleCompare("shadow",option+1) == 0)
2721 {
2722 /*
2723 Shadow image.
2724 */
cristy6fccee12011-10-20 18:43:18 +00002725 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002726 flags=ParseGeometry(argv[i+1],&geometry_info);
2727 if ((flags & SigmaValue) == 0)
2728 geometry_info.sigma=1.0;
2729 if ((flags & XiValue) == 0)
2730 geometry_info.xi=4.0;
2731 if ((flags & PsiValue) == 0)
2732 geometry_info.psi=4.0;
2733 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002734 geometry_info.sigma,(*image)->bias,(ssize_t)
2735 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2736 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002737 break;
2738 }
2739 if (LocaleCompare("sharpen",option+1) == 0)
2740 {
2741 /*
2742 Sharpen image.
2743 */
cristy6fccee12011-10-20 18:43:18 +00002744 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002745 flags=ParseGeometry(argv[i+1],&geometry_info);
2746 if ((flags & SigmaValue) == 0)
2747 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002748 if ((flags & XiValue) == 0)
2749 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002750 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002751 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002752 break;
2753 }
2754 if (LocaleCompare("shave",option+1) == 0)
2755 {
2756 /*
2757 Shave the image edges.
2758 */
cristy6fccee12011-10-20 18:43:18 +00002759 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002760 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2761 mogrify_image=ShaveImage(*image,&geometry,exception);
2762 break;
2763 }
2764 if (LocaleCompare("shear",option+1) == 0)
2765 {
2766 /*
2767 Shear image.
2768 */
cristy6fccee12011-10-20 18:43:18 +00002769 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002770 flags=ParseGeometry(argv[i+1],&geometry_info);
2771 if ((flags & SigmaValue) == 0)
2772 geometry_info.sigma=geometry_info.rho;
2773 mogrify_image=ShearImage(*image,geometry_info.rho,
2774 geometry_info.sigma,exception);
2775 break;
2776 }
2777 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2778 {
2779 /*
2780 Sigmoidal non-linearity contrast control.
2781 */
cristy6fccee12011-10-20 18:43:18 +00002782 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002783 flags=ParseGeometry(argv[i+1],&geometry_info);
2784 if ((flags & SigmaValue) == 0)
2785 geometry_info.sigma=(double) QuantumRange/2.0;
2786 if ((flags & PercentValue) != 0)
2787 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2788 100.0;
cristy9ee60942011-07-06 14:54:38 +00002789 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002790 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2791 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002792 break;
2793 }
2794 if (LocaleCompare("sketch",option+1) == 0)
2795 {
2796 /*
2797 Sketch image.
2798 */
cristy6fccee12011-10-20 18:43:18 +00002799 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002800 flags=ParseGeometry(argv[i+1],&geometry_info);
2801 if ((flags & SigmaValue) == 0)
2802 geometry_info.sigma=1.0;
2803 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002804 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002805 break;
2806 }
2807 if (LocaleCompare("solarize",option+1) == 0)
2808 {
2809 double
2810 threshold;
2811
cristy6fccee12011-10-20 18:43:18 +00002812 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002813 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2814 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002815 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002816 break;
2817 }
2818 if (LocaleCompare("sparse-color",option+1) == 0)
2819 {
2820 SparseColorMethod
2821 method;
2822
2823 char
2824 *arguments;
2825
2826 /*
2827 Sparse Color Interpolated Gradient
2828 */
cristy6fccee12011-10-20 18:43:18 +00002829 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002830 method=(SparseColorMethod) ParseCommandOption(
2831 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002832 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2833 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002834 if (arguments == (char *) NULL)
2835 break;
cristy3884f692011-07-08 18:00:18 +00002836 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002837 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2838 arguments=DestroyString(arguments);
2839 break;
2840 }
2841 if (LocaleCompare("splice",option+1) == 0)
2842 {
2843 /*
2844 Splice a solid color into the image.
2845 */
cristy6fccee12011-10-20 18:43:18 +00002846 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002847 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2848 mogrify_image=SpliceImage(*image,&geometry,exception);
2849 break;
2850 }
2851 if (LocaleCompare("spread",option+1) == 0)
2852 {
2853 /*
2854 Spread an image.
2855 */
cristy6fccee12011-10-20 18:43:18 +00002856 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002857 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002858 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002859 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002860 break;
2861 }
2862 if (LocaleCompare("statistic",option+1) == 0)
2863 {
2864 StatisticType
2865 type;
2866
cristy6fccee12011-10-20 18:43:18 +00002867 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002868 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2869 MagickFalse,argv[i+1]);
2870 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002871 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2872 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002873 break;
2874 }
2875 if (LocaleCompare("stretch",option+1) == 0)
2876 {
2877 if (*option == '+')
2878 {
2879 draw_info->stretch=UndefinedStretch;
2880 break;
2881 }
2882 draw_info->stretch=(StretchType) ParseCommandOption(
2883 MagickStretchOptions,MagickFalse,argv[i+1]);
2884 break;
2885 }
2886 if (LocaleCompare("strip",option+1) == 0)
2887 {
2888 /*
2889 Strip image of profiles and comments.
2890 */
cristy6fccee12011-10-20 18:43:18 +00002891 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002892 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002893 break;
2894 }
2895 if (LocaleCompare("stroke",option+1) == 0)
2896 {
2897 ExceptionInfo
2898 *sans;
2899
2900 if (*option == '+')
2901 {
cristy9950d572011-10-01 18:22:35 +00002902 (void) QueryColorCompliance("none",AllCompliance,
2903 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002904 if (draw_info->stroke_pattern != (Image *) NULL)
2905 draw_info->stroke_pattern=DestroyImage(
2906 draw_info->stroke_pattern);
2907 break;
2908 }
2909 sans=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00002910 status=QueryColorCompliance(argv[i+1],AllCompliance,
2911 &draw_info->stroke,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002912 sans=DestroyExceptionInfo(sans);
2913 if (status == MagickFalse)
2914 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2915 exception);
2916 break;
2917 }
2918 if (LocaleCompare("strokewidth",option+1) == 0)
2919 {
cristy9b34e302011-11-05 02:15:45 +00002920 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002921 break;
2922 }
2923 if (LocaleCompare("style",option+1) == 0)
2924 {
2925 if (*option == '+')
2926 {
2927 draw_info->style=UndefinedStyle;
2928 break;
2929 }
2930 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2931 MagickFalse,argv[i+1]);
2932 break;
2933 }
2934 if (LocaleCompare("swirl",option+1) == 0)
2935 {
2936 /*
2937 Swirl image.
2938 */
cristy6fccee12011-10-20 18:43:18 +00002939 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002940 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002941 mogrify_image=SwirlImage(*image,geometry_info.rho,
2942 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002943 break;
2944 }
2945 break;
2946 }
2947 case 't':
2948 {
2949 if (LocaleCompare("threshold",option+1) == 0)
2950 {
2951 double
2952 threshold;
2953
2954 /*
2955 Threshold image.
2956 */
cristy6fccee12011-10-20 18:43:18 +00002957 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002958 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002959 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002960 else
cristy9b34e302011-11-05 02:15:45 +00002961 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2962 1.0);
cristye941a752011-10-15 01:52:48 +00002963 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002964 break;
2965 }
2966 if (LocaleCompare("thumbnail",option+1) == 0)
2967 {
2968 /*
2969 Thumbnail image.
2970 */
cristy6fccee12011-10-20 18:43:18 +00002971 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002972 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2973 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2974 exception);
2975 break;
2976 }
2977 if (LocaleCompare("tile",option+1) == 0)
2978 {
2979 if (*option == '+')
2980 {
2981 if (draw_info->fill_pattern != (Image *) NULL)
2982 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2983 break;
2984 }
2985 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2986 exception);
2987 break;
2988 }
2989 if (LocaleCompare("tint",option+1) == 0)
2990 {
2991 /*
2992 Tint the image.
2993 */
cristy6fccee12011-10-20 18:43:18 +00002994 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002995 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002996 break;
2997 }
2998 if (LocaleCompare("transform",option+1) == 0)
2999 {
3000 /*
3001 Affine transform image.
3002 */
cristy6fccee12011-10-20 18:43:18 +00003003 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003004 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3005 exception);
3006 break;
3007 }
3008 if (LocaleCompare("transparent",option+1) == 0)
3009 {
cristy4c08aed2011-07-01 19:47:50 +00003010 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00003011 target;
3012
cristy6fccee12011-10-20 18:43:18 +00003013 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003014 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003015 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003016 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003017 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003018 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003019 break;
3020 }
3021 if (LocaleCompare("transpose",option+1) == 0)
3022 {
3023 /*
3024 Transpose image scanlines.
3025 */
cristy6fccee12011-10-20 18:43:18 +00003026 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003027 mogrify_image=TransposeImage(*image,exception);
3028 break;
3029 }
3030 if (LocaleCompare("transverse",option+1) == 0)
3031 {
3032 /*
3033 Transverse image scanlines.
3034 */
cristy6fccee12011-10-20 18:43:18 +00003035 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003036 mogrify_image=TransverseImage(*image,exception);
3037 break;
3038 }
3039 if (LocaleCompare("treedepth",option+1) == 0)
3040 {
3041 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3042 break;
3043 }
3044 if (LocaleCompare("trim",option+1) == 0)
3045 {
3046 /*
3047 Trim image.
3048 */
cristy6fccee12011-10-20 18:43:18 +00003049 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003050 mogrify_image=TrimImage(*image,exception);
3051 break;
3052 }
3053 if (LocaleCompare("type",option+1) == 0)
3054 {
3055 ImageType
3056 type;
3057
cristy6fccee12011-10-20 18:43:18 +00003058 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003059 if (*option == '+')
3060 type=UndefinedType;
3061 else
3062 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3063 argv[i+1]);
3064 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003065 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003066 break;
3067 }
3068 break;
3069 }
3070 case 'u':
3071 {
3072 if (LocaleCompare("undercolor",option+1) == 0)
3073 {
cristy9950d572011-10-01 18:22:35 +00003074 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3075 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003076 break;
3077 }
3078 if (LocaleCompare("unique",option+1) == 0)
3079 {
3080 if (*option == '+')
3081 {
3082 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3083 break;
3084 }
3085 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3086 (void) SetImageArtifact(*image,"verbose","true");
3087 break;
3088 }
3089 if (LocaleCompare("unique-colors",option+1) == 0)
3090 {
3091 /*
3092 Unique image colors.
3093 */
cristy6fccee12011-10-20 18:43:18 +00003094 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003095 mogrify_image=UniqueImageColors(*image,exception);
3096 break;
3097 }
3098 if (LocaleCompare("unsharp",option+1) == 0)
3099 {
3100 /*
3101 Unsharp mask image.
3102 */
cristy6fccee12011-10-20 18:43:18 +00003103 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003104 flags=ParseGeometry(argv[i+1],&geometry_info);
3105 if ((flags & SigmaValue) == 0)
3106 geometry_info.sigma=1.0;
3107 if ((flags & XiValue) == 0)
3108 geometry_info.xi=1.0;
3109 if ((flags & PsiValue) == 0)
3110 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003111 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3112 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003113 break;
3114 }
3115 break;
3116 }
3117 case 'v':
3118 {
3119 if (LocaleCompare("verbose",option+1) == 0)
3120 {
3121 (void) SetImageArtifact(*image,option+1,
3122 *option == '+' ? "false" : "true");
3123 break;
3124 }
3125 if (LocaleCompare("vignette",option+1) == 0)
3126 {
3127 /*
3128 Vignette image.
3129 */
cristy6fccee12011-10-20 18:43:18 +00003130 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003131 flags=ParseGeometry(argv[i+1],&geometry_info);
3132 if ((flags & SigmaValue) == 0)
3133 geometry_info.sigma=1.0;
3134 if ((flags & XiValue) == 0)
3135 geometry_info.xi=0.1*(*image)->columns;
3136 if ((flags & PsiValue) == 0)
3137 geometry_info.psi=0.1*(*image)->rows;
3138 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003139 geometry_info.sigma,(*image)->bias,(ssize_t)
3140 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3141 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003142 break;
3143 }
3144 if (LocaleCompare("virtual-pixel",option+1) == 0)
3145 {
3146 if (*option == '+')
3147 {
3148 (void) SetImageVirtualPixelMethod(*image,
3149 UndefinedVirtualPixelMethod);
3150 break;
3151 }
3152 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3153 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3154 argv[i+1]));
3155 break;
3156 }
3157 break;
3158 }
3159 case 'w':
3160 {
3161 if (LocaleCompare("wave",option+1) == 0)
3162 {
3163 /*
3164 Wave image.
3165 */
cristy6fccee12011-10-20 18:43:18 +00003166 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003167 flags=ParseGeometry(argv[i+1],&geometry_info);
3168 if ((flags & SigmaValue) == 0)
3169 geometry_info.sigma=1.0;
3170 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003171 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003172 break;
3173 }
3174 if (LocaleCompare("weight",option+1) == 0)
3175 {
3176 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3177 if (LocaleCompare(argv[i+1],"all") == 0)
3178 draw_info->weight=0;
3179 if (LocaleCompare(argv[i+1],"bold") == 0)
3180 draw_info->weight=700;
3181 if (LocaleCompare(argv[i+1],"bolder") == 0)
3182 if (draw_info->weight <= 800)
3183 draw_info->weight+=100;
3184 if (LocaleCompare(argv[i+1],"lighter") == 0)
3185 if (draw_info->weight >= 100)
3186 draw_info->weight-=100;
3187 if (LocaleCompare(argv[i+1],"normal") == 0)
3188 draw_info->weight=400;
3189 break;
3190 }
3191 if (LocaleCompare("white-threshold",option+1) == 0)
3192 {
3193 /*
3194 White threshold image.
3195 */
cristy6fccee12011-10-20 18:43:18 +00003196 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003197 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003198 break;
3199 }
3200 break;
3201 }
3202 default:
3203 break;
3204 }
3205 /*
3206 Replace current image with any image that was generated
3207 */
3208 if (mogrify_image != (Image *) NULL)
3209 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003210 i+=count;
3211 }
3212 if (region_image != (Image *) NULL)
3213 {
anthonydf8ebac2011-04-27 09:03:19 +00003214 /*
3215 Composite transformed region onto image.
3216 */
cristy6fccee12011-10-20 18:43:18 +00003217 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003218 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003219 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003220 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003221 *image=DestroyImage(*image);
3222 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003223 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003224 }
3225 /*
3226 Free resources.
3227 */
anthonydf8ebac2011-04-27 09:03:19 +00003228 quantize_info=DestroyQuantizeInfo(quantize_info);
3229 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003230 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003231 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003232 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003233}
3234
3235/*
3236%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3237% %
3238% %
3239% %
cristy5063d812010-10-19 16:28:10 +00003240+ 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 +00003241% %
3242% %
3243% %
3244%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3245%
3246% MogrifyImageCommand() transforms an image or a sequence of images. These
3247% transforms include image scaling, image rotation, color reduction, and
3248% others. The transmogrified image overwrites the original image.
3249%
3250% The format of the MogrifyImageCommand method is:
3251%
3252% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3253% const char **argv,char **metadata,ExceptionInfo *exception)
3254%
3255% A description of each parameter follows:
3256%
3257% o image_info: the image info.
3258%
3259% o argc: the number of elements in the argument vector.
3260%
3261% o argv: A text array containing the command line arguments.
3262%
3263% o metadata: any metadata is returned here.
3264%
3265% o exception: return any errors or warnings in this structure.
3266%
3267*/
3268
3269static MagickBooleanType MogrifyUsage(void)
3270{
3271 static const char
3272 *miscellaneous[]=
3273 {
3274 "-debug events display copious debugging information",
3275 "-help print program options",
3276 "-list type print a list of supported option arguments",
3277 "-log format format of debugging information",
3278 "-version print version information",
3279 (char *) NULL
3280 },
3281 *operators[]=
3282 {
3283 "-adaptive-blur geometry",
3284 " adaptively blur pixels; decrease effect near edges",
3285 "-adaptive-resize geometry",
3286 " adaptively resize image using 'mesh' interpolation",
3287 "-adaptive-sharpen geometry",
3288 " adaptively sharpen pixels; increase effect near edges",
3289 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3290 " transparent, extract, background, or shape",
3291 "-annotate geometry text",
3292 " annotate the image with text",
3293 "-auto-gamma automagically adjust gamma level of image",
3294 "-auto-level automagically adjust color levels of image",
3295 "-auto-orient automagically orient (rotate) image",
3296 "-bench iterations measure performance",
3297 "-black-threshold value",
3298 " force all pixels below the threshold into black",
3299 "-blue-shift simulate a scene at nighttime in the moonlight",
3300 "-blur geometry reduce image noise and reduce detail levels",
3301 "-border geometry surround image with a border of color",
3302 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003303 "-brightness-contrast geometry",
3304 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003305 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003306 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003307 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003308 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003309 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003310 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003311 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003312 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003313 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003314 "-contrast enhance or reduce the image contrast",
3315 "-contrast-stretch geometry",
3316 " improve contrast by `stretching' the intensity range",
3317 "-convolve coefficients",
3318 " apply a convolution kernel to the image",
3319 "-cycle amount cycle the image colormap",
3320 "-decipher filename convert cipher pixels to plain pixels",
3321 "-deskew threshold straighten an image",
3322 "-despeckle reduce the speckles within an image",
3323 "-distort method args",
3324 " distort images according to given method ad args",
3325 "-draw string annotate the image with a graphic primitive",
3326 "-edge radius apply a filter to detect edges in the image",
3327 "-encipher filename convert plain pixels to cipher pixels",
3328 "-emboss radius emboss an image",
3329 "-enhance apply a digital filter to enhance a noisy image",
3330 "-equalize perform histogram equalization to an image",
3331 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003332 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003333 "-extent geometry set the image size",
3334 "-extract geometry extract area from image",
3335 "-fft implements the discrete Fourier transform (DFT)",
3336 "-flip flip image vertically",
3337 "-floodfill geometry color",
3338 " floodfill the image with color",
3339 "-flop flop image horizontally",
3340 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003341 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003342 " apply function over image values",
3343 "-gamma value level of gamma correction",
3344 "-gaussian-blur geometry",
3345 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003346 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003347 "-identify identify the format and characteristics of the image",
3348 "-ift implements the inverse discrete Fourier transform (DFT)",
3349 "-implode amount implode image pixels about the center",
3350 "-lat geometry local adaptive thresholding",
3351 "-layers method optimize, merge, or compare image layers",
3352 "-level value adjust the level of image contrast",
3353 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003354 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003355 "-linear-stretch geometry",
3356 " improve contrast by `stretching with saturation'",
3357 "-liquid-rescale geometry",
3358 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003359 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003360 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003361 "-modulate value vary the brightness, saturation, and hue",
3362 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003363 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003364 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-motion-blur geometry",
3366 " simulate motion blur",
3367 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003368 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-normalize transform image to span the full range of colors",
3370 "-opaque color change this color to the fill color",
3371 "-ordered-dither NxN",
3372 " add a noise pattern to the image with specific",
3373 " amplitudes",
3374 "-paint radius simulate an oil painting",
3375 "-polaroid angle simulate a Polaroid picture",
3376 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-profile filename add, delete, or apply an image profile",
3378 "-quantize colorspace reduce colors in this colorspace",
3379 "-radial-blur angle radial blur the image",
3380 "-raise value lighten/darken image edges to create a 3-D effect",
3381 "-random-threshold low,high",
3382 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003383 "-region geometry apply options to a portion of the image",
3384 "-render render vector graphics",
3385 "-repage geometry size and location of an image canvas",
3386 "-resample geometry change the resolution of an image",
3387 "-resize geometry resize the image",
3388 "-roll geometry roll an image vertically or horizontally",
3389 "-rotate degrees apply Paeth rotation to the image",
3390 "-sample geometry scale image with pixel sampling",
3391 "-scale geometry scale the image",
3392 "-segment values segment an image",
3393 "-selective-blur geometry",
3394 " selectively blur pixels within a contrast threshold",
3395 "-sepia-tone threshold",
3396 " simulate a sepia-toned photo",
3397 "-set property value set an image property",
3398 "-shade degrees shade the image using a distant light source",
3399 "-shadow geometry simulate an image shadow",
3400 "-sharpen geometry sharpen the image",
3401 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003402 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003403 "-sigmoidal-contrast geometry",
3404 " increase the contrast without saturating highlights or shadows",
3405 "-sketch geometry simulate a pencil sketch",
3406 "-solarize threshold negate all pixels above the threshold level",
3407 "-sparse-color method args",
3408 " fill in a image based on a few color points",
3409 "-splice geometry splice the background color into the image",
3410 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003411 "-statistic type radius",
3412 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003413 "-strip strip image of all profiles and comments",
3414 "-swirl degrees swirl image pixels about the center",
3415 "-threshold value threshold the image",
3416 "-thumbnail geometry create a thumbnail of the image",
3417 "-tile filename tile image when filling a graphic primitive",
3418 "-tint value tint the image with the fill color",
3419 "-transform affine transform image",
3420 "-transparent color make this color transparent within the image",
3421 "-transpose flip image vertically and rotate 90 degrees",
3422 "-transverse flop image horizontally and rotate 270 degrees",
3423 "-trim trim image edges",
3424 "-type type image type",
3425 "-unique-colors discard all but one of any pixel color",
3426 "-unsharp geometry sharpen the image",
3427 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003428 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003429 "-white-threshold value",
3430 " force all pixels above the threshold into white",
3431 (char *) NULL
3432 },
3433 *sequence_operators[]=
3434 {
cristy4285d782011-02-09 20:12:28 +00003435 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003436 "-clut apply a color lookup table to the image",
3437 "-coalesce merge a sequence of images",
3438 "-combine combine a sequence of images",
3439 "-composite composite image",
3440 "-crop geometry cut out a rectangular region of the image",
3441 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003442 "-evaluate-sequence operator",
3443 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003444 "-flatten flatten a sequence of images",
3445 "-fx expression apply mathematical expression to an image channel(s)",
3446 "-hald-clut apply a Hald color lookup table to the image",
3447 "-morph value morph an image sequence",
3448 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003449 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003450 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003451 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003452 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003453 "-write filename write images to this file",
3454 (char *) NULL
3455 },
3456 *settings[]=
3457 {
3458 "-adjoin join images into a single multi-image file",
3459 "-affine matrix affine transform matrix",
3460 "-alpha option activate, deactivate, reset, or set the alpha channel",
3461 "-antialias remove pixel-aliasing",
3462 "-authenticate password",
3463 " decipher image with this password",
3464 "-attenuate value lessen (or intensify) when adding noise to an image",
3465 "-background color background color",
3466 "-bias value add bias when convolving an image",
3467 "-black-point-compensation",
3468 " use black point compensation",
3469 "-blue-primary point chromaticity blue primary point",
3470 "-bordercolor color border color",
3471 "-caption string assign a caption to an image",
3472 "-channel type apply option to select image channels",
3473 "-colors value preferred number of colors in the image",
3474 "-colorspace type alternate image colorspace",
3475 "-comment string annotate image with comment",
3476 "-compose operator set image composite operator",
3477 "-compress type type of pixel compression when writing the image",
3478 "-define format:option",
3479 " define one or more image format options",
3480 "-delay value display the next image after pausing",
3481 "-density geometry horizontal and vertical density of the image",
3482 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003483 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003484 "-display server get image or font from this X server",
3485 "-dispose method layer disposal method",
3486 "-dither method apply error diffusion to image",
3487 "-encoding type text encoding type",
3488 "-endian type endianness (MSB or LSB) of the image",
3489 "-family name render text with this font family",
3490 "-fill color color to use when filling a graphic primitive",
3491 "-filter type use this filter when resizing an image",
3492 "-font name render text with this font",
3493 "-format \"string\" output formatted image characteristics",
3494 "-fuzz distance colors within this distance are considered equal",
3495 "-gravity type horizontal and vertical text placement",
3496 "-green-primary point chromaticity green primary point",
3497 "-intent type type of rendering intent when managing the image color",
3498 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003499 "-interline-spacing value",
3500 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003501 "-interpolate method pixel color interpolation method",
3502 "-interword-spacing value",
3503 " set the space between two words",
3504 "-kerning value set the space between two letters",
3505 "-label string assign a label to an image",
3506 "-limit type value pixel cache resource limit",
3507 "-loop iterations add Netscape loop extension to your GIF animation",
3508 "-mask filename associate a mask with the image",
3509 "-mattecolor color frame color",
3510 "-monitor monitor progress",
3511 "-orient type image orientation",
3512 "-page geometry size and location of an image canvas (setting)",
3513 "-ping efficiently determine image attributes",
3514 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003515 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003516 "-preview type image preview type",
3517 "-quality value JPEG/MIFF/PNG compression level",
3518 "-quiet suppress all warning messages",
3519 "-red-primary point chromaticity red primary point",
3520 "-regard-warnings pay attention to warning messages",
3521 "-remap filename transform image colors to match this set of colors",
3522 "-respect-parentheses settings remain in effect until parenthesis boundary",
3523 "-sampling-factor geometry",
3524 " horizontal and vertical sampling factor",
3525 "-scene value image scene number",
3526 "-seed value seed a new sequence of pseudo-random numbers",
3527 "-size geometry width and height of image",
3528 "-stretch type render text with this font stretch",
3529 "-stroke color graphic primitive stroke color",
3530 "-strokewidth value graphic primitive stroke width",
3531 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003532 "-synchronize synchronize image to storage device",
3533 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003534 "-texture filename name of texture to tile onto the image background",
3535 "-tile-offset geometry",
3536 " tile offset",
3537 "-treedepth value color tree depth",
3538 "-transparent-color color",
3539 " transparent color",
3540 "-undercolor color annotation bounding box color",
3541 "-units type the units of image resolution",
3542 "-verbose print detailed information about the image",
3543 "-view FlashPix viewing transforms",
3544 "-virtual-pixel method",
3545 " virtual pixel access method",
3546 "-weight type render text with this font weight",
3547 "-white-point point chromaticity white point",
3548 (char *) NULL
3549 },
3550 *stack_operators[]=
3551 {
anthonyb69c4b32011-03-23 04:37:44 +00003552 "-delete indexes delete the image from the image sequence",
3553 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003554 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003555 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003556 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003557 "-swap indexes swap two images in the image sequence",
3558 (char *) NULL
3559 };
3560
3561 const char
3562 **p;
3563
cristybb503372010-05-27 20:51:26 +00003564 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003565 (void) printf("Copyright: %s\n",GetMagickCopyright());
3566 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003567 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3568 GetClientName());
3569 (void) printf("\nImage Settings:\n");
3570 for (p=settings; *p != (char *) NULL; p++)
3571 (void) printf(" %s\n",*p);
3572 (void) printf("\nImage Operators:\n");
3573 for (p=operators; *p != (char *) NULL; p++)
3574 (void) printf(" %s\n",*p);
3575 (void) printf("\nImage Sequence Operators:\n");
3576 for (p=sequence_operators; *p != (char *) NULL; p++)
3577 (void) printf(" %s\n",*p);
3578 (void) printf("\nImage Stack Operators:\n");
3579 for (p=stack_operators; *p != (char *) NULL; p++)
3580 (void) printf(" %s\n",*p);
3581 (void) printf("\nMiscellaneous Options:\n");
3582 for (p=miscellaneous; *p != (char *) NULL; p++)
3583 (void) printf(" %s\n",*p);
3584 (void) printf(
3585 "\nBy default, the image format of `file' is determined by its magic\n");
3586 (void) printf(
3587 "number. To specify a particular image format, precede the filename\n");
3588 (void) printf(
3589 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3590 (void) printf(
3591 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3592 (void) printf("'-' for standard input or output.\n");
3593 return(MagickFalse);
3594}
3595
3596WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3597 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3598{
3599#define DestroyMogrify() \
3600{ \
3601 if (format != (char *) NULL) \
3602 format=DestroyString(format); \
3603 if (path != (char *) NULL) \
3604 path=DestroyString(path); \
3605 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003606 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003607 argv[i]=DestroyString(argv[i]); \
3608 argv=(char **) RelinquishMagickMemory(argv); \
3609}
3610#define ThrowMogrifyException(asperity,tag,option) \
3611{ \
3612 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3613 option); \
3614 DestroyMogrify(); \
3615 return(MagickFalse); \
3616}
3617#define ThrowMogrifyInvalidArgumentException(option,argument) \
3618{ \
3619 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3620 "InvalidArgument","`%s': %s",argument,option); \
3621 DestroyMogrify(); \
3622 return(MagickFalse); \
3623}
3624
3625 char
3626 *format,
3627 *option,
3628 *path;
3629
3630 Image
3631 *image;
3632
3633 ImageStack
3634 image_stack[MaxImageStackDepth+1];
3635
cristy3ed852e2009-09-05 21:47:34 +00003636 MagickBooleanType
3637 global_colormap;
3638
3639 MagickBooleanType
3640 fire,
cristyebbcfea2011-02-25 02:43:54 +00003641 pend,
3642 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003643
3644 MagickStatusType
3645 status;
3646
cristyebbcfea2011-02-25 02:43:54 +00003647 register ssize_t
3648 i;
3649
3650 ssize_t
3651 j,
3652 k;
3653
cristy3ed852e2009-09-05 21:47:34 +00003654 /*
3655 Set defaults.
3656 */
3657 assert(image_info != (ImageInfo *) NULL);
3658 assert(image_info->signature == MagickSignature);
3659 if (image_info->debug != MagickFalse)
3660 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3661 assert(exception != (ExceptionInfo *) NULL);
3662 if (argc == 2)
3663 {
3664 option=argv[1];
3665 if ((LocaleCompare("version",option+1) == 0) ||
3666 (LocaleCompare("-version",option+1) == 0))
3667 {
cristyb51dff52011-05-19 16:55:47 +00003668 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003669 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003670 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3671 GetMagickCopyright());
3672 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3673 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003674 return(MagickFalse);
3675 }
3676 }
3677 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003678 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003679 format=(char *) NULL;
3680 path=(char *) NULL;
3681 global_colormap=MagickFalse;
3682 k=0;
3683 j=1;
3684 NewImageStack();
3685 option=(char *) NULL;
3686 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003687 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003688 status=MagickTrue;
3689 /*
3690 Parse command line.
3691 */
3692 ReadCommandlLine(argc,&argv);
3693 status=ExpandFilenames(&argc,&argv);
3694 if (status == MagickFalse)
3695 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3696 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003697 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003698 {
3699 option=argv[i];
3700 if (LocaleCompare(option,"(") == 0)
3701 {
3702 FireImageStack(MagickFalse,MagickTrue,pend);
3703 if (k == MaxImageStackDepth)
3704 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3705 option);
3706 PushImageStack();
3707 continue;
3708 }
3709 if (LocaleCompare(option,")") == 0)
3710 {
3711 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3712 if (k == 0)
3713 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3714 PopImageStack();
3715 continue;
3716 }
cristy042ee782011-04-22 18:48:30 +00003717 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003718 {
3719 char
3720 backup_filename[MaxTextExtent],
3721 *filename;
3722
3723 Image
3724 *images;
3725
3726 /*
3727 Option is a file name: begin by reading image from specified file.
3728 */
3729 FireImageStack(MagickFalse,MagickFalse,pend);
3730 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003731 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003732 filename=argv[++i];
3733 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3734 images=ReadImages(image_info,exception);
3735 status&=(images != (Image *) NULL) &&
3736 (exception->severity < ErrorException);
3737 if (images == (Image *) NULL)
3738 continue;
cristydaa76602010-06-30 13:05:11 +00003739 if (format != (char *) NULL)
3740 (void) CopyMagickString(images->filename,images->magick_filename,
3741 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003742 if (path != (char *) NULL)
3743 {
3744 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003745 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003746 path,*DirectorySeparator,filename);
3747 }
3748 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003749 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003750 AppendImageStack(images);
3751 FinalizeImageSettings(image_info,image,MagickFalse);
3752 if (global_colormap != MagickFalse)
3753 {
3754 QuantizeInfo
3755 *quantize_info;
3756
3757 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003758 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003759 quantize_info=DestroyQuantizeInfo(quantize_info);
3760 }
3761 *backup_filename='\0';
3762 if ((LocaleCompare(image->filename,"-") != 0) &&
3763 (IsPathWritable(image->filename) != MagickFalse))
3764 {
cristybb503372010-05-27 20:51:26 +00003765 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003766 i;
3767
3768 /*
3769 Rename image file as backup.
3770 */
3771 (void) CopyMagickString(backup_filename,image->filename,
3772 MaxTextExtent);
3773 for (i=0; i < 6; i++)
3774 {
3775 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3776 if (IsPathAccessible(backup_filename) == MagickFalse)
3777 break;
3778 }
3779 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003780 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003781 *backup_filename='\0';
3782 }
3783 /*
3784 Write transmogrified image to disk.
3785 */
3786 image_info->synchronize=MagickTrue;
3787 status&=WriteImages(image_info,image,image->filename,exception);
3788 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003789 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003790 RemoveAllImageStack();
3791 continue;
3792 }
3793 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3794 switch (*(option+1))
3795 {
3796 case 'a':
3797 {
3798 if (LocaleCompare("adaptive-blur",option+1) == 0)
3799 {
3800 i++;
cristybb503372010-05-27 20:51:26 +00003801 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003802 ThrowMogrifyException(OptionError,"MissingArgument",option);
3803 if (IsGeometry(argv[i]) == MagickFalse)
3804 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3805 break;
3806 }
3807 if (LocaleCompare("adaptive-resize",option+1) == 0)
3808 {
3809 i++;
cristybb503372010-05-27 20:51:26 +00003810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003811 ThrowMogrifyException(OptionError,"MissingArgument",option);
3812 if (IsGeometry(argv[i]) == MagickFalse)
3813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3814 break;
3815 }
3816 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3817 {
3818 i++;
cristybb503372010-05-27 20:51:26 +00003819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003820 ThrowMogrifyException(OptionError,"MissingArgument",option);
3821 if (IsGeometry(argv[i]) == MagickFalse)
3822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3823 break;
3824 }
3825 if (LocaleCompare("affine",option+1) == 0)
3826 {
3827 if (*option == '+')
3828 break;
3829 i++;
cristybb503372010-05-27 20:51:26 +00003830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003831 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003832 break;
3833 }
3834 if (LocaleCompare("alpha",option+1) == 0)
3835 {
cristybb503372010-05-27 20:51:26 +00003836 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003837 type;
3838
3839 if (*option == '+')
3840 break;
3841 i++;
cristybb503372010-05-27 20:51:26 +00003842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003843 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003844 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003845 if (type < 0)
3846 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3847 argv[i]);
3848 break;
3849 }
3850 if (LocaleCompare("annotate",option+1) == 0)
3851 {
3852 if (*option == '+')
3853 break;
3854 i++;
cristybb503372010-05-27 20:51:26 +00003855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003856 ThrowMogrifyException(OptionError,"MissingArgument",option);
3857 if (IsGeometry(argv[i]) == MagickFalse)
3858 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003860 ThrowMogrifyException(OptionError,"MissingArgument",option);
3861 i++;
3862 break;
3863 }
3864 if (LocaleCompare("antialias",option+1) == 0)
3865 break;
3866 if (LocaleCompare("append",option+1) == 0)
3867 break;
3868 if (LocaleCompare("attenuate",option+1) == 0)
3869 {
3870 if (*option == '+')
3871 break;
3872 i++;
cristybb503372010-05-27 20:51:26 +00003873 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003874 ThrowMogrifyException(OptionError,"MissingArgument",option);
3875 if (IsGeometry(argv[i]) == MagickFalse)
3876 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3877 break;
3878 }
3879 if (LocaleCompare("authenticate",option+1) == 0)
3880 {
3881 if (*option == '+')
3882 break;
3883 i++;
cristybb503372010-05-27 20:51:26 +00003884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003885 ThrowMogrifyException(OptionError,"MissingArgument",option);
3886 break;
3887 }
3888 if (LocaleCompare("auto-gamma",option+1) == 0)
3889 break;
3890 if (LocaleCompare("auto-level",option+1) == 0)
3891 break;
3892 if (LocaleCompare("auto-orient",option+1) == 0)
3893 break;
3894 if (LocaleCompare("average",option+1) == 0)
3895 break;
3896 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3897 }
3898 case 'b':
3899 {
3900 if (LocaleCompare("background",option+1) == 0)
3901 {
3902 if (*option == '+')
3903 break;
3904 i++;
cristybb503372010-05-27 20:51:26 +00003905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003906 ThrowMogrifyException(OptionError,"MissingArgument",option);
3907 break;
3908 }
3909 if (LocaleCompare("bias",option+1) == 0)
3910 {
3911 if (*option == '+')
3912 break;
3913 i++;
cristybb503372010-05-27 20:51:26 +00003914 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003915 ThrowMogrifyException(OptionError,"MissingArgument",option);
3916 if (IsGeometry(argv[i]) == MagickFalse)
3917 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3918 break;
3919 }
3920 if (LocaleCompare("black-point-compensation",option+1) == 0)
3921 break;
3922 if (LocaleCompare("black-threshold",option+1) == 0)
3923 {
3924 if (*option == '+')
3925 break;
3926 i++;
cristybb503372010-05-27 20:51:26 +00003927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003928 ThrowMogrifyException(OptionError,"MissingArgument",option);
3929 if (IsGeometry(argv[i]) == MagickFalse)
3930 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3931 break;
3932 }
3933 if (LocaleCompare("blue-primary",option+1) == 0)
3934 {
3935 if (*option == '+')
3936 break;
3937 i++;
cristybb503372010-05-27 20:51:26 +00003938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003939 ThrowMogrifyException(OptionError,"MissingArgument",option);
3940 if (IsGeometry(argv[i]) == MagickFalse)
3941 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3942 break;
3943 }
3944 if (LocaleCompare("blue-shift",option+1) == 0)
3945 {
3946 i++;
cristybb503372010-05-27 20:51:26 +00003947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003948 ThrowMogrifyException(OptionError,"MissingArgument",option);
3949 if (IsGeometry(argv[i]) == MagickFalse)
3950 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3951 break;
3952 }
3953 if (LocaleCompare("blur",option+1) == 0)
3954 {
3955 i++;
cristybb503372010-05-27 20:51:26 +00003956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003957 ThrowMogrifyException(OptionError,"MissingArgument",option);
3958 if (IsGeometry(argv[i]) == MagickFalse)
3959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3960 break;
3961 }
3962 if (LocaleCompare("border",option+1) == 0)
3963 {
3964 if (*option == '+')
3965 break;
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 if (IsGeometry(argv[i]) == MagickFalse)
3970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3971 break;
3972 }
3973 if (LocaleCompare("bordercolor",option+1) == 0)
3974 {
3975 if (*option == '+')
3976 break;
3977 i++;
cristybb503372010-05-27 20:51:26 +00003978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003979 ThrowMogrifyException(OptionError,"MissingArgument",option);
3980 break;
3981 }
3982 if (LocaleCompare("box",option+1) == 0)
3983 {
3984 if (*option == '+')
3985 break;
3986 i++;
cristybb503372010-05-27 20:51:26 +00003987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003988 ThrowMogrifyException(OptionError,"MissingArgument",option);
3989 break;
3990 }
cristya28d6b82010-01-11 20:03:47 +00003991 if (LocaleCompare("brightness-contrast",option+1) == 0)
3992 {
3993 i++;
cristybb503372010-05-27 20:51:26 +00003994 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003995 ThrowMogrifyException(OptionError,"MissingArgument",option);
3996 if (IsGeometry(argv[i]) == MagickFalse)
3997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3998 break;
3999 }
cristy3ed852e2009-09-05 21:47:34 +00004000 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4001 }
4002 case 'c':
4003 {
4004 if (LocaleCompare("cache",option+1) == 0)
4005 {
4006 if (*option == '+')
4007 break;
4008 i++;
cristybb503372010-05-27 20:51:26 +00004009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004010 ThrowMogrifyException(OptionError,"MissingArgument",option);
4011 if (IsGeometry(argv[i]) == MagickFalse)
4012 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4013 break;
4014 }
4015 if (LocaleCompare("caption",option+1) == 0)
4016 {
4017 if (*option == '+')
4018 break;
4019 i++;
cristybb503372010-05-27 20:51:26 +00004020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004021 ThrowMogrifyException(OptionError,"MissingArgument",option);
4022 break;
4023 }
4024 if (LocaleCompare("channel",option+1) == 0)
4025 {
cristybb503372010-05-27 20:51:26 +00004026 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004027 channel;
4028
4029 if (*option == '+')
4030 break;
4031 i++;
cristybb503372010-05-27 20:51:26 +00004032 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004033 ThrowMogrifyException(OptionError,"MissingArgument",option);
4034 channel=ParseChannelOption(argv[i]);
4035 if (channel < 0)
4036 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4037 argv[i]);
4038 break;
4039 }
4040 if (LocaleCompare("cdl",option+1) == 0)
4041 {
4042 if (*option == '+')
4043 break;
4044 i++;
cristybb503372010-05-27 20:51:26 +00004045 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004046 ThrowMogrifyException(OptionError,"MissingArgument",option);
4047 break;
4048 }
4049 if (LocaleCompare("charcoal",option+1) == 0)
4050 {
4051 if (*option == '+')
4052 break;
4053 i++;
cristybb503372010-05-27 20:51:26 +00004054 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004055 ThrowMogrifyException(OptionError,"MissingArgument",option);
4056 if (IsGeometry(argv[i]) == MagickFalse)
4057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4058 break;
4059 }
4060 if (LocaleCompare("chop",option+1) == 0)
4061 {
4062 if (*option == '+')
4063 break;
4064 i++;
cristybb503372010-05-27 20:51:26 +00004065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004066 ThrowMogrifyException(OptionError,"MissingArgument",option);
4067 if (IsGeometry(argv[i]) == MagickFalse)
4068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4069 break;
4070 }
cristy1eb45dd2009-09-25 16:38:06 +00004071 if (LocaleCompare("clamp",option+1) == 0)
4072 break;
4073 if (LocaleCompare("clip",option+1) == 0)
4074 break;
cristy3ed852e2009-09-05 21:47:34 +00004075 if (LocaleCompare("clip-mask",option+1) == 0)
4076 {
4077 if (*option == '+')
4078 break;
4079 i++;
cristybb503372010-05-27 20:51:26 +00004080 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004081 ThrowMogrifyException(OptionError,"MissingArgument",option);
4082 break;
4083 }
4084 if (LocaleCompare("clut",option+1) == 0)
4085 break;
4086 if (LocaleCompare("coalesce",option+1) == 0)
4087 break;
4088 if (LocaleCompare("colorize",option+1) == 0)
4089 {
4090 if (*option == '+')
4091 break;
4092 i++;
cristybb503372010-05-27 20:51:26 +00004093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004094 ThrowMogrifyException(OptionError,"MissingArgument",option);
4095 if (IsGeometry(argv[i]) == MagickFalse)
4096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4097 break;
4098 }
cristye6365592010-04-02 17:31:23 +00004099 if (LocaleCompare("color-matrix",option+1) == 0)
4100 {
cristyb6bd4ad2010-08-08 01:12:27 +00004101 KernelInfo
4102 *kernel_info;
4103
cristye6365592010-04-02 17:31:23 +00004104 if (*option == '+')
4105 break;
4106 i++;
cristybb503372010-05-27 20:51:26 +00004107 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004108 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004109 kernel_info=AcquireKernelInfo(argv[i]);
4110 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004111 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004112 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004113 break;
4114 }
cristy3ed852e2009-09-05 21:47:34 +00004115 if (LocaleCompare("colors",option+1) == 0)
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);
4122 if (IsGeometry(argv[i]) == MagickFalse)
4123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4124 break;
4125 }
4126 if (LocaleCompare("colorspace",option+1) == 0)
4127 {
cristybb503372010-05-27 20:51:26 +00004128 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004129 colorspace;
4130
4131 if (*option == '+')
4132 break;
4133 i++;
cristybb503372010-05-27 20:51:26 +00004134 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004135 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004136 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004137 argv[i]);
4138 if (colorspace < 0)
4139 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4140 argv[i]);
4141 break;
4142 }
4143 if (LocaleCompare("combine",option+1) == 0)
4144 break;
4145 if (LocaleCompare("comment",option+1) == 0)
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);
4152 break;
4153 }
4154 if (LocaleCompare("composite",option+1) == 0)
4155 break;
4156 if (LocaleCompare("compress",option+1) == 0)
4157 {
cristybb503372010-05-27 20:51:26 +00004158 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004159 compress;
4160
4161 if (*option == '+')
4162 break;
4163 i++;
cristybb503372010-05-27 20:51:26 +00004164 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004165 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004166 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004167 argv[i]);
4168 if (compress < 0)
4169 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4170 argv[i]);
4171 break;
4172 }
cristy22879752009-10-25 23:55:40 +00004173 if (LocaleCompare("concurrent",option+1) == 0)
4174 break;
cristy3ed852e2009-09-05 21:47:34 +00004175 if (LocaleCompare("contrast",option+1) == 0)
4176 break;
4177 if (LocaleCompare("contrast-stretch",option+1) == 0)
4178 {
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);
4182 if (IsGeometry(argv[i]) == MagickFalse)
4183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4184 break;
4185 }
4186 if (LocaleCompare("convolve",option+1) == 0)
4187 {
cristyb6bd4ad2010-08-08 01:12:27 +00004188 KernelInfo
4189 *kernel_info;
4190
cristy3ed852e2009-09-05 21:47:34 +00004191 if (*option == '+')
4192 break;
4193 i++;
cristybb503372010-05-27 20:51:26 +00004194 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004195 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004196 kernel_info=AcquireKernelInfo(argv[i]);
4197 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004198 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004199 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004200 break;
4201 }
4202 if (LocaleCompare("crop",option+1) == 0)
4203 {
4204 if (*option == '+')
4205 break;
4206 i++;
cristybb503372010-05-27 20:51:26 +00004207 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004208 ThrowMogrifyException(OptionError,"MissingArgument",option);
4209 if (IsGeometry(argv[i]) == MagickFalse)
4210 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4211 break;
4212 }
4213 if (LocaleCompare("cycle",option+1) == 0)
4214 {
4215 if (*option == '+')
4216 break;
4217 i++;
cristybb503372010-05-27 20:51:26 +00004218 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004219 ThrowMogrifyException(OptionError,"MissingArgument",option);
4220 if (IsGeometry(argv[i]) == MagickFalse)
4221 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4222 break;
4223 }
4224 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4225 }
4226 case 'd':
4227 {
4228 if (LocaleCompare("decipher",option+1) == 0)
4229 {
4230 if (*option == '+')
4231 break;
4232 i++;
cristybb503372010-05-27 20:51:26 +00004233 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004234 ThrowMogrifyException(OptionError,"MissingArgument",option);
4235 break;
4236 }
4237 if (LocaleCompare("deconstruct",option+1) == 0)
4238 break;
4239 if (LocaleCompare("debug",option+1) == 0)
4240 {
cristybb503372010-05-27 20:51:26 +00004241 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004242 event;
4243
4244 if (*option == '+')
4245 break;
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004249 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004250 if (event < 0)
4251 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4252 argv[i]);
4253 (void) SetLogEventMask(argv[i]);
4254 break;
4255 }
4256 if (LocaleCompare("define",option+1) == 0)
4257 {
4258 i++;
cristybb503372010-05-27 20:51:26 +00004259 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004260 ThrowMogrifyException(OptionError,"MissingArgument",option);
4261 if (*option == '+')
4262 {
4263 const char
4264 *define;
4265
4266 define=GetImageOption(image_info,argv[i]);
4267 if (define == (const char *) NULL)
4268 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4269 break;
4270 }
4271 break;
4272 }
4273 if (LocaleCompare("delay",option+1) == 0)
4274 {
4275 if (*option == '+')
4276 break;
4277 i++;
cristybb503372010-05-27 20:51:26 +00004278 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004279 ThrowMogrifyException(OptionError,"MissingArgument",option);
4280 if (IsGeometry(argv[i]) == MagickFalse)
4281 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4282 break;
4283 }
cristyecb10ff2011-03-22 13:14:03 +00004284 if (LocaleCompare("delete",option+1) == 0)
4285 {
4286 if (*option == '+')
4287 break;
4288 i++;
4289 if (i == (ssize_t) (argc-1))
4290 ThrowMogrifyException(OptionError,"MissingArgument",option);
4291 if (IsGeometry(argv[i]) == MagickFalse)
4292 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4293 break;
4294 }
cristy3ed852e2009-09-05 21:47:34 +00004295 if (LocaleCompare("density",option+1) == 0)
4296 {
4297 if (*option == '+')
4298 break;
4299 i++;
cristybb503372010-05-27 20:51:26 +00004300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004301 ThrowMogrifyException(OptionError,"MissingArgument",option);
4302 if (IsGeometry(argv[i]) == MagickFalse)
4303 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4304 break;
4305 }
4306 if (LocaleCompare("depth",option+1) == 0)
4307 {
4308 if (*option == '+')
4309 break;
4310 i++;
cristybb503372010-05-27 20:51:26 +00004311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004312 ThrowMogrifyException(OptionError,"MissingArgument",option);
4313 if (IsGeometry(argv[i]) == MagickFalse)
4314 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4315 break;
4316 }
4317 if (LocaleCompare("deskew",option+1) == 0)
4318 {
4319 if (*option == '+')
4320 break;
4321 i++;
cristybb503372010-05-27 20:51:26 +00004322 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004323 ThrowMogrifyException(OptionError,"MissingArgument",option);
4324 if (IsGeometry(argv[i]) == MagickFalse)
4325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4326 break;
4327 }
4328 if (LocaleCompare("despeckle",option+1) == 0)
4329 break;
4330 if (LocaleCompare("dft",option+1) == 0)
4331 break;
cristyc9b12952010-03-28 01:12:28 +00004332 if (LocaleCompare("direction",option+1) == 0)
4333 {
cristybb503372010-05-27 20:51:26 +00004334 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004335 direction;
4336
4337 if (*option == '+')
4338 break;
4339 i++;
cristybb503372010-05-27 20:51:26 +00004340 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004341 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004342 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004343 argv[i]);
4344 if (direction < 0)
4345 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4346 argv[i]);
4347 break;
4348 }
cristy3ed852e2009-09-05 21:47:34 +00004349 if (LocaleCompare("display",option+1) == 0)
4350 {
4351 if (*option == '+')
4352 break;
4353 i++;
cristybb503372010-05-27 20:51:26 +00004354 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004355 ThrowMogrifyException(OptionError,"MissingArgument",option);
4356 break;
4357 }
4358 if (LocaleCompare("dispose",option+1) == 0)
4359 {
cristybb503372010-05-27 20:51:26 +00004360 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004361 dispose;
4362
4363 if (*option == '+')
4364 break;
4365 i++;
cristybb503372010-05-27 20:51:26 +00004366 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004367 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004368 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004369 if (dispose < 0)
4370 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4371 argv[i]);
4372 break;
4373 }
4374 if (LocaleCompare("distort",option+1) == 0)
4375 {
cristybb503372010-05-27 20:51:26 +00004376 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004377 op;
4378
4379 i++;
cristybb503372010-05-27 20:51:26 +00004380 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004381 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004382 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004383 if (op < 0)
4384 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4385 argv[i]);
4386 i++;
cristybb503372010-05-27 20:51:26 +00004387 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004388 ThrowMogrifyException(OptionError,"MissingArgument",option);
4389 break;
4390 }
4391 if (LocaleCompare("dither",option+1) == 0)
4392 {
cristybb503372010-05-27 20:51:26 +00004393 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004394 method;
4395
4396 if (*option == '+')
4397 break;
4398 i++;
cristybb503372010-05-27 20:51:26 +00004399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004400 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004401 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004402 if (method < 0)
4403 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4404 argv[i]);
4405 break;
4406 }
4407 if (LocaleCompare("draw",option+1) == 0)
4408 {
4409 if (*option == '+')
4410 break;
4411 i++;
cristybb503372010-05-27 20:51:26 +00004412 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004413 ThrowMogrifyException(OptionError,"MissingArgument",option);
4414 break;
4415 }
cristyecb10ff2011-03-22 13:14:03 +00004416 if (LocaleCompare("duplicate",option+1) == 0)
4417 {
4418 if (*option == '+')
4419 break;
4420 i++;
4421 if (i == (ssize_t) (argc-1))
4422 ThrowMogrifyException(OptionError,"MissingArgument",option);
4423 if (IsGeometry(argv[i]) == MagickFalse)
4424 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4425 break;
4426 }
cristy22879752009-10-25 23:55:40 +00004427 if (LocaleCompare("duration",option+1) == 0)
4428 {
4429 if (*option == '+')
4430 break;
4431 i++;
cristybb503372010-05-27 20:51:26 +00004432 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004433 ThrowMogrifyException(OptionError,"MissingArgument",option);
4434 if (IsGeometry(argv[i]) == MagickFalse)
4435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4436 break;
4437 }
cristy3ed852e2009-09-05 21:47:34 +00004438 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4439 }
4440 case 'e':
4441 {
4442 if (LocaleCompare("edge",option+1) == 0)
4443 {
4444 if (*option == '+')
4445 break;
4446 i++;
cristybb503372010-05-27 20:51:26 +00004447 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004448 ThrowMogrifyException(OptionError,"MissingArgument",option);
4449 if (IsGeometry(argv[i]) == MagickFalse)
4450 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4451 break;
4452 }
4453 if (LocaleCompare("emboss",option+1) == 0)
4454 {
4455 if (*option == '+')
4456 break;
4457 i++;
cristybb503372010-05-27 20:51:26 +00004458 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004459 ThrowMogrifyException(OptionError,"MissingArgument",option);
4460 if (IsGeometry(argv[i]) == MagickFalse)
4461 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4462 break;
4463 }
4464 if (LocaleCompare("encipher",option+1) == 0)
4465 {
4466 if (*option == '+')
4467 break;
4468 i++;
cristybb503372010-05-27 20:51:26 +00004469 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004470 ThrowMogrifyException(OptionError,"MissingArgument",option);
4471 break;
4472 }
4473 if (LocaleCompare("encoding",option+1) == 0)
4474 {
4475 if (*option == '+')
4476 break;
4477 i++;
cristybb503372010-05-27 20:51:26 +00004478 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004479 ThrowMogrifyException(OptionError,"MissingArgument",option);
4480 break;
4481 }
4482 if (LocaleCompare("endian",option+1) == 0)
4483 {
cristybb503372010-05-27 20:51:26 +00004484 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004485 endian;
4486
4487 if (*option == '+')
4488 break;
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004492 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004493 if (endian < 0)
4494 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4495 argv[i]);
4496 break;
4497 }
4498 if (LocaleCompare("enhance",option+1) == 0)
4499 break;
4500 if (LocaleCompare("equalize",option+1) == 0)
4501 break;
4502 if (LocaleCompare("evaluate",option+1) == 0)
4503 {
cristybb503372010-05-27 20:51:26 +00004504 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004505 op;
4506
4507 if (*option == '+')
4508 break;
4509 i++;
cristybb503372010-05-27 20:51:26 +00004510 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004511 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004512 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004513 if (op < 0)
4514 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4515 argv[i]);
4516 i++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
4519 if (IsGeometry(argv[i]) == MagickFalse)
4520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4521 break;
4522 }
cristyd18ae7c2010-03-07 17:39:52 +00004523 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4524 {
cristybb503372010-05-27 20:51:26 +00004525 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004526 op;
4527
4528 if (*option == '+')
4529 break;
4530 i++;
cristybb503372010-05-27 20:51:26 +00004531 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004532 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004533 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004534 if (op < 0)
4535 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4536 argv[i]);
4537 break;
4538 }
cristy3ed852e2009-09-05 21:47:34 +00004539 if (LocaleCompare("extent",option+1) == 0)
4540 {
4541 if (*option == '+')
4542 break;
4543 i++;
cristybb503372010-05-27 20:51:26 +00004544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004545 ThrowMogrifyException(OptionError,"MissingArgument",option);
4546 if (IsGeometry(argv[i]) == MagickFalse)
4547 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4548 break;
4549 }
4550 if (LocaleCompare("extract",option+1) == 0)
4551 {
4552 if (*option == '+')
4553 break;
4554 i++;
cristybb503372010-05-27 20:51:26 +00004555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004556 ThrowMogrifyException(OptionError,"MissingArgument",option);
4557 if (IsGeometry(argv[i]) == MagickFalse)
4558 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4559 break;
4560 }
4561 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4562 }
4563 case 'f':
4564 {
4565 if (LocaleCompare("family",option+1) == 0)
4566 {
4567 if (*option == '+')
4568 break;
4569 i++;
cristybb503372010-05-27 20:51:26 +00004570 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004571 ThrowMogrifyException(OptionError,"MissingArgument",option);
4572 break;
4573 }
4574 if (LocaleCompare("fill",option+1) == 0)
4575 {
4576 if (*option == '+')
4577 break;
4578 i++;
cristybb503372010-05-27 20:51:26 +00004579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004580 ThrowMogrifyException(OptionError,"MissingArgument",option);
4581 break;
4582 }
4583 if (LocaleCompare("filter",option+1) == 0)
4584 {
cristybb503372010-05-27 20:51:26 +00004585 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004586 filter;
4587
4588 if (*option == '+')
4589 break;
4590 i++;
cristybb503372010-05-27 20:51:26 +00004591 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004592 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004593 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004594 if (filter < 0)
4595 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4596 argv[i]);
4597 break;
4598 }
4599 if (LocaleCompare("flatten",option+1) == 0)
4600 break;
4601 if (LocaleCompare("flip",option+1) == 0)
4602 break;
4603 if (LocaleCompare("flop",option+1) == 0)
4604 break;
4605 if (LocaleCompare("floodfill",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 if (IsGeometry(argv[i]) == MagickFalse)
4613 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4614 i++;
cristybb503372010-05-27 20:51:26 +00004615 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004616 ThrowMogrifyException(OptionError,"MissingArgument",option);
4617 break;
4618 }
4619 if (LocaleCompare("font",option+1) == 0)
4620 {
4621 if (*option == '+')
4622 break;
4623 i++;
cristybb503372010-05-27 20:51:26 +00004624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004625 ThrowMogrifyException(OptionError,"MissingArgument",option);
4626 break;
4627 }
4628 if (LocaleCompare("format",option+1) == 0)
4629 {
4630 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4631 (void) CloneString(&format,(char *) NULL);
4632 if (*option == '+')
4633 break;
4634 i++;
cristybb503372010-05-27 20:51:26 +00004635 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004636 ThrowMogrifyException(OptionError,"MissingArgument",option);
4637 (void) CloneString(&format,argv[i]);
4638 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4639 (void) ConcatenateMagickString(image_info->filename,":",
4640 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004641 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004642 if (*image_info->magick == '\0')
4643 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4644 format);
4645 break;
4646 }
4647 if (LocaleCompare("frame",option+1) == 0)
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);
4654 if (IsGeometry(argv[i]) == MagickFalse)
4655 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4656 break;
4657 }
4658 if (LocaleCompare("function",option+1) == 0)
4659 {
cristybb503372010-05-27 20:51:26 +00004660 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004661 op;
4662
4663 if (*option == '+')
4664 break;
4665 i++;
cristybb503372010-05-27 20:51:26 +00004666 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004667 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004668 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004669 if (op < 0)
4670 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4671 i++;
cristybb503372010-05-27 20:51:26 +00004672 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 break;
4675 }
4676 if (LocaleCompare("fuzz",option+1) == 0)
4677 {
4678 if (*option == '+')
4679 break;
4680 i++;
cristybb503372010-05-27 20:51:26 +00004681 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004682 ThrowMogrifyException(OptionError,"MissingArgument",option);
4683 if (IsGeometry(argv[i]) == MagickFalse)
4684 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4685 break;
4686 }
4687 if (LocaleCompare("fx",option+1) == 0)
4688 {
4689 if (*option == '+')
4690 break;
4691 i++;
cristybb503372010-05-27 20:51:26 +00004692 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004693 ThrowMogrifyException(OptionError,"MissingArgument",option);
4694 break;
4695 }
4696 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4697 }
4698 case 'g':
4699 {
4700 if (LocaleCompare("gamma",option+1) == 0)
4701 {
4702 i++;
cristybb503372010-05-27 20:51:26 +00004703 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004704 ThrowMogrifyException(OptionError,"MissingArgument",option);
4705 if (IsGeometry(argv[i]) == MagickFalse)
4706 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4707 break;
4708 }
4709 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4710 (LocaleCompare("gaussian",option+1) == 0))
4711 {
4712 i++;
cristybb503372010-05-27 20:51:26 +00004713 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004714 ThrowMogrifyException(OptionError,"MissingArgument",option);
4715 if (IsGeometry(argv[i]) == MagickFalse)
4716 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4717 break;
4718 }
4719 if (LocaleCompare("geometry",option+1) == 0)
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);
4726 if (IsGeometry(argv[i]) == MagickFalse)
4727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4728 break;
4729 }
4730 if (LocaleCompare("gravity",option+1) == 0)
4731 {
cristybb503372010-05-27 20:51:26 +00004732 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004733 gravity;
4734
4735 if (*option == '+')
4736 break;
4737 i++;
cristybb503372010-05-27 20:51:26 +00004738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004739 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004740 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004741 if (gravity < 0)
4742 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4743 argv[i]);
4744 break;
4745 }
4746 if (LocaleCompare("green-primary",option+1) == 0)
4747 {
4748 if (*option == '+')
4749 break;
4750 i++;
cristybb503372010-05-27 20:51:26 +00004751 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004752 ThrowMogrifyException(OptionError,"MissingArgument",option);
4753 if (IsGeometry(argv[i]) == MagickFalse)
4754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4755 break;
4756 }
4757 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4758 }
4759 case 'h':
4760 {
4761 if (LocaleCompare("hald-clut",option+1) == 0)
4762 break;
4763 if ((LocaleCompare("help",option+1) == 0) ||
4764 (LocaleCompare("-help",option+1) == 0))
4765 return(MogrifyUsage());
4766 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4767 }
4768 case 'i':
4769 {
4770 if (LocaleCompare("identify",option+1) == 0)
4771 break;
4772 if (LocaleCompare("idft",option+1) == 0)
4773 break;
4774 if (LocaleCompare("implode",option+1) == 0)
4775 {
4776 if (*option == '+')
4777 break;
4778 i++;
cristybb503372010-05-27 20:51:26 +00004779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004780 ThrowMogrifyException(OptionError,"MissingArgument",option);
4781 if (IsGeometry(argv[i]) == MagickFalse)
4782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4783 break;
4784 }
4785 if (LocaleCompare("intent",option+1) == 0)
4786 {
cristybb503372010-05-27 20:51:26 +00004787 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004788 intent;
4789
4790 if (*option == '+')
4791 break;
4792 i++;
cristybb503372010-05-27 20:51:26 +00004793 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004794 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004795 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004796 if (intent < 0)
4797 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4798 argv[i]);
4799 break;
4800 }
4801 if (LocaleCompare("interlace",option+1) == 0)
4802 {
cristybb503372010-05-27 20:51:26 +00004803 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004804 interlace;
4805
4806 if (*option == '+')
4807 break;
4808 i++;
cristybb503372010-05-27 20:51:26 +00004809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004810 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004811 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004812 argv[i]);
4813 if (interlace < 0)
4814 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4815 argv[i]);
4816 break;
4817 }
cristyb32b90a2009-09-07 21:45:48 +00004818 if (LocaleCompare("interline-spacing",option+1) == 0)
4819 {
4820 if (*option == '+')
4821 break;
4822 i++;
cristybb503372010-05-27 20:51:26 +00004823 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004824 ThrowMogrifyException(OptionError,"MissingArgument",option);
4825 if (IsGeometry(argv[i]) == MagickFalse)
4826 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4827 break;
4828 }
cristy3ed852e2009-09-05 21:47:34 +00004829 if (LocaleCompare("interpolate",option+1) == 0)
4830 {
cristybb503372010-05-27 20:51:26 +00004831 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004832 interpolate;
4833
4834 if (*option == '+')
4835 break;
4836 i++;
cristybb503372010-05-27 20:51:26 +00004837 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004838 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004839 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004840 argv[i]);
4841 if (interpolate < 0)
4842 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4843 argv[i]);
4844 break;
4845 }
4846 if (LocaleCompare("interword-spacing",option+1) == 0)
4847 {
4848 if (*option == '+')
4849 break;
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 if (IsGeometry(argv[i]) == MagickFalse)
4854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4855 break;
4856 }
4857 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4858 }
4859 case 'k':
4860 {
4861 if (LocaleCompare("kerning",option+1) == 0)
4862 {
4863 if (*option == '+')
4864 break;
4865 i++;
cristybb503372010-05-27 20:51:26 +00004866 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004867 ThrowMogrifyException(OptionError,"MissingArgument",option);
4868 if (IsGeometry(argv[i]) == MagickFalse)
4869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4870 break;
4871 }
4872 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4873 }
4874 case 'l':
4875 {
4876 if (LocaleCompare("label",option+1) == 0)
4877 {
4878 if (*option == '+')
4879 break;
4880 i++;
cristybb503372010-05-27 20:51:26 +00004881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004882 ThrowMogrifyException(OptionError,"MissingArgument",option);
4883 break;
4884 }
4885 if (LocaleCompare("lat",option+1) == 0)
4886 {
4887 if (*option == '+')
4888 break;
4889 i++;
cristybb503372010-05-27 20:51:26 +00004890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004891 ThrowMogrifyException(OptionError,"MissingArgument",option);
4892 if (IsGeometry(argv[i]) == MagickFalse)
4893 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4894 }
4895 if (LocaleCompare("layers",option+1) == 0)
4896 {
cristybb503372010-05-27 20:51:26 +00004897 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004898 type;
4899
4900 if (*option == '+')
4901 break;
4902 i++;
cristybb503372010-05-27 20:51:26 +00004903 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004904 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004905 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004906 if (type < 0)
4907 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4908 argv[i]);
4909 break;
4910 }
4911 if (LocaleCompare("level",option+1) == 0)
4912 {
4913 i++;
cristybb503372010-05-27 20:51:26 +00004914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004915 ThrowMogrifyException(OptionError,"MissingArgument",option);
4916 if (IsGeometry(argv[i]) == MagickFalse)
4917 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4918 break;
4919 }
4920 if (LocaleCompare("level-colors",option+1) == 0)
4921 {
4922 i++;
cristybb503372010-05-27 20:51:26 +00004923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004924 ThrowMogrifyException(OptionError,"MissingArgument",option);
4925 break;
4926 }
4927 if (LocaleCompare("linewidth",option+1) == 0)
4928 {
4929 if (*option == '+')
4930 break;
4931 i++;
cristybb503372010-05-27 20:51:26 +00004932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004933 ThrowMogrifyException(OptionError,"MissingArgument",option);
4934 if (IsGeometry(argv[i]) == MagickFalse)
4935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4936 break;
4937 }
4938 if (LocaleCompare("limit",option+1) == 0)
4939 {
4940 char
4941 *p;
4942
4943 double
4944 value;
4945
cristybb503372010-05-27 20:51:26 +00004946 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004947 resource;
4948
4949 if (*option == '+')
4950 break;
4951 i++;
cristybb503372010-05-27 20:51:26 +00004952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004953 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004954 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004955 argv[i]);
4956 if (resource < 0)
4957 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4958 argv[i]);
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);
cristydbdd0e32011-11-04 23:29:40 +00004962 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004963 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004964 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4965 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4966 break;
4967 }
4968 if (LocaleCompare("liquid-rescale",option+1) == 0)
4969 {
4970 i++;
cristybb503372010-05-27 20:51:26 +00004971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004972 ThrowMogrifyException(OptionError,"MissingArgument",option);
4973 if (IsGeometry(argv[i]) == MagickFalse)
4974 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4975 break;
4976 }
4977 if (LocaleCompare("list",option+1) == 0)
4978 {
cristybb503372010-05-27 20:51:26 +00004979 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004980 list;
4981
4982 if (*option == '+')
4983 break;
4984 i++;
cristybb503372010-05-27 20:51:26 +00004985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004986 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004987 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004988 if (list < 0)
4989 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004990 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004991 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004992 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004993 }
4994 if (LocaleCompare("log",option+1) == 0)
4995 {
4996 if (*option == '+')
4997 break;
4998 i++;
cristybb503372010-05-27 20:51:26 +00004999 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005000 (strchr(argv[i],'%') == (char *) NULL))
5001 ThrowMogrifyException(OptionError,"MissingArgument",option);
5002 break;
5003 }
5004 if (LocaleCompare("loop",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 if (IsGeometry(argv[i]) == MagickFalse)
5012 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5013 break;
5014 }
5015 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5016 }
5017 case 'm':
5018 {
5019 if (LocaleCompare("map",option+1) == 0)
5020 {
5021 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5022 if (*option == '+')
5023 break;
5024 i++;
cristybb503372010-05-27 20:51:26 +00005025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005026 ThrowMogrifyException(OptionError,"MissingArgument",option);
5027 break;
5028 }
5029 if (LocaleCompare("mask",option+1) == 0)
5030 {
5031 if (*option == '+')
5032 break;
5033 i++;
cristybb503372010-05-27 20:51:26 +00005034 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005035 ThrowMogrifyException(OptionError,"MissingArgument",option);
5036 break;
5037 }
5038 if (LocaleCompare("matte",option+1) == 0)
5039 break;
5040 if (LocaleCompare("mattecolor",option+1) == 0)
5041 {
5042 if (*option == '+')
5043 break;
5044 i++;
cristybb503372010-05-27 20:51:26 +00005045 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005046 ThrowMogrifyException(OptionError,"MissingArgument",option);
5047 break;
5048 }
cristyf40785b2010-03-06 02:27:27 +00005049 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005050 break;
cristyf40785b2010-03-06 02:27:27 +00005051 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005052 break;
cristy3ed852e2009-09-05 21:47:34 +00005053 if (LocaleCompare("modulate",option+1) == 0)
5054 {
5055 if (*option == '+')
5056 break;
5057 i++;
cristybb503372010-05-27 20:51:26 +00005058 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005059 ThrowMogrifyException(OptionError,"MissingArgument",option);
5060 if (IsGeometry(argv[i]) == MagickFalse)
5061 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5062 break;
5063 }
5064 if (LocaleCompare("median",option+1) == 0)
5065 {
5066 if (*option == '+')
5067 break;
5068 i++;
cristybb503372010-05-27 20:51:26 +00005069 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005070 ThrowMogrifyException(OptionError,"MissingArgument",option);
5071 if (IsGeometry(argv[i]) == MagickFalse)
5072 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5073 break;
5074 }
cristy69ec32d2011-02-27 23:57:09 +00005075 if (LocaleCompare("mode",option+1) == 0)
5076 {
5077 if (*option == '+')
5078 break;
5079 i++;
5080 if (i == (ssize_t) argc)
5081 ThrowMogrifyException(OptionError,"MissingArgument",option);
5082 if (IsGeometry(argv[i]) == MagickFalse)
5083 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5084 break;
5085 }
cristy3ed852e2009-09-05 21:47:34 +00005086 if (LocaleCompare("monitor",option+1) == 0)
5087 break;
5088 if (LocaleCompare("monochrome",option+1) == 0)
5089 break;
5090 if (LocaleCompare("morph",option+1) == 0)
5091 {
5092 if (*option == '+')
5093 break;
5094 i++;
cristybb503372010-05-27 20:51:26 +00005095 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005096 ThrowMogrifyException(OptionError,"MissingArgument",option);
5097 if (IsGeometry(argv[i]) == MagickFalse)
5098 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5099 break;
5100 }
anthony29188a82010-01-22 10:12:34 +00005101 if (LocaleCompare("morphology",option+1) == 0)
5102 {
anthony29188a82010-01-22 10:12:34 +00005103 char
5104 token[MaxTextExtent];
5105
cristyb6bd4ad2010-08-08 01:12:27 +00005106 KernelInfo
5107 *kernel_info;
5108
5109 ssize_t
5110 op;
5111
anthony29188a82010-01-22 10:12:34 +00005112 i++;
cristybb503372010-05-27 20:51:26 +00005113 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005114 ThrowMogrifyException(OptionError,"MissingArgument",option);
5115 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005116 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005117 if (op < 0)
5118 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005119 token);
anthony29188a82010-01-22 10:12:34 +00005120 i++;
cristybb503372010-05-27 20:51:26 +00005121 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005122 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005123 kernel_info=AcquireKernelInfo(argv[i]);
5124 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005125 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005126 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005127 break;
5128 }
cristy3ed852e2009-09-05 21:47:34 +00005129 if (LocaleCompare("mosaic",option+1) == 0)
5130 break;
5131 if (LocaleCompare("motion-blur",option+1) == 0)
5132 {
5133 if (*option == '+')
5134 break;
5135 i++;
cristybb503372010-05-27 20:51:26 +00005136 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005137 ThrowMogrifyException(OptionError,"MissingArgument",option);
5138 if (IsGeometry(argv[i]) == MagickFalse)
5139 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5140 break;
5141 }
5142 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5143 }
5144 case 'n':
5145 {
5146 if (LocaleCompare("negate",option+1) == 0)
5147 break;
5148 if (LocaleCompare("noise",option+1) == 0)
5149 {
5150 i++;
cristybb503372010-05-27 20:51:26 +00005151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005152 ThrowMogrifyException(OptionError,"MissingArgument",option);
5153 if (*option == '+')
5154 {
cristybb503372010-05-27 20:51:26 +00005155 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005156 noise;
5157
cristy042ee782011-04-22 18:48:30 +00005158 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005159 if (noise < 0)
5160 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5161 argv[i]);
5162 break;
5163 }
5164 if (IsGeometry(argv[i]) == MagickFalse)
5165 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5166 break;
5167 }
5168 if (LocaleCompare("noop",option+1) == 0)
5169 break;
5170 if (LocaleCompare("normalize",option+1) == 0)
5171 break;
5172 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5173 }
5174 case 'o':
5175 {
5176 if (LocaleCompare("opaque",option+1) == 0)
5177 {
cristy3ed852e2009-09-05 21:47:34 +00005178 i++;
cristybb503372010-05-27 20:51:26 +00005179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005180 ThrowMogrifyException(OptionError,"MissingArgument",option);
5181 break;
5182 }
5183 if (LocaleCompare("ordered-dither",option+1) == 0)
5184 {
5185 if (*option == '+')
5186 break;
5187 i++;
cristybb503372010-05-27 20:51:26 +00005188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005189 ThrowMogrifyException(OptionError,"MissingArgument",option);
5190 break;
5191 }
5192 if (LocaleCompare("orient",option+1) == 0)
5193 {
cristybb503372010-05-27 20:51:26 +00005194 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005195 orientation;
5196
5197 orientation=UndefinedOrientation;
5198 if (*option == '+')
5199 break;
5200 i++;
cristybb503372010-05-27 20:51:26 +00005201 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005202 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005203 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005204 argv[i]);
5205 if (orientation < 0)
5206 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5207 argv[i]);
5208 break;
5209 }
5210 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5211 }
5212 case 'p':
5213 {
5214 if (LocaleCompare("page",option+1) == 0)
5215 {
5216 if (*option == '+')
5217 break;
5218 i++;
cristybb503372010-05-27 20:51:26 +00005219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005220 ThrowMogrifyException(OptionError,"MissingArgument",option);
5221 break;
5222 }
5223 if (LocaleCompare("paint",option+1) == 0)
5224 {
5225 if (*option == '+')
5226 break;
5227 i++;
cristybb503372010-05-27 20:51:26 +00005228 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005229 ThrowMogrifyException(OptionError,"MissingArgument",option);
5230 if (IsGeometry(argv[i]) == MagickFalse)
5231 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5232 break;
5233 }
5234 if (LocaleCompare("path",option+1) == 0)
5235 {
5236 (void) CloneString(&path,(char *) NULL);
5237 if (*option == '+')
5238 break;
5239 i++;
cristybb503372010-05-27 20:51:26 +00005240 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005241 ThrowMogrifyException(OptionError,"MissingArgument",option);
5242 (void) CloneString(&path,argv[i]);
5243 break;
5244 }
5245 if (LocaleCompare("pointsize",option+1) == 0)
5246 {
5247 if (*option == '+')
5248 break;
5249 i++;
cristybb503372010-05-27 20:51:26 +00005250 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005251 ThrowMogrifyException(OptionError,"MissingArgument",option);
5252 if (IsGeometry(argv[i]) == MagickFalse)
5253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5254 break;
5255 }
5256 if (LocaleCompare("polaroid",option+1) == 0)
5257 {
5258 if (*option == '+')
5259 break;
5260 i++;
cristybb503372010-05-27 20:51:26 +00005261 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005262 ThrowMogrifyException(OptionError,"MissingArgument",option);
5263 if (IsGeometry(argv[i]) == MagickFalse)
5264 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5265 break;
5266 }
5267 if (LocaleCompare("posterize",option+1) == 0)
5268 {
5269 if (*option == '+')
5270 break;
5271 i++;
cristybb503372010-05-27 20:51:26 +00005272 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005273 ThrowMogrifyException(OptionError,"MissingArgument",option);
5274 if (IsGeometry(argv[i]) == MagickFalse)
5275 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5276 break;
5277 }
cristye7f51092010-01-17 00:39:37 +00005278 if (LocaleCompare("precision",option+1) == 0)
5279 {
5280 if (*option == '+')
5281 break;
5282 i++;
cristybb503372010-05-27 20:51:26 +00005283 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005284 ThrowMogrifyException(OptionError,"MissingArgument",option);
5285 if (IsGeometry(argv[i]) == MagickFalse)
5286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5287 break;
5288 }
cristy3ed852e2009-09-05 21:47:34 +00005289 if (LocaleCompare("print",option+1) == 0)
5290 {
5291 if (*option == '+')
5292 break;
5293 i++;
cristybb503372010-05-27 20:51:26 +00005294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005295 ThrowMogrifyException(OptionError,"MissingArgument",option);
5296 break;
5297 }
5298 if (LocaleCompare("process",option+1) == 0)
5299 {
5300 if (*option == '+')
5301 break;
5302 i++;
cristybb503372010-05-27 20:51:26 +00005303 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005304 ThrowMogrifyException(OptionError,"MissingArgument",option);
5305 break;
5306 }
5307 if (LocaleCompare("profile",option+1) == 0)
5308 {
5309 i++;
cristybb503372010-05-27 20:51:26 +00005310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005311 ThrowMogrifyException(OptionError,"MissingArgument",option);
5312 break;
5313 }
5314 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5315 }
5316 case 'q':
5317 {
5318 if (LocaleCompare("quality",option+1) == 0)
5319 {
5320 if (*option == '+')
5321 break;
5322 i++;
cristybb503372010-05-27 20:51:26 +00005323 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005324 ThrowMogrifyException(OptionError,"MissingArgument",option);
5325 if (IsGeometry(argv[i]) == MagickFalse)
5326 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5327 break;
5328 }
5329 if (LocaleCompare("quantize",option+1) == 0)
5330 {
cristybb503372010-05-27 20:51:26 +00005331 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005332 colorspace;
5333
5334 if (*option == '+')
5335 break;
5336 i++;
cristybb503372010-05-27 20:51:26 +00005337 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005338 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005339 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005340 argv[i]);
5341 if (colorspace < 0)
5342 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5343 argv[i]);
5344 break;
5345 }
5346 if (LocaleCompare("quiet",option+1) == 0)
5347 break;
5348 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5349 }
5350 case 'r':
5351 {
5352 if (LocaleCompare("radial-blur",option+1) == 0)
5353 {
5354 i++;
cristybb503372010-05-27 20:51:26 +00005355 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005356 ThrowMogrifyException(OptionError,"MissingArgument",option);
5357 if (IsGeometry(argv[i]) == MagickFalse)
5358 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5359 break;
5360 }
5361 if (LocaleCompare("raise",option+1) == 0)
5362 {
5363 i++;
cristybb503372010-05-27 20:51:26 +00005364 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005365 ThrowMogrifyException(OptionError,"MissingArgument",option);
5366 if (IsGeometry(argv[i]) == MagickFalse)
5367 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5368 break;
5369 }
5370 if (LocaleCompare("random-threshold",option+1) == 0)
5371 {
5372 if (*option == '+')
5373 break;
5374 i++;
cristybb503372010-05-27 20:51:26 +00005375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005376 ThrowMogrifyException(OptionError,"MissingArgument",option);
5377 if (IsGeometry(argv[i]) == MagickFalse)
5378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5379 break;
5380 }
cristye6365592010-04-02 17:31:23 +00005381 if (LocaleCompare("recolor",option+1) == 0)
5382 {
5383 if (*option == '+')
5384 break;
5385 i++;
cristybb503372010-05-27 20:51:26 +00005386 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005387 ThrowMogrifyException(OptionError,"MissingArgument",option);
5388 if (IsGeometry(argv[i]) == MagickFalse)
5389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5390 break;
5391 }
cristy3ed852e2009-09-05 21:47:34 +00005392 if (LocaleCompare("red-primary",option+1) == 0)
5393 {
5394 if (*option == '+')
5395 break;
5396 i++;
cristybb503372010-05-27 20:51:26 +00005397 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005398 ThrowMogrifyException(OptionError,"MissingArgument",option);
5399 if (IsGeometry(argv[i]) == MagickFalse)
5400 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5401 }
cristy9f2083a2010-04-22 19:48:05 +00005402 if (LocaleCompare("regard-warnings",option+1) == 0)
5403 break;
cristy3ed852e2009-09-05 21:47:34 +00005404 if (LocaleCompare("region",option+1) == 0)
5405 {
5406 if (*option == '+')
5407 break;
5408 i++;
cristybb503372010-05-27 20:51:26 +00005409 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005410 ThrowMogrifyException(OptionError,"MissingArgument",option);
5411 if (IsGeometry(argv[i]) == MagickFalse)
5412 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5413 break;
5414 }
cristyf0c78232010-03-15 12:53:40 +00005415 if (LocaleCompare("remap",option+1) == 0)
5416 {
5417 if (*option == '+')
5418 break;
5419 i++;
cristybb503372010-05-27 20:51:26 +00005420 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005421 ThrowMogrifyException(OptionError,"MissingArgument",option);
5422 break;
5423 }
cristy3ed852e2009-09-05 21:47:34 +00005424 if (LocaleCompare("render",option+1) == 0)
5425 break;
5426 if (LocaleCompare("repage",option+1) == 0)
5427 {
5428 if (*option == '+')
5429 break;
5430 i++;
cristybb503372010-05-27 20:51:26 +00005431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005432 ThrowMogrifyException(OptionError,"MissingArgument",option);
5433 if (IsGeometry(argv[i]) == MagickFalse)
5434 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5435 break;
5436 }
5437 if (LocaleCompare("resample",option+1) == 0)
5438 {
5439 if (*option == '+')
5440 break;
5441 i++;
cristybb503372010-05-27 20:51:26 +00005442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005443 ThrowMogrifyException(OptionError,"MissingArgument",option);
5444 if (IsGeometry(argv[i]) == MagickFalse)
5445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5446 break;
5447 }
5448 if (LocaleCompare("resize",option+1) == 0)
5449 {
5450 if (*option == '+')
5451 break;
5452 i++;
cristybb503372010-05-27 20:51:26 +00005453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005454 ThrowMogrifyException(OptionError,"MissingArgument",option);
5455 if (IsGeometry(argv[i]) == MagickFalse)
5456 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5457 break;
5458 }
cristyebbcfea2011-02-25 02:43:54 +00005459 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5460 {
5461 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5462 break;
5463 }
cristy3ed852e2009-09-05 21:47:34 +00005464 if (LocaleCompare("reverse",option+1) == 0)
5465 break;
5466 if (LocaleCompare("roll",option+1) == 0)
5467 {
5468 if (*option == '+')
5469 break;
5470 i++;
cristybb503372010-05-27 20:51:26 +00005471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005472 ThrowMogrifyException(OptionError,"MissingArgument",option);
5473 if (IsGeometry(argv[i]) == MagickFalse)
5474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5475 break;
5476 }
5477 if (LocaleCompare("rotate",option+1) == 0)
5478 {
5479 i++;
cristybb503372010-05-27 20:51:26 +00005480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005481 ThrowMogrifyException(OptionError,"MissingArgument",option);
5482 if (IsGeometry(argv[i]) == MagickFalse)
5483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484 break;
5485 }
5486 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5487 }
5488 case 's':
5489 {
5490 if (LocaleCompare("sample",option+1) == 0)
5491 {
5492 if (*option == '+')
5493 break;
5494 i++;
cristybb503372010-05-27 20:51:26 +00005495 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005496 ThrowMogrifyException(OptionError,"MissingArgument",option);
5497 if (IsGeometry(argv[i]) == MagickFalse)
5498 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5499 break;
5500 }
5501 if (LocaleCompare("sampling-factor",option+1) == 0)
5502 {
5503 if (*option == '+')
5504 break;
5505 i++;
cristybb503372010-05-27 20:51:26 +00005506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005507 ThrowMogrifyException(OptionError,"MissingArgument",option);
5508 if (IsGeometry(argv[i]) == MagickFalse)
5509 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5510 break;
5511 }
5512 if (LocaleCompare("scale",option+1) == 0)
5513 {
5514 if (*option == '+')
5515 break;
5516 i++;
cristybb503372010-05-27 20:51:26 +00005517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005518 ThrowMogrifyException(OptionError,"MissingArgument",option);
5519 if (IsGeometry(argv[i]) == MagickFalse)
5520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5521 break;
5522 }
5523 if (LocaleCompare("scene",option+1) == 0)
5524 {
5525 if (*option == '+')
5526 break;
5527 i++;
cristybb503372010-05-27 20:51:26 +00005528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005529 ThrowMogrifyException(OptionError,"MissingArgument",option);
5530 if (IsGeometry(argv[i]) == MagickFalse)
5531 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5532 break;
5533 }
5534 if (LocaleCompare("seed",option+1) == 0)
5535 {
5536 if (*option == '+')
5537 break;
5538 i++;
cristybb503372010-05-27 20:51:26 +00005539 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005540 ThrowMogrifyException(OptionError,"MissingArgument",option);
5541 if (IsGeometry(argv[i]) == MagickFalse)
5542 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5543 break;
5544 }
5545 if (LocaleCompare("segment",option+1) == 0)
5546 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5553 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5554 break;
5555 }
5556 if (LocaleCompare("selective-blur",option+1) == 0)
5557 {
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 if (IsGeometry(argv[i]) == MagickFalse)
5562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563 break;
5564 }
5565 if (LocaleCompare("separate",option+1) == 0)
5566 break;
5567 if (LocaleCompare("sepia-tone",option+1) == 0)
5568 {
5569 if (*option == '+')
5570 break;
5571 i++;
cristybb503372010-05-27 20:51:26 +00005572 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005573 ThrowMogrifyException(OptionError,"MissingArgument",option);
5574 if (IsGeometry(argv[i]) == MagickFalse)
5575 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5576 break;
5577 }
5578 if (LocaleCompare("set",option+1) == 0)
5579 {
5580 i++;
cristybb503372010-05-27 20:51:26 +00005581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005582 ThrowMogrifyException(OptionError,"MissingArgument",option);
5583 if (*option == '+')
5584 break;
5585 i++;
cristybb503372010-05-27 20:51:26 +00005586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 break;
5589 }
5590 if (LocaleCompare("shade",option+1) == 0)
5591 {
5592 i++;
cristybb503372010-05-27 20:51:26 +00005593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005594 ThrowMogrifyException(OptionError,"MissingArgument",option);
5595 if (IsGeometry(argv[i]) == MagickFalse)
5596 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5597 break;
5598 }
5599 if (LocaleCompare("shadow",option+1) == 0)
5600 {
5601 if (*option == '+')
5602 break;
5603 i++;
cristybb503372010-05-27 20:51:26 +00005604 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005605 ThrowMogrifyException(OptionError,"MissingArgument",option);
5606 if (IsGeometry(argv[i]) == MagickFalse)
5607 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5608 break;
5609 }
5610 if (LocaleCompare("sharpen",option+1) == 0)
5611 {
5612 i++;
cristybb503372010-05-27 20:51:26 +00005613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005614 ThrowMogrifyException(OptionError,"MissingArgument",option);
5615 if (IsGeometry(argv[i]) == MagickFalse)
5616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5617 break;
5618 }
5619 if (LocaleCompare("shave",option+1) == 0)
5620 {
5621 if (*option == '+')
5622 break;
5623 i++;
cristybb503372010-05-27 20:51:26 +00005624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005625 ThrowMogrifyException(OptionError,"MissingArgument",option);
5626 if (IsGeometry(argv[i]) == MagickFalse)
5627 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5628 break;
5629 }
5630 if (LocaleCompare("shear",option+1) == 0)
5631 {
5632 i++;
cristybb503372010-05-27 20:51:26 +00005633 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005634 ThrowMogrifyException(OptionError,"MissingArgument",option);
5635 if (IsGeometry(argv[i]) == MagickFalse)
5636 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5637 break;
5638 }
5639 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5640 {
5641 i++;
cristybb503372010-05-27 20:51:26 +00005642 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005643 ThrowMogrifyException(OptionError,"MissingArgument",option);
5644 if (IsGeometry(argv[i]) == MagickFalse)
5645 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5646 break;
5647 }
5648 if (LocaleCompare("size",option+1) == 0)
5649 {
5650 if (*option == '+')
5651 break;
5652 i++;
cristybb503372010-05-27 20:51:26 +00005653 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005654 ThrowMogrifyException(OptionError,"MissingArgument",option);
5655 if (IsGeometry(argv[i]) == MagickFalse)
5656 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5657 break;
5658 }
5659 if (LocaleCompare("sketch",option+1) == 0)
5660 {
5661 if (*option == '+')
5662 break;
5663 i++;
cristybb503372010-05-27 20:51:26 +00005664 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005665 ThrowMogrifyException(OptionError,"MissingArgument",option);
5666 if (IsGeometry(argv[i]) == MagickFalse)
5667 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5668 break;
5669 }
cristy4285d782011-02-09 20:12:28 +00005670 if (LocaleCompare("smush",option+1) == 0)
5671 {
cristy4285d782011-02-09 20:12:28 +00005672 i++;
5673 if (i == (ssize_t) argc)
5674 ThrowMogrifyException(OptionError,"MissingArgument",option);
5675 if (IsGeometry(argv[i]) == MagickFalse)
5676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005677 i++;
5678 break;
5679 }
cristy3ed852e2009-09-05 21:47:34 +00005680 if (LocaleCompare("solarize",option+1) == 0)
5681 {
5682 if (*option == '+')
5683 break;
5684 i++;
cristybb503372010-05-27 20:51:26 +00005685 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005686 ThrowMogrifyException(OptionError,"MissingArgument",option);
5687 if (IsGeometry(argv[i]) == MagickFalse)
5688 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5689 break;
5690 }
5691 if (LocaleCompare("sparse-color",option+1) == 0)
5692 {
cristybb503372010-05-27 20:51:26 +00005693 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005694 op;
5695
5696 i++;
cristybb503372010-05-27 20:51:26 +00005697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005698 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005699 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005700 if (op < 0)
5701 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5702 argv[i]);
5703 i++;
cristybb503372010-05-27 20:51:26 +00005704 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005705 ThrowMogrifyException(OptionError,"MissingArgument",option);
5706 break;
5707 }
5708 if (LocaleCompare("spread",option+1) == 0)
5709 {
5710 if (*option == '+')
5711 break;
5712 i++;
cristybb503372010-05-27 20:51:26 +00005713 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005714 ThrowMogrifyException(OptionError,"MissingArgument",option);
5715 if (IsGeometry(argv[i]) == MagickFalse)
5716 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5717 break;
5718 }
cristy0834d642011-03-18 18:26:08 +00005719 if (LocaleCompare("statistic",option+1) == 0)
5720 {
5721 ssize_t
5722 op;
5723
5724 if (*option == '+')
5725 break;
5726 i++;
5727 if (i == (ssize_t) argc)
5728 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005729 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005730 if (op < 0)
5731 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5732 argv[i]);
5733 i++;
5734 if (i == (ssize_t) (argc-1))
5735 ThrowMogrifyException(OptionError,"MissingArgument",option);
5736 if (IsGeometry(argv[i]) == MagickFalse)
5737 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5738 break;
5739 }
cristy3ed852e2009-09-05 21:47:34 +00005740 if (LocaleCompare("stretch",option+1) == 0)
5741 {
cristybb503372010-05-27 20:51:26 +00005742 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005743 stretch;
5744
5745 if (*option == '+')
5746 break;
5747 i++;
cristybb503372010-05-27 20:51:26 +00005748 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005749 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005750 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005751 if (stretch < 0)
5752 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5753 argv[i]);
5754 break;
5755 }
5756 if (LocaleCompare("strip",option+1) == 0)
5757 break;
5758 if (LocaleCompare("stroke",option+1) == 0)
5759 {
5760 if (*option == '+')
5761 break;
5762 i++;
cristybb503372010-05-27 20:51:26 +00005763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005764 ThrowMogrifyException(OptionError,"MissingArgument",option);
5765 break;
5766 }
5767 if (LocaleCompare("strokewidth",option+1) == 0)
5768 {
5769 if (*option == '+')
5770 break;
5771 i++;
cristybb503372010-05-27 20:51:26 +00005772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005773 ThrowMogrifyException(OptionError,"MissingArgument",option);
5774 if (IsGeometry(argv[i]) == MagickFalse)
5775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5776 break;
5777 }
5778 if (LocaleCompare("style",option+1) == 0)
5779 {
cristybb503372010-05-27 20:51:26 +00005780 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005781 style;
5782
5783 if (*option == '+')
5784 break;
5785 i++;
cristybb503372010-05-27 20:51:26 +00005786 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005787 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005788 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005789 if (style < 0)
5790 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5791 argv[i]);
5792 break;
5793 }
cristyecb10ff2011-03-22 13:14:03 +00005794 if (LocaleCompare("swap",option+1) == 0)
5795 {
5796 if (*option == '+')
5797 break;
5798 i++;
5799 if (i == (ssize_t) (argc-1))
5800 ThrowMogrifyException(OptionError,"MissingArgument",option);
5801 if (IsGeometry(argv[i]) == MagickFalse)
5802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5803 break;
5804 }
cristy3ed852e2009-09-05 21:47:34 +00005805 if (LocaleCompare("swirl",option+1) == 0)
5806 {
5807 if (*option == '+')
5808 break;
5809 i++;
cristybb503372010-05-27 20:51:26 +00005810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005811 ThrowMogrifyException(OptionError,"MissingArgument",option);
5812 if (IsGeometry(argv[i]) == MagickFalse)
5813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5814 break;
5815 }
cristyd9a29192010-10-16 16:49:53 +00005816 if (LocaleCompare("synchronize",option+1) == 0)
5817 break;
cristy3ed852e2009-09-05 21:47:34 +00005818 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5819 }
5820 case 't':
5821 {
5822 if (LocaleCompare("taint",option+1) == 0)
5823 break;
5824 if (LocaleCompare("texture",option+1) == 0)
5825 {
5826 if (*option == '+')
5827 break;
5828 i++;
cristybb503372010-05-27 20:51:26 +00005829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005830 ThrowMogrifyException(OptionError,"MissingArgument",option);
5831 break;
5832 }
5833 if (LocaleCompare("tile",option+1) == 0)
5834 {
5835 if (*option == '+')
5836 break;
5837 i++;
cristybb503372010-05-27 20:51:26 +00005838 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005839 ThrowMogrifyException(OptionError,"MissingArgument",option);
5840 break;
5841 }
5842 if (LocaleCompare("tile-offset",option+1) == 0)
5843 {
5844 if (*option == '+')
5845 break;
5846 i++;
cristybb503372010-05-27 20:51:26 +00005847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005848 ThrowMogrifyException(OptionError,"MissingArgument",option);
5849 if (IsGeometry(argv[i]) == MagickFalse)
5850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5851 break;
5852 }
5853 if (LocaleCompare("tint",option+1) == 0)
5854 {
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 if (IsGeometry(argv[i]) == MagickFalse)
5861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5862 break;
5863 }
5864 if (LocaleCompare("transform",option+1) == 0)
5865 break;
5866 if (LocaleCompare("transpose",option+1) == 0)
5867 break;
5868 if (LocaleCompare("transverse",option+1) == 0)
5869 break;
5870 if (LocaleCompare("threshold",option+1) == 0)
5871 {
5872 if (*option == '+')
5873 break;
5874 i++;
cristybb503372010-05-27 20:51:26 +00005875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005876 ThrowMogrifyException(OptionError,"MissingArgument",option);
5877 if (IsGeometry(argv[i]) == MagickFalse)
5878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5879 break;
5880 }
5881 if (LocaleCompare("thumbnail",option+1) == 0)
5882 {
5883 if (*option == '+')
5884 break;
5885 i++;
cristybb503372010-05-27 20:51:26 +00005886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005887 ThrowMogrifyException(OptionError,"MissingArgument",option);
5888 if (IsGeometry(argv[i]) == MagickFalse)
5889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5890 break;
5891 }
5892 if (LocaleCompare("transparent",option+1) == 0)
5893 {
5894 i++;
cristybb503372010-05-27 20:51:26 +00005895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005896 ThrowMogrifyException(OptionError,"MissingArgument",option);
5897 break;
5898 }
5899 if (LocaleCompare("transparent-color",option+1) == 0)
5900 {
5901 if (*option == '+')
5902 break;
5903 i++;
cristybb503372010-05-27 20:51:26 +00005904 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005905 ThrowMogrifyException(OptionError,"MissingArgument",option);
5906 break;
5907 }
5908 if (LocaleCompare("treedepth",option+1) == 0)
5909 {
5910 if (*option == '+')
5911 break;
5912 i++;
cristybb503372010-05-27 20:51:26 +00005913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005914 ThrowMogrifyException(OptionError,"MissingArgument",option);
5915 if (IsGeometry(argv[i]) == MagickFalse)
5916 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5917 break;
5918 }
5919 if (LocaleCompare("trim",option+1) == 0)
5920 break;
5921 if (LocaleCompare("type",option+1) == 0)
5922 {
cristybb503372010-05-27 20:51:26 +00005923 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005924 type;
5925
5926 if (*option == '+')
5927 break;
5928 i++;
cristybb503372010-05-27 20:51:26 +00005929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005930 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005931 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005932 if (type < 0)
5933 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5934 argv[i]);
5935 break;
5936 }
5937 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5938 }
5939 case 'u':
5940 {
5941 if (LocaleCompare("undercolor",option+1) == 0)
5942 {
5943 if (*option == '+')
5944 break;
5945 i++;
cristybb503372010-05-27 20:51:26 +00005946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005947 ThrowMogrifyException(OptionError,"MissingArgument",option);
5948 break;
5949 }
5950 if (LocaleCompare("unique-colors",option+1) == 0)
5951 break;
5952 if (LocaleCompare("units",option+1) == 0)
5953 {
cristybb503372010-05-27 20:51:26 +00005954 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005955 units;
5956
5957 if (*option == '+')
5958 break;
5959 i++;
cristybb503372010-05-27 20:51:26 +00005960 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005961 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005962 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005963 argv[i]);
5964 if (units < 0)
5965 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5966 argv[i]);
5967 break;
5968 }
5969 if (LocaleCompare("unsharp",option+1) == 0)
5970 {
5971 i++;
cristybb503372010-05-27 20:51:26 +00005972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005973 ThrowMogrifyException(OptionError,"MissingArgument",option);
5974 if (IsGeometry(argv[i]) == MagickFalse)
5975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5976 break;
5977 }
5978 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5979 }
5980 case 'v':
5981 {
5982 if (LocaleCompare("verbose",option+1) == 0)
5983 {
5984 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5985 break;
5986 }
5987 if ((LocaleCompare("version",option+1) == 0) ||
5988 (LocaleCompare("-version",option+1) == 0))
5989 {
cristyb51dff52011-05-19 16:55:47 +00005990 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005991 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005992 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5993 GetMagickCopyright());
5994 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5995 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005996 break;
5997 }
5998 if (LocaleCompare("view",option+1) == 0)
5999 {
6000 if (*option == '+')
6001 break;
6002 i++;
cristybb503372010-05-27 20:51:26 +00006003 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006004 ThrowMogrifyException(OptionError,"MissingArgument",option);
6005 break;
6006 }
6007 if (LocaleCompare("vignette",option+1) == 0)
6008 {
6009 if (*option == '+')
6010 break;
6011 i++;
cristybb503372010-05-27 20:51:26 +00006012 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006013 ThrowMogrifyException(OptionError,"MissingArgument",option);
6014 if (IsGeometry(argv[i]) == MagickFalse)
6015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6016 break;
6017 }
6018 if (LocaleCompare("virtual-pixel",option+1) == 0)
6019 {
cristybb503372010-05-27 20:51:26 +00006020 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006021 method;
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);
cristy042ee782011-04-22 18:48:30 +00006028 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006029 argv[i]);
6030 if (method < 0)
6031 ThrowMogrifyException(OptionError,
6032 "UnrecognizedVirtualPixelMethod",argv[i]);
6033 break;
6034 }
6035 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6036 }
6037 case 'w':
6038 {
6039 if (LocaleCompare("wave",option+1) == 0)
6040 {
6041 i++;
cristybb503372010-05-27 20:51:26 +00006042 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006043 ThrowMogrifyException(OptionError,"MissingArgument",option);
6044 if (IsGeometry(argv[i]) == MagickFalse)
6045 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6046 break;
6047 }
6048 if (LocaleCompare("weight",option+1) == 0)
6049 {
6050 if (*option == '+')
6051 break;
6052 i++;
cristybb503372010-05-27 20:51:26 +00006053 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006054 ThrowMogrifyException(OptionError,"MissingArgument",option);
6055 break;
6056 }
6057 if (LocaleCompare("white-point",option+1) == 0)
6058 {
6059 if (*option == '+')
6060 break;
6061 i++;
cristybb503372010-05-27 20:51:26 +00006062 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006063 ThrowMogrifyException(OptionError,"MissingArgument",option);
6064 if (IsGeometry(argv[i]) == MagickFalse)
6065 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6066 break;
6067 }
6068 if (LocaleCompare("white-threshold",option+1) == 0)
6069 {
6070 if (*option == '+')
6071 break;
6072 i++;
cristybb503372010-05-27 20:51:26 +00006073 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006074 ThrowMogrifyException(OptionError,"MissingArgument",option);
6075 if (IsGeometry(argv[i]) == MagickFalse)
6076 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6077 break;
6078 }
6079 if (LocaleCompare("write",option+1) == 0)
6080 {
6081 i++;
cristybb503372010-05-27 20:51:26 +00006082 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006083 ThrowMogrifyException(OptionError,"MissingArgument",option);
6084 break;
6085 }
6086 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6087 }
6088 case '?':
6089 break;
6090 default:
6091 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6092 }
cristy042ee782011-04-22 18:48:30 +00006093 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6094 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006095 if (fire != MagickFalse)
6096 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6097 }
6098 if (k != 0)
6099 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006100 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006101 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6102 DestroyMogrify();
6103 return(status != 0 ? MagickTrue : MagickFalse);
6104}
6105
6106/*
6107%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6108% %
6109% %
6110% %
6111+ M o g r i f y I m a g e I n f o %
6112% %
6113% %
6114% %
6115%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6116%
6117% MogrifyImageInfo() applies image processing settings to the image as
6118% prescribed by command line options.
6119%
6120% The format of the MogrifyImageInfo method is:
6121%
6122% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6123% const char **argv,ExceptionInfo *exception)
6124%
6125% A description of each parameter follows:
6126%
6127% o image_info: the image info..
6128%
6129% o argc: Specifies a pointer to an integer describing the number of
6130% elements in the argument vector.
6131%
6132% o argv: Specifies a pointer to a text array containing the command line
6133% arguments.
6134%
6135% o exception: return any errors or warnings in this structure.
6136%
6137*/
6138WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6139 const int argc,const char **argv,ExceptionInfo *exception)
6140{
6141 const char
6142 *option;
6143
6144 GeometryInfo
6145 geometry_info;
6146
cristybb503372010-05-27 20:51:26 +00006147 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006148 count;
6149
cristybb503372010-05-27 20:51:26 +00006150 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006151 i;
6152
6153 /*
6154 Initialize method variables.
6155 */
6156 assert(image_info != (ImageInfo *) NULL);
6157 assert(image_info->signature == MagickSignature);
6158 if (image_info->debug != MagickFalse)
6159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6160 image_info->filename);
6161 if (argc < 0)
6162 return(MagickTrue);
6163 /*
6164 Set the image settings.
6165 */
cristybb503372010-05-27 20:51:26 +00006166 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006167 {
6168 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006169 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006170 continue;
cristy042ee782011-04-22 18:48:30 +00006171 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006172 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006173 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006174 break;
6175 switch (*(option+1))
6176 {
6177 case 'a':
6178 {
6179 if (LocaleCompare("adjoin",option+1) == 0)
6180 {
6181 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6182 break;
6183 }
6184 if (LocaleCompare("antialias",option+1) == 0)
6185 {
6186 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6187 break;
6188 }
cristy3ed852e2009-09-05 21:47:34 +00006189 if (LocaleCompare("authenticate",option+1) == 0)
6190 {
6191 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006192 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006193 else
anthony1afdc7a2011-10-05 11:54:28 +00006194 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006195 break;
6196 }
6197 break;
6198 }
6199 case 'b':
6200 {
6201 if (LocaleCompare("background",option+1) == 0)
6202 {
6203 if (*option == '+')
6204 {
6205 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006206 (void) QueryColorCompliance(MogrifyBackgroundColor,
6207 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006208 break;
6209 }
6210 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006211 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6212 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006213 break;
6214 }
6215 if (LocaleCompare("bias",option+1) == 0)
6216 {
6217 if (*option == '+')
6218 {
6219 (void) SetImageOption(image_info,option+1,"0.0");
6220 break;
6221 }
6222 (void) SetImageOption(image_info,option+1,argv[i+1]);
6223 break;
6224 }
6225 if (LocaleCompare("black-point-compensation",option+1) == 0)
6226 {
6227 if (*option == '+')
6228 {
6229 (void) SetImageOption(image_info,option+1,"false");
6230 break;
6231 }
6232 (void) SetImageOption(image_info,option+1,"true");
6233 break;
6234 }
6235 if (LocaleCompare("blue-primary",option+1) == 0)
6236 {
6237 if (*option == '+')
6238 {
6239 (void) SetImageOption(image_info,option+1,"0.0");
6240 break;
6241 }
6242 (void) SetImageOption(image_info,option+1,argv[i+1]);
6243 break;
6244 }
6245 if (LocaleCompare("bordercolor",option+1) == 0)
6246 {
6247 if (*option == '+')
6248 {
6249 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006250 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006251 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006252 break;
6253 }
cristy9950d572011-10-01 18:22:35 +00006254 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6255 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006256 (void) SetImageOption(image_info,option+1,argv[i+1]);
6257 break;
6258 }
6259 if (LocaleCompare("box",option+1) == 0)
6260 {
6261 if (*option == '+')
6262 {
6263 (void) SetImageOption(image_info,"undercolor","none");
6264 break;
6265 }
6266 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6267 break;
6268 }
6269 break;
6270 }
6271 case 'c':
6272 {
6273 if (LocaleCompare("cache",option+1) == 0)
6274 {
6275 MagickSizeType
6276 limit;
6277
6278 limit=MagickResourceInfinity;
6279 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006280 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6281 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006282 (void) SetMagickResourceLimit(MemoryResource,limit);
6283 (void) SetMagickResourceLimit(MapResource,2*limit);
6284 break;
6285 }
6286 if (LocaleCompare("caption",option+1) == 0)
6287 {
6288 if (*option == '+')
6289 {
6290 (void) DeleteImageOption(image_info,option+1);
6291 break;
6292 }
6293 (void) SetImageOption(image_info,option+1,argv[i+1]);
6294 break;
6295 }
6296 if (LocaleCompare("channel",option+1) == 0)
6297 {
6298 if (*option == '+')
6299 {
6300 image_info->channel=DefaultChannels;
6301 break;
6302 }
6303 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6304 break;
6305 }
cristy3ed852e2009-09-05 21:47:34 +00006306 if (LocaleCompare("colorspace",option+1) == 0)
6307 {
6308 if (*option == '+')
6309 {
6310 image_info->colorspace=UndefinedColorspace;
6311 (void) SetImageOption(image_info,option+1,"undefined");
6312 break;
6313 }
cristy042ee782011-04-22 18:48:30 +00006314 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006315 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6316 (void) SetImageOption(image_info,option+1,argv[i+1]);
6317 break;
6318 }
cristy3ed852e2009-09-05 21:47:34 +00006319 if (LocaleCompare("comment",option+1) == 0)
6320 {
6321 if (*option == '+')
6322 {
6323 (void) DeleteImageOption(image_info,option+1);
6324 break;
6325 }
6326 (void) SetImageOption(image_info,option+1,argv[i+1]);
6327 break;
6328 }
6329 if (LocaleCompare("compose",option+1) == 0)
6330 {
6331 if (*option == '+')
6332 {
6333 (void) SetImageOption(image_info,option+1,"undefined");
6334 break;
6335 }
6336 (void) SetImageOption(image_info,option+1,argv[i+1]);
6337 break;
6338 }
6339 if (LocaleCompare("compress",option+1) == 0)
6340 {
6341 if (*option == '+')
6342 {
6343 image_info->compression=UndefinedCompression;
6344 (void) SetImageOption(image_info,option+1,"undefined");
6345 break;
6346 }
cristy042ee782011-04-22 18:48:30 +00006347 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006348 MagickCompressOptions,MagickFalse,argv[i+1]);
6349 (void) SetImageOption(image_info,option+1,argv[i+1]);
6350 break;
6351 }
6352 break;
6353 }
6354 case 'd':
6355 {
6356 if (LocaleCompare("debug",option+1) == 0)
6357 {
6358 if (*option == '+')
6359 (void) SetLogEventMask("none");
6360 else
6361 (void) SetLogEventMask(argv[i+1]);
6362 image_info->debug=IsEventLogging();
6363 break;
6364 }
6365 if (LocaleCompare("define",option+1) == 0)
6366 {
6367 if (*option == '+')
6368 {
6369 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6370 (void) DeleteImageRegistry(argv[i+1]+9);
6371 else
6372 (void) DeleteImageOption(image_info,argv[i+1]);
6373 break;
6374 }
6375 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6376 {
6377 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6378 exception);
6379 break;
6380 }
6381 (void) DefineImageOption(image_info,argv[i+1]);
6382 break;
6383 }
6384 if (LocaleCompare("delay",option+1) == 0)
6385 {
6386 if (*option == '+')
6387 {
6388 (void) SetImageOption(image_info,option+1,"0");
6389 break;
6390 }
6391 (void) SetImageOption(image_info,option+1,argv[i+1]);
6392 break;
6393 }
6394 if (LocaleCompare("density",option+1) == 0)
6395 {
6396 /*
6397 Set image density.
6398 */
6399 if (*option == '+')
6400 {
6401 if (image_info->density != (char *) NULL)
6402 image_info->density=DestroyString(image_info->density);
6403 (void) SetImageOption(image_info,option+1,"72");
6404 break;
6405 }
6406 (void) CloneString(&image_info->density,argv[i+1]);
6407 (void) SetImageOption(image_info,option+1,argv[i+1]);
6408 break;
6409 }
6410 if (LocaleCompare("depth",option+1) == 0)
6411 {
6412 if (*option == '+')
6413 {
6414 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6415 break;
6416 }
cristye27293e2009-12-18 02:53:20 +00006417 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006418 break;
6419 }
cristyc9b12952010-03-28 01:12:28 +00006420 if (LocaleCompare("direction",option+1) == 0)
6421 {
6422 if (*option == '+')
6423 {
6424 (void) SetImageOption(image_info,option+1,"undefined");
6425 break;
6426 }
6427 (void) SetImageOption(image_info,option+1,argv[i+1]);
6428 break;
6429 }
cristy3ed852e2009-09-05 21:47:34 +00006430 if (LocaleCompare("display",option+1) == 0)
6431 {
6432 if (*option == '+')
6433 {
6434 if (image_info->server_name != (char *) NULL)
6435 image_info->server_name=DestroyString(
6436 image_info->server_name);
6437 break;
6438 }
6439 (void) CloneString(&image_info->server_name,argv[i+1]);
6440 break;
6441 }
6442 if (LocaleCompare("dispose",option+1) == 0)
6443 {
6444 if (*option == '+')
6445 {
6446 (void) SetImageOption(image_info,option+1,"undefined");
6447 break;
6448 }
6449 (void) SetImageOption(image_info,option+1,argv[i+1]);
6450 break;
6451 }
6452 if (LocaleCompare("dither",option+1) == 0)
6453 {
6454 if (*option == '+')
6455 {
6456 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006457 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006458 break;
6459 }
6460 (void) SetImageOption(image_info,option+1,argv[i+1]);
6461 image_info->dither=MagickTrue;
6462 break;
6463 }
6464 break;
6465 }
6466 case 'e':
6467 {
6468 if (LocaleCompare("encoding",option+1) == 0)
6469 {
6470 if (*option == '+')
6471 {
6472 (void) SetImageOption(image_info,option+1,"undefined");
6473 break;
6474 }
6475 (void) SetImageOption(image_info,option+1,argv[i+1]);
6476 break;
6477 }
6478 if (LocaleCompare("endian",option+1) == 0)
6479 {
6480 if (*option == '+')
6481 {
6482 image_info->endian=UndefinedEndian;
6483 (void) SetImageOption(image_info,option+1,"undefined");
6484 break;
6485 }
cristy042ee782011-04-22 18:48:30 +00006486 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006487 MagickEndianOptions,MagickFalse,argv[i+1]);
6488 (void) SetImageOption(image_info,option+1,argv[i+1]);
6489 break;
6490 }
6491 if (LocaleCompare("extract",option+1) == 0)
6492 {
6493 /*
6494 Set image extract geometry.
6495 */
6496 if (*option == '+')
6497 {
6498 if (image_info->extract != (char *) NULL)
6499 image_info->extract=DestroyString(image_info->extract);
6500 break;
6501 }
6502 (void) CloneString(&image_info->extract,argv[i+1]);
6503 break;
6504 }
6505 break;
6506 }
6507 case 'f':
6508 {
6509 if (LocaleCompare("fill",option+1) == 0)
6510 {
6511 if (*option == '+')
6512 {
6513 (void) SetImageOption(image_info,option+1,"none");
6514 break;
6515 }
6516 (void) SetImageOption(image_info,option+1,argv[i+1]);
6517 break;
6518 }
6519 if (LocaleCompare("filter",option+1) == 0)
6520 {
6521 if (*option == '+')
6522 {
6523 (void) SetImageOption(image_info,option+1,"undefined");
6524 break;
6525 }
6526 (void) SetImageOption(image_info,option+1,argv[i+1]);
6527 break;
6528 }
6529 if (LocaleCompare("font",option+1) == 0)
6530 {
6531 if (*option == '+')
6532 {
6533 if (image_info->font != (char *) NULL)
6534 image_info->font=DestroyString(image_info->font);
6535 break;
6536 }
6537 (void) CloneString(&image_info->font,argv[i+1]);
6538 break;
6539 }
6540 if (LocaleCompare("format",option+1) == 0)
6541 {
6542 register const char
6543 *q;
6544
6545 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006546 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006547 image_info->ping=MagickFalse;
6548 (void) SetImageOption(image_info,option+1,argv[i+1]);
6549 break;
6550 }
6551 if (LocaleCompare("fuzz",option+1) == 0)
6552 {
6553 if (*option == '+')
6554 {
6555 image_info->fuzz=0.0;
6556 (void) SetImageOption(image_info,option+1,"0");
6557 break;
6558 }
cristydbdd0e32011-11-04 23:29:40 +00006559 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6560 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006561 (void) SetImageOption(image_info,option+1,argv[i+1]);
6562 break;
6563 }
6564 break;
6565 }
6566 case 'g':
6567 {
6568 if (LocaleCompare("gravity",option+1) == 0)
6569 {
6570 if (*option == '+')
6571 {
6572 (void) SetImageOption(image_info,option+1,"undefined");
6573 break;
6574 }
6575 (void) SetImageOption(image_info,option+1,argv[i+1]);
6576 break;
6577 }
6578 if (LocaleCompare("green-primary",option+1) == 0)
6579 {
6580 if (*option == '+')
6581 {
6582 (void) SetImageOption(image_info,option+1,"0.0");
6583 break;
6584 }
6585 (void) SetImageOption(image_info,option+1,argv[i+1]);
6586 break;
6587 }
6588 break;
6589 }
6590 case 'i':
6591 {
6592 if (LocaleCompare("intent",option+1) == 0)
6593 {
6594 if (*option == '+')
6595 {
6596 (void) SetImageOption(image_info,option+1,"undefined");
6597 break;
6598 }
6599 (void) SetImageOption(image_info,option+1,argv[i+1]);
6600 break;
6601 }
6602 if (LocaleCompare("interlace",option+1) == 0)
6603 {
6604 if (*option == '+')
6605 {
6606 image_info->interlace=UndefinedInterlace;
6607 (void) SetImageOption(image_info,option+1,"undefined");
6608 break;
6609 }
cristy042ee782011-04-22 18:48:30 +00006610 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006611 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6612 (void) SetImageOption(image_info,option+1,argv[i+1]);
6613 break;
6614 }
cristyb32b90a2009-09-07 21:45:48 +00006615 if (LocaleCompare("interline-spacing",option+1) == 0)
6616 {
6617 if (*option == '+')
6618 {
6619 (void) SetImageOption(image_info,option+1,"undefined");
6620 break;
6621 }
6622 (void) SetImageOption(image_info,option+1,argv[i+1]);
6623 break;
6624 }
cristy3ed852e2009-09-05 21:47:34 +00006625 if (LocaleCompare("interpolate",option+1) == 0)
6626 {
6627 if (*option == '+')
6628 {
6629 (void) SetImageOption(image_info,option+1,"undefined");
6630 break;
6631 }
6632 (void) SetImageOption(image_info,option+1,argv[i+1]);
6633 break;
6634 }
6635 if (LocaleCompare("interword-spacing",option+1) == 0)
6636 {
6637 if (*option == '+')
6638 {
6639 (void) SetImageOption(image_info,option+1,"undefined");
6640 break;
6641 }
6642 (void) SetImageOption(image_info,option+1,argv[i+1]);
6643 break;
6644 }
6645 break;
6646 }
6647 case 'k':
6648 {
6649 if (LocaleCompare("kerning",option+1) == 0)
6650 {
6651 if (*option == '+')
6652 {
6653 (void) SetImageOption(image_info,option+1,"undefined");
6654 break;
6655 }
6656 (void) SetImageOption(image_info,option+1,argv[i+1]);
6657 break;
6658 }
6659 break;
6660 }
6661 case 'l':
6662 {
6663 if (LocaleCompare("label",option+1) == 0)
6664 {
6665 if (*option == '+')
6666 {
6667 (void) DeleteImageOption(image_info,option+1);
6668 break;
6669 }
6670 (void) SetImageOption(image_info,option+1,argv[i+1]);
6671 break;
6672 }
6673 if (LocaleCompare("limit",option+1) == 0)
6674 {
6675 MagickSizeType
6676 limit;
6677
6678 ResourceType
6679 type;
6680
6681 if (*option == '+')
6682 break;
cristy042ee782011-04-22 18:48:30 +00006683 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006684 MagickFalse,argv[i+1]);
6685 limit=MagickResourceInfinity;
6686 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006687 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006688 (void) SetMagickResourceLimit(type,limit);
6689 break;
6690 }
6691 if (LocaleCompare("list",option+1) == 0)
6692 {
cristybb503372010-05-27 20:51:26 +00006693 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006694 list;
6695
6696 /*
6697 Display configuration list.
6698 */
cristy042ee782011-04-22 18:48:30 +00006699 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006700 switch (list)
6701 {
6702 case MagickCoderOptions:
6703 {
6704 (void) ListCoderInfo((FILE *) NULL,exception);
6705 break;
6706 }
6707 case MagickColorOptions:
6708 {
6709 (void) ListColorInfo((FILE *) NULL,exception);
6710 break;
6711 }
6712 case MagickConfigureOptions:
6713 {
6714 (void) ListConfigureInfo((FILE *) NULL,exception);
6715 break;
6716 }
6717 case MagickDelegateOptions:
6718 {
6719 (void) ListDelegateInfo((FILE *) NULL,exception);
6720 break;
6721 }
6722 case MagickFontOptions:
6723 {
6724 (void) ListTypeInfo((FILE *) NULL,exception);
6725 break;
6726 }
6727 case MagickFormatOptions:
6728 {
6729 (void) ListMagickInfo((FILE *) NULL,exception);
6730 break;
6731 }
6732 case MagickLocaleOptions:
6733 {
6734 (void) ListLocaleInfo((FILE *) NULL,exception);
6735 break;
6736 }
6737 case MagickLogOptions:
6738 {
6739 (void) ListLogInfo((FILE *) NULL,exception);
6740 break;
6741 }
6742 case MagickMagicOptions:
6743 {
6744 (void) ListMagicInfo((FILE *) NULL,exception);
6745 break;
6746 }
6747 case MagickMimeOptions:
6748 {
6749 (void) ListMimeInfo((FILE *) NULL,exception);
6750 break;
6751 }
6752 case MagickModuleOptions:
6753 {
6754 (void) ListModuleInfo((FILE *) NULL,exception);
6755 break;
6756 }
6757 case MagickPolicyOptions:
6758 {
6759 (void) ListPolicyInfo((FILE *) NULL,exception);
6760 break;
6761 }
6762 case MagickResourceOptions:
6763 {
6764 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6765 break;
6766 }
6767 case MagickThresholdOptions:
6768 {
6769 (void) ListThresholdMaps((FILE *) NULL,exception);
6770 break;
6771 }
6772 default:
6773 {
cristy042ee782011-04-22 18:48:30 +00006774 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006775 exception);
6776 break;
6777 }
6778 }
cristyaeb2cbc2010-05-07 13:28:58 +00006779 break;
cristy3ed852e2009-09-05 21:47:34 +00006780 }
6781 if (LocaleCompare("log",option+1) == 0)
6782 {
6783 if (*option == '+')
6784 break;
6785 (void) SetLogFormat(argv[i+1]);
6786 break;
6787 }
6788 if (LocaleCompare("loop",option+1) == 0)
6789 {
6790 if (*option == '+')
6791 {
6792 (void) SetImageOption(image_info,option+1,"0");
6793 break;
6794 }
6795 (void) SetImageOption(image_info,option+1,argv[i+1]);
6796 break;
6797 }
6798 break;
6799 }
6800 case 'm':
6801 {
6802 if (LocaleCompare("matte",option+1) == 0)
6803 {
6804 if (*option == '+')
6805 {
6806 (void) SetImageOption(image_info,option+1,"false");
6807 break;
6808 }
6809 (void) SetImageOption(image_info,option+1,"true");
6810 break;
6811 }
6812 if (LocaleCompare("mattecolor",option+1) == 0)
6813 {
6814 if (*option == '+')
6815 {
6816 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006817 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006818 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006819 break;
6820 }
6821 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006822 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6823 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006824 break;
6825 }
6826 if (LocaleCompare("monitor",option+1) == 0)
6827 {
6828 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6829 (void *) NULL);
6830 break;
6831 }
6832 if (LocaleCompare("monochrome",option+1) == 0)
6833 {
6834 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6835 break;
6836 }
6837 break;
6838 }
6839 case 'o':
6840 {
6841 if (LocaleCompare("orient",option+1) == 0)
6842 {
6843 if (*option == '+')
6844 {
6845 image_info->orientation=UndefinedOrientation;
6846 (void) SetImageOption(image_info,option+1,"undefined");
6847 break;
6848 }
cristy042ee782011-04-22 18:48:30 +00006849 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006850 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006851 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006852 break;
6853 }
6854 }
6855 case 'p':
6856 {
6857 if (LocaleCompare("page",option+1) == 0)
6858 {
6859 char
6860 *canonical_page,
6861 page[MaxTextExtent];
6862
6863 const char
6864 *image_option;
6865
6866 MagickStatusType
6867 flags;
6868
6869 RectangleInfo
6870 geometry;
6871
6872 if (*option == '+')
6873 {
6874 (void) DeleteImageOption(image_info,option+1);
6875 (void) CloneString(&image_info->page,(char *) NULL);
6876 break;
6877 }
6878 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6879 image_option=GetImageOption(image_info,"page");
6880 if (image_option != (const char *) NULL)
6881 flags=ParseAbsoluteGeometry(image_option,&geometry);
6882 canonical_page=GetPageGeometry(argv[i+1]);
6883 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6884 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006885 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006886 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006887 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006888 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006889 (unsigned long) geometry.width,(unsigned long) geometry.height,
6890 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006891 (void) SetImageOption(image_info,option+1,page);
6892 (void) CloneString(&image_info->page,page);
6893 break;
6894 }
cristy3ed852e2009-09-05 21:47:34 +00006895 if (LocaleCompare("ping",option+1) == 0)
6896 {
6897 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6898 break;
6899 }
6900 if (LocaleCompare("pointsize",option+1) == 0)
6901 {
6902 if (*option == '+')
6903 geometry_info.rho=0.0;
6904 else
6905 (void) ParseGeometry(argv[i+1],&geometry_info);
6906 image_info->pointsize=geometry_info.rho;
6907 break;
6908 }
cristye7f51092010-01-17 00:39:37 +00006909 if (LocaleCompare("precision",option+1) == 0)
6910 {
cristybf2766a2010-01-17 03:33:23 +00006911 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006912 break;
6913 }
cristy3ed852e2009-09-05 21:47:34 +00006914 if (LocaleCompare("preview",option+1) == 0)
6915 {
6916 /*
6917 Preview image.
6918 */
6919 if (*option == '+')
6920 {
6921 image_info->preview_type=UndefinedPreview;
6922 break;
6923 }
cristy042ee782011-04-22 18:48:30 +00006924 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006925 MagickPreviewOptions,MagickFalse,argv[i+1]);
6926 break;
6927 }
6928 break;
6929 }
6930 case 'q':
6931 {
6932 if (LocaleCompare("quality",option+1) == 0)
6933 {
6934 /*
6935 Set image compression quality.
6936 */
6937 if (*option == '+')
6938 {
6939 image_info->quality=UndefinedCompressionQuality;
6940 (void) SetImageOption(image_info,option+1,"0");
6941 break;
6942 }
cristye27293e2009-12-18 02:53:20 +00006943 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006944 (void) SetImageOption(image_info,option+1,argv[i+1]);
6945 break;
6946 }
6947 if (LocaleCompare("quiet",option+1) == 0)
6948 {
6949 static WarningHandler
6950 warning_handler = (WarningHandler) NULL;
6951
6952 if (*option == '+')
6953 {
6954 /*
6955 Restore error or warning messages.
6956 */
6957 warning_handler=SetWarningHandler(warning_handler);
6958 break;
6959 }
6960 /*
6961 Suppress error or warning messages.
6962 */
6963 warning_handler=SetWarningHandler((WarningHandler) NULL);
6964 break;
6965 }
6966 break;
6967 }
6968 case 'r':
6969 {
6970 if (LocaleCompare("red-primary",option+1) == 0)
6971 {
6972 if (*option == '+')
6973 {
6974 (void) SetImageOption(image_info,option+1,"0.0");
6975 break;
6976 }
6977 (void) SetImageOption(image_info,option+1,argv[i+1]);
6978 break;
6979 }
6980 break;
6981 }
6982 case 's':
6983 {
6984 if (LocaleCompare("sampling-factor",option+1) == 0)
6985 {
6986 /*
6987 Set image sampling factor.
6988 */
6989 if (*option == '+')
6990 {
6991 if (image_info->sampling_factor != (char *) NULL)
6992 image_info->sampling_factor=DestroyString(
6993 image_info->sampling_factor);
6994 break;
6995 }
6996 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6997 break;
6998 }
6999 if (LocaleCompare("scene",option+1) == 0)
7000 {
7001 /*
7002 Set image scene.
7003 */
7004 if (*option == '+')
7005 {
7006 image_info->scene=0;
7007 (void) SetImageOption(image_info,option+1,"0");
7008 break;
7009 }
cristye27293e2009-12-18 02:53:20 +00007010 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007011 (void) SetImageOption(image_info,option+1,argv[i+1]);
7012 break;
7013 }
7014 if (LocaleCompare("seed",option+1) == 0)
7015 {
cristybb503372010-05-27 20:51:26 +00007016 size_t
cristy3ed852e2009-09-05 21:47:34 +00007017 seed;
7018
7019 if (*option == '+')
7020 {
cristybb503372010-05-27 20:51:26 +00007021 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007022 SeedPseudoRandomGenerator(seed);
7023 break;
7024 }
cristye27293e2009-12-18 02:53:20 +00007025 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007026 SeedPseudoRandomGenerator(seed);
7027 break;
7028 }
7029 if (LocaleCompare("size",option+1) == 0)
7030 {
7031 if (*option == '+')
7032 {
7033 if (image_info->size != (char *) NULL)
7034 image_info->size=DestroyString(image_info->size);
7035 break;
7036 }
7037 (void) CloneString(&image_info->size,argv[i+1]);
7038 break;
7039 }
7040 if (LocaleCompare("stroke",option+1) == 0)
7041 {
7042 if (*option == '+')
7043 {
7044 (void) SetImageOption(image_info,option+1,"none");
7045 break;
7046 }
7047 (void) SetImageOption(image_info,option+1,argv[i+1]);
7048 break;
7049 }
7050 if (LocaleCompare("strokewidth",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 {
7054 (void) SetImageOption(image_info,option+1,"0");
7055 break;
7056 }
7057 (void) SetImageOption(image_info,option+1,argv[i+1]);
7058 break;
7059 }
cristyd9a29192010-10-16 16:49:53 +00007060 if (LocaleCompare("synchronize",option+1) == 0)
7061 {
7062 if (*option == '+')
7063 {
7064 image_info->synchronize=MagickFalse;
7065 break;
7066 }
7067 image_info->synchronize=MagickTrue;
7068 break;
7069 }
cristy3ed852e2009-09-05 21:47:34 +00007070 break;
7071 }
7072 case 't':
7073 {
7074 if (LocaleCompare("taint",option+1) == 0)
7075 {
7076 if (*option == '+')
7077 {
7078 (void) SetImageOption(image_info,option+1,"false");
7079 break;
7080 }
7081 (void) SetImageOption(image_info,option+1,"true");
7082 break;
7083 }
7084 if (LocaleCompare("texture",option+1) == 0)
7085 {
7086 if (*option == '+')
7087 {
7088 if (image_info->texture != (char *) NULL)
7089 image_info->texture=DestroyString(image_info->texture);
7090 break;
7091 }
7092 (void) CloneString(&image_info->texture,argv[i+1]);
7093 break;
7094 }
7095 if (LocaleCompare("tile-offset",option+1) == 0)
7096 {
7097 if (*option == '+')
7098 {
7099 (void) SetImageOption(image_info,option+1,"0");
7100 break;
7101 }
7102 (void) SetImageOption(image_info,option+1,argv[i+1]);
7103 break;
7104 }
7105 if (LocaleCompare("transparent-color",option+1) == 0)
7106 {
7107 if (*option == '+')
7108 {
cristy9950d572011-10-01 18:22:35 +00007109 (void) QueryColorCompliance("none",AllCompliance,
7110 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007111 (void) SetImageOption(image_info,option+1,"none");
7112 break;
7113 }
cristy9950d572011-10-01 18:22:35 +00007114 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7115 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007116 (void) SetImageOption(image_info,option+1,argv[i+1]);
7117 break;
7118 }
7119 if (LocaleCompare("type",option+1) == 0)
7120 {
7121 if (*option == '+')
7122 {
cristy5f1c1ff2010-12-23 21:38:06 +00007123 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007124 (void) SetImageOption(image_info,option+1,"undefined");
7125 break;
7126 }
cristy042ee782011-04-22 18:48:30 +00007127 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007128 MagickFalse,argv[i+1]);
7129 (void) SetImageOption(image_info,option+1,argv[i+1]);
7130 break;
7131 }
7132 break;
7133 }
7134 case 'u':
7135 {
7136 if (LocaleCompare("undercolor",option+1) == 0)
7137 {
7138 if (*option == '+')
7139 {
7140 (void) DeleteImageOption(image_info,option+1);
7141 break;
7142 }
7143 (void) SetImageOption(image_info,option+1,argv[i+1]);
7144 break;
7145 }
7146 if (LocaleCompare("units",option+1) == 0)
7147 {
7148 if (*option == '+')
7149 {
7150 image_info->units=UndefinedResolution;
7151 (void) SetImageOption(image_info,option+1,"undefined");
7152 break;
7153 }
cristy042ee782011-04-22 18:48:30 +00007154 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007155 MagickResolutionOptions,MagickFalse,argv[i+1]);
7156 (void) SetImageOption(image_info,option+1,argv[i+1]);
7157 break;
7158 }
7159 break;
7160 }
7161 case 'v':
7162 {
7163 if (LocaleCompare("verbose",option+1) == 0)
7164 {
7165 if (*option == '+')
7166 {
7167 image_info->verbose=MagickFalse;
7168 break;
7169 }
7170 image_info->verbose=MagickTrue;
7171 image_info->ping=MagickFalse;
7172 break;
7173 }
7174 if (LocaleCompare("view",option+1) == 0)
7175 {
7176 if (*option == '+')
7177 {
7178 if (image_info->view != (char *) NULL)
7179 image_info->view=DestroyString(image_info->view);
7180 break;
7181 }
7182 (void) CloneString(&image_info->view,argv[i+1]);
7183 break;
7184 }
7185 if (LocaleCompare("virtual-pixel",option+1) == 0)
7186 {
7187 if (*option == '+')
7188 {
7189 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7190 (void) SetImageOption(image_info,option+1,"undefined");
7191 break;
7192 }
7193 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007194 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007195 argv[i+1]);
7196 (void) SetImageOption(image_info,option+1,argv[i+1]);
7197 break;
7198 }
7199 break;
7200 }
7201 case 'w':
7202 {
7203 if (LocaleCompare("white-point",option+1) == 0)
7204 {
7205 if (*option == '+')
7206 {
7207 (void) SetImageOption(image_info,option+1,"0.0");
7208 break;
7209 }
7210 (void) SetImageOption(image_info,option+1,argv[i+1]);
7211 break;
7212 }
7213 break;
7214 }
7215 default:
7216 break;
7217 }
7218 i+=count;
7219 }
7220 return(MagickTrue);
7221}
7222
7223/*
7224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7225% %
7226% %
7227% %
7228+ M o g r i f y I m a g e L i s t %
7229% %
7230% %
7231% %
7232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7233%
7234% MogrifyImageList() applies any command line options that might affect the
7235% entire image list (e.g. -append, -coalesce, etc.).
7236%
7237% The format of the MogrifyImage method is:
7238%
7239% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7240% const char **argv,Image **images,ExceptionInfo *exception)
7241%
7242% A description of each parameter follows:
7243%
7244% o image_info: the image info..
7245%
7246% o argc: Specifies a pointer to an integer describing the number of
7247% elements in the argument vector.
7248%
7249% o argv: Specifies a pointer to a text array containing the command line
7250% arguments.
7251%
anthonye9c27192011-03-27 08:07:06 +00007252% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007253%
7254% o exception: return any errors or warnings in this structure.
7255%
7256*/
7257WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7258 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7259{
cristy3ed852e2009-09-05 21:47:34 +00007260 const char
7261 *option;
7262
cristy6b3da3a2010-06-20 02:21:46 +00007263 ImageInfo
7264 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007265
7266 MagickStatusType
7267 status;
7268
cristy28474bf2011-09-11 23:32:52 +00007269 PixelInterpolateMethod
7270 interpolate_method;
7271
cristy3ed852e2009-09-05 21:47:34 +00007272 QuantizeInfo
7273 *quantize_info;
7274
cristybb503372010-05-27 20:51:26 +00007275 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007276 i;
7277
cristy6b3da3a2010-06-20 02:21:46 +00007278 ssize_t
7279 count,
7280 index;
7281
cristy3ed852e2009-09-05 21:47:34 +00007282 /*
7283 Apply options to the image list.
7284 */
7285 assert(image_info != (ImageInfo *) NULL);
7286 assert(image_info->signature == MagickSignature);
7287 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007288 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007289 assert((*images)->signature == MagickSignature);
7290 if ((*images)->debug != MagickFalse)
7291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7292 (*images)->filename);
7293 if ((argc <= 0) || (*argv == (char *) NULL))
7294 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007295 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007296 mogrify_info=CloneImageInfo(image_info);
7297 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007298 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007299 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007300 {
cristy74fe8f12009-10-03 19:09:01 +00007301 if (*images == (Image *) NULL)
7302 break;
cristy3ed852e2009-09-05 21:47:34 +00007303 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007304 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007305 continue;
cristy042ee782011-04-22 18:48:30 +00007306 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007307 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007308 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007309 break;
cristy6b3da3a2010-06-20 02:21:46 +00007310 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007311 switch (*(option+1))
7312 {
7313 case 'a':
7314 {
7315 if (LocaleCompare("affinity",option+1) == 0)
7316 {
cristy6fccee12011-10-20 18:43:18 +00007317 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007318 if (*option == '+')
7319 {
cristy018f07f2011-09-04 21:15:19 +00007320 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7321 exception);
cristy3ed852e2009-09-05 21:47:34 +00007322 break;
7323 }
7324 i++;
7325 break;
7326 }
7327 if (LocaleCompare("append",option+1) == 0)
7328 {
7329 Image
7330 *append_image;
7331
cristy6fccee12011-10-20 18:43:18 +00007332 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007333 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7334 MagickFalse,exception);
7335 if (append_image == (Image *) NULL)
7336 {
7337 status=MagickFalse;
7338 break;
7339 }
7340 *images=DestroyImageList(*images);
7341 *images=append_image;
7342 break;
7343 }
7344 if (LocaleCompare("average",option+1) == 0)
7345 {
7346 Image
7347 *average_image;
7348
cristyd18ae7c2010-03-07 17:39:52 +00007349 /*
7350 Average an image sequence (deprecated).
7351 */
cristy6fccee12011-10-20 18:43:18 +00007352 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007353 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7354 exception);
cristy3ed852e2009-09-05 21:47:34 +00007355 if (average_image == (Image *) NULL)
7356 {
7357 status=MagickFalse;
7358 break;
7359 }
7360 *images=DestroyImageList(*images);
7361 *images=average_image;
7362 break;
7363 }
7364 break;
7365 }
7366 case 'c':
7367 {
7368 if (LocaleCompare("channel",option+1) == 0)
7369 {
cristyf4ad9df2011-07-08 16:49:03 +00007370 ChannelType
7371 channel;
7372
cristy3ed852e2009-09-05 21:47:34 +00007373 if (*option == '+')
7374 {
7375 channel=DefaultChannels;
7376 break;
7377 }
7378 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00007379 SetPixelChannelMapMask(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007380 break;
7381 }
7382 if (LocaleCompare("clut",option+1) == 0)
7383 {
7384 Image
7385 *clut_image,
7386 *image;
7387
cristy6fccee12011-10-20 18:43:18 +00007388 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007389 image=RemoveFirstImageFromList(images);
7390 clut_image=RemoveFirstImageFromList(images);
7391 if (clut_image == (Image *) NULL)
7392 {
7393 status=MagickFalse;
7394 break;
7395 }
cristy28474bf2011-09-11 23:32:52 +00007396 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007397 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007398 *images=DestroyImageList(*images);
7399 *images=image;
7400 break;
7401 }
7402 if (LocaleCompare("coalesce",option+1) == 0)
7403 {
7404 Image
7405 *coalesce_image;
7406
cristy6fccee12011-10-20 18:43:18 +00007407 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007408 coalesce_image=CoalesceImages(*images,exception);
7409 if (coalesce_image == (Image *) NULL)
7410 {
7411 status=MagickFalse;
7412 break;
7413 }
7414 *images=DestroyImageList(*images);
7415 *images=coalesce_image;
7416 break;
7417 }
7418 if (LocaleCompare("combine",option+1) == 0)
7419 {
7420 Image
7421 *combine_image;
7422
cristy6fccee12011-10-20 18:43:18 +00007423 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007424 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007425 if (combine_image == (Image *) NULL)
7426 {
7427 status=MagickFalse;
7428 break;
7429 }
7430 *images=DestroyImageList(*images);
7431 *images=combine_image;
7432 break;
7433 }
7434 if (LocaleCompare("composite",option+1) == 0)
7435 {
7436 Image
7437 *mask_image,
7438 *composite_image,
7439 *image;
7440
7441 RectangleInfo
7442 geometry;
7443
cristy6fccee12011-10-20 18:43:18 +00007444 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007445 image=RemoveFirstImageFromList(images);
7446 composite_image=RemoveFirstImageFromList(images);
7447 if (composite_image == (Image *) NULL)
7448 {
7449 status=MagickFalse;
7450 break;
7451 }
7452 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007453 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007454 SetGeometry(composite_image,&geometry);
7455 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7456 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7457 &geometry);
7458 mask_image=RemoveFirstImageFromList(images);
7459 if (mask_image != (Image *) NULL)
7460 {
7461 if ((image->compose == DisplaceCompositeOp) ||
7462 (image->compose == DistortCompositeOp))
7463 {
7464 /*
7465 Merge Y displacement into X displacement image.
7466 */
7467 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007468 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007469 mask_image=DestroyImage(mask_image);
7470 }
7471 else
7472 {
7473 /*
anthony80c37752012-01-16 01:03:11 +00007474 Set a blending mask for the composition.
7475 Possible problem, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007476 */
7477 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007478 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007479 }
7480 }
cristyf4ad9df2011-07-08 16:49:03 +00007481 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007482 geometry.x,geometry.y,exception);
anthonya129f702011-04-14 01:08:48 +00007483 if (mask_image != (Image *) NULL)
cristyd197cbb2012-01-13 02:14:12 +00007484 {
7485 image->mask=DestroyImage(image->mask);
7486 mask_image=(Image *) NULL;
7487 }
cristy3ed852e2009-09-05 21:47:34 +00007488 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007489 *images=DestroyImageList(*images);
7490 *images=image;
7491 break;
7492 }
cristy3ed852e2009-09-05 21:47:34 +00007493 break;
7494 }
7495 case 'd':
7496 {
7497 if (LocaleCompare("deconstruct",option+1) == 0)
7498 {
7499 Image
7500 *deconstruct_image;
7501
cristy6fccee12011-10-20 18:43:18 +00007502 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007503 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007504 exception);
cristy3ed852e2009-09-05 21:47:34 +00007505 if (deconstruct_image == (Image *) NULL)
7506 {
7507 status=MagickFalse;
7508 break;
7509 }
7510 *images=DestroyImageList(*images);
7511 *images=deconstruct_image;
7512 break;
7513 }
7514 if (LocaleCompare("delete",option+1) == 0)
7515 {
7516 if (*option == '+')
7517 DeleteImages(images,"-1",exception);
7518 else
7519 DeleteImages(images,argv[i+1],exception);
7520 break;
7521 }
7522 if (LocaleCompare("dither",option+1) == 0)
7523 {
7524 if (*option == '+')
7525 {
7526 quantize_info->dither=MagickFalse;
7527 break;
7528 }
7529 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007530 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007531 MagickDitherOptions,MagickFalse,argv[i+1]);
7532 break;
7533 }
cristyecb10ff2011-03-22 13:14:03 +00007534 if (LocaleCompare("duplicate",option+1) == 0)
7535 {
cristy72988482011-03-29 16:34:38 +00007536 Image
7537 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007538
anthony2b6bcae2011-03-23 13:05:34 +00007539 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007540 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7541 else
7542 {
7543 const char
7544 *p;
7545
anthony2b6bcae2011-03-23 13:05:34 +00007546 size_t
7547 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007548
anthony2b6bcae2011-03-23 13:05:34 +00007549 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007550 p=strchr(argv[i+1],',');
7551 if (p == (const char *) NULL)
7552 duplicate_images=DuplicateImages(*images,number_duplicates,
7553 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007554 else
cristy72988482011-03-29 16:34:38 +00007555 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7556 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007557 }
7558 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007559 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007560 break;
7561 }
cristy3ed852e2009-09-05 21:47:34 +00007562 break;
7563 }
cristyd18ae7c2010-03-07 17:39:52 +00007564 case 'e':
7565 {
7566 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7567 {
7568 Image
7569 *evaluate_image;
7570
7571 MagickEvaluateOperator
7572 op;
7573
cristy6fccee12011-10-20 18:43:18 +00007574 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007575 op=(MagickEvaluateOperator) ParseCommandOption(
7576 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007577 evaluate_image=EvaluateImages(*images,op,exception);
7578 if (evaluate_image == (Image *) NULL)
7579 {
7580 status=MagickFalse;
7581 break;
7582 }
7583 *images=DestroyImageList(*images);
7584 *images=evaluate_image;
7585 break;
7586 }
7587 break;
7588 }
cristy3ed852e2009-09-05 21:47:34 +00007589 case 'f':
7590 {
cristyf0a247f2009-10-04 00:20:03 +00007591 if (LocaleCompare("fft",option+1) == 0)
7592 {
7593 Image
7594 *fourier_image;
7595
7596 /*
7597 Implements the discrete Fourier transform (DFT).
7598 */
cristy6fccee12011-10-20 18:43:18 +00007599 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007600 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7601 MagickTrue : MagickFalse,exception);
7602 if (fourier_image == (Image *) NULL)
7603 break;
7604 *images=DestroyImage(*images);
7605 *images=fourier_image;
7606 break;
7607 }
cristy3ed852e2009-09-05 21:47:34 +00007608 if (LocaleCompare("flatten",option+1) == 0)
7609 {
7610 Image
7611 *flatten_image;
7612
cristy6fccee12011-10-20 18:43:18 +00007613 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007614 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7615 if (flatten_image == (Image *) NULL)
7616 break;
7617 *images=DestroyImageList(*images);
7618 *images=flatten_image;
7619 break;
7620 }
7621 if (LocaleCompare("fx",option+1) == 0)
7622 {
7623 Image
7624 *fx_image;
7625
cristy6fccee12011-10-20 18:43:18 +00007626 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007627 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007628 if (fx_image == (Image *) NULL)
7629 {
7630 status=MagickFalse;
7631 break;
7632 }
7633 *images=DestroyImageList(*images);
7634 *images=fx_image;
7635 break;
7636 }
7637 break;
7638 }
7639 case 'h':
7640 {
7641 if (LocaleCompare("hald-clut",option+1) == 0)
7642 {
7643 Image
7644 *hald_image,
7645 *image;
7646
cristy6fccee12011-10-20 18:43:18 +00007647 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007648 image=RemoveFirstImageFromList(images);
7649 hald_image=RemoveFirstImageFromList(images);
7650 if (hald_image == (Image *) NULL)
7651 {
7652 status=MagickFalse;
7653 break;
7654 }
cristy7c0a0a42011-08-23 17:57:25 +00007655 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007656 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007657 if (*images != (Image *) NULL)
7658 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007659 *images=image;
7660 break;
7661 }
7662 break;
7663 }
7664 case 'i':
7665 {
7666 if (LocaleCompare("ift",option+1) == 0)
7667 {
7668 Image
cristy8587f882009-11-13 20:28:49 +00007669 *fourier_image,
7670 *magnitude_image,
7671 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007672
7673 /*
7674 Implements the inverse fourier discrete Fourier transform (DFT).
7675 */
cristy6fccee12011-10-20 18:43:18 +00007676 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007677 magnitude_image=RemoveFirstImageFromList(images);
7678 phase_image=RemoveFirstImageFromList(images);
7679 if (phase_image == (Image *) NULL)
7680 {
7681 status=MagickFalse;
7682 break;
7683 }
7684 fourier_image=InverseFourierTransformImage(magnitude_image,
7685 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007686 if (fourier_image == (Image *) NULL)
7687 break;
cristy0aff6ea2009-11-14 01:40:53 +00007688 if (*images != (Image *) NULL)
7689 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007690 *images=fourier_image;
7691 break;
7692 }
7693 if (LocaleCompare("insert",option+1) == 0)
7694 {
7695 Image
7696 *p,
7697 *q;
7698
7699 index=0;
7700 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007701 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007702 p=RemoveLastImageFromList(images);
7703 if (p == (Image *) NULL)
7704 {
7705 (void) ThrowMagickException(exception,GetMagickModule(),
7706 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7707 status=MagickFalse;
7708 break;
7709 }
7710 q=p;
7711 if (index == 0)
7712 PrependImageToList(images,q);
7713 else
cristybb503372010-05-27 20:51:26 +00007714 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007715 AppendImageToList(images,q);
7716 else
7717 {
7718 q=GetImageFromList(*images,index-1);
7719 if (q == (Image *) NULL)
7720 {
7721 (void) ThrowMagickException(exception,GetMagickModule(),
7722 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7723 status=MagickFalse;
7724 break;
7725 }
7726 InsertImageInList(&q,p);
7727 }
7728 *images=GetFirstImageInList(q);
7729 break;
7730 }
cristy28474bf2011-09-11 23:32:52 +00007731 if (LocaleCompare("interpolate",option+1) == 0)
7732 {
7733 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7734 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7735 break;
7736 }
cristy3ed852e2009-09-05 21:47:34 +00007737 break;
7738 }
7739 case 'l':
7740 {
7741 if (LocaleCompare("layers",option+1) == 0)
7742 {
7743 Image
7744 *layers;
7745
7746 ImageLayerMethod
7747 method;
7748
cristy6fccee12011-10-20 18:43:18 +00007749 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007750 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007751 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007752 MagickFalse,argv[i+1]);
7753 switch (method)
7754 {
7755 case CoalesceLayer:
7756 {
7757 layers=CoalesceImages(*images,exception);
7758 break;
7759 }
7760 case CompareAnyLayer:
7761 case CompareClearLayer:
7762 case CompareOverlayLayer:
7763 default:
7764 {
cristy8a9106f2011-07-05 14:39:26 +00007765 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007766 break;
7767 }
7768 case MergeLayer:
7769 case FlattenLayer:
7770 case MosaicLayer:
7771 case TrimBoundsLayer:
7772 {
7773 layers=MergeImageLayers(*images,method,exception);
7774 break;
7775 }
7776 case DisposeLayer:
7777 {
7778 layers=DisposeImages(*images,exception);
7779 break;
7780 }
7781 case OptimizeImageLayer:
7782 {
7783 layers=OptimizeImageLayers(*images,exception);
7784 break;
7785 }
7786 case OptimizePlusLayer:
7787 {
7788 layers=OptimizePlusImageLayers(*images,exception);
7789 break;
7790 }
7791 case OptimizeTransLayer:
7792 {
7793 OptimizeImageTransparency(*images,exception);
7794 break;
7795 }
7796 case RemoveDupsLayer:
7797 {
7798 RemoveDuplicateLayers(images,exception);
7799 break;
7800 }
7801 case RemoveZeroLayer:
7802 {
7803 RemoveZeroDelayLayers(images,exception);
7804 break;
7805 }
7806 case OptimizeLayer:
7807 {
7808 /*
7809 General Purpose, GIF Animation Optimizer.
7810 */
7811 layers=CoalesceImages(*images,exception);
7812 if (layers == (Image *) NULL)
7813 {
7814 status=MagickFalse;
7815 break;
7816 }
cristy3ed852e2009-09-05 21:47:34 +00007817 *images=DestroyImageList(*images);
7818 *images=layers;
7819 layers=OptimizeImageLayers(*images,exception);
7820 if (layers == (Image *) NULL)
7821 {
7822 status=MagickFalse;
7823 break;
7824 }
cristy3ed852e2009-09-05 21:47:34 +00007825 *images=DestroyImageList(*images);
7826 *images=layers;
7827 layers=(Image *) NULL;
7828 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007829 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7830 exception);
cristy3ed852e2009-09-05 21:47:34 +00007831 break;
7832 }
7833 case CompositeLayer:
7834 {
7835 CompositeOperator
7836 compose;
7837
7838 Image
7839 *source;
7840
7841 RectangleInfo
7842 geometry;
7843
7844 /*
7845 Split image sequence at the first 'NULL:' image.
7846 */
7847 source=(*images);
7848 while (source != (Image *) NULL)
7849 {
7850 source=GetNextImageInList(source);
7851 if ((source != (Image *) NULL) &&
7852 (LocaleCompare(source->magick,"NULL") == 0))
7853 break;
7854 }
7855 if (source != (Image *) NULL)
7856 {
7857 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7858 (GetNextImageInList(source) == (Image *) NULL))
7859 source=(Image *) NULL;
7860 else
7861 {
7862 /*
7863 Separate the two lists, junk the null: image.
7864 */
7865 source=SplitImageList(source->previous);
7866 DeleteImageFromList(&source);
7867 }
7868 }
7869 if (source == (Image *) NULL)
7870 {
7871 (void) ThrowMagickException(exception,GetMagickModule(),
7872 OptionError,"MissingNullSeparator","layers Composite");
7873 status=MagickFalse;
7874 break;
7875 }
7876 /*
7877 Adjust offset with gravity and virtual canvas.
7878 */
7879 SetGeometry(*images,&geometry);
7880 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7881 geometry.width=source->page.width != 0 ?
7882 source->page.width : source->columns;
7883 geometry.height=source->page.height != 0 ?
7884 source->page.height : source->rows;
7885 GravityAdjustGeometry((*images)->page.width != 0 ?
7886 (*images)->page.width : (*images)->columns,
7887 (*images)->page.height != 0 ? (*images)->page.height :
7888 (*images)->rows,(*images)->gravity,&geometry);
7889 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007890 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007891 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007892 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007893 MagickComposeOptions,MagickFalse,option);
7894 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7895 exception);
7896 source=DestroyImageList(source);
7897 break;
7898 }
7899 }
7900 if (layers == (Image *) NULL)
7901 break;
cristy3ed852e2009-09-05 21:47:34 +00007902 *images=DestroyImageList(*images);
7903 *images=layers;
7904 break;
7905 }
7906 break;
7907 }
7908 case 'm':
7909 {
7910 if (LocaleCompare("map",option+1) == 0)
7911 {
cristy6fccee12011-10-20 18:43:18 +00007912 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007913 if (*option == '+')
7914 {
cristy018f07f2011-09-04 21:15:19 +00007915 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7916 exception);
cristy3ed852e2009-09-05 21:47:34 +00007917 break;
7918 }
7919 i++;
7920 break;
7921 }
cristyf40785b2010-03-06 02:27:27 +00007922 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007923 {
7924 Image
cristyf40785b2010-03-06 02:27:27 +00007925 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007926
cristyd18ae7c2010-03-07 17:39:52 +00007927 /*
7928 Maximum image sequence (deprecated).
7929 */
cristy6fccee12011-10-20 18:43:18 +00007930 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007931 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007932 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007933 {
7934 status=MagickFalse;
7935 break;
7936 }
7937 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007938 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007939 break;
7940 }
cristyf40785b2010-03-06 02:27:27 +00007941 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007942 {
7943 Image
cristyf40785b2010-03-06 02:27:27 +00007944 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007945
cristyd18ae7c2010-03-07 17:39:52 +00007946 /*
7947 Minimum image sequence (deprecated).
7948 */
cristy6fccee12011-10-20 18:43:18 +00007949 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007950 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007951 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007952 {
7953 status=MagickFalse;
7954 break;
7955 }
7956 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007957 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007958 break;
7959 }
cristy3ed852e2009-09-05 21:47:34 +00007960 if (LocaleCompare("morph",option+1) == 0)
7961 {
7962 Image
7963 *morph_image;
7964
cristy6fccee12011-10-20 18:43:18 +00007965 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007966 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007967 exception);
7968 if (morph_image == (Image *) NULL)
7969 {
7970 status=MagickFalse;
7971 break;
7972 }
7973 *images=DestroyImageList(*images);
7974 *images=morph_image;
7975 break;
7976 }
7977 if (LocaleCompare("mosaic",option+1) == 0)
7978 {
7979 Image
7980 *mosaic_image;
7981
cristy6fccee12011-10-20 18:43:18 +00007982 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007983 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7984 if (mosaic_image == (Image *) NULL)
7985 {
7986 status=MagickFalse;
7987 break;
7988 }
7989 *images=DestroyImageList(*images);
7990 *images=mosaic_image;
7991 break;
7992 }
7993 break;
7994 }
7995 case 'p':
7996 {
7997 if (LocaleCompare("print",option+1) == 0)
7998 {
7999 char
8000 *string;
8001
cristy6fccee12011-10-20 18:43:18 +00008002 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00008003 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8004 exception);
cristy3ed852e2009-09-05 21:47:34 +00008005 if (string == (char *) NULL)
8006 break;
cristyb51dff52011-05-19 16:55:47 +00008007 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008008 string=DestroyString(string);
8009 }
8010 if (LocaleCompare("process",option+1) == 0)
8011 {
8012 char
8013 **arguments;
8014
8015 int
8016 j,
8017 number_arguments;
8018
cristy6fccee12011-10-20 18:43:18 +00008019 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008020 arguments=StringToArgv(argv[i+1],&number_arguments);
8021 if (arguments == (char **) NULL)
8022 break;
8023 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8024 {
8025 char
8026 breaker,
8027 quote,
8028 *token;
8029
8030 const char
8031 *arguments;
8032
8033 int
8034 next,
8035 status;
8036
8037 size_t
8038 length;
8039
8040 TokenInfo
8041 *token_info;
8042
8043 /*
8044 Support old style syntax, filter="-option arg".
8045 */
8046 length=strlen(argv[i+1]);
8047 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008048 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008049 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8050 sizeof(*token));
8051 if (token == (char *) NULL)
8052 break;
8053 next=0;
8054 arguments=argv[i+1];
8055 token_info=AcquireTokenInfo();
8056 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8057 "\"",'\0',&breaker,&next,&quote);
8058 token_info=DestroyTokenInfo(token_info);
8059 if (status == 0)
8060 {
8061 const char
8062 *argv;
8063
8064 argv=(&(arguments[next]));
8065 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8066 exception);
8067 }
8068 token=DestroyString(token);
8069 break;
8070 }
cristy91c0da22010-05-02 01:44:07 +00008071 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008072 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8073 number_arguments-2,(const char **) arguments+2,exception);
8074 for (j=0; j < number_arguments; j++)
8075 arguments[j]=DestroyString(arguments[j]);
8076 arguments=(char **) RelinquishMagickMemory(arguments);
8077 break;
8078 }
8079 break;
8080 }
8081 case 'r':
8082 {
8083 if (LocaleCompare("reverse",option+1) == 0)
8084 {
8085 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008086 break;
8087 }
8088 break;
8089 }
8090 case 's':
8091 {
cristy4285d782011-02-09 20:12:28 +00008092 if (LocaleCompare("smush",option+1) == 0)
8093 {
8094 Image
8095 *smush_image;
8096
8097 ssize_t
8098 offset;
8099
cristy6fccee12011-10-20 18:43:18 +00008100 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008101 offset=(ssize_t) StringToLong(argv[i+1]);
8102 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8103 MagickFalse,offset,exception);
8104 if (smush_image == (Image *) NULL)
8105 {
8106 status=MagickFalse;
8107 break;
8108 }
8109 *images=DestroyImageList(*images);
8110 *images=smush_image;
8111 break;
8112 }
cristy3ed852e2009-09-05 21:47:34 +00008113 if (LocaleCompare("swap",option+1) == 0)
8114 {
8115 Image
8116 *p,
8117 *q,
8118 *swap;
8119
cristybb503372010-05-27 20:51:26 +00008120 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008121 swap_index;
8122
8123 index=(-1);
8124 swap_index=(-2);
8125 if (*option != '+')
8126 {
8127 GeometryInfo
8128 geometry_info;
8129
8130 MagickStatusType
8131 flags;
8132
8133 swap_index=(-1);
8134 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008135 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008136 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008137 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008138 }
8139 p=GetImageFromList(*images,index);
8140 q=GetImageFromList(*images,swap_index);
8141 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8142 {
8143 (void) ThrowMagickException(exception,GetMagickModule(),
8144 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8145 status=MagickFalse;
8146 break;
8147 }
8148 if (p == q)
8149 break;
8150 swap=CloneImage(p,0,0,MagickTrue,exception);
8151 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8152 ReplaceImageInList(&q,swap);
8153 *images=GetFirstImageInList(q);
8154 break;
8155 }
8156 break;
8157 }
8158 case 'w':
8159 {
8160 if (LocaleCompare("write",option+1) == 0)
8161 {
cristy071dd7b2010-04-09 13:04:54 +00008162 char
cristy06609ee2010-03-17 20:21:27 +00008163 key[MaxTextExtent];
8164
cristy3ed852e2009-09-05 21:47:34 +00008165 Image
8166 *write_images;
8167
8168 ImageInfo
8169 *write_info;
8170
cristy6fccee12011-10-20 18:43:18 +00008171 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008172 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008173 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008174 write_images=(*images);
8175 if (*option == '+')
8176 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008177 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008178 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8179 write_info=DestroyImageInfo(write_info);
8180 if (*option == '+')
8181 write_images=DestroyImageList(write_images);
8182 break;
8183 }
8184 break;
8185 }
8186 default:
8187 break;
8188 }
8189 i+=count;
8190 }
8191 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008192 mogrify_info=DestroyImageInfo(mogrify_info);
8193 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008194 return(status != 0 ? MagickTrue : MagickFalse);
8195}
8196
8197/*
8198%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8199% %
8200% %
8201% %
8202+ M o g r i f y I m a g e s %
8203% %
8204% %
8205% %
8206%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8207%
8208% MogrifyImages() applies image processing options to a sequence of images as
8209% prescribed by command line options.
8210%
8211% The format of the MogrifyImage method is:
8212%
8213% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8214% const MagickBooleanType post,const int argc,const char **argv,
8215% Image **images,Exceptioninfo *exception)
8216%
8217% A description of each parameter follows:
8218%
8219% o image_info: the image info..
8220%
8221% o post: If true, post process image list operators otherwise pre-process.
8222%
8223% o argc: Specifies a pointer to an integer describing the number of
8224% elements in the argument vector.
8225%
8226% o argv: Specifies a pointer to a text array containing the command line
8227% arguments.
8228%
anthonye9c27192011-03-27 08:07:06 +00008229% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008230%
8231% o exception: return any errors or warnings in this structure.
8232%
8233*/
8234WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8235 const MagickBooleanType post,const int argc,const char **argv,
8236 Image **images,ExceptionInfo *exception)
8237{
8238#define MogrifyImageTag "Mogrify/Image"
8239
anthonye9c27192011-03-27 08:07:06 +00008240 MagickStatusType
8241 status;
cristy3ed852e2009-09-05 21:47:34 +00008242
cristy0e9f9c12010-02-11 03:00:47 +00008243 MagickBooleanType
8244 proceed;
8245
anthonye9c27192011-03-27 08:07:06 +00008246 size_t
8247 n;
cristy3ed852e2009-09-05 21:47:34 +00008248
cristybb503372010-05-27 20:51:26 +00008249 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008250 i;
8251
cristy3ed852e2009-09-05 21:47:34 +00008252 assert(image_info != (ImageInfo *) NULL);
8253 assert(image_info->signature == MagickSignature);
8254 if (images == (Image **) NULL)
8255 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008256 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008257 assert((*images)->signature == MagickSignature);
8258 if ((*images)->debug != MagickFalse)
8259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8260 (*images)->filename);
8261 if ((argc <= 0) || (*argv == (char *) NULL))
8262 return(MagickTrue);
8263 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8264 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008265 status=0;
anthonye9c27192011-03-27 08:07:06 +00008266
anthonyce2716b2011-04-22 09:51:34 +00008267#if 0
cristy1e604812011-05-19 18:07:50 +00008268 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8269 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008270#endif
8271
anthonye9c27192011-03-27 08:07:06 +00008272 /*
8273 Pre-process multi-image sequence operators
8274 */
cristy3ed852e2009-09-05 21:47:34 +00008275 if (post == MagickFalse)
8276 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008277 /*
8278 For each image, process simple single image operators
8279 */
8280 i=0;
8281 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008282 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008283 {
anthonyce2716b2011-04-22 09:51:34 +00008284#if 0
cristy1e604812011-05-19 18:07:50 +00008285 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8286 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008287#endif
anthonye9c27192011-03-27 08:07:06 +00008288 status&=MogrifyImage(image_info,argc,argv,images,exception);
8289 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008290 if (proceed == MagickFalse)
8291 break;
anthonye9c27192011-03-27 08:07:06 +00008292 if ( (*images)->next == (Image *) NULL )
8293 break;
8294 *images=(*images)->next;
8295 i++;
cristy3ed852e2009-09-05 21:47:34 +00008296 }
anthonye9c27192011-03-27 08:07:06 +00008297 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008298#if 0
cristy1e604812011-05-19 18:07:50 +00008299 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8300 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008301#endif
anthonye9c27192011-03-27 08:07:06 +00008302
8303 /*
8304 Post-process, multi-image sequence operators
8305 */
8306 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008307 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008308 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008309 return(status != 0 ? MagickTrue : MagickFalse);
8310}