blob: 3cc8f0df70a1dfec3b438acf020e2b5b4f31b0d2 [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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,
120 elapsed_time,
121 user_time;
122
cristy3980b0d2009-10-25 14:37:13 +0000123 MagickBooleanType
124 concurrent,
125 regard_warnings,
126 status;
127
cristybb503372010-05-27 20:51:26 +0000128 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000129 i;
130
131 TimerInfo
132 *timer;
133
cristybb503372010-05-27 20:51:26 +0000134 size_t
cristy3980b0d2009-10-25 14:37:13 +0000135 iterations;
136
cristyd0a94fa2010-03-12 14:18:11 +0000137 (void) setlocale(LC_ALL,"");
138 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000139 concurrent=MagickFalse;
140 duration=(-1.0);
141 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000142 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000143 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000144 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000145 {
146 option=argv[i];
147 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
148 continue;
149 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000150 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000151 if (LocaleCompare("concurrent",option+1) == 0)
152 concurrent=MagickTrue;
153 if (LocaleCompare("debug",option+1) == 0)
154 (void) SetLogEventMask(argv[++i]);
155 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000156 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000157 if (LocaleCompare("regard-warnings",option+1) == 0)
158 regard_warnings=MagickTrue;
159 }
160 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000161 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000162 {
cristybb503372010-05-27 20:51:26 +0000163 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000164 {
cristy33557d72009-11-06 00:54:33 +0000165 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000166 continue;
167 if (duration > 0)
168 {
169 if (GetElapsedTime(timer) > duration)
170 continue;
171 (void) ContinueTimer(timer);
172 }
173 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000174 if (exception->severity != UndefinedException)
175 {
176 if ((exception->severity > ErrorException) ||
177 (regard_warnings != MagickFalse))
178 status=MagickTrue;
179 CatchException(exception);
180 }
cristy3d1a5512009-10-25 21:23:27 +0000181 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000182 {
183 (void) fputs(*metadata,stdout);
184 (void) fputc('\n',stdout);
185 *metadata=DestroyString(*metadata);
186 }
187 }
188 }
cristyceae09d2009-10-28 17:18:47 +0000189 else
190 {
191 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000192#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000193 # pragma omp parallel for shared(status)
194#endif
cristybb503372010-05-27 20:51:26 +0000195 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000196 {
cristy33557d72009-11-06 00:54:33 +0000197 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000198 continue;
199 if (duration > 0)
200 {
201 if (GetElapsedTime(timer) > duration)
202 continue;
203 (void) ContinueTimer(timer);
204 }
205 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000206#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000207 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000208#endif
209 {
210 if (exception->severity != UndefinedException)
211 {
212 if ((exception->severity > ErrorException) ||
213 (regard_warnings != MagickFalse))
214 status=MagickTrue;
215 CatchException(exception);
216 }
217 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
218 {
219 (void) fputs(*metadata,stdout);
220 (void) fputc('\n',stdout);
221 *metadata=DestroyString(*metadata);
222 }
223 }
224 }
225 }
cristy3980b0d2009-10-25 14:37:13 +0000226 if (iterations > 1)
227 {
228 elapsed_time=GetElapsedTime(timer);
229 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000230 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000231 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
232 iterations,1.0*iterations/elapsed_time,user_time,(double)
233 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
234 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000235 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000236 }
237 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000238 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000239}
240
241/*
242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243% %
244% %
245% %
cristy3ed852e2009-09-05 21:47:34 +0000246+ M o g r i f y I m a g e %
247% %
248% %
249% %
250%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251%
anthonye9c27192011-03-27 08:07:06 +0000252% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000253% image that may be part of a large list, but also handles any 'region'
254% image handling.
anthonye9c27192011-03-27 08:07:06 +0000255%
256% The image in the list may be modified in three different ways...
257%
258% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
259% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
260% * replace by a list of images (only the -separate option!)
261%
262% In each case the result is returned into the list, and a pointer to the
263% modified image (last image added if replaced by a list of images) is
264% returned.
265%
266% ASIDE: The -crop is present but restricted to non-tile single image crops
267%
268% This means if all the images are being processed (such as by
269% MogrifyImages(), next image to be processed will be as per the pointer
270% (*image)->next. Also the image list may grow as a result of some specific
271% operations but as images are never merged or deleted, it will never shrink
272% in length. Typically the list will remain the same length.
273%
274% WARNING: As the image pointed to may be replaced, the first image in the
275% list may also change. GetFirstImageInList() should be used by caller if
276% they wish return the Image pointer to the first image in list.
277%
cristy3ed852e2009-09-05 21:47:34 +0000278%
279% The format of the MogrifyImage method is:
280%
281% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
282% const char **argv,Image **image)
283%
284% A description of each parameter follows:
285%
286% o image_info: the image info..
287%
288% o argc: Specifies a pointer to an integer describing the number of
289% elements in the argument vector.
290%
291% o argv: Specifies a pointer to a text array containing the command line
292% arguments.
293%
294% o image: the image.
295%
296% o exception: return any errors or warnings in this structure.
297%
298*/
299
anthonydf8ebac2011-04-27 09:03:19 +0000300static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
301 ExceptionInfo *exception)
302{
303 char
304 key[MaxTextExtent];
305
306 ExceptionInfo
307 *sans_exception;
308
309 Image
310 *image;
311
312 ImageInfo
313 *read_info;
314
cristyfcd785b2011-11-08 01:48:33 +0000315 /*
316 Read an image into a image cache if not already present. Return the image
317 that is in the cache under that filename.
318 */
cristyb51dff52011-05-19 16:55:47 +0000319 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000320 sans_exception=AcquireExceptionInfo();
321 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
322 sans_exception=DestroyExceptionInfo(sans_exception);
323 if (image != (Image *) NULL)
324 return(image);
325 read_info=CloneImageInfo(image_info);
326 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
327 image=ReadImage(read_info,exception);
328 read_info=DestroyImageInfo(read_info);
329 if (image != (Image *) NULL)
330 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
331 return(image);
332}
333
cristy3ed852e2009-09-05 21:47:34 +0000334static MagickBooleanType IsPathWritable(const char *path)
335{
336 if (IsPathAccessible(path) == MagickFalse)
337 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000338 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000339 return(MagickFalse);
340 return(MagickTrue);
341}
342
cristybb503372010-05-27 20:51:26 +0000343static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000344{
345 if (x > y)
346 return(x);
347 return(y);
348}
349
anthonydf8ebac2011-04-27 09:03:19 +0000350static MagickBooleanType MonitorProgress(const char *text,
351 const MagickOffsetType offset,const MagickSizeType extent,
352 void *wand_unused(client_data))
353{
354 char
355 message[MaxTextExtent],
356 tag[MaxTextExtent];
357
358 const char
359 *locale_message;
360
361 register char
362 *p;
363
364 if (extent < 2)
365 return(MagickTrue);
366 (void) CopyMagickMemory(tag,text,MaxTextExtent);
367 p=strrchr(tag,'/');
368 if (p != (char *) NULL)
369 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000370 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000371 locale_message=GetLocaleMessage(message);
372 if (locale_message == message)
373 locale_message=tag;
374 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000375 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
376 locale_message,(long) offset,(unsigned long) extent,(long)
377 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000378 else
cristyb51dff52011-05-19 16:55:47 +0000379 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000380 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
381 (100L*offset/(extent-1)));
382 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000383 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000384 (void) fflush(stderr);
385 return(MagickTrue);
386}
387
cristy3884f692011-07-08 18:00:18 +0000388static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000389 const SparseColorMethod method,const char *arguments,
390 const MagickBooleanType color_from_image,ExceptionInfo *exception)
391{
anthonydf8ebac2011-04-27 09:03:19 +0000392 char
393 token[MaxTextExtent];
394
395 const char
396 *p;
397
398 double
399 *sparse_arguments;
400
anthonydf8ebac2011-04-27 09:03:19 +0000401 Image
402 *sparse_image;
403
cristy4c08aed2011-07-01 19:47:50 +0000404 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000405 color;
406
407 MagickBooleanType
408 error;
409
cristy5f09d852011-05-29 01:39:29 +0000410 register size_t
411 x;
412
413 size_t
414 number_arguments,
415 number_colors;
416
cristyf4425a72011-11-08 01:52:04 +0000417 /*
418 SparseColorOption() parses the complex -sparse-color argument into an an
419 array of floating point values then calls SparseColorImage(). Argument is
420 a complex mix of floating-point pixel coodinates, and color specifications
421 (or direct floating point numbers). The number of floats needed to
422 represent a color varies depending on the current channel setting.
423 */
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristydbdd0e32011-11-04 23:29:40 +0000510 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristydbdd0e32011-11-04 23:29:40 +0000521 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000536 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristydbdd0e32011-11-04 23:29:40 +0000558 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristydbdd0e32011-11-04 23:29:40 +0000566 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristydbdd0e32011-11-04 23:29:40 +0000574 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristydbdd0e32011-11-04 23:29:40 +0000583 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristydbdd0e32011-11-04 23:29:40 +0000592 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
cristy633f0c62011-09-15 13:27:36 +0000620 CompositeOperator
621 compose;
622
anthonydf8ebac2011-04-27 09:03:19 +0000623 const char
624 *format,
625 *option;
626
cristy9ed1f812011-10-08 02:00:08 +0000627 double
628 attenuate;
629
anthonydf8ebac2011-04-27 09:03:19 +0000630 DrawInfo
631 *draw_info;
632
633 GeometryInfo
634 geometry_info;
635
cristy3ed852e2009-09-05 21:47:34 +0000636 Image
637 *region_image;
638
anthonydf8ebac2011-04-27 09:03:19 +0000639 ImageInfo
640 *mogrify_info;
641
cristyebbcfea2011-02-25 02:43:54 +0000642 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000643 status;
644
cristy4c08aed2011-07-01 19:47:50 +0000645 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000646 fill;
cristy3ed852e2009-09-05 21:47:34 +0000647
anthonydf8ebac2011-04-27 09:03:19 +0000648 MagickStatusType
649 flags;
650
cristy28474bf2011-09-11 23:32:52 +0000651 PixelInterpolateMethod
652 interpolate_method;
653
anthonydf8ebac2011-04-27 09:03:19 +0000654 QuantizeInfo
655 *quantize_info;
656
657 RectangleInfo
658 geometry,
659 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000660
cristybb503372010-05-27 20:51:26 +0000661 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000662 i;
663
664 /*
665 Initialize method variables.
666 */
667 assert(image_info != (const ImageInfo *) NULL);
668 assert(image_info->signature == MagickSignature);
669 assert(image != (Image **) NULL);
670 assert((*image)->signature == MagickSignature);
671 if ((*image)->debug != MagickFalse)
672 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
673 if (argc < 0)
674 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000675 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000676 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
677 quantize_info=AcquireQuantizeInfo(mogrify_info);
678 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000679 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000680 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000681 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000682 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000683 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000684 channel=mogrify_info->channel;
685 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000686 SetGeometry(*image,&region_geometry);
687 region_image=NewImageList();
688 /*
689 Transmogrify the image.
690 */
cristybb503372010-05-27 20:51:26 +0000691 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000692 {
anthonydf8ebac2011-04-27 09:03:19 +0000693 Image
694 *mogrify_image;
695
anthonye9c27192011-03-27 08:07:06 +0000696 ssize_t
697 count;
698
anthonydf8ebac2011-04-27 09:03:19 +0000699 option=argv[i];
700 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000701 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000702 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
703 0L);
cristycee97112010-05-28 00:44:52 +0000704 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000705 break;
cristy6b3da3a2010-06-20 02:21:46 +0000706 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000707 mogrify_image=(Image *)NULL;
708 switch (*(option+1))
709 {
710 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000711 {
anthonydf8ebac2011-04-27 09:03:19 +0000712 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000713 {
anthonydf8ebac2011-04-27 09:03:19 +0000714 /*
715 Adaptive blur image.
716 */
cristy6fccee12011-10-20 18:43:18 +0000717 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000718 flags=ParseGeometry(argv[i+1],&geometry_info);
719 if ((flags & SigmaValue) == 0)
720 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000721 if ((flags & XiValue) == 0)
722 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000723 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000724 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000725 break;
cristy3ed852e2009-09-05 21:47:34 +0000726 }
anthonydf8ebac2011-04-27 09:03:19 +0000727 if (LocaleCompare("adaptive-resize",option+1) == 0)
728 {
729 /*
730 Adaptive resize image.
731 */
cristy6fccee12011-10-20 18:43:18 +0000732 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000733 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
734 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000735 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000736 break;
737 }
738 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
739 {
740 /*
741 Adaptive sharpen image.
742 */
cristy6fccee12011-10-20 18:43:18 +0000743 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000744 flags=ParseGeometry(argv[i+1],&geometry_info);
745 if ((flags & SigmaValue) == 0)
746 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000747 if ((flags & XiValue) == 0)
748 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000749 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000750 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000751 break;
752 }
753 if (LocaleCompare("affine",option+1) == 0)
754 {
755 /*
756 Affine matrix.
757 */
758 if (*option == '+')
759 {
760 GetAffineMatrix(&draw_info->affine);
761 break;
762 }
763 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
764 break;
765 }
766 if (LocaleCompare("alpha",option+1) == 0)
767 {
768 AlphaChannelType
769 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000770
cristy6fccee12011-10-20 18:43:18 +0000771 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000772 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
773 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000774 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000775 break;
776 }
777 if (LocaleCompare("annotate",option+1) == 0)
778 {
779 char
780 *text,
781 geometry[MaxTextExtent];
782
783 /*
784 Annotate image.
785 */
cristy6fccee12011-10-20 18:43:18 +0000786 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000787 SetGeometryInfo(&geometry_info);
788 flags=ParseGeometry(argv[i+1],&geometry_info);
789 if ((flags & SigmaValue) == 0)
790 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000791 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
792 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000793 if (text == (char *) NULL)
794 break;
795 (void) CloneString(&draw_info->text,text);
796 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000797 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000798 geometry_info.xi,geometry_info.psi);
799 (void) CloneString(&draw_info->geometry,geometry);
800 draw_info->affine.sx=cos(DegreesToRadians(
801 fmod(geometry_info.rho,360.0)));
802 draw_info->affine.rx=sin(DegreesToRadians(
803 fmod(geometry_info.rho,360.0)));
804 draw_info->affine.ry=(-sin(DegreesToRadians(
805 fmod(geometry_info.sigma,360.0))));
806 draw_info->affine.sy=cos(DegreesToRadians(
807 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000808 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000809 break;
810 }
811 if (LocaleCompare("antialias",option+1) == 0)
812 {
813 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
814 MagickFalse;
815 draw_info->text_antialias=(*option == '-') ? MagickTrue :
816 MagickFalse;
817 break;
818 }
cristy9ed1f812011-10-08 02:00:08 +0000819 if (LocaleCompare("attenuate",option+1) == 0)
820 {
821 if (*option == '+')
822 {
823 attenuate=1.0;
824 break;
825 }
cristydbdd0e32011-11-04 23:29:40 +0000826 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000827 break;
828 }
anthonydf8ebac2011-04-27 09:03:19 +0000829 if (LocaleCompare("auto-gamma",option+1) == 0)
830 {
831 /*
832 Auto Adjust Gamma of image based on its mean
833 */
cristy6fccee12011-10-20 18:43:18 +0000834 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000835 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000836 break;
837 }
838 if (LocaleCompare("auto-level",option+1) == 0)
839 {
840 /*
841 Perfectly Normalize (max/min stretch) the image
842 */
cristy6fccee12011-10-20 18:43:18 +0000843 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000844 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000845 break;
846 }
847 if (LocaleCompare("auto-orient",option+1) == 0)
848 {
cristy6fccee12011-10-20 18:43:18 +0000849 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000850 switch ((*image)->orientation)
851 {
852 case TopRightOrientation:
853 {
854 mogrify_image=FlopImage(*image,exception);
855 break;
856 }
857 case BottomRightOrientation:
858 {
859 mogrify_image=RotateImage(*image,180.0,exception);
860 break;
861 }
862 case BottomLeftOrientation:
863 {
864 mogrify_image=FlipImage(*image,exception);
865 break;
866 }
867 case LeftTopOrientation:
868 {
869 mogrify_image=TransposeImage(*image,exception);
870 break;
871 }
872 case RightTopOrientation:
873 {
874 mogrify_image=RotateImage(*image,90.0,exception);
875 break;
876 }
877 case RightBottomOrientation:
878 {
879 mogrify_image=TransverseImage(*image,exception);
880 break;
881 }
882 case LeftBottomOrientation:
883 {
884 mogrify_image=RotateImage(*image,270.0,exception);
885 break;
886 }
887 default:
888 break;
889 }
890 if (mogrify_image != (Image *) NULL)
891 mogrify_image->orientation=TopLeftOrientation;
892 break;
893 }
894 break;
895 }
896 case 'b':
897 {
898 if (LocaleCompare("black-threshold",option+1) == 0)
899 {
900 /*
901 Black threshold image.
902 */
cristy6fccee12011-10-20 18:43:18 +0000903 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000904 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000905 break;
906 }
907 if (LocaleCompare("blue-shift",option+1) == 0)
908 {
909 /*
910 Blue shift image.
911 */
cristy6fccee12011-10-20 18:43:18 +0000912 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000913 geometry_info.rho=1.5;
914 if (*option == '-')
915 flags=ParseGeometry(argv[i+1],&geometry_info);
916 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
917 break;
918 }
919 if (LocaleCompare("blur",option+1) == 0)
920 {
921 /*
922 Gaussian blur image.
923 */
cristy6fccee12011-10-20 18:43:18 +0000924 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000925 flags=ParseGeometry(argv[i+1],&geometry_info);
926 if ((flags & SigmaValue) == 0)
927 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000928 if ((flags & XiValue) == 0)
929 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000930 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000931 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000932 break;
933 }
934 if (LocaleCompare("border",option+1) == 0)
935 {
936 /*
937 Surround image with a border of solid color.
938 */
cristy6fccee12011-10-20 18:43:18 +0000939 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000940 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
941 if ((flags & SigmaValue) == 0)
942 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000943 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000944 break;
945 }
946 if (LocaleCompare("bordercolor",option+1) == 0)
947 {
948 if (*option == '+')
949 {
cristy9950d572011-10-01 18:22:35 +0000950 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000951 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000952 break;
953 }
cristy9950d572011-10-01 18:22:35 +0000954 (void) QueryColorCompliance(argv[i+1],AllCompliance,
955 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000956 break;
957 }
958 if (LocaleCompare("box",option+1) == 0)
959 {
cristy9950d572011-10-01 18:22:35 +0000960 (void) QueryColorCompliance(argv[i+1],AllCompliance,
961 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000962 break;
963 }
964 if (LocaleCompare("brightness-contrast",option+1) == 0)
965 {
966 double
967 brightness,
968 contrast;
969
970 GeometryInfo
971 geometry_info;
972
973 MagickStatusType
974 flags;
975
976 /*
977 Brightness / contrast image.
978 */
cristy6fccee12011-10-20 18:43:18 +0000979 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000980 flags=ParseGeometry(argv[i+1],&geometry_info);
981 brightness=geometry_info.rho;
982 contrast=0.0;
983 if ((flags & SigmaValue) != 0)
984 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000985 (void) BrightnessContrastImage(*image,brightness,contrast,
986 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000987 break;
988 }
989 break;
990 }
991 case 'c':
992 {
993 if (LocaleCompare("cdl",option+1) == 0)
994 {
995 char
996 *color_correction_collection;
997
998 /*
999 Color correct with a color decision list.
1000 */
cristy6fccee12011-10-20 18:43:18 +00001001 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001002 color_correction_collection=FileToString(argv[i+1],~0,exception);
1003 if (color_correction_collection == (char *) NULL)
1004 break;
cristy1bfa9f02011-08-11 02:35:43 +00001005 (void) ColorDecisionListImage(*image,color_correction_collection,
1006 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001007 break;
1008 }
1009 if (LocaleCompare("channel",option+1) == 0)
1010 {
1011 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001012 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001013 else
cristyfa806a72011-07-04 02:06:13 +00001014 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00001015 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001016 break;
1017 }
1018 if (LocaleCompare("charcoal",option+1) == 0)
1019 {
1020 /*
1021 Charcoal image.
1022 */
cristy6fccee12011-10-20 18:43:18 +00001023 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001024 flags=ParseGeometry(argv[i+1],&geometry_info);
1025 if ((flags & SigmaValue) == 0)
1026 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001027 if ((flags & XiValue) == 0)
1028 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001029 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001030 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001031 break;
1032 }
1033 if (LocaleCompare("chop",option+1) == 0)
1034 {
1035 /*
1036 Chop the image.
1037 */
cristy6fccee12011-10-20 18:43:18 +00001038 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001039 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1040 mogrify_image=ChopImage(*image,&geometry,exception);
1041 break;
1042 }
1043 if (LocaleCompare("clamp",option+1) == 0)
1044 {
1045 /*
1046 Clamp image.
1047 */
cristy6fccee12011-10-20 18:43:18 +00001048 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001049 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001050 break;
1051 }
1052 if (LocaleCompare("clip",option+1) == 0)
1053 {
cristy6fccee12011-10-20 18:43:18 +00001054 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001055 if (*option == '+')
1056 {
cristy018f07f2011-09-04 21:15:19 +00001057 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001058 break;
1059 }
cristy018f07f2011-09-04 21:15:19 +00001060 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001061 break;
1062 }
1063 if (LocaleCompare("clip-mask",option+1) == 0)
1064 {
1065 CacheView
1066 *mask_view;
1067
1068 Image
1069 *mask_image;
1070
cristy4c08aed2011-07-01 19:47:50 +00001071 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001072 *restrict q;
1073
1074 register ssize_t
1075 x;
1076
1077 ssize_t
1078 y;
1079
cristy6fccee12011-10-20 18:43:18 +00001080 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001081 if (*option == '+')
1082 {
1083 /*
1084 Remove a mask.
1085 */
cristy018f07f2011-09-04 21:15:19 +00001086 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001087 break;
1088 }
1089 /*
1090 Set the image mask.
1091 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1092 */
1093 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1094 if (mask_image == (Image *) NULL)
1095 break;
cristy574cc262011-08-05 01:23:58 +00001096 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001097 return(MagickFalse);
1098 mask_view=AcquireCacheView(mask_image);
1099 for (y=0; y < (ssize_t) mask_image->rows; y++)
1100 {
1101 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1102 exception);
cristyacd2ed22011-08-30 01:44:23 +00001103 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001104 break;
1105 for (x=0; x < (ssize_t) mask_image->columns; x++)
1106 {
1107 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001108 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1109 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1110 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1111 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001112 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001113 }
1114 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1115 break;
1116 }
1117 mask_view=DestroyCacheView(mask_view);
1118 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001119 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001120 break;
1121 }
1122 if (LocaleCompare("clip-path",option+1) == 0)
1123 {
cristy6fccee12011-10-20 18:43:18 +00001124 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001125 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001126 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001127 break;
1128 }
1129 if (LocaleCompare("colorize",option+1) == 0)
1130 {
1131 /*
1132 Colorize the image.
1133 */
cristy6fccee12011-10-20 18:43:18 +00001134 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001135 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001136 break;
1137 }
1138 if (LocaleCompare("color-matrix",option+1) == 0)
1139 {
1140 KernelInfo
1141 *kernel;
1142
cristy6fccee12011-10-20 18:43:18 +00001143 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001144 kernel=AcquireKernelInfo(argv[i+1]);
1145 if (kernel == (KernelInfo *) NULL)
1146 break;
1147 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1148 kernel=DestroyKernelInfo(kernel);
1149 break;
1150 }
1151 if (LocaleCompare("colors",option+1) == 0)
1152 {
1153 /*
1154 Reduce the number of colors in the image.
1155 */
cristy6fccee12011-10-20 18:43:18 +00001156 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001157 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1158 if (quantize_info->number_colors == 0)
1159 break;
1160 if (((*image)->storage_class == DirectClass) ||
1161 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001162 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001163 else
cristy018f07f2011-09-04 21:15:19 +00001164 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001165 break;
1166 }
1167 if (LocaleCompare("colorspace",option+1) == 0)
1168 {
1169 ColorspaceType
1170 colorspace;
1171
cristy6fccee12011-10-20 18:43:18 +00001172 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001173 if (*option == '+')
1174 {
cristye941a752011-10-15 01:52:48 +00001175 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001176 break;
1177 }
1178 colorspace=(ColorspaceType) ParseCommandOption(
1179 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001180 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001181 break;
1182 }
cristy633f0c62011-09-15 13:27:36 +00001183 if (LocaleCompare("compose",option+1) == 0)
1184 {
cristy6fccee12011-10-20 18:43:18 +00001185 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001186 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1187 MagickFalse,argv[i+1]);
1188 break;
1189 }
anthonydf8ebac2011-04-27 09:03:19 +00001190 if (LocaleCompare("contrast",option+1) == 0)
1191 {
cristy6fccee12011-10-20 18:43:18 +00001192 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001193 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001194 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001195 break;
1196 }
1197 if (LocaleCompare("contrast-stretch",option+1) == 0)
1198 {
1199 double
1200 black_point,
1201 white_point;
1202
1203 MagickStatusType
1204 flags;
1205
1206 /*
1207 Contrast stretch image.
1208 */
cristy6fccee12011-10-20 18:43:18 +00001209 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001210 flags=ParseGeometry(argv[i+1],&geometry_info);
1211 black_point=geometry_info.rho;
1212 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1213 black_point;
1214 if ((flags & PercentValue) != 0)
1215 {
1216 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1217 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1218 }
1219 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1220 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001221 (void) ContrastStretchImage(*image,black_point,white_point,
1222 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001223 break;
1224 }
1225 if (LocaleCompare("convolve",option+1) == 0)
1226 {
anthonydf8ebac2011-04-27 09:03:19 +00001227 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001228 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001229
cristy6fccee12011-10-20 18:43:18 +00001230 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001231 kernel_info=AcquireKernelInfo(argv[i+1]);
1232 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001233 break;
cristy0a922382011-07-16 15:30:34 +00001234 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001235 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001236 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001237 break;
1238 }
1239 if (LocaleCompare("crop",option+1) == 0)
1240 {
1241 /*
1242 Crop a image to a smaller size
1243 */
cristy6fccee12011-10-20 18:43:18 +00001244 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001245 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001246 break;
1247 }
1248 if (LocaleCompare("cycle",option+1) == 0)
1249 {
1250 /*
1251 Cycle an image colormap.
1252 */
cristy6fccee12011-10-20 18:43:18 +00001253 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001254 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1255 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001256 break;
1257 }
1258 break;
1259 }
1260 case 'd':
1261 {
1262 if (LocaleCompare("decipher",option+1) == 0)
1263 {
1264 StringInfo
1265 *passkey;
1266
1267 /*
1268 Decipher pixels.
1269 */
cristy6fccee12011-10-20 18:43:18 +00001270 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001271 passkey=FileToStringInfo(argv[i+1],~0,exception);
1272 if (passkey != (StringInfo *) NULL)
1273 {
1274 (void) PasskeyDecipherImage(*image,passkey,exception);
1275 passkey=DestroyStringInfo(passkey);
1276 }
1277 break;
1278 }
1279 if (LocaleCompare("density",option+1) == 0)
1280 {
1281 /*
1282 Set image density.
1283 */
1284 (void) CloneString(&draw_info->density,argv[i+1]);
1285 break;
1286 }
1287 if (LocaleCompare("depth",option+1) == 0)
1288 {
cristy6fccee12011-10-20 18:43:18 +00001289 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001290 if (*option == '+')
1291 {
cristy8a11cb12011-10-19 23:53:34 +00001292 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001293 break;
1294 }
cristy8a11cb12011-10-19 23:53:34 +00001295 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1296 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001297 break;
1298 }
1299 if (LocaleCompare("deskew",option+1) == 0)
1300 {
1301 double
1302 threshold;
1303
1304 /*
1305 Straighten the image.
1306 */
cristy6fccee12011-10-20 18:43:18 +00001307 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001308 if (*option == '+')
1309 threshold=40.0*QuantumRange/100.0;
1310 else
cristy9b34e302011-11-05 02:15:45 +00001311 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1312 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001313 mogrify_image=DeskewImage(*image,threshold,exception);
1314 break;
1315 }
1316 if (LocaleCompare("despeckle",option+1) == 0)
1317 {
1318 /*
1319 Reduce the speckles within an image.
1320 */
cristy6fccee12011-10-20 18:43:18 +00001321 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001322 mogrify_image=DespeckleImage(*image,exception);
1323 break;
1324 }
1325 if (LocaleCompare("display",option+1) == 0)
1326 {
1327 (void) CloneString(&draw_info->server_name,argv[i+1]);
1328 break;
1329 }
1330 if (LocaleCompare("distort",option+1) == 0)
1331 {
1332 char
1333 *args,
1334 token[MaxTextExtent];
1335
1336 const char
1337 *p;
1338
1339 DistortImageMethod
1340 method;
1341
1342 double
1343 *arguments;
1344
1345 register ssize_t
1346 x;
1347
1348 size_t
1349 number_arguments;
1350
1351 /*
1352 Distort image.
1353 */
cristy6fccee12011-10-20 18:43:18 +00001354 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001355 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1356 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001357 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001358 {
anthonydf8ebac2011-04-27 09:03:19 +00001359 double
1360 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001361
1362 /*
1363 Special Case - Argument is actually a resize geometry!
1364 Convert that to an appropriate distortion argument array.
1365 */
anthonydf8ebac2011-04-27 09:03:19 +00001366 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001367 exception);
1368 resize_args[0]=(double) geometry.width;
1369 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001370 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001371 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001372 break;
1373 }
cristy018f07f2011-09-04 21:15:19 +00001374 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1375 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001376 if (args == (char *) NULL)
1377 break;
1378 p=(char *) args;
1379 for (x=0; *p != '\0'; x++)
1380 {
1381 GetMagickToken(p,&p,token);
1382 if (*token == ',')
1383 GetMagickToken(p,&p,token);
1384 }
1385 number_arguments=(size_t) x;
1386 arguments=(double *) AcquireQuantumMemory(number_arguments,
1387 sizeof(*arguments));
1388 if (arguments == (double *) NULL)
1389 ThrowWandFatalException(ResourceLimitFatalError,
1390 "MemoryAllocationFailed",(*image)->filename);
1391 (void) ResetMagickMemory(arguments,0,number_arguments*
1392 sizeof(*arguments));
1393 p=(char *) args;
1394 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1395 {
1396 GetMagickToken(p,&p,token);
1397 if (*token == ',')
1398 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001399 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001400 }
1401 args=DestroyString(args);
1402 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1403 (*option == '+') ? MagickTrue : MagickFalse,exception);
1404 arguments=(double *) RelinquishMagickMemory(arguments);
1405 break;
1406 }
1407 if (LocaleCompare("dither",option+1) == 0)
1408 {
1409 if (*option == '+')
1410 {
1411 quantize_info->dither=MagickFalse;
1412 break;
1413 }
1414 quantize_info->dither=MagickTrue;
1415 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1416 MagickDitherOptions,MagickFalse,argv[i+1]);
1417 if (quantize_info->dither_method == NoDitherMethod)
1418 quantize_info->dither=MagickFalse;
1419 break;
1420 }
1421 if (LocaleCompare("draw",option+1) == 0)
1422 {
1423 /*
1424 Draw image.
1425 */
cristy6fccee12011-10-20 18:43:18 +00001426 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001427 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001428 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001429 break;
1430 }
1431 break;
1432 }
1433 case 'e':
1434 {
1435 if (LocaleCompare("edge",option+1) == 0)
1436 {
1437 /*
1438 Enhance edges in the image.
1439 */
cristy6fccee12011-10-20 18:43:18 +00001440 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001441 flags=ParseGeometry(argv[i+1],&geometry_info);
1442 if ((flags & SigmaValue) == 0)
1443 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001444 mogrify_image=EdgeImage(*image,geometry_info.rho,
1445 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001446 break;
1447 }
1448 if (LocaleCompare("emboss",option+1) == 0)
1449 {
1450 /*
1451 Gaussian embossen image.
1452 */
cristy6fccee12011-10-20 18:43:18 +00001453 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001454 flags=ParseGeometry(argv[i+1],&geometry_info);
1455 if ((flags & SigmaValue) == 0)
1456 geometry_info.sigma=1.0;
1457 mogrify_image=EmbossImage(*image,geometry_info.rho,
1458 geometry_info.sigma,exception);
1459 break;
1460 }
1461 if (LocaleCompare("encipher",option+1) == 0)
1462 {
1463 StringInfo
1464 *passkey;
1465
1466 /*
1467 Encipher pixels.
1468 */
cristy6fccee12011-10-20 18:43:18 +00001469 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001470 passkey=FileToStringInfo(argv[i+1],~0,exception);
1471 if (passkey != (StringInfo *) NULL)
1472 {
1473 (void) PasskeyEncipherImage(*image,passkey,exception);
1474 passkey=DestroyStringInfo(passkey);
1475 }
1476 break;
1477 }
1478 if (LocaleCompare("encoding",option+1) == 0)
1479 {
1480 (void) CloneString(&draw_info->encoding,argv[i+1]);
1481 break;
1482 }
1483 if (LocaleCompare("enhance",option+1) == 0)
1484 {
1485 /*
1486 Enhance image.
1487 */
cristy6fccee12011-10-20 18:43:18 +00001488 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001489 mogrify_image=EnhanceImage(*image,exception);
1490 break;
1491 }
1492 if (LocaleCompare("equalize",option+1) == 0)
1493 {
1494 /*
1495 Equalize image.
1496 */
cristy6fccee12011-10-20 18:43:18 +00001497 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001498 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001499 break;
1500 }
1501 if (LocaleCompare("evaluate",option+1) == 0)
1502 {
1503 double
1504 constant;
1505
1506 MagickEvaluateOperator
1507 op;
1508
cristy6fccee12011-10-20 18:43:18 +00001509 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001510 op=(MagickEvaluateOperator) ParseCommandOption(
1511 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001512 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1513 1.0);
cristyd42d9952011-07-08 14:21:50 +00001514 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001515 break;
1516 }
1517 if (LocaleCompare("extent",option+1) == 0)
1518 {
1519 /*
1520 Set the image extent.
1521 */
cristy6fccee12011-10-20 18:43:18 +00001522 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001523 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1524 if (geometry.width == 0)
1525 geometry.width=(*image)->columns;
1526 if (geometry.height == 0)
1527 geometry.height=(*image)->rows;
1528 mogrify_image=ExtentImage(*image,&geometry,exception);
1529 break;
1530 }
1531 break;
1532 }
1533 case 'f':
1534 {
1535 if (LocaleCompare("family",option+1) == 0)
1536 {
1537 if (*option == '+')
1538 {
1539 if (draw_info->family != (char *) NULL)
1540 draw_info->family=DestroyString(draw_info->family);
1541 break;
1542 }
1543 (void) CloneString(&draw_info->family,argv[i+1]);
1544 break;
1545 }
1546 if (LocaleCompare("features",option+1) == 0)
1547 {
1548 if (*option == '+')
1549 {
1550 (void) DeleteImageArtifact(*image,"identify:features");
1551 break;
1552 }
1553 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1554 break;
1555 }
1556 if (LocaleCompare("fill",option+1) == 0)
1557 {
1558 ExceptionInfo
1559 *sans;
1560
cristy4c08aed2011-07-01 19:47:50 +00001561 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001562 if (*option == '+')
1563 {
cristy269c9412011-10-13 23:41:15 +00001564 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001565 exception);
1566 (void) QueryColorCompliance("none",AllCompliance,
1567 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001568 if (draw_info->fill_pattern != (Image *) NULL)
1569 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1570 break;
1571 }
1572 sans=AcquireExceptionInfo();
cristy269c9412011-10-13 23:41:15 +00001573 (void) QueryColorCompliance(argv[i+1],AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001574 sans);
1575 status=QueryColorCompliance(argv[i+1],AllCompliance,
1576 &draw_info->fill,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001577 sans=DestroyExceptionInfo(sans);
1578 if (status == MagickFalse)
1579 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1580 exception);
1581 break;
1582 }
1583 if (LocaleCompare("flip",option+1) == 0)
1584 {
1585 /*
1586 Flip image scanlines.
1587 */
cristy6fccee12011-10-20 18:43:18 +00001588 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001589 mogrify_image=FlipImage(*image,exception);
1590 break;
1591 }
anthonydf8ebac2011-04-27 09:03:19 +00001592 if (LocaleCompare("floodfill",option+1) == 0)
1593 {
cristy4c08aed2011-07-01 19:47:50 +00001594 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001595 target;
1596
1597 /*
1598 Floodfill image.
1599 */
cristy6fccee12011-10-20 18:43:18 +00001600 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001601 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001602 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001603 exception);
cristyd42d9952011-07-08 14:21:50 +00001604 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001605 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001606 break;
1607 }
anthony3d2f4862011-05-01 13:48:16 +00001608 if (LocaleCompare("flop",option+1) == 0)
1609 {
1610 /*
1611 Flop image scanlines.
1612 */
cristy6fccee12011-10-20 18:43:18 +00001613 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001614 mogrify_image=FlopImage(*image,exception);
1615 break;
1616 }
anthonydf8ebac2011-04-27 09:03:19 +00001617 if (LocaleCompare("font",option+1) == 0)
1618 {
1619 if (*option == '+')
1620 {
1621 if (draw_info->font != (char *) NULL)
1622 draw_info->font=DestroyString(draw_info->font);
1623 break;
1624 }
1625 (void) CloneString(&draw_info->font,argv[i+1]);
1626 break;
1627 }
1628 if (LocaleCompare("format",option+1) == 0)
1629 {
1630 format=argv[i+1];
1631 break;
1632 }
1633 if (LocaleCompare("frame",option+1) == 0)
1634 {
1635 FrameInfo
1636 frame_info;
1637
1638 /*
1639 Surround image with an ornamental border.
1640 */
cristy6fccee12011-10-20 18:43:18 +00001641 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001642 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1643 frame_info.width=geometry.width;
1644 frame_info.height=geometry.height;
1645 if ((flags & HeightValue) == 0)
1646 frame_info.height=geometry.width;
1647 frame_info.outer_bevel=geometry.x;
1648 frame_info.inner_bevel=geometry.y;
1649 frame_info.x=(ssize_t) frame_info.width;
1650 frame_info.y=(ssize_t) frame_info.height;
1651 frame_info.width=(*image)->columns+2*frame_info.width;
1652 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001653 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001654 break;
1655 }
1656 if (LocaleCompare("function",option+1) == 0)
1657 {
1658 char
1659 *arguments,
1660 token[MaxTextExtent];
1661
1662 const char
1663 *p;
1664
1665 double
1666 *parameters;
1667
1668 MagickFunction
1669 function;
1670
1671 register ssize_t
1672 x;
1673
1674 size_t
1675 number_parameters;
1676
1677 /*
1678 Function Modify Image Values
1679 */
cristy6fccee12011-10-20 18:43:18 +00001680 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001681 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1682 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001683 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1684 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001685 if (arguments == (char *) NULL)
1686 break;
1687 p=(char *) arguments;
1688 for (x=0; *p != '\0'; x++)
1689 {
1690 GetMagickToken(p,&p,token);
1691 if (*token == ',')
1692 GetMagickToken(p,&p,token);
1693 }
1694 number_parameters=(size_t) x;
1695 parameters=(double *) AcquireQuantumMemory(number_parameters,
1696 sizeof(*parameters));
1697 if (parameters == (double *) NULL)
1698 ThrowWandFatalException(ResourceLimitFatalError,
1699 "MemoryAllocationFailed",(*image)->filename);
1700 (void) ResetMagickMemory(parameters,0,number_parameters*
1701 sizeof(*parameters));
1702 p=(char *) arguments;
1703 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1704 {
1705 GetMagickToken(p,&p,token);
1706 if (*token == ',')
1707 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001708 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001709 }
1710 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001711 (void) FunctionImage(*image,function,number_parameters,parameters,
1712 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001713 parameters=(double *) RelinquishMagickMemory(parameters);
1714 break;
1715 }
1716 break;
1717 }
1718 case 'g':
1719 {
1720 if (LocaleCompare("gamma",option+1) == 0)
1721 {
1722 /*
1723 Gamma image.
1724 */
cristy6fccee12011-10-20 18:43:18 +00001725 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001726 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001727 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001728 else
cristydbdd0e32011-11-04 23:29:40 +00001729 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001730 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001731 break;
1732 }
1733 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1734 (LocaleCompare("gaussian",option+1) == 0))
1735 {
1736 /*
1737 Gaussian blur image.
1738 */
cristy6fccee12011-10-20 18:43:18 +00001739 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001740 flags=ParseGeometry(argv[i+1],&geometry_info);
1741 if ((flags & SigmaValue) == 0)
1742 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001743 if ((flags & XiValue) == 0)
1744 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001745 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001746 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001747 break;
1748 }
1749 if (LocaleCompare("geometry",option+1) == 0)
1750 {
1751 /*
1752 Record Image offset, Resize last image.
1753 */
cristy6fccee12011-10-20 18:43:18 +00001754 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001755 if (*option == '+')
1756 {
1757 if ((*image)->geometry != (char *) NULL)
1758 (*image)->geometry=DestroyString((*image)->geometry);
1759 break;
1760 }
1761 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1762 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1763 (void) CloneString(&(*image)->geometry,argv[i+1]);
1764 else
1765 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1766 (*image)->filter,(*image)->blur,exception);
1767 break;
1768 }
1769 if (LocaleCompare("gravity",option+1) == 0)
1770 {
1771 if (*option == '+')
1772 {
1773 draw_info->gravity=UndefinedGravity;
1774 break;
1775 }
1776 draw_info->gravity=(GravityType) ParseCommandOption(
1777 MagickGravityOptions,MagickFalse,argv[i+1]);
1778 break;
1779 }
1780 break;
1781 }
1782 case 'h':
1783 {
1784 if (LocaleCompare("highlight-color",option+1) == 0)
1785 {
1786 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1787 break;
1788 }
1789 break;
1790 }
1791 case 'i':
1792 {
1793 if (LocaleCompare("identify",option+1) == 0)
1794 {
1795 char
1796 *text;
1797
cristy6fccee12011-10-20 18:43:18 +00001798 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001799 if (format == (char *) NULL)
1800 {
cristya4037272011-08-28 15:11:39 +00001801 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1802 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001803 break;
1804 }
cristy018f07f2011-09-04 21:15:19 +00001805 text=InterpretImageProperties(mogrify_info,*image,format,
1806 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001807 if (text == (char *) NULL)
1808 break;
1809 (void) fputs(text,stdout);
1810 (void) fputc('\n',stdout);
1811 text=DestroyString(text);
1812 break;
1813 }
1814 if (LocaleCompare("implode",option+1) == 0)
1815 {
1816 /*
1817 Implode image.
1818 */
cristy6fccee12011-10-20 18:43:18 +00001819 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001820 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001821 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1822 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001823 break;
1824 }
1825 if (LocaleCompare("interline-spacing",option+1) == 0)
1826 {
1827 if (*option == '+')
1828 (void) ParseGeometry("0",&geometry_info);
1829 else
1830 (void) ParseGeometry(argv[i+1],&geometry_info);
1831 draw_info->interline_spacing=geometry_info.rho;
1832 break;
1833 }
cristy28474bf2011-09-11 23:32:52 +00001834 if (LocaleCompare("interpolate",option+1) == 0)
1835 {
1836 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1837 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1838 break;
1839 }
anthonydf8ebac2011-04-27 09:03:19 +00001840 if (LocaleCompare("interword-spacing",option+1) == 0)
1841 {
1842 if (*option == '+')
1843 (void) ParseGeometry("0",&geometry_info);
1844 else
1845 (void) ParseGeometry(argv[i+1],&geometry_info);
1846 draw_info->interword_spacing=geometry_info.rho;
1847 break;
1848 }
1849 break;
1850 }
1851 case 'k':
1852 {
1853 if (LocaleCompare("kerning",option+1) == 0)
1854 {
1855 if (*option == '+')
1856 (void) ParseGeometry("0",&geometry_info);
1857 else
1858 (void) ParseGeometry(argv[i+1],&geometry_info);
1859 draw_info->kerning=geometry_info.rho;
1860 break;
1861 }
1862 break;
1863 }
1864 case 'l':
1865 {
1866 if (LocaleCompare("lat",option+1) == 0)
1867 {
1868 /*
1869 Local adaptive threshold image.
1870 */
cristy6fccee12011-10-20 18:43:18 +00001871 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001872 flags=ParseGeometry(argv[i+1],&geometry_info);
1873 if ((flags & PercentValue) != 0)
1874 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1875 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001876 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001877 geometry_info.xi,exception);
1878 break;
1879 }
1880 if (LocaleCompare("level",option+1) == 0)
1881 {
1882 MagickRealType
1883 black_point,
1884 gamma,
1885 white_point;
1886
1887 MagickStatusType
1888 flags;
1889
1890 /*
1891 Parse levels.
1892 */
cristy6fccee12011-10-20 18:43:18 +00001893 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001894 flags=ParseGeometry(argv[i+1],&geometry_info);
1895 black_point=geometry_info.rho;
1896 white_point=(MagickRealType) QuantumRange;
1897 if ((flags & SigmaValue) != 0)
1898 white_point=geometry_info.sigma;
1899 gamma=1.0;
1900 if ((flags & XiValue) != 0)
1901 gamma=geometry_info.xi;
1902 if ((flags & PercentValue) != 0)
1903 {
1904 black_point*=(MagickRealType) (QuantumRange/100.0);
1905 white_point*=(MagickRealType) (QuantumRange/100.0);
1906 }
1907 if ((flags & SigmaValue) == 0)
1908 white_point=(MagickRealType) QuantumRange-black_point;
1909 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001910 (void) LevelizeImage(*image,black_point,white_point,gamma,
1911 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001912 else
cristy01e9afd2011-08-10 17:38:41 +00001913 (void) LevelImage(*image,black_point,white_point,gamma,
1914 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001915 break;
1916 }
1917 if (LocaleCompare("level-colors",option+1) == 0)
1918 {
1919 char
1920 token[MaxTextExtent];
1921
1922 const char
1923 *p;
1924
cristy4c08aed2011-07-01 19:47:50 +00001925 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001926 black_point,
1927 white_point;
1928
1929 p=(const char *) argv[i+1];
1930 GetMagickToken(p,&p,token); /* get black point color */
1931 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001932 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001933 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001934 else
cristy269c9412011-10-13 23:41:15 +00001935 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001936 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001937 if (isalpha((int) token[0]) || (token[0] == '#'))
1938 GetMagickToken(p,&p,token);
1939 if (*token == '\0')
1940 white_point=black_point; /* set everything to that color */
1941 else
1942 {
1943 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1944 GetMagickToken(p,&p,token); /* Get white point color. */
1945 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001946 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001947 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001948 else
cristy269c9412011-10-13 23:41:15 +00001949 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001950 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001951 }
cristy490408a2011-07-07 14:42:05 +00001952 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001953 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001954 break;
1955 }
1956 if (LocaleCompare("linear-stretch",option+1) == 0)
1957 {
1958 double
1959 black_point,
1960 white_point;
1961
1962 MagickStatusType
1963 flags;
1964
cristy6fccee12011-10-20 18:43:18 +00001965 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001966 flags=ParseGeometry(argv[i+1],&geometry_info);
1967 black_point=geometry_info.rho;
1968 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1969 if ((flags & SigmaValue) != 0)
1970 white_point=geometry_info.sigma;
1971 if ((flags & PercentValue) != 0)
1972 {
1973 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1974 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1975 }
1976 if ((flags & SigmaValue) == 0)
1977 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1978 black_point;
cristy33bd5152011-08-24 01:42:24 +00001979 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001980 break;
1981 }
1982 if (LocaleCompare("linewidth",option+1) == 0)
1983 {
cristy9b34e302011-11-05 02:15:45 +00001984 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001985 break;
1986 }
1987 if (LocaleCompare("liquid-rescale",option+1) == 0)
1988 {
1989 /*
1990 Liquid rescale image.
1991 */
cristy6fccee12011-10-20 18:43:18 +00001992 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001993 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1994 if ((flags & XValue) == 0)
1995 geometry.x=1;
1996 if ((flags & YValue) == 0)
1997 geometry.y=0;
1998 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1999 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2000 break;
2001 }
2002 if (LocaleCompare("lowlight-color",option+1) == 0)
2003 {
2004 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2005 break;
2006 }
2007 break;
2008 }
2009 case 'm':
2010 {
2011 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002012 {
cristy3ed852e2009-09-05 21:47:34 +00002013 Image
anthonydf8ebac2011-04-27 09:03:19 +00002014 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002015
anthonydf8ebac2011-04-27 09:03:19 +00002016 /*
2017 Transform image colors to match this set of colors.
2018 */
cristy6fccee12011-10-20 18:43:18 +00002019 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002020 if (*option == '+')
2021 break;
2022 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2023 if (remap_image == (Image *) NULL)
2024 break;
cristy018f07f2011-09-04 21:15:19 +00002025 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002026 remap_image=DestroyImage(remap_image);
2027 break;
2028 }
2029 if (LocaleCompare("mask",option+1) == 0)
2030 {
2031 Image
2032 *mask;
2033
cristy6fccee12011-10-20 18:43:18 +00002034 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002035 if (*option == '+')
2036 {
2037 /*
2038 Remove a mask.
2039 */
cristy018f07f2011-09-04 21:15:19 +00002040 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002041 break;
2042 }
2043 /*
2044 Set the image mask.
2045 */
2046 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2047 if (mask == (Image *) NULL)
2048 break;
cristy018f07f2011-09-04 21:15:19 +00002049 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002050 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002051 break;
2052 }
2053 if (LocaleCompare("matte",option+1) == 0)
2054 {
2055 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002056 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002057 break;
2058 }
2059 if (LocaleCompare("median",option+1) == 0)
2060 {
2061 /*
2062 Median filter image.
2063 */
cristy6fccee12011-10-20 18:43:18 +00002064 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002065 flags=ParseGeometry(argv[i+1],&geometry_info);
2066 if ((flags & SigmaValue) == 0)
2067 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002068 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002069 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002070 break;
2071 }
2072 if (LocaleCompare("mode",option+1) == 0)
2073 {
2074 /*
2075 Mode image.
2076 */
cristy6fccee12011-10-20 18:43:18 +00002077 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002078 flags=ParseGeometry(argv[i+1],&geometry_info);
2079 if ((flags & SigmaValue) == 0)
2080 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002081 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002082 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002083 break;
2084 }
2085 if (LocaleCompare("modulate",option+1) == 0)
2086 {
cristy6fccee12011-10-20 18:43:18 +00002087 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002088 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002089 break;
2090 }
2091 if (LocaleCompare("monitor",option+1) == 0)
2092 {
2093 if (*option == '+')
2094 {
2095 (void) SetImageProgressMonitor(*image,
2096 (MagickProgressMonitor) NULL,(void *) NULL);
2097 break;
2098 }
2099 (void) SetImageProgressMonitor(*image,MonitorProgress,
2100 (void *) NULL);
2101 break;
2102 }
2103 if (LocaleCompare("monochrome",option+1) == 0)
2104 {
cristy6fccee12011-10-20 18:43:18 +00002105 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002106 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002107 break;
2108 }
2109 if (LocaleCompare("morphology",option+1) == 0)
2110 {
2111 char
2112 token[MaxTextExtent];
2113
2114 const char
2115 *p;
2116
2117 KernelInfo
2118 *kernel;
2119
2120 MorphologyMethod
2121 method;
2122
2123 ssize_t
2124 iterations;
2125
2126 /*
2127 Morphological Image Operation
2128 */
cristy6fccee12011-10-20 18:43:18 +00002129 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002130 p=argv[i+1];
2131 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002132 method=(MorphologyMethod) ParseCommandOption(
2133 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002134 iterations=1L;
2135 GetMagickToken(p,&p,token);
2136 if ((*p == ':') || (*p == ','))
2137 GetMagickToken(p,&p,token);
2138 if ((*p != '\0'))
2139 iterations=(ssize_t) StringToLong(p);
2140 kernel=AcquireKernelInfo(argv[i+2]);
2141 if (kernel == (KernelInfo *) NULL)
2142 {
2143 (void) ThrowMagickException(exception,GetMagickModule(),
2144 OptionError,"UnabletoParseKernel","morphology");
2145 status=MagickFalse;
2146 break;
2147 }
cristyf4ad9df2011-07-08 16:49:03 +00002148 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2149 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002150 kernel=DestroyKernelInfo(kernel);
2151 break;
2152 }
2153 if (LocaleCompare("motion-blur",option+1) == 0)
2154 {
2155 /*
2156 Motion blur image.
2157 */
cristy6fccee12011-10-20 18:43:18 +00002158 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002159 flags=ParseGeometry(argv[i+1],&geometry_info);
2160 if ((flags & SigmaValue) == 0)
2161 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002162 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002163 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2164 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002165 break;
2166 }
2167 break;
2168 }
2169 case 'n':
2170 {
2171 if (LocaleCompare("negate",option+1) == 0)
2172 {
cristy6fccee12011-10-20 18:43:18 +00002173 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002174 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002175 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002176 break;
2177 }
2178 if (LocaleCompare("noise",option+1) == 0)
2179 {
cristy6fccee12011-10-20 18:43:18 +00002180 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002181 if (*option == '-')
2182 {
cristyf36cbcb2011-09-07 13:28:22 +00002183 flags=ParseGeometry(argv[i+1],&geometry_info);
2184 if ((flags & SigmaValue) == 0)
2185 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002186 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002187 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002188 }
2189 else
2190 {
2191 NoiseType
2192 noise;
2193
2194 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2195 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002196 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002197 }
2198 break;
2199 }
2200 if (LocaleCompare("normalize",option+1) == 0)
2201 {
cristy6fccee12011-10-20 18:43:18 +00002202 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002203 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002204 break;
2205 }
2206 break;
2207 }
2208 case 'o':
2209 {
2210 if (LocaleCompare("opaque",option+1) == 0)
2211 {
cristy4c08aed2011-07-01 19:47:50 +00002212 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002213 target;
2214
cristy6fccee12011-10-20 18:43:18 +00002215 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002216 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002217 exception);
cristyd42d9952011-07-08 14:21:50 +00002218 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002219 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002220 break;
2221 }
2222 if (LocaleCompare("ordered-dither",option+1) == 0)
2223 {
cristy6fccee12011-10-20 18:43:18 +00002224 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002225 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002226 break;
2227 }
2228 break;
2229 }
2230 case 'p':
2231 {
2232 if (LocaleCompare("paint",option+1) == 0)
2233 {
cristy6fccee12011-10-20 18:43:18 +00002234 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002235 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002236 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2237 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002238 break;
2239 }
2240 if (LocaleCompare("pen",option+1) == 0)
2241 {
2242 if (*option == '+')
2243 {
cristy9950d572011-10-01 18:22:35 +00002244 (void) QueryColorCompliance("none",AllCompliance,
2245 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002246 break;
2247 }
cristy9950d572011-10-01 18:22:35 +00002248 (void) QueryColorCompliance(argv[i+1],AllCompliance,
2249 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002250 break;
2251 }
2252 if (LocaleCompare("pointsize",option+1) == 0)
2253 {
2254 if (*option == '+')
2255 (void) ParseGeometry("12",&geometry_info);
2256 else
2257 (void) ParseGeometry(argv[i+1],&geometry_info);
2258 draw_info->pointsize=geometry_info.rho;
2259 break;
2260 }
2261 if (LocaleCompare("polaroid",option+1) == 0)
2262 {
2263 double
2264 angle;
2265
2266 RandomInfo
2267 *random_info;
2268
2269 /*
2270 Simulate a Polaroid picture.
2271 */
cristy6fccee12011-10-20 18:43:18 +00002272 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002273 random_info=AcquireRandomInfo();
2274 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2275 random_info=DestroyRandomInfo(random_info);
2276 if (*option == '-')
2277 {
2278 SetGeometryInfo(&geometry_info);
2279 flags=ParseGeometry(argv[i+1],&geometry_info);
2280 angle=geometry_info.rho;
2281 }
cristy5c4e2582011-09-11 19:21:03 +00002282 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002283 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002284 break;
2285 }
2286 if (LocaleCompare("posterize",option+1) == 0)
2287 {
2288 /*
2289 Posterize image.
2290 */
cristy6fccee12011-10-20 18:43:18 +00002291 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002292 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002293 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002294 break;
2295 }
2296 if (LocaleCompare("preview",option+1) == 0)
2297 {
2298 PreviewType
2299 preview_type;
2300
2301 /*
2302 Preview image.
2303 */
cristy6fccee12011-10-20 18:43:18 +00002304 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002305 if (*option == '+')
2306 preview_type=UndefinedPreview;
2307 else
cristy28474bf2011-09-11 23:32:52 +00002308 preview_type=(PreviewType) ParseCommandOption(
2309 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002310 mogrify_image=PreviewImage(*image,preview_type,exception);
2311 break;
2312 }
2313 if (LocaleCompare("profile",option+1) == 0)
2314 {
2315 const char
2316 *name;
2317
2318 const StringInfo
2319 *profile;
2320
2321 Image
2322 *profile_image;
2323
2324 ImageInfo
2325 *profile_info;
2326
cristy6fccee12011-10-20 18:43:18 +00002327 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002328 if (*option == '+')
2329 {
2330 /*
2331 Remove a profile from the image.
2332 */
2333 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002334 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002335 break;
2336 }
2337 /*
2338 Associate a profile with the image.
2339 */
2340 profile_info=CloneImageInfo(mogrify_info);
2341 profile=GetImageProfile(*image,"iptc");
2342 if (profile != (StringInfo *) NULL)
2343 profile_info->profile=(void *) CloneStringInfo(profile);
2344 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2345 profile_info=DestroyImageInfo(profile_info);
2346 if (profile_image == (Image *) NULL)
2347 {
2348 StringInfo
2349 *profile;
2350
2351 profile_info=CloneImageInfo(mogrify_info);
2352 (void) CopyMagickString(profile_info->filename,argv[i+1],
2353 MaxTextExtent);
2354 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2355 if (profile != (StringInfo *) NULL)
2356 {
2357 (void) ProfileImage(*image,profile_info->magick,
2358 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002359 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002360 profile=DestroyStringInfo(profile);
2361 }
2362 profile_info=DestroyImageInfo(profile_info);
2363 break;
2364 }
2365 ResetImageProfileIterator(profile_image);
2366 name=GetNextImageProfile(profile_image);
2367 while (name != (const char *) NULL)
2368 {
2369 profile=GetImageProfile(profile_image,name);
2370 if (profile != (StringInfo *) NULL)
2371 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002372 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002373 name=GetNextImageProfile(profile_image);
2374 }
2375 profile_image=DestroyImage(profile_image);
2376 break;
2377 }
2378 break;
2379 }
2380 case 'q':
2381 {
2382 if (LocaleCompare("quantize",option+1) == 0)
2383 {
2384 if (*option == '+')
2385 {
2386 quantize_info->colorspace=UndefinedColorspace;
2387 break;
2388 }
2389 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2390 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2391 break;
2392 }
2393 break;
2394 }
2395 case 'r':
2396 {
2397 if (LocaleCompare("radial-blur",option+1) == 0)
2398 {
2399 /*
2400 Radial blur image.
2401 */
cristy6fccee12011-10-20 18:43:18 +00002402 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002403 flags=ParseGeometry(argv[i+1],&geometry_info);
2404 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2405 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002406 break;
2407 }
2408 if (LocaleCompare("raise",option+1) == 0)
2409 {
2410 /*
2411 Surround image with a raise of solid color.
2412 */
2413 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2414 if ((flags & SigmaValue) == 0)
2415 geometry.height=geometry.width;
2416 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002417 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002418 break;
2419 }
2420 if (LocaleCompare("random-threshold",option+1) == 0)
2421 {
2422 /*
2423 Threshold image.
2424 */
cristy6fccee12011-10-20 18:43:18 +00002425 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002426 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002427 break;
2428 }
2429 if (LocaleCompare("recolor",option+1) == 0)
2430 {
2431 KernelInfo
2432 *kernel;
2433
cristy6fccee12011-10-20 18:43:18 +00002434 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002435 kernel=AcquireKernelInfo(argv[i+1]);
2436 if (kernel == (KernelInfo *) NULL)
2437 break;
2438 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2439 kernel=DestroyKernelInfo(kernel);
2440 break;
2441 }
2442 if (LocaleCompare("region",option+1) == 0)
2443 {
cristy6fccee12011-10-20 18:43:18 +00002444 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002445 if (region_image != (Image *) NULL)
2446 {
2447 /*
2448 Composite region.
2449 */
2450 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002451 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002452 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002453 *image=DestroyImage(*image);
2454 *image=region_image;
2455 region_image = (Image *) NULL;
2456 }
2457 if (*option == '+')
2458 break;
2459 /*
2460 Apply transformations to a selected region of the image.
2461 */
cristy3ed852e2009-09-05 21:47:34 +00002462 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2463 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002464 mogrify_image=CropImage(*image,&region_geometry,exception);
2465 if (mogrify_image == (Image *) NULL)
2466 break;
2467 region_image=(*image);
2468 *image=mogrify_image;
2469 mogrify_image=(Image *) NULL;
2470 break;
cristy3ed852e2009-09-05 21:47:34 +00002471 }
anthonydf8ebac2011-04-27 09:03:19 +00002472 if (LocaleCompare("render",option+1) == 0)
2473 {
cristy6fccee12011-10-20 18:43:18 +00002474 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002475 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2476 break;
2477 }
2478 if (LocaleCompare("remap",option+1) == 0)
2479 {
2480 Image
2481 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002482
anthonydf8ebac2011-04-27 09:03:19 +00002483 /*
2484 Transform image colors to match this set of colors.
2485 */
cristy6fccee12011-10-20 18:43:18 +00002486 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002487 if (*option == '+')
2488 break;
2489 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2490 if (remap_image == (Image *) NULL)
2491 break;
cristy018f07f2011-09-04 21:15:19 +00002492 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002493 remap_image=DestroyImage(remap_image);
2494 break;
2495 }
2496 if (LocaleCompare("repage",option+1) == 0)
2497 {
2498 if (*option == '+')
2499 {
2500 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2501 break;
2502 }
2503 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002504 break;
2505 }
2506 if (LocaleCompare("resample",option+1) == 0)
2507 {
2508 /*
2509 Resample image.
2510 */
cristy6fccee12011-10-20 18:43:18 +00002511 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002512 flags=ParseGeometry(argv[i+1],&geometry_info);
2513 if ((flags & SigmaValue) == 0)
2514 geometry_info.sigma=geometry_info.rho;
2515 mogrify_image=ResampleImage(*image,geometry_info.rho,
2516 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2517 break;
2518 }
2519 if (LocaleCompare("resize",option+1) == 0)
2520 {
2521 /*
2522 Resize image.
2523 */
cristy6fccee12011-10-20 18:43:18 +00002524 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002525 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2526 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2527 (*image)->filter,(*image)->blur,exception);
2528 break;
2529 }
2530 if (LocaleCompare("roll",option+1) == 0)
2531 {
2532 /*
2533 Roll image.
2534 */
cristy6fccee12011-10-20 18:43:18 +00002535 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002536 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2537 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2538 break;
2539 }
2540 if (LocaleCompare("rotate",option+1) == 0)
2541 {
2542 char
2543 *geometry;
2544
2545 /*
2546 Check for conditional image rotation.
2547 */
cristy6fccee12011-10-20 18:43:18 +00002548 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002549 if (strchr(argv[i+1],'>') != (char *) NULL)
2550 if ((*image)->columns <= (*image)->rows)
2551 break;
2552 if (strchr(argv[i+1],'<') != (char *) NULL)
2553 if ((*image)->columns >= (*image)->rows)
2554 break;
2555 /*
2556 Rotate image.
2557 */
2558 geometry=ConstantString(argv[i+1]);
2559 (void) SubstituteString(&geometry,">","");
2560 (void) SubstituteString(&geometry,"<","");
2561 (void) ParseGeometry(geometry,&geometry_info);
2562 geometry=DestroyString(geometry);
2563 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2564 break;
2565 }
2566 break;
2567 }
2568 case 's':
2569 {
2570 if (LocaleCompare("sample",option+1) == 0)
2571 {
2572 /*
2573 Sample image with pixel replication.
2574 */
cristy6fccee12011-10-20 18:43:18 +00002575 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002576 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2577 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2578 exception);
2579 break;
2580 }
2581 if (LocaleCompare("scale",option+1) == 0)
2582 {
2583 /*
2584 Resize image.
2585 */
cristy6fccee12011-10-20 18:43:18 +00002586 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002587 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2588 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2589 exception);
2590 break;
2591 }
2592 if (LocaleCompare("selective-blur",option+1) == 0)
2593 {
2594 /*
2595 Selectively blur pixels within a contrast threshold.
2596 */
cristy6fccee12011-10-20 18:43:18 +00002597 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002598 flags=ParseGeometry(argv[i+1],&geometry_info);
2599 if ((flags & PercentValue) != 0)
2600 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002601 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002602 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002603 break;
2604 }
2605 if (LocaleCompare("separate",option+1) == 0)
2606 {
2607 /*
2608 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002609 */
cristy6fccee12011-10-20 18:43:18 +00002610 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002611 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002612 break;
2613 }
2614 if (LocaleCompare("sepia-tone",option+1) == 0)
2615 {
2616 double
2617 threshold;
2618
2619 /*
2620 Sepia-tone image.
2621 */
cristy6fccee12011-10-20 18:43:18 +00002622 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002623 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2624 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002625 mogrify_image=SepiaToneImage(*image,threshold,exception);
2626 break;
2627 }
2628 if (LocaleCompare("segment",option+1) == 0)
2629 {
2630 /*
2631 Segment image.
2632 */
cristy6fccee12011-10-20 18:43:18 +00002633 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002634 flags=ParseGeometry(argv[i+1],&geometry_info);
2635 if ((flags & SigmaValue) == 0)
2636 geometry_info.sigma=1.0;
2637 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002638 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2639 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002640 break;
2641 }
2642 if (LocaleCompare("set",option+1) == 0)
2643 {
2644 char
2645 *value;
2646
2647 /*
2648 Set image option.
2649 */
2650 if (*option == '+')
2651 {
2652 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2653 (void) DeleteImageRegistry(argv[i+1]+9);
2654 else
2655 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2656 {
2657 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2658 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2659 }
2660 else
2661 (void) DeleteImageProperty(*image,argv[i+1]);
2662 break;
2663 }
cristy018f07f2011-09-04 21:15:19 +00002664 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2665 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002666 if (value == (char *) NULL)
2667 break;
2668 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2669 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2670 exception);
2671 else
2672 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2673 {
2674 (void) SetImageOption(image_info,argv[i+1]+7,value);
2675 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2676 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2677 }
2678 else
cristyd15e6592011-10-15 00:13:06 +00002679 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002680 value=DestroyString(value);
2681 break;
2682 }
2683 if (LocaleCompare("shade",option+1) == 0)
2684 {
2685 /*
2686 Shade image.
2687 */
cristy6fccee12011-10-20 18:43:18 +00002688 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002689 flags=ParseGeometry(argv[i+1],&geometry_info);
2690 if ((flags & SigmaValue) == 0)
2691 geometry_info.sigma=1.0;
2692 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2693 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2694 break;
2695 }
2696 if (LocaleCompare("shadow",option+1) == 0)
2697 {
2698 /*
2699 Shadow image.
2700 */
cristy6fccee12011-10-20 18:43:18 +00002701 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002702 flags=ParseGeometry(argv[i+1],&geometry_info);
2703 if ((flags & SigmaValue) == 0)
2704 geometry_info.sigma=1.0;
2705 if ((flags & XiValue) == 0)
2706 geometry_info.xi=4.0;
2707 if ((flags & PsiValue) == 0)
2708 geometry_info.psi=4.0;
2709 mogrify_image=ShadowImage(*image,geometry_info.rho,
2710 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2711 ceil(geometry_info.psi-0.5),exception);
2712 break;
2713 }
2714 if (LocaleCompare("sharpen",option+1) == 0)
2715 {
2716 /*
2717 Sharpen image.
2718 */
cristy6fccee12011-10-20 18:43:18 +00002719 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002720 flags=ParseGeometry(argv[i+1],&geometry_info);
2721 if ((flags & SigmaValue) == 0)
2722 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002723 if ((flags & XiValue) == 0)
2724 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002725 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002726 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002727 break;
2728 }
2729 if (LocaleCompare("shave",option+1) == 0)
2730 {
2731 /*
2732 Shave the image edges.
2733 */
cristy6fccee12011-10-20 18:43:18 +00002734 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002735 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2736 mogrify_image=ShaveImage(*image,&geometry,exception);
2737 break;
2738 }
2739 if (LocaleCompare("shear",option+1) == 0)
2740 {
2741 /*
2742 Shear 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=geometry_info.rho;
2748 mogrify_image=ShearImage(*image,geometry_info.rho,
2749 geometry_info.sigma,exception);
2750 break;
2751 }
2752 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2753 {
2754 /*
2755 Sigmoidal non-linearity contrast control.
2756 */
cristy6fccee12011-10-20 18:43:18 +00002757 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002758 flags=ParseGeometry(argv[i+1],&geometry_info);
2759 if ((flags & SigmaValue) == 0)
2760 geometry_info.sigma=(double) QuantumRange/2.0;
2761 if ((flags & PercentValue) != 0)
2762 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2763 100.0;
cristy9ee60942011-07-06 14:54:38 +00002764 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002765 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2766 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002767 break;
2768 }
2769 if (LocaleCompare("sketch",option+1) == 0)
2770 {
2771 /*
2772 Sketch image.
2773 */
cristy6fccee12011-10-20 18:43:18 +00002774 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002775 flags=ParseGeometry(argv[i+1],&geometry_info);
2776 if ((flags & SigmaValue) == 0)
2777 geometry_info.sigma=1.0;
2778 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002779 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002780 break;
2781 }
2782 if (LocaleCompare("solarize",option+1) == 0)
2783 {
2784 double
2785 threshold;
2786
cristy6fccee12011-10-20 18:43:18 +00002787 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002788 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2789 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002790 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002791 break;
2792 }
2793 if (LocaleCompare("sparse-color",option+1) == 0)
2794 {
2795 SparseColorMethod
2796 method;
2797
2798 char
2799 *arguments;
2800
2801 /*
2802 Sparse Color Interpolated Gradient
2803 */
cristy6fccee12011-10-20 18:43:18 +00002804 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002805 method=(SparseColorMethod) ParseCommandOption(
2806 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002807 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2808 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002809 if (arguments == (char *) NULL)
2810 break;
cristy3884f692011-07-08 18:00:18 +00002811 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002812 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2813 arguments=DestroyString(arguments);
2814 break;
2815 }
2816 if (LocaleCompare("splice",option+1) == 0)
2817 {
2818 /*
2819 Splice a solid color into the image.
2820 */
cristy6fccee12011-10-20 18:43:18 +00002821 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002822 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2823 mogrify_image=SpliceImage(*image,&geometry,exception);
2824 break;
2825 }
2826 if (LocaleCompare("spread",option+1) == 0)
2827 {
2828 /*
2829 Spread an image.
2830 */
cristy6fccee12011-10-20 18:43:18 +00002831 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002832 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002833 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002834 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002835 break;
2836 }
2837 if (LocaleCompare("statistic",option+1) == 0)
2838 {
2839 StatisticType
2840 type;
2841
cristy6fccee12011-10-20 18:43:18 +00002842 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002843 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2844 MagickFalse,argv[i+1]);
2845 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002846 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2847 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002848 break;
2849 }
2850 if (LocaleCompare("stretch",option+1) == 0)
2851 {
2852 if (*option == '+')
2853 {
2854 draw_info->stretch=UndefinedStretch;
2855 break;
2856 }
2857 draw_info->stretch=(StretchType) ParseCommandOption(
2858 MagickStretchOptions,MagickFalse,argv[i+1]);
2859 break;
2860 }
2861 if (LocaleCompare("strip",option+1) == 0)
2862 {
2863 /*
2864 Strip image of profiles and comments.
2865 */
cristy6fccee12011-10-20 18:43:18 +00002866 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002867 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002868 break;
2869 }
2870 if (LocaleCompare("stroke",option+1) == 0)
2871 {
2872 ExceptionInfo
2873 *sans;
2874
2875 if (*option == '+')
2876 {
cristy9950d572011-10-01 18:22:35 +00002877 (void) QueryColorCompliance("none",AllCompliance,
2878 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002879 if (draw_info->stroke_pattern != (Image *) NULL)
2880 draw_info->stroke_pattern=DestroyImage(
2881 draw_info->stroke_pattern);
2882 break;
2883 }
2884 sans=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00002885 status=QueryColorCompliance(argv[i+1],AllCompliance,
2886 &draw_info->stroke,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002887 sans=DestroyExceptionInfo(sans);
2888 if (status == MagickFalse)
2889 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2890 exception);
2891 break;
2892 }
2893 if (LocaleCompare("strokewidth",option+1) == 0)
2894 {
cristy9b34e302011-11-05 02:15:45 +00002895 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002896 break;
2897 }
2898 if (LocaleCompare("style",option+1) == 0)
2899 {
2900 if (*option == '+')
2901 {
2902 draw_info->style=UndefinedStyle;
2903 break;
2904 }
2905 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2906 MagickFalse,argv[i+1]);
2907 break;
2908 }
2909 if (LocaleCompare("swirl",option+1) == 0)
2910 {
2911 /*
2912 Swirl image.
2913 */
cristy6fccee12011-10-20 18:43:18 +00002914 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002915 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002916 mogrify_image=SwirlImage(*image,geometry_info.rho,
2917 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002918 break;
2919 }
2920 break;
2921 }
2922 case 't':
2923 {
2924 if (LocaleCompare("threshold",option+1) == 0)
2925 {
2926 double
2927 threshold;
2928
2929 /*
2930 Threshold image.
2931 */
cristy6fccee12011-10-20 18:43:18 +00002932 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002933 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002934 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002935 else
cristy9b34e302011-11-05 02:15:45 +00002936 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2937 1.0);
cristye941a752011-10-15 01:52:48 +00002938 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002939 break;
2940 }
2941 if (LocaleCompare("thumbnail",option+1) == 0)
2942 {
2943 /*
2944 Thumbnail image.
2945 */
cristy6fccee12011-10-20 18:43:18 +00002946 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002947 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2948 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2949 exception);
2950 break;
2951 }
2952 if (LocaleCompare("tile",option+1) == 0)
2953 {
2954 if (*option == '+')
2955 {
2956 if (draw_info->fill_pattern != (Image *) NULL)
2957 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2958 break;
2959 }
2960 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2961 exception);
2962 break;
2963 }
2964 if (LocaleCompare("tint",option+1) == 0)
2965 {
2966 /*
2967 Tint the image.
2968 */
cristy6fccee12011-10-20 18:43:18 +00002969 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002970 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002971 break;
2972 }
2973 if (LocaleCompare("transform",option+1) == 0)
2974 {
2975 /*
2976 Affine transform image.
2977 */
cristy6fccee12011-10-20 18:43:18 +00002978 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002979 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2980 exception);
2981 break;
2982 }
2983 if (LocaleCompare("transparent",option+1) == 0)
2984 {
cristy4c08aed2011-07-01 19:47:50 +00002985 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002986 target;
2987
cristy6fccee12011-10-20 18:43:18 +00002988 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002989 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002990 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002991 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002992 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00002993 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002994 break;
2995 }
2996 if (LocaleCompare("transpose",option+1) == 0)
2997 {
2998 /*
2999 Transpose image scanlines.
3000 */
cristy6fccee12011-10-20 18:43:18 +00003001 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003002 mogrify_image=TransposeImage(*image,exception);
3003 break;
3004 }
3005 if (LocaleCompare("transverse",option+1) == 0)
3006 {
3007 /*
3008 Transverse image scanlines.
3009 */
cristy6fccee12011-10-20 18:43:18 +00003010 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003011 mogrify_image=TransverseImage(*image,exception);
3012 break;
3013 }
3014 if (LocaleCompare("treedepth",option+1) == 0)
3015 {
3016 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3017 break;
3018 }
3019 if (LocaleCompare("trim",option+1) == 0)
3020 {
3021 /*
3022 Trim image.
3023 */
cristy6fccee12011-10-20 18:43:18 +00003024 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003025 mogrify_image=TrimImage(*image,exception);
3026 break;
3027 }
3028 if (LocaleCompare("type",option+1) == 0)
3029 {
3030 ImageType
3031 type;
3032
cristy6fccee12011-10-20 18:43:18 +00003033 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003034 if (*option == '+')
3035 type=UndefinedType;
3036 else
3037 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3038 argv[i+1]);
3039 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003040 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003041 break;
3042 }
3043 break;
3044 }
3045 case 'u':
3046 {
3047 if (LocaleCompare("undercolor",option+1) == 0)
3048 {
cristy9950d572011-10-01 18:22:35 +00003049 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3050 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003051 break;
3052 }
3053 if (LocaleCompare("unique",option+1) == 0)
3054 {
3055 if (*option == '+')
3056 {
3057 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3058 break;
3059 }
3060 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3061 (void) SetImageArtifact(*image,"verbose","true");
3062 break;
3063 }
3064 if (LocaleCompare("unique-colors",option+1) == 0)
3065 {
3066 /*
3067 Unique image colors.
3068 */
cristy6fccee12011-10-20 18:43:18 +00003069 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003070 mogrify_image=UniqueImageColors(*image,exception);
3071 break;
3072 }
3073 if (LocaleCompare("unsharp",option+1) == 0)
3074 {
3075 /*
3076 Unsharp mask image.
3077 */
cristy6fccee12011-10-20 18:43:18 +00003078 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003079 flags=ParseGeometry(argv[i+1],&geometry_info);
3080 if ((flags & SigmaValue) == 0)
3081 geometry_info.sigma=1.0;
3082 if ((flags & XiValue) == 0)
3083 geometry_info.xi=1.0;
3084 if ((flags & PsiValue) == 0)
3085 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003086 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3087 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003088 break;
3089 }
3090 break;
3091 }
3092 case 'v':
3093 {
3094 if (LocaleCompare("verbose",option+1) == 0)
3095 {
3096 (void) SetImageArtifact(*image,option+1,
3097 *option == '+' ? "false" : "true");
3098 break;
3099 }
3100 if (LocaleCompare("vignette",option+1) == 0)
3101 {
3102 /*
3103 Vignette image.
3104 */
cristy6fccee12011-10-20 18:43:18 +00003105 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003106 flags=ParseGeometry(argv[i+1],&geometry_info);
3107 if ((flags & SigmaValue) == 0)
3108 geometry_info.sigma=1.0;
3109 if ((flags & XiValue) == 0)
3110 geometry_info.xi=0.1*(*image)->columns;
3111 if ((flags & PsiValue) == 0)
3112 geometry_info.psi=0.1*(*image)->rows;
3113 mogrify_image=VignetteImage(*image,geometry_info.rho,
3114 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3115 ceil(geometry_info.psi-0.5),exception);
3116 break;
3117 }
3118 if (LocaleCompare("virtual-pixel",option+1) == 0)
3119 {
3120 if (*option == '+')
3121 {
3122 (void) SetImageVirtualPixelMethod(*image,
3123 UndefinedVirtualPixelMethod);
3124 break;
3125 }
3126 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3127 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3128 argv[i+1]));
3129 break;
3130 }
3131 break;
3132 }
3133 case 'w':
3134 {
3135 if (LocaleCompare("wave",option+1) == 0)
3136 {
3137 /*
3138 Wave image.
3139 */
cristy6fccee12011-10-20 18:43:18 +00003140 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003141 flags=ParseGeometry(argv[i+1],&geometry_info);
3142 if ((flags & SigmaValue) == 0)
3143 geometry_info.sigma=1.0;
3144 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003145 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003146 break;
3147 }
3148 if (LocaleCompare("weight",option+1) == 0)
3149 {
3150 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3151 if (LocaleCompare(argv[i+1],"all") == 0)
3152 draw_info->weight=0;
3153 if (LocaleCompare(argv[i+1],"bold") == 0)
3154 draw_info->weight=700;
3155 if (LocaleCompare(argv[i+1],"bolder") == 0)
3156 if (draw_info->weight <= 800)
3157 draw_info->weight+=100;
3158 if (LocaleCompare(argv[i+1],"lighter") == 0)
3159 if (draw_info->weight >= 100)
3160 draw_info->weight-=100;
3161 if (LocaleCompare(argv[i+1],"normal") == 0)
3162 draw_info->weight=400;
3163 break;
3164 }
3165 if (LocaleCompare("white-threshold",option+1) == 0)
3166 {
3167 /*
3168 White threshold image.
3169 */
cristy6fccee12011-10-20 18:43:18 +00003170 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003171 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003172 break;
3173 }
3174 break;
3175 }
3176 default:
3177 break;
3178 }
3179 /*
3180 Replace current image with any image that was generated
3181 */
3182 if (mogrify_image != (Image *) NULL)
3183 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003184 i+=count;
3185 }
3186 if (region_image != (Image *) NULL)
3187 {
anthonydf8ebac2011-04-27 09:03:19 +00003188 /*
3189 Composite transformed region onto image.
3190 */
cristy6fccee12011-10-20 18:43:18 +00003191 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003192 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003193 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003194 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003195 *image=DestroyImage(*image);
3196 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003197 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003198 }
3199 /*
3200 Free resources.
3201 */
anthonydf8ebac2011-04-27 09:03:19 +00003202 quantize_info=DestroyQuantizeInfo(quantize_info);
3203 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003204 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003205 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003206 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003207}
3208
3209/*
3210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3211% %
3212% %
3213% %
cristy5063d812010-10-19 16:28:10 +00003214+ 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 +00003215% %
3216% %
3217% %
3218%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3219%
3220% MogrifyImageCommand() transforms an image or a sequence of images. These
3221% transforms include image scaling, image rotation, color reduction, and
3222% others. The transmogrified image overwrites the original image.
3223%
3224% The format of the MogrifyImageCommand method is:
3225%
3226% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3227% const char **argv,char **metadata,ExceptionInfo *exception)
3228%
3229% A description of each parameter follows:
3230%
3231% o image_info: the image info.
3232%
3233% o argc: the number of elements in the argument vector.
3234%
3235% o argv: A text array containing the command line arguments.
3236%
3237% o metadata: any metadata is returned here.
3238%
3239% o exception: return any errors or warnings in this structure.
3240%
3241*/
3242
3243static MagickBooleanType MogrifyUsage(void)
3244{
3245 static const char
3246 *miscellaneous[]=
3247 {
3248 "-debug events display copious debugging information",
3249 "-help print program options",
3250 "-list type print a list of supported option arguments",
3251 "-log format format of debugging information",
3252 "-version print version information",
3253 (char *) NULL
3254 },
3255 *operators[]=
3256 {
3257 "-adaptive-blur geometry",
3258 " adaptively blur pixels; decrease effect near edges",
3259 "-adaptive-resize geometry",
3260 " adaptively resize image using 'mesh' interpolation",
3261 "-adaptive-sharpen geometry",
3262 " adaptively sharpen pixels; increase effect near edges",
3263 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3264 " transparent, extract, background, or shape",
3265 "-annotate geometry text",
3266 " annotate the image with text",
3267 "-auto-gamma automagically adjust gamma level of image",
3268 "-auto-level automagically adjust color levels of image",
3269 "-auto-orient automagically orient (rotate) image",
3270 "-bench iterations measure performance",
3271 "-black-threshold value",
3272 " force all pixels below the threshold into black",
3273 "-blue-shift simulate a scene at nighttime in the moonlight",
3274 "-blur geometry reduce image noise and reduce detail levels",
3275 "-border geometry surround image with a border of color",
3276 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003277 "-brightness-contrast geometry",
3278 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003279 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003280 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003281 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003282 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003283 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003284 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003285 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003286 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003287 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003288 "-contrast enhance or reduce the image contrast",
3289 "-contrast-stretch geometry",
3290 " improve contrast by `stretching' the intensity range",
3291 "-convolve coefficients",
3292 " apply a convolution kernel to the image",
3293 "-cycle amount cycle the image colormap",
3294 "-decipher filename convert cipher pixels to plain pixels",
3295 "-deskew threshold straighten an image",
3296 "-despeckle reduce the speckles within an image",
3297 "-distort method args",
3298 " distort images according to given method ad args",
3299 "-draw string annotate the image with a graphic primitive",
3300 "-edge radius apply a filter to detect edges in the image",
3301 "-encipher filename convert plain pixels to cipher pixels",
3302 "-emboss radius emboss an image",
3303 "-enhance apply a digital filter to enhance a noisy image",
3304 "-equalize perform histogram equalization to an image",
3305 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003306 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003307 "-extent geometry set the image size",
3308 "-extract geometry extract area from image",
3309 "-fft implements the discrete Fourier transform (DFT)",
3310 "-flip flip image vertically",
3311 "-floodfill geometry color",
3312 " floodfill the image with color",
3313 "-flop flop image horizontally",
3314 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003315 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003316 " apply function over image values",
3317 "-gamma value level of gamma correction",
3318 "-gaussian-blur geometry",
3319 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003320 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003321 "-identify identify the format and characteristics of the image",
3322 "-ift implements the inverse discrete Fourier transform (DFT)",
3323 "-implode amount implode image pixels about the center",
3324 "-lat geometry local adaptive thresholding",
3325 "-layers method optimize, merge, or compare image layers",
3326 "-level value adjust the level of image contrast",
3327 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003328 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003329 "-linear-stretch geometry",
3330 " improve contrast by `stretching with saturation'",
3331 "-liquid-rescale geometry",
3332 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003333 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003334 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003335 "-modulate value vary the brightness, saturation, and hue",
3336 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003337 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003338 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003339 "-motion-blur geometry",
3340 " simulate motion blur",
3341 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003342 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-normalize transform image to span the full range of colors",
3344 "-opaque color change this color to the fill color",
3345 "-ordered-dither NxN",
3346 " add a noise pattern to the image with specific",
3347 " amplitudes",
3348 "-paint radius simulate an oil painting",
3349 "-polaroid angle simulate a Polaroid picture",
3350 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003351 "-profile filename add, delete, or apply an image profile",
3352 "-quantize colorspace reduce colors in this colorspace",
3353 "-radial-blur angle radial blur the image",
3354 "-raise value lighten/darken image edges to create a 3-D effect",
3355 "-random-threshold low,high",
3356 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-region geometry apply options to a portion of the image",
3358 "-render render vector graphics",
3359 "-repage geometry size and location of an image canvas",
3360 "-resample geometry change the resolution of an image",
3361 "-resize geometry resize the image",
3362 "-roll geometry roll an image vertically or horizontally",
3363 "-rotate degrees apply Paeth rotation to the image",
3364 "-sample geometry scale image with pixel sampling",
3365 "-scale geometry scale the image",
3366 "-segment values segment an image",
3367 "-selective-blur geometry",
3368 " selectively blur pixels within a contrast threshold",
3369 "-sepia-tone threshold",
3370 " simulate a sepia-toned photo",
3371 "-set property value set an image property",
3372 "-shade degrees shade the image using a distant light source",
3373 "-shadow geometry simulate an image shadow",
3374 "-sharpen geometry sharpen the image",
3375 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003376 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-sigmoidal-contrast geometry",
3378 " increase the contrast without saturating highlights or shadows",
3379 "-sketch geometry simulate a pencil sketch",
3380 "-solarize threshold negate all pixels above the threshold level",
3381 "-sparse-color method args",
3382 " fill in a image based on a few color points",
3383 "-splice geometry splice the background color into the image",
3384 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003385 "-statistic type radius",
3386 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003387 "-strip strip image of all profiles and comments",
3388 "-swirl degrees swirl image pixels about the center",
3389 "-threshold value threshold the image",
3390 "-thumbnail geometry create a thumbnail of the image",
3391 "-tile filename tile image when filling a graphic primitive",
3392 "-tint value tint the image with the fill color",
3393 "-transform affine transform image",
3394 "-transparent color make this color transparent within the image",
3395 "-transpose flip image vertically and rotate 90 degrees",
3396 "-transverse flop image horizontally and rotate 270 degrees",
3397 "-trim trim image edges",
3398 "-type type image type",
3399 "-unique-colors discard all but one of any pixel color",
3400 "-unsharp geometry sharpen the image",
3401 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003402 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003403 "-white-threshold value",
3404 " force all pixels above the threshold into white",
3405 (char *) NULL
3406 },
3407 *sequence_operators[]=
3408 {
cristy4285d782011-02-09 20:12:28 +00003409 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003410 "-clut apply a color lookup table to the image",
3411 "-coalesce merge a sequence of images",
3412 "-combine combine a sequence of images",
3413 "-composite composite image",
3414 "-crop geometry cut out a rectangular region of the image",
3415 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003416 "-evaluate-sequence operator",
3417 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003418 "-flatten flatten a sequence of images",
3419 "-fx expression apply mathematical expression to an image channel(s)",
3420 "-hald-clut apply a Hald color lookup table to the image",
3421 "-morph value morph an image sequence",
3422 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003423 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003424 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003425 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003426 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003427 "-write filename write images to this file",
3428 (char *) NULL
3429 },
3430 *settings[]=
3431 {
3432 "-adjoin join images into a single multi-image file",
3433 "-affine matrix affine transform matrix",
3434 "-alpha option activate, deactivate, reset, or set the alpha channel",
3435 "-antialias remove pixel-aliasing",
3436 "-authenticate password",
3437 " decipher image with this password",
3438 "-attenuate value lessen (or intensify) when adding noise to an image",
3439 "-background color background color",
3440 "-bias value add bias when convolving an image",
3441 "-black-point-compensation",
3442 " use black point compensation",
3443 "-blue-primary point chromaticity blue primary point",
3444 "-bordercolor color border color",
3445 "-caption string assign a caption to an image",
3446 "-channel type apply option to select image channels",
3447 "-colors value preferred number of colors in the image",
3448 "-colorspace type alternate image colorspace",
3449 "-comment string annotate image with comment",
3450 "-compose operator set image composite operator",
3451 "-compress type type of pixel compression when writing the image",
3452 "-define format:option",
3453 " define one or more image format options",
3454 "-delay value display the next image after pausing",
3455 "-density geometry horizontal and vertical density of the image",
3456 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003457 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003458 "-display server get image or font from this X server",
3459 "-dispose method layer disposal method",
3460 "-dither method apply error diffusion to image",
3461 "-encoding type text encoding type",
3462 "-endian type endianness (MSB or LSB) of the image",
3463 "-family name render text with this font family",
3464 "-fill color color to use when filling a graphic primitive",
3465 "-filter type use this filter when resizing an image",
3466 "-font name render text with this font",
3467 "-format \"string\" output formatted image characteristics",
3468 "-fuzz distance colors within this distance are considered equal",
3469 "-gravity type horizontal and vertical text placement",
3470 "-green-primary point chromaticity green primary point",
3471 "-intent type type of rendering intent when managing the image color",
3472 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003473 "-interline-spacing value",
3474 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003475 "-interpolate method pixel color interpolation method",
3476 "-interword-spacing value",
3477 " set the space between two words",
3478 "-kerning value set the space between two letters",
3479 "-label string assign a label to an image",
3480 "-limit type value pixel cache resource limit",
3481 "-loop iterations add Netscape loop extension to your GIF animation",
3482 "-mask filename associate a mask with the image",
3483 "-mattecolor color frame color",
3484 "-monitor monitor progress",
3485 "-orient type image orientation",
3486 "-page geometry size and location of an image canvas (setting)",
3487 "-ping efficiently determine image attributes",
3488 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003489 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003490 "-preview type image preview type",
3491 "-quality value JPEG/MIFF/PNG compression level",
3492 "-quiet suppress all warning messages",
3493 "-red-primary point chromaticity red primary point",
3494 "-regard-warnings pay attention to warning messages",
3495 "-remap filename transform image colors to match this set of colors",
3496 "-respect-parentheses settings remain in effect until parenthesis boundary",
3497 "-sampling-factor geometry",
3498 " horizontal and vertical sampling factor",
3499 "-scene value image scene number",
3500 "-seed value seed a new sequence of pseudo-random numbers",
3501 "-size geometry width and height of image",
3502 "-stretch type render text with this font stretch",
3503 "-stroke color graphic primitive stroke color",
3504 "-strokewidth value graphic primitive stroke width",
3505 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003506 "-synchronize synchronize image to storage device",
3507 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003508 "-texture filename name of texture to tile onto the image background",
3509 "-tile-offset geometry",
3510 " tile offset",
3511 "-treedepth value color tree depth",
3512 "-transparent-color color",
3513 " transparent color",
3514 "-undercolor color annotation bounding box color",
3515 "-units type the units of image resolution",
3516 "-verbose print detailed information about the image",
3517 "-view FlashPix viewing transforms",
3518 "-virtual-pixel method",
3519 " virtual pixel access method",
3520 "-weight type render text with this font weight",
3521 "-white-point point chromaticity white point",
3522 (char *) NULL
3523 },
3524 *stack_operators[]=
3525 {
anthonyb69c4b32011-03-23 04:37:44 +00003526 "-delete indexes delete the image from the image sequence",
3527 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003528 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003529 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003530 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003531 "-swap indexes swap two images in the image sequence",
3532 (char *) NULL
3533 };
3534
3535 const char
3536 **p;
3537
cristybb503372010-05-27 20:51:26 +00003538 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003539 (void) printf("Copyright: %s\n",GetMagickCopyright());
3540 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003541 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3542 GetClientName());
3543 (void) printf("\nImage Settings:\n");
3544 for (p=settings; *p != (char *) NULL; p++)
3545 (void) printf(" %s\n",*p);
3546 (void) printf("\nImage Operators:\n");
3547 for (p=operators; *p != (char *) NULL; p++)
3548 (void) printf(" %s\n",*p);
3549 (void) printf("\nImage Sequence Operators:\n");
3550 for (p=sequence_operators; *p != (char *) NULL; p++)
3551 (void) printf(" %s\n",*p);
3552 (void) printf("\nImage Stack Operators:\n");
3553 for (p=stack_operators; *p != (char *) NULL; p++)
3554 (void) printf(" %s\n",*p);
3555 (void) printf("\nMiscellaneous Options:\n");
3556 for (p=miscellaneous; *p != (char *) NULL; p++)
3557 (void) printf(" %s\n",*p);
3558 (void) printf(
3559 "\nBy default, the image format of `file' is determined by its magic\n");
3560 (void) printf(
3561 "number. To specify a particular image format, precede the filename\n");
3562 (void) printf(
3563 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3564 (void) printf(
3565 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3566 (void) printf("'-' for standard input or output.\n");
3567 return(MagickFalse);
3568}
3569
3570WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3571 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3572{
3573#define DestroyMogrify() \
3574{ \
3575 if (format != (char *) NULL) \
3576 format=DestroyString(format); \
3577 if (path != (char *) NULL) \
3578 path=DestroyString(path); \
3579 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003580 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003581 argv[i]=DestroyString(argv[i]); \
3582 argv=(char **) RelinquishMagickMemory(argv); \
3583}
3584#define ThrowMogrifyException(asperity,tag,option) \
3585{ \
3586 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3587 option); \
3588 DestroyMogrify(); \
3589 return(MagickFalse); \
3590}
3591#define ThrowMogrifyInvalidArgumentException(option,argument) \
3592{ \
3593 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3594 "InvalidArgument","`%s': %s",argument,option); \
3595 DestroyMogrify(); \
3596 return(MagickFalse); \
3597}
3598
3599 char
3600 *format,
3601 *option,
3602 *path;
3603
3604 Image
3605 *image;
3606
3607 ImageStack
3608 image_stack[MaxImageStackDepth+1];
3609
cristy3ed852e2009-09-05 21:47:34 +00003610 MagickBooleanType
3611 global_colormap;
3612
3613 MagickBooleanType
3614 fire,
cristyebbcfea2011-02-25 02:43:54 +00003615 pend,
3616 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003617
3618 MagickStatusType
3619 status;
3620
cristyebbcfea2011-02-25 02:43:54 +00003621 register ssize_t
3622 i;
3623
3624 ssize_t
3625 j,
3626 k;
3627
cristy3ed852e2009-09-05 21:47:34 +00003628 /*
3629 Set defaults.
3630 */
3631 assert(image_info != (ImageInfo *) NULL);
3632 assert(image_info->signature == MagickSignature);
3633 if (image_info->debug != MagickFalse)
3634 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3635 assert(exception != (ExceptionInfo *) NULL);
3636 if (argc == 2)
3637 {
3638 option=argv[1];
3639 if ((LocaleCompare("version",option+1) == 0) ||
3640 (LocaleCompare("-version",option+1) == 0))
3641 {
cristyb51dff52011-05-19 16:55:47 +00003642 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003643 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003644 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3645 GetMagickCopyright());
3646 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3647 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003648 return(MagickFalse);
3649 }
3650 }
3651 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003652 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003653 format=(char *) NULL;
3654 path=(char *) NULL;
3655 global_colormap=MagickFalse;
3656 k=0;
3657 j=1;
3658 NewImageStack();
3659 option=(char *) NULL;
3660 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003661 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003662 status=MagickTrue;
3663 /*
3664 Parse command line.
3665 */
3666 ReadCommandlLine(argc,&argv);
3667 status=ExpandFilenames(&argc,&argv);
3668 if (status == MagickFalse)
3669 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3670 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003671 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003672 {
3673 option=argv[i];
3674 if (LocaleCompare(option,"(") == 0)
3675 {
3676 FireImageStack(MagickFalse,MagickTrue,pend);
3677 if (k == MaxImageStackDepth)
3678 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3679 option);
3680 PushImageStack();
3681 continue;
3682 }
3683 if (LocaleCompare(option,")") == 0)
3684 {
3685 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3686 if (k == 0)
3687 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3688 PopImageStack();
3689 continue;
3690 }
cristy042ee782011-04-22 18:48:30 +00003691 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003692 {
3693 char
3694 backup_filename[MaxTextExtent],
3695 *filename;
3696
3697 Image
3698 *images;
3699
3700 /*
3701 Option is a file name: begin by reading image from specified file.
3702 */
3703 FireImageStack(MagickFalse,MagickFalse,pend);
3704 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003705 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003706 filename=argv[++i];
3707 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3708 images=ReadImages(image_info,exception);
3709 status&=(images != (Image *) NULL) &&
3710 (exception->severity < ErrorException);
3711 if (images == (Image *) NULL)
3712 continue;
cristydaa76602010-06-30 13:05:11 +00003713 if (format != (char *) NULL)
3714 (void) CopyMagickString(images->filename,images->magick_filename,
3715 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003716 if (path != (char *) NULL)
3717 {
3718 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003719 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003720 path,*DirectorySeparator,filename);
3721 }
3722 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003723 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003724 AppendImageStack(images);
3725 FinalizeImageSettings(image_info,image,MagickFalse);
3726 if (global_colormap != MagickFalse)
3727 {
3728 QuantizeInfo
3729 *quantize_info;
3730
3731 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003732 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003733 quantize_info=DestroyQuantizeInfo(quantize_info);
3734 }
3735 *backup_filename='\0';
3736 if ((LocaleCompare(image->filename,"-") != 0) &&
3737 (IsPathWritable(image->filename) != MagickFalse))
3738 {
cristybb503372010-05-27 20:51:26 +00003739 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003740 i;
3741
3742 /*
3743 Rename image file as backup.
3744 */
3745 (void) CopyMagickString(backup_filename,image->filename,
3746 MaxTextExtent);
3747 for (i=0; i < 6; i++)
3748 {
3749 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3750 if (IsPathAccessible(backup_filename) == MagickFalse)
3751 break;
3752 }
3753 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003754 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003755 *backup_filename='\0';
3756 }
3757 /*
3758 Write transmogrified image to disk.
3759 */
3760 image_info->synchronize=MagickTrue;
3761 status&=WriteImages(image_info,image,image->filename,exception);
3762 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003763 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003764 RemoveAllImageStack();
3765 continue;
3766 }
3767 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3768 switch (*(option+1))
3769 {
3770 case 'a':
3771 {
3772 if (LocaleCompare("adaptive-blur",option+1) == 0)
3773 {
3774 i++;
cristybb503372010-05-27 20:51:26 +00003775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003776 ThrowMogrifyException(OptionError,"MissingArgument",option);
3777 if (IsGeometry(argv[i]) == MagickFalse)
3778 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3779 break;
3780 }
3781 if (LocaleCompare("adaptive-resize",option+1) == 0)
3782 {
3783 i++;
cristybb503372010-05-27 20:51:26 +00003784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003785 ThrowMogrifyException(OptionError,"MissingArgument",option);
3786 if (IsGeometry(argv[i]) == MagickFalse)
3787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3788 break;
3789 }
3790 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3791 {
3792 i++;
cristybb503372010-05-27 20:51:26 +00003793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003794 ThrowMogrifyException(OptionError,"MissingArgument",option);
3795 if (IsGeometry(argv[i]) == MagickFalse)
3796 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3797 break;
3798 }
3799 if (LocaleCompare("affine",option+1) == 0)
3800 {
3801 if (*option == '+')
3802 break;
3803 i++;
cristybb503372010-05-27 20:51:26 +00003804 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003805 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003806 break;
3807 }
3808 if (LocaleCompare("alpha",option+1) == 0)
3809 {
cristybb503372010-05-27 20:51:26 +00003810 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003811 type;
3812
3813 if (*option == '+')
3814 break;
3815 i++;
cristybb503372010-05-27 20:51:26 +00003816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003817 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003818 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003819 if (type < 0)
3820 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3821 argv[i]);
3822 break;
3823 }
3824 if (LocaleCompare("annotate",option+1) == 0)
3825 {
3826 if (*option == '+')
3827 break;
3828 i++;
cristybb503372010-05-27 20:51:26 +00003829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003830 ThrowMogrifyException(OptionError,"MissingArgument",option);
3831 if (IsGeometry(argv[i]) == MagickFalse)
3832 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003833 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003834 ThrowMogrifyException(OptionError,"MissingArgument",option);
3835 i++;
3836 break;
3837 }
3838 if (LocaleCompare("antialias",option+1) == 0)
3839 break;
3840 if (LocaleCompare("append",option+1) == 0)
3841 break;
3842 if (LocaleCompare("attenuate",option+1) == 0)
3843 {
3844 if (*option == '+')
3845 break;
3846 i++;
cristybb503372010-05-27 20:51:26 +00003847 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003848 ThrowMogrifyException(OptionError,"MissingArgument",option);
3849 if (IsGeometry(argv[i]) == MagickFalse)
3850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3851 break;
3852 }
3853 if (LocaleCompare("authenticate",option+1) == 0)
3854 {
3855 if (*option == '+')
3856 break;
3857 i++;
cristybb503372010-05-27 20:51:26 +00003858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003859 ThrowMogrifyException(OptionError,"MissingArgument",option);
3860 break;
3861 }
3862 if (LocaleCompare("auto-gamma",option+1) == 0)
3863 break;
3864 if (LocaleCompare("auto-level",option+1) == 0)
3865 break;
3866 if (LocaleCompare("auto-orient",option+1) == 0)
3867 break;
3868 if (LocaleCompare("average",option+1) == 0)
3869 break;
3870 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3871 }
3872 case 'b':
3873 {
3874 if (LocaleCompare("background",option+1) == 0)
3875 {
3876 if (*option == '+')
3877 break;
3878 i++;
cristybb503372010-05-27 20:51:26 +00003879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003880 ThrowMogrifyException(OptionError,"MissingArgument",option);
3881 break;
3882 }
3883 if (LocaleCompare("bias",option+1) == 0)
3884 {
3885 if (*option == '+')
3886 break;
3887 i++;
cristybb503372010-05-27 20:51:26 +00003888 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003889 ThrowMogrifyException(OptionError,"MissingArgument",option);
3890 if (IsGeometry(argv[i]) == MagickFalse)
3891 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3892 break;
3893 }
3894 if (LocaleCompare("black-point-compensation",option+1) == 0)
3895 break;
3896 if (LocaleCompare("black-threshold",option+1) == 0)
3897 {
3898 if (*option == '+')
3899 break;
3900 i++;
cristybb503372010-05-27 20:51:26 +00003901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003902 ThrowMogrifyException(OptionError,"MissingArgument",option);
3903 if (IsGeometry(argv[i]) == MagickFalse)
3904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3905 break;
3906 }
3907 if (LocaleCompare("blue-primary",option+1) == 0)
3908 {
3909 if (*option == '+')
3910 break;
3911 i++;
cristybb503372010-05-27 20:51:26 +00003912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003913 ThrowMogrifyException(OptionError,"MissingArgument",option);
3914 if (IsGeometry(argv[i]) == MagickFalse)
3915 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3916 break;
3917 }
3918 if (LocaleCompare("blue-shift",option+1) == 0)
3919 {
3920 i++;
cristybb503372010-05-27 20:51:26 +00003921 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003922 ThrowMogrifyException(OptionError,"MissingArgument",option);
3923 if (IsGeometry(argv[i]) == MagickFalse)
3924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3925 break;
3926 }
3927 if (LocaleCompare("blur",option+1) == 0)
3928 {
3929 i++;
cristybb503372010-05-27 20:51:26 +00003930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003931 ThrowMogrifyException(OptionError,"MissingArgument",option);
3932 if (IsGeometry(argv[i]) == MagickFalse)
3933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3934 break;
3935 }
3936 if (LocaleCompare("border",option+1) == 0)
3937 {
3938 if (*option == '+')
3939 break;
3940 i++;
cristybb503372010-05-27 20:51:26 +00003941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003942 ThrowMogrifyException(OptionError,"MissingArgument",option);
3943 if (IsGeometry(argv[i]) == MagickFalse)
3944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3945 break;
3946 }
3947 if (LocaleCompare("bordercolor",option+1) == 0)
3948 {
3949 if (*option == '+')
3950 break;
3951 i++;
cristybb503372010-05-27 20:51:26 +00003952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003953 ThrowMogrifyException(OptionError,"MissingArgument",option);
3954 break;
3955 }
3956 if (LocaleCompare("box",option+1) == 0)
3957 {
3958 if (*option == '+')
3959 break;
3960 i++;
cristybb503372010-05-27 20:51:26 +00003961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003962 ThrowMogrifyException(OptionError,"MissingArgument",option);
3963 break;
3964 }
cristya28d6b82010-01-11 20:03:47 +00003965 if (LocaleCompare("brightness-contrast",option+1) == 0)
3966 {
3967 i++;
cristybb503372010-05-27 20:51:26 +00003968 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003969 ThrowMogrifyException(OptionError,"MissingArgument",option);
3970 if (IsGeometry(argv[i]) == MagickFalse)
3971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3972 break;
3973 }
cristy3ed852e2009-09-05 21:47:34 +00003974 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3975 }
3976 case 'c':
3977 {
3978 if (LocaleCompare("cache",option+1) == 0)
3979 {
3980 if (*option == '+')
3981 break;
3982 i++;
cristybb503372010-05-27 20:51:26 +00003983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003984 ThrowMogrifyException(OptionError,"MissingArgument",option);
3985 if (IsGeometry(argv[i]) == MagickFalse)
3986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3987 break;
3988 }
3989 if (LocaleCompare("caption",option+1) == 0)
3990 {
3991 if (*option == '+')
3992 break;
3993 i++;
cristybb503372010-05-27 20:51:26 +00003994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003995 ThrowMogrifyException(OptionError,"MissingArgument",option);
3996 break;
3997 }
3998 if (LocaleCompare("channel",option+1) == 0)
3999 {
cristybb503372010-05-27 20:51:26 +00004000 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004001 channel;
4002
4003 if (*option == '+')
4004 break;
4005 i++;
cristybb503372010-05-27 20:51:26 +00004006 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004007 ThrowMogrifyException(OptionError,"MissingArgument",option);
4008 channel=ParseChannelOption(argv[i]);
4009 if (channel < 0)
4010 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4011 argv[i]);
4012 break;
4013 }
4014 if (LocaleCompare("cdl",option+1) == 0)
4015 {
4016 if (*option == '+')
4017 break;
4018 i++;
cristybb503372010-05-27 20:51:26 +00004019 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004020 ThrowMogrifyException(OptionError,"MissingArgument",option);
4021 break;
4022 }
4023 if (LocaleCompare("charcoal",option+1) == 0)
4024 {
4025 if (*option == '+')
4026 break;
4027 i++;
cristybb503372010-05-27 20:51:26 +00004028 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004029 ThrowMogrifyException(OptionError,"MissingArgument",option);
4030 if (IsGeometry(argv[i]) == MagickFalse)
4031 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4032 break;
4033 }
4034 if (LocaleCompare("chop",option+1) == 0)
4035 {
4036 if (*option == '+')
4037 break;
4038 i++;
cristybb503372010-05-27 20:51:26 +00004039 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004040 ThrowMogrifyException(OptionError,"MissingArgument",option);
4041 if (IsGeometry(argv[i]) == MagickFalse)
4042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4043 break;
4044 }
cristy1eb45dd2009-09-25 16:38:06 +00004045 if (LocaleCompare("clamp",option+1) == 0)
4046 break;
4047 if (LocaleCompare("clip",option+1) == 0)
4048 break;
cristy3ed852e2009-09-05 21:47:34 +00004049 if (LocaleCompare("clip-mask",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 break;
4057 }
4058 if (LocaleCompare("clut",option+1) == 0)
4059 break;
4060 if (LocaleCompare("coalesce",option+1) == 0)
4061 break;
4062 if (LocaleCompare("colorize",option+1) == 0)
4063 {
4064 if (*option == '+')
4065 break;
4066 i++;
cristybb503372010-05-27 20:51:26 +00004067 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004068 ThrowMogrifyException(OptionError,"MissingArgument",option);
4069 if (IsGeometry(argv[i]) == MagickFalse)
4070 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4071 break;
4072 }
cristye6365592010-04-02 17:31:23 +00004073 if (LocaleCompare("color-matrix",option+1) == 0)
4074 {
cristyb6bd4ad2010-08-08 01:12:27 +00004075 KernelInfo
4076 *kernel_info;
4077
cristye6365592010-04-02 17:31:23 +00004078 if (*option == '+')
4079 break;
4080 i++;
cristybb503372010-05-27 20:51:26 +00004081 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004082 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004083 kernel_info=AcquireKernelInfo(argv[i]);
4084 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004085 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004086 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004087 break;
4088 }
cristy3ed852e2009-09-05 21:47:34 +00004089 if (LocaleCompare("colors",option+1) == 0)
4090 {
4091 if (*option == '+')
4092 break;
4093 i++;
cristybb503372010-05-27 20:51:26 +00004094 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004095 ThrowMogrifyException(OptionError,"MissingArgument",option);
4096 if (IsGeometry(argv[i]) == MagickFalse)
4097 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4098 break;
4099 }
4100 if (LocaleCompare("colorspace",option+1) == 0)
4101 {
cristybb503372010-05-27 20:51:26 +00004102 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004103 colorspace;
4104
4105 if (*option == '+')
4106 break;
4107 i++;
cristybb503372010-05-27 20:51:26 +00004108 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004109 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004110 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004111 argv[i]);
4112 if (colorspace < 0)
4113 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4114 argv[i]);
4115 break;
4116 }
4117 if (LocaleCompare("combine",option+1) == 0)
4118 break;
4119 if (LocaleCompare("comment",option+1) == 0)
4120 {
4121 if (*option == '+')
4122 break;
4123 i++;
cristybb503372010-05-27 20:51:26 +00004124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004125 ThrowMogrifyException(OptionError,"MissingArgument",option);
4126 break;
4127 }
4128 if (LocaleCompare("composite",option+1) == 0)
4129 break;
4130 if (LocaleCompare("compress",option+1) == 0)
4131 {
cristybb503372010-05-27 20:51:26 +00004132 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004133 compress;
4134
4135 if (*option == '+')
4136 break;
4137 i++;
cristybb503372010-05-27 20:51:26 +00004138 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004139 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004140 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004141 argv[i]);
4142 if (compress < 0)
4143 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4144 argv[i]);
4145 break;
4146 }
cristy22879752009-10-25 23:55:40 +00004147 if (LocaleCompare("concurrent",option+1) == 0)
4148 break;
cristy3ed852e2009-09-05 21:47:34 +00004149 if (LocaleCompare("contrast",option+1) == 0)
4150 break;
4151 if (LocaleCompare("contrast-stretch",option+1) == 0)
4152 {
4153 i++;
cristybb503372010-05-27 20:51:26 +00004154 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004155 ThrowMogrifyException(OptionError,"MissingArgument",option);
4156 if (IsGeometry(argv[i]) == MagickFalse)
4157 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4158 break;
4159 }
4160 if (LocaleCompare("convolve",option+1) == 0)
4161 {
cristyb6bd4ad2010-08-08 01:12:27 +00004162 KernelInfo
4163 *kernel_info;
4164
cristy3ed852e2009-09-05 21:47:34 +00004165 if (*option == '+')
4166 break;
4167 i++;
cristybb503372010-05-27 20:51:26 +00004168 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004169 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004170 kernel_info=AcquireKernelInfo(argv[i]);
4171 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004172 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004173 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004174 break;
4175 }
4176 if (LocaleCompare("crop",option+1) == 0)
4177 {
4178 if (*option == '+')
4179 break;
4180 i++;
cristybb503372010-05-27 20:51:26 +00004181 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004182 ThrowMogrifyException(OptionError,"MissingArgument",option);
4183 if (IsGeometry(argv[i]) == MagickFalse)
4184 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4185 break;
4186 }
4187 if (LocaleCompare("cycle",option+1) == 0)
4188 {
4189 if (*option == '+')
4190 break;
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
4194 if (IsGeometry(argv[i]) == MagickFalse)
4195 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4196 break;
4197 }
4198 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4199 }
4200 case 'd':
4201 {
4202 if (LocaleCompare("decipher",option+1) == 0)
4203 {
4204 if (*option == '+')
4205 break;
4206 i++;
cristybb503372010-05-27 20:51:26 +00004207 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004208 ThrowMogrifyException(OptionError,"MissingArgument",option);
4209 break;
4210 }
4211 if (LocaleCompare("deconstruct",option+1) == 0)
4212 break;
4213 if (LocaleCompare("debug",option+1) == 0)
4214 {
cristybb503372010-05-27 20:51:26 +00004215 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004216 event;
4217
4218 if (*option == '+')
4219 break;
4220 i++;
cristybb503372010-05-27 20:51:26 +00004221 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004222 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004223 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004224 if (event < 0)
4225 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4226 argv[i]);
4227 (void) SetLogEventMask(argv[i]);
4228 break;
4229 }
4230 if (LocaleCompare("define",option+1) == 0)
4231 {
4232 i++;
cristybb503372010-05-27 20:51:26 +00004233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004234 ThrowMogrifyException(OptionError,"MissingArgument",option);
4235 if (*option == '+')
4236 {
4237 const char
4238 *define;
4239
4240 define=GetImageOption(image_info,argv[i]);
4241 if (define == (const char *) NULL)
4242 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4243 break;
4244 }
4245 break;
4246 }
4247 if (LocaleCompare("delay",option+1) == 0)
4248 {
4249 if (*option == '+')
4250 break;
4251 i++;
cristybb503372010-05-27 20:51:26 +00004252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004253 ThrowMogrifyException(OptionError,"MissingArgument",option);
4254 if (IsGeometry(argv[i]) == MagickFalse)
4255 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4256 break;
4257 }
cristyecb10ff2011-03-22 13:14:03 +00004258 if (LocaleCompare("delete",option+1) == 0)
4259 {
4260 if (*option == '+')
4261 break;
4262 i++;
4263 if (i == (ssize_t) (argc-1))
4264 ThrowMogrifyException(OptionError,"MissingArgument",option);
4265 if (IsGeometry(argv[i]) == MagickFalse)
4266 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4267 break;
4268 }
cristy3ed852e2009-09-05 21:47:34 +00004269 if (LocaleCompare("density",option+1) == 0)
4270 {
4271 if (*option == '+')
4272 break;
4273 i++;
cristybb503372010-05-27 20:51:26 +00004274 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004275 ThrowMogrifyException(OptionError,"MissingArgument",option);
4276 if (IsGeometry(argv[i]) == MagickFalse)
4277 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4278 break;
4279 }
4280 if (LocaleCompare("depth",option+1) == 0)
4281 {
4282 if (*option == '+')
4283 break;
4284 i++;
cristybb503372010-05-27 20:51:26 +00004285 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004286 ThrowMogrifyException(OptionError,"MissingArgument",option);
4287 if (IsGeometry(argv[i]) == MagickFalse)
4288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4289 break;
4290 }
4291 if (LocaleCompare("deskew",option+1) == 0)
4292 {
4293 if (*option == '+')
4294 break;
4295 i++;
cristybb503372010-05-27 20:51:26 +00004296 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004297 ThrowMogrifyException(OptionError,"MissingArgument",option);
4298 if (IsGeometry(argv[i]) == MagickFalse)
4299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4300 break;
4301 }
4302 if (LocaleCompare("despeckle",option+1) == 0)
4303 break;
4304 if (LocaleCompare("dft",option+1) == 0)
4305 break;
cristyc9b12952010-03-28 01:12:28 +00004306 if (LocaleCompare("direction",option+1) == 0)
4307 {
cristybb503372010-05-27 20:51:26 +00004308 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004309 direction;
4310
4311 if (*option == '+')
4312 break;
4313 i++;
cristybb503372010-05-27 20:51:26 +00004314 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004315 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004316 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004317 argv[i]);
4318 if (direction < 0)
4319 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4320 argv[i]);
4321 break;
4322 }
cristy3ed852e2009-09-05 21:47:34 +00004323 if (LocaleCompare("display",option+1) == 0)
4324 {
4325 if (*option == '+')
4326 break;
4327 i++;
cristybb503372010-05-27 20:51:26 +00004328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004329 ThrowMogrifyException(OptionError,"MissingArgument",option);
4330 break;
4331 }
4332 if (LocaleCompare("dispose",option+1) == 0)
4333 {
cristybb503372010-05-27 20:51:26 +00004334 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004335 dispose;
4336
4337 if (*option == '+')
4338 break;
4339 i++;
cristybb503372010-05-27 20:51:26 +00004340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004341 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004342 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004343 if (dispose < 0)
4344 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4345 argv[i]);
4346 break;
4347 }
4348 if (LocaleCompare("distort",option+1) == 0)
4349 {
cristybb503372010-05-27 20:51:26 +00004350 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004351 op;
4352
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);
cristy042ee782011-04-22 18:48:30 +00004356 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004357 if (op < 0)
4358 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4359 argv[i]);
4360 i++;
cristybb503372010-05-27 20:51:26 +00004361 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004362 ThrowMogrifyException(OptionError,"MissingArgument",option);
4363 break;
4364 }
4365 if (LocaleCompare("dither",option+1) == 0)
4366 {
cristybb503372010-05-27 20:51:26 +00004367 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004368 method;
4369
4370 if (*option == '+')
4371 break;
4372 i++;
cristybb503372010-05-27 20:51:26 +00004373 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004374 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004375 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004376 if (method < 0)
4377 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4378 argv[i]);
4379 break;
4380 }
4381 if (LocaleCompare("draw",option+1) == 0)
4382 {
4383 if (*option == '+')
4384 break;
4385 i++;
cristybb503372010-05-27 20:51:26 +00004386 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004387 ThrowMogrifyException(OptionError,"MissingArgument",option);
4388 break;
4389 }
cristyecb10ff2011-03-22 13:14:03 +00004390 if (LocaleCompare("duplicate",option+1) == 0)
4391 {
4392 if (*option == '+')
4393 break;
4394 i++;
4395 if (i == (ssize_t) (argc-1))
4396 ThrowMogrifyException(OptionError,"MissingArgument",option);
4397 if (IsGeometry(argv[i]) == MagickFalse)
4398 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4399 break;
4400 }
cristy22879752009-10-25 23:55:40 +00004401 if (LocaleCompare("duration",option+1) == 0)
4402 {
4403 if (*option == '+')
4404 break;
4405 i++;
cristybb503372010-05-27 20:51:26 +00004406 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004407 ThrowMogrifyException(OptionError,"MissingArgument",option);
4408 if (IsGeometry(argv[i]) == MagickFalse)
4409 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4410 break;
4411 }
cristy3ed852e2009-09-05 21:47:34 +00004412 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4413 }
4414 case 'e':
4415 {
4416 if (LocaleCompare("edge",option+1) == 0)
4417 {
4418 if (*option == '+')
4419 break;
4420 i++;
cristybb503372010-05-27 20:51:26 +00004421 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004422 ThrowMogrifyException(OptionError,"MissingArgument",option);
4423 if (IsGeometry(argv[i]) == MagickFalse)
4424 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4425 break;
4426 }
4427 if (LocaleCompare("emboss",option+1) == 0)
4428 {
4429 if (*option == '+')
4430 break;
4431 i++;
cristybb503372010-05-27 20:51:26 +00004432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004433 ThrowMogrifyException(OptionError,"MissingArgument",option);
4434 if (IsGeometry(argv[i]) == MagickFalse)
4435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4436 break;
4437 }
4438 if (LocaleCompare("encipher",option+1) == 0)
4439 {
4440 if (*option == '+')
4441 break;
4442 i++;
cristybb503372010-05-27 20:51:26 +00004443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004444 ThrowMogrifyException(OptionError,"MissingArgument",option);
4445 break;
4446 }
4447 if (LocaleCompare("encoding",option+1) == 0)
4448 {
4449 if (*option == '+')
4450 break;
4451 i++;
cristybb503372010-05-27 20:51:26 +00004452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004453 ThrowMogrifyException(OptionError,"MissingArgument",option);
4454 break;
4455 }
4456 if (LocaleCompare("endian",option+1) == 0)
4457 {
cristybb503372010-05-27 20:51:26 +00004458 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004459 endian;
4460
4461 if (*option == '+')
4462 break;
4463 i++;
cristybb503372010-05-27 20:51:26 +00004464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004465 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004466 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004467 if (endian < 0)
4468 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4469 argv[i]);
4470 break;
4471 }
4472 if (LocaleCompare("enhance",option+1) == 0)
4473 break;
4474 if (LocaleCompare("equalize",option+1) == 0)
4475 break;
4476 if (LocaleCompare("evaluate",option+1) == 0)
4477 {
cristybb503372010-05-27 20:51:26 +00004478 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004479 op;
4480
4481 if (*option == '+')
4482 break;
4483 i++;
cristybb503372010-05-27 20:51:26 +00004484 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004485 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004486 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004487 if (op < 0)
4488 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4489 argv[i]);
4490 i++;
cristybb503372010-05-27 20:51:26 +00004491 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004492 ThrowMogrifyException(OptionError,"MissingArgument",option);
4493 if (IsGeometry(argv[i]) == MagickFalse)
4494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4495 break;
4496 }
cristyd18ae7c2010-03-07 17:39:52 +00004497 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4498 {
cristybb503372010-05-27 20:51:26 +00004499 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004500 op;
4501
4502 if (*option == '+')
4503 break;
4504 i++;
cristybb503372010-05-27 20:51:26 +00004505 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004506 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004507 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004508 if (op < 0)
4509 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4510 argv[i]);
4511 break;
4512 }
cristy3ed852e2009-09-05 21:47:34 +00004513 if (LocaleCompare("extent",option+1) == 0)
4514 {
4515 if (*option == '+')
4516 break;
4517 i++;
cristybb503372010-05-27 20:51:26 +00004518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004519 ThrowMogrifyException(OptionError,"MissingArgument",option);
4520 if (IsGeometry(argv[i]) == MagickFalse)
4521 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4522 break;
4523 }
4524 if (LocaleCompare("extract",option+1) == 0)
4525 {
4526 if (*option == '+')
4527 break;
4528 i++;
cristybb503372010-05-27 20:51:26 +00004529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004530 ThrowMogrifyException(OptionError,"MissingArgument",option);
4531 if (IsGeometry(argv[i]) == MagickFalse)
4532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4533 break;
4534 }
4535 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4536 }
4537 case 'f':
4538 {
4539 if (LocaleCompare("family",option+1) == 0)
4540 {
4541 if (*option == '+')
4542 break;
4543 i++;
cristybb503372010-05-27 20:51:26 +00004544 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004545 ThrowMogrifyException(OptionError,"MissingArgument",option);
4546 break;
4547 }
4548 if (LocaleCompare("fill",option+1) == 0)
4549 {
4550 if (*option == '+')
4551 break;
4552 i++;
cristybb503372010-05-27 20:51:26 +00004553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004554 ThrowMogrifyException(OptionError,"MissingArgument",option);
4555 break;
4556 }
4557 if (LocaleCompare("filter",option+1) == 0)
4558 {
cristybb503372010-05-27 20:51:26 +00004559 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004560 filter;
4561
4562 if (*option == '+')
4563 break;
4564 i++;
cristybb503372010-05-27 20:51:26 +00004565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004566 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004567 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004568 if (filter < 0)
4569 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4570 argv[i]);
4571 break;
4572 }
4573 if (LocaleCompare("flatten",option+1) == 0)
4574 break;
4575 if (LocaleCompare("flip",option+1) == 0)
4576 break;
4577 if (LocaleCompare("flop",option+1) == 0)
4578 break;
4579 if (LocaleCompare("floodfill",option+1) == 0)
4580 {
4581 if (*option == '+')
4582 break;
4583 i++;
cristybb503372010-05-27 20:51:26 +00004584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004585 ThrowMogrifyException(OptionError,"MissingArgument",option);
4586 if (IsGeometry(argv[i]) == MagickFalse)
4587 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4588 i++;
cristybb503372010-05-27 20:51:26 +00004589 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004590 ThrowMogrifyException(OptionError,"MissingArgument",option);
4591 break;
4592 }
4593 if (LocaleCompare("font",option+1) == 0)
4594 {
4595 if (*option == '+')
4596 break;
4597 i++;
cristybb503372010-05-27 20:51:26 +00004598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004599 ThrowMogrifyException(OptionError,"MissingArgument",option);
4600 break;
4601 }
4602 if (LocaleCompare("format",option+1) == 0)
4603 {
4604 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4605 (void) CloneString(&format,(char *) NULL);
4606 if (*option == '+')
4607 break;
4608 i++;
cristybb503372010-05-27 20:51:26 +00004609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004610 ThrowMogrifyException(OptionError,"MissingArgument",option);
4611 (void) CloneString(&format,argv[i]);
4612 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4613 (void) ConcatenateMagickString(image_info->filename,":",
4614 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004615 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004616 if (*image_info->magick == '\0')
4617 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4618 format);
4619 break;
4620 }
4621 if (LocaleCompare("frame",option+1) == 0)
4622 {
4623 if (*option == '+')
4624 break;
4625 i++;
cristybb503372010-05-27 20:51:26 +00004626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004627 ThrowMogrifyException(OptionError,"MissingArgument",option);
4628 if (IsGeometry(argv[i]) == MagickFalse)
4629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4630 break;
4631 }
4632 if (LocaleCompare("function",option+1) == 0)
4633 {
cristybb503372010-05-27 20:51:26 +00004634 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004635 op;
4636
4637 if (*option == '+')
4638 break;
4639 i++;
cristybb503372010-05-27 20:51:26 +00004640 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004641 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004642 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004643 if (op < 0)
4644 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4645 i++;
cristybb503372010-05-27 20:51:26 +00004646 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004647 ThrowMogrifyException(OptionError,"MissingArgument",option);
4648 break;
4649 }
4650 if (LocaleCompare("fuzz",option+1) == 0)
4651 {
4652 if (*option == '+')
4653 break;
4654 i++;
cristybb503372010-05-27 20:51:26 +00004655 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004656 ThrowMogrifyException(OptionError,"MissingArgument",option);
4657 if (IsGeometry(argv[i]) == MagickFalse)
4658 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4659 break;
4660 }
4661 if (LocaleCompare("fx",option+1) == 0)
4662 {
4663 if (*option == '+')
4664 break;
4665 i++;
cristybb503372010-05-27 20:51:26 +00004666 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004667 ThrowMogrifyException(OptionError,"MissingArgument",option);
4668 break;
4669 }
4670 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4671 }
4672 case 'g':
4673 {
4674 if (LocaleCompare("gamma",option+1) == 0)
4675 {
4676 i++;
cristybb503372010-05-27 20:51:26 +00004677 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004678 ThrowMogrifyException(OptionError,"MissingArgument",option);
4679 if (IsGeometry(argv[i]) == MagickFalse)
4680 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4681 break;
4682 }
4683 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4684 (LocaleCompare("gaussian",option+1) == 0))
4685 {
4686 i++;
cristybb503372010-05-27 20:51:26 +00004687 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004688 ThrowMogrifyException(OptionError,"MissingArgument",option);
4689 if (IsGeometry(argv[i]) == MagickFalse)
4690 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4691 break;
4692 }
4693 if (LocaleCompare("geometry",option+1) == 0)
4694 {
4695 if (*option == '+')
4696 break;
4697 i++;
cristybb503372010-05-27 20:51:26 +00004698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004699 ThrowMogrifyException(OptionError,"MissingArgument",option);
4700 if (IsGeometry(argv[i]) == MagickFalse)
4701 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4702 break;
4703 }
4704 if (LocaleCompare("gravity",option+1) == 0)
4705 {
cristybb503372010-05-27 20:51:26 +00004706 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004707 gravity;
4708
4709 if (*option == '+')
4710 break;
4711 i++;
cristybb503372010-05-27 20:51:26 +00004712 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004713 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004714 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004715 if (gravity < 0)
4716 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4717 argv[i]);
4718 break;
4719 }
4720 if (LocaleCompare("green-primary",option+1) == 0)
4721 {
4722 if (*option == '+')
4723 break;
4724 i++;
cristybb503372010-05-27 20:51:26 +00004725 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004726 ThrowMogrifyException(OptionError,"MissingArgument",option);
4727 if (IsGeometry(argv[i]) == MagickFalse)
4728 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4729 break;
4730 }
4731 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4732 }
4733 case 'h':
4734 {
4735 if (LocaleCompare("hald-clut",option+1) == 0)
4736 break;
4737 if ((LocaleCompare("help",option+1) == 0) ||
4738 (LocaleCompare("-help",option+1) == 0))
4739 return(MogrifyUsage());
4740 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4741 }
4742 case 'i':
4743 {
4744 if (LocaleCompare("identify",option+1) == 0)
4745 break;
4746 if (LocaleCompare("idft",option+1) == 0)
4747 break;
4748 if (LocaleCompare("implode",option+1) == 0)
4749 {
4750 if (*option == '+')
4751 break;
4752 i++;
cristybb503372010-05-27 20:51:26 +00004753 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004754 ThrowMogrifyException(OptionError,"MissingArgument",option);
4755 if (IsGeometry(argv[i]) == MagickFalse)
4756 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4757 break;
4758 }
4759 if (LocaleCompare("intent",option+1) == 0)
4760 {
cristybb503372010-05-27 20:51:26 +00004761 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004762 intent;
4763
4764 if (*option == '+')
4765 break;
4766 i++;
cristybb503372010-05-27 20:51:26 +00004767 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004768 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004769 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004770 if (intent < 0)
4771 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4772 argv[i]);
4773 break;
4774 }
4775 if (LocaleCompare("interlace",option+1) == 0)
4776 {
cristybb503372010-05-27 20:51:26 +00004777 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004778 interlace;
4779
4780 if (*option == '+')
4781 break;
4782 i++;
cristybb503372010-05-27 20:51:26 +00004783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004784 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004785 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004786 argv[i]);
4787 if (interlace < 0)
4788 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4789 argv[i]);
4790 break;
4791 }
cristyb32b90a2009-09-07 21:45:48 +00004792 if (LocaleCompare("interline-spacing",option+1) == 0)
4793 {
4794 if (*option == '+')
4795 break;
4796 i++;
cristybb503372010-05-27 20:51:26 +00004797 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004798 ThrowMogrifyException(OptionError,"MissingArgument",option);
4799 if (IsGeometry(argv[i]) == MagickFalse)
4800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4801 break;
4802 }
cristy3ed852e2009-09-05 21:47:34 +00004803 if (LocaleCompare("interpolate",option+1) == 0)
4804 {
cristybb503372010-05-27 20:51:26 +00004805 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004806 interpolate;
4807
4808 if (*option == '+')
4809 break;
4810 i++;
cristybb503372010-05-27 20:51:26 +00004811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004812 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004813 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004814 argv[i]);
4815 if (interpolate < 0)
4816 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4817 argv[i]);
4818 break;
4819 }
4820 if (LocaleCompare("interword-spacing",option+1) == 0)
4821 {
4822 if (*option == '+')
4823 break;
4824 i++;
cristybb503372010-05-27 20:51:26 +00004825 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004826 ThrowMogrifyException(OptionError,"MissingArgument",option);
4827 if (IsGeometry(argv[i]) == MagickFalse)
4828 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4829 break;
4830 }
4831 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4832 }
4833 case 'k':
4834 {
4835 if (LocaleCompare("kerning",option+1) == 0)
4836 {
4837 if (*option == '+')
4838 break;
4839 i++;
cristybb503372010-05-27 20:51:26 +00004840 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004841 ThrowMogrifyException(OptionError,"MissingArgument",option);
4842 if (IsGeometry(argv[i]) == MagickFalse)
4843 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4844 break;
4845 }
4846 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4847 }
4848 case 'l':
4849 {
4850 if (LocaleCompare("label",option+1) == 0)
4851 {
4852 if (*option == '+')
4853 break;
4854 i++;
cristybb503372010-05-27 20:51:26 +00004855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004856 ThrowMogrifyException(OptionError,"MissingArgument",option);
4857 break;
4858 }
4859 if (LocaleCompare("lat",option+1) == 0)
4860 {
4861 if (*option == '+')
4862 break;
4863 i++;
cristybb503372010-05-27 20:51:26 +00004864 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004865 ThrowMogrifyException(OptionError,"MissingArgument",option);
4866 if (IsGeometry(argv[i]) == MagickFalse)
4867 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4868 }
4869 if (LocaleCompare("layers",option+1) == 0)
4870 {
cristybb503372010-05-27 20:51:26 +00004871 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004872 type;
4873
4874 if (*option == '+')
4875 break;
4876 i++;
cristybb503372010-05-27 20:51:26 +00004877 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004878 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004879 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004880 if (type < 0)
4881 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4882 argv[i]);
4883 break;
4884 }
4885 if (LocaleCompare("level",option+1) == 0)
4886 {
4887 i++;
cristybb503372010-05-27 20:51:26 +00004888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004889 ThrowMogrifyException(OptionError,"MissingArgument",option);
4890 if (IsGeometry(argv[i]) == MagickFalse)
4891 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4892 break;
4893 }
4894 if (LocaleCompare("level-colors",option+1) == 0)
4895 {
4896 i++;
cristybb503372010-05-27 20:51:26 +00004897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004898 ThrowMogrifyException(OptionError,"MissingArgument",option);
4899 break;
4900 }
4901 if (LocaleCompare("linewidth",option+1) == 0)
4902 {
4903 if (*option == '+')
4904 break;
4905 i++;
cristybb503372010-05-27 20:51:26 +00004906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004907 ThrowMogrifyException(OptionError,"MissingArgument",option);
4908 if (IsGeometry(argv[i]) == MagickFalse)
4909 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4910 break;
4911 }
4912 if (LocaleCompare("limit",option+1) == 0)
4913 {
4914 char
4915 *p;
4916
4917 double
4918 value;
4919
cristybb503372010-05-27 20:51:26 +00004920 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004921 resource;
4922
4923 if (*option == '+')
4924 break;
4925 i++;
cristybb503372010-05-27 20:51:26 +00004926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004927 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004928 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004929 argv[i]);
4930 if (resource < 0)
4931 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4932 argv[i]);
4933 i++;
cristybb503372010-05-27 20:51:26 +00004934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004935 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004936 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004937 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004938 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4939 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4940 break;
4941 }
4942 if (LocaleCompare("liquid-rescale",option+1) == 0)
4943 {
4944 i++;
cristybb503372010-05-27 20:51:26 +00004945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004946 ThrowMogrifyException(OptionError,"MissingArgument",option);
4947 if (IsGeometry(argv[i]) == MagickFalse)
4948 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4949 break;
4950 }
4951 if (LocaleCompare("list",option+1) == 0)
4952 {
cristybb503372010-05-27 20:51:26 +00004953 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004954 list;
4955
4956 if (*option == '+')
4957 break;
4958 i++;
cristybb503372010-05-27 20:51:26 +00004959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004960 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004961 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004962 if (list < 0)
4963 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004964 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004965 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004966 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004967 }
4968 if (LocaleCompare("log",option+1) == 0)
4969 {
4970 if (*option == '+')
4971 break;
4972 i++;
cristybb503372010-05-27 20:51:26 +00004973 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004974 (strchr(argv[i],'%') == (char *) NULL))
4975 ThrowMogrifyException(OptionError,"MissingArgument",option);
4976 break;
4977 }
4978 if (LocaleCompare("loop",option+1) == 0)
4979 {
4980 if (*option == '+')
4981 break;
4982 i++;
cristybb503372010-05-27 20:51:26 +00004983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004984 ThrowMogrifyException(OptionError,"MissingArgument",option);
4985 if (IsGeometry(argv[i]) == MagickFalse)
4986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4987 break;
4988 }
4989 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4990 }
4991 case 'm':
4992 {
4993 if (LocaleCompare("map",option+1) == 0)
4994 {
4995 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
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 ThrowMogrifyException(OptionError,"MissingArgument",option);
5001 break;
5002 }
5003 if (LocaleCompare("mask",option+1) == 0)
5004 {
5005 if (*option == '+')
5006 break;
5007 i++;
cristybb503372010-05-27 20:51:26 +00005008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005009 ThrowMogrifyException(OptionError,"MissingArgument",option);
5010 break;
5011 }
5012 if (LocaleCompare("matte",option+1) == 0)
5013 break;
5014 if (LocaleCompare("mattecolor",option+1) == 0)
5015 {
5016 if (*option == '+')
5017 break;
5018 i++;
cristybb503372010-05-27 20:51:26 +00005019 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005020 ThrowMogrifyException(OptionError,"MissingArgument",option);
5021 break;
5022 }
cristyf40785b2010-03-06 02:27:27 +00005023 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005024 break;
cristyf40785b2010-03-06 02:27:27 +00005025 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005026 break;
cristy3ed852e2009-09-05 21:47:34 +00005027 if (LocaleCompare("modulate",option+1) == 0)
5028 {
5029 if (*option == '+')
5030 break;
5031 i++;
cristybb503372010-05-27 20:51:26 +00005032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005033 ThrowMogrifyException(OptionError,"MissingArgument",option);
5034 if (IsGeometry(argv[i]) == MagickFalse)
5035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5036 break;
5037 }
5038 if (LocaleCompare("median",option+1) == 0)
5039 {
5040 if (*option == '+')
5041 break;
5042 i++;
cristybb503372010-05-27 20:51:26 +00005043 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005044 ThrowMogrifyException(OptionError,"MissingArgument",option);
5045 if (IsGeometry(argv[i]) == MagickFalse)
5046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5047 break;
5048 }
cristy69ec32d2011-02-27 23:57:09 +00005049 if (LocaleCompare("mode",option+1) == 0)
5050 {
5051 if (*option == '+')
5052 break;
5053 i++;
5054 if (i == (ssize_t) argc)
5055 ThrowMogrifyException(OptionError,"MissingArgument",option);
5056 if (IsGeometry(argv[i]) == MagickFalse)
5057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5058 break;
5059 }
cristy3ed852e2009-09-05 21:47:34 +00005060 if (LocaleCompare("monitor",option+1) == 0)
5061 break;
5062 if (LocaleCompare("monochrome",option+1) == 0)
5063 break;
5064 if (LocaleCompare("morph",option+1) == 0)
5065 {
5066 if (*option == '+')
5067 break;
5068 i++;
cristybb503372010-05-27 20:51:26 +00005069 if (i == (ssize_t) (argc-1))
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 }
anthony29188a82010-01-22 10:12:34 +00005075 if (LocaleCompare("morphology",option+1) == 0)
5076 {
anthony29188a82010-01-22 10:12:34 +00005077 char
5078 token[MaxTextExtent];
5079
cristyb6bd4ad2010-08-08 01:12:27 +00005080 KernelInfo
5081 *kernel_info;
5082
5083 ssize_t
5084 op;
5085
anthony29188a82010-01-22 10:12:34 +00005086 i++;
cristybb503372010-05-27 20:51:26 +00005087 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005088 ThrowMogrifyException(OptionError,"MissingArgument",option);
5089 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005090 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005091 if (op < 0)
5092 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005093 token);
anthony29188a82010-01-22 10:12:34 +00005094 i++;
cristybb503372010-05-27 20:51:26 +00005095 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005096 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005097 kernel_info=AcquireKernelInfo(argv[i]);
5098 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005099 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005100 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005101 break;
5102 }
cristy3ed852e2009-09-05 21:47:34 +00005103 if (LocaleCompare("mosaic",option+1) == 0)
5104 break;
5105 if (LocaleCompare("motion-blur",option+1) == 0)
5106 {
5107 if (*option == '+')
5108 break;
5109 i++;
cristybb503372010-05-27 20:51:26 +00005110 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005111 ThrowMogrifyException(OptionError,"MissingArgument",option);
5112 if (IsGeometry(argv[i]) == MagickFalse)
5113 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5114 break;
5115 }
5116 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5117 }
5118 case 'n':
5119 {
5120 if (LocaleCompare("negate",option+1) == 0)
5121 break;
5122 if (LocaleCompare("noise",option+1) == 0)
5123 {
5124 i++;
cristybb503372010-05-27 20:51:26 +00005125 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005126 ThrowMogrifyException(OptionError,"MissingArgument",option);
5127 if (*option == '+')
5128 {
cristybb503372010-05-27 20:51:26 +00005129 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005130 noise;
5131
cristy042ee782011-04-22 18:48:30 +00005132 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005133 if (noise < 0)
5134 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5135 argv[i]);
5136 break;
5137 }
5138 if (IsGeometry(argv[i]) == MagickFalse)
5139 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5140 break;
5141 }
5142 if (LocaleCompare("noop",option+1) == 0)
5143 break;
5144 if (LocaleCompare("normalize",option+1) == 0)
5145 break;
5146 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5147 }
5148 case 'o':
5149 {
5150 if (LocaleCompare("opaque",option+1) == 0)
5151 {
cristy3ed852e2009-09-05 21:47:34 +00005152 i++;
cristybb503372010-05-27 20:51:26 +00005153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005154 ThrowMogrifyException(OptionError,"MissingArgument",option);
5155 break;
5156 }
5157 if (LocaleCompare("ordered-dither",option+1) == 0)
5158 {
5159 if (*option == '+')
5160 break;
5161 i++;
cristybb503372010-05-27 20:51:26 +00005162 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005163 ThrowMogrifyException(OptionError,"MissingArgument",option);
5164 break;
5165 }
5166 if (LocaleCompare("orient",option+1) == 0)
5167 {
cristybb503372010-05-27 20:51:26 +00005168 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005169 orientation;
5170
5171 orientation=UndefinedOrientation;
5172 if (*option == '+')
5173 break;
5174 i++;
cristybb503372010-05-27 20:51:26 +00005175 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005176 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005177 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005178 argv[i]);
5179 if (orientation < 0)
5180 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5181 argv[i]);
5182 break;
5183 }
5184 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5185 }
5186 case 'p':
5187 {
5188 if (LocaleCompare("page",option+1) == 0)
5189 {
5190 if (*option == '+')
5191 break;
5192 i++;
cristybb503372010-05-27 20:51:26 +00005193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005194 ThrowMogrifyException(OptionError,"MissingArgument",option);
5195 break;
5196 }
5197 if (LocaleCompare("paint",option+1) == 0)
5198 {
5199 if (*option == '+')
5200 break;
5201 i++;
cristybb503372010-05-27 20:51:26 +00005202 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005203 ThrowMogrifyException(OptionError,"MissingArgument",option);
5204 if (IsGeometry(argv[i]) == MagickFalse)
5205 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5206 break;
5207 }
5208 if (LocaleCompare("path",option+1) == 0)
5209 {
5210 (void) CloneString(&path,(char *) NULL);
5211 if (*option == '+')
5212 break;
5213 i++;
cristybb503372010-05-27 20:51:26 +00005214 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005215 ThrowMogrifyException(OptionError,"MissingArgument",option);
5216 (void) CloneString(&path,argv[i]);
5217 break;
5218 }
5219 if (LocaleCompare("pointsize",option+1) == 0)
5220 {
5221 if (*option == '+')
5222 break;
5223 i++;
cristybb503372010-05-27 20:51:26 +00005224 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005225 ThrowMogrifyException(OptionError,"MissingArgument",option);
5226 if (IsGeometry(argv[i]) == MagickFalse)
5227 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5228 break;
5229 }
5230 if (LocaleCompare("polaroid",option+1) == 0)
5231 {
5232 if (*option == '+')
5233 break;
5234 i++;
cristybb503372010-05-27 20:51:26 +00005235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 if (IsGeometry(argv[i]) == MagickFalse)
5238 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5239 break;
5240 }
5241 if (LocaleCompare("posterize",option+1) == 0)
5242 {
5243 if (*option == '+')
5244 break;
5245 i++;
cristybb503372010-05-27 20:51:26 +00005246 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005247 ThrowMogrifyException(OptionError,"MissingArgument",option);
5248 if (IsGeometry(argv[i]) == MagickFalse)
5249 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5250 break;
5251 }
cristye7f51092010-01-17 00:39:37 +00005252 if (LocaleCompare("precision",option+1) == 0)
5253 {
5254 if (*option == '+')
5255 break;
5256 i++;
cristybb503372010-05-27 20:51:26 +00005257 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005258 ThrowMogrifyException(OptionError,"MissingArgument",option);
5259 if (IsGeometry(argv[i]) == MagickFalse)
5260 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5261 break;
5262 }
cristy3ed852e2009-09-05 21:47:34 +00005263 if (LocaleCompare("print",option+1) == 0)
5264 {
5265 if (*option == '+')
5266 break;
5267 i++;
cristybb503372010-05-27 20:51:26 +00005268 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005269 ThrowMogrifyException(OptionError,"MissingArgument",option);
5270 break;
5271 }
5272 if (LocaleCompare("process",option+1) == 0)
5273 {
5274 if (*option == '+')
5275 break;
5276 i++;
cristybb503372010-05-27 20:51:26 +00005277 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005278 ThrowMogrifyException(OptionError,"MissingArgument",option);
5279 break;
5280 }
5281 if (LocaleCompare("profile",option+1) == 0)
5282 {
5283 i++;
cristybb503372010-05-27 20:51:26 +00005284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005285 ThrowMogrifyException(OptionError,"MissingArgument",option);
5286 break;
5287 }
5288 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5289 }
5290 case 'q':
5291 {
5292 if (LocaleCompare("quality",option+1) == 0)
5293 {
5294 if (*option == '+')
5295 break;
5296 i++;
cristybb503372010-05-27 20:51:26 +00005297 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005298 ThrowMogrifyException(OptionError,"MissingArgument",option);
5299 if (IsGeometry(argv[i]) == MagickFalse)
5300 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5301 break;
5302 }
5303 if (LocaleCompare("quantize",option+1) == 0)
5304 {
cristybb503372010-05-27 20:51:26 +00005305 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005306 colorspace;
5307
5308 if (*option == '+')
5309 break;
5310 i++;
cristybb503372010-05-27 20:51:26 +00005311 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005312 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005313 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005314 argv[i]);
5315 if (colorspace < 0)
5316 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5317 argv[i]);
5318 break;
5319 }
5320 if (LocaleCompare("quiet",option+1) == 0)
5321 break;
5322 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5323 }
5324 case 'r':
5325 {
5326 if (LocaleCompare("radial-blur",option+1) == 0)
5327 {
5328 i++;
cristybb503372010-05-27 20:51:26 +00005329 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005330 ThrowMogrifyException(OptionError,"MissingArgument",option);
5331 if (IsGeometry(argv[i]) == MagickFalse)
5332 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5333 break;
5334 }
5335 if (LocaleCompare("raise",option+1) == 0)
5336 {
5337 i++;
cristybb503372010-05-27 20:51:26 +00005338 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005339 ThrowMogrifyException(OptionError,"MissingArgument",option);
5340 if (IsGeometry(argv[i]) == MagickFalse)
5341 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5342 break;
5343 }
5344 if (LocaleCompare("random-threshold",option+1) == 0)
5345 {
5346 if (*option == '+')
5347 break;
5348 i++;
cristybb503372010-05-27 20:51:26 +00005349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005350 ThrowMogrifyException(OptionError,"MissingArgument",option);
5351 if (IsGeometry(argv[i]) == MagickFalse)
5352 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5353 break;
5354 }
cristye6365592010-04-02 17:31:23 +00005355 if (LocaleCompare("recolor",option+1) == 0)
5356 {
5357 if (*option == '+')
5358 break;
5359 i++;
cristybb503372010-05-27 20:51:26 +00005360 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005361 ThrowMogrifyException(OptionError,"MissingArgument",option);
5362 if (IsGeometry(argv[i]) == MagickFalse)
5363 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5364 break;
5365 }
cristy3ed852e2009-09-05 21:47:34 +00005366 if (LocaleCompare("red-primary",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
cristybb503372010-05-27 20:51:26 +00005371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 }
cristy9f2083a2010-04-22 19:48:05 +00005376 if (LocaleCompare("regard-warnings",option+1) == 0)
5377 break;
cristy3ed852e2009-09-05 21:47:34 +00005378 if (LocaleCompare("region",option+1) == 0)
5379 {
5380 if (*option == '+')
5381 break;
5382 i++;
cristybb503372010-05-27 20:51:26 +00005383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005384 ThrowMogrifyException(OptionError,"MissingArgument",option);
5385 if (IsGeometry(argv[i]) == MagickFalse)
5386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5387 break;
5388 }
cristyf0c78232010-03-15 12:53:40 +00005389 if (LocaleCompare("remap",option+1) == 0)
5390 {
5391 if (*option == '+')
5392 break;
5393 i++;
cristybb503372010-05-27 20:51:26 +00005394 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005395 ThrowMogrifyException(OptionError,"MissingArgument",option);
5396 break;
5397 }
cristy3ed852e2009-09-05 21:47:34 +00005398 if (LocaleCompare("render",option+1) == 0)
5399 break;
5400 if (LocaleCompare("repage",option+1) == 0)
5401 {
5402 if (*option == '+')
5403 break;
5404 i++;
cristybb503372010-05-27 20:51:26 +00005405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 if (IsGeometry(argv[i]) == MagickFalse)
5408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5409 break;
5410 }
5411 if (LocaleCompare("resample",option+1) == 0)
5412 {
5413 if (*option == '+')
5414 break;
5415 i++;
cristybb503372010-05-27 20:51:26 +00005416 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005417 ThrowMogrifyException(OptionError,"MissingArgument",option);
5418 if (IsGeometry(argv[i]) == MagickFalse)
5419 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5420 break;
5421 }
5422 if (LocaleCompare("resize",option+1) == 0)
5423 {
5424 if (*option == '+')
5425 break;
5426 i++;
cristybb503372010-05-27 20:51:26 +00005427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005428 ThrowMogrifyException(OptionError,"MissingArgument",option);
5429 if (IsGeometry(argv[i]) == MagickFalse)
5430 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5431 break;
5432 }
cristyebbcfea2011-02-25 02:43:54 +00005433 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5434 {
5435 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5436 break;
5437 }
cristy3ed852e2009-09-05 21:47:34 +00005438 if (LocaleCompare("reverse",option+1) == 0)
5439 break;
5440 if (LocaleCompare("roll",option+1) == 0)
5441 {
5442 if (*option == '+')
5443 break;
5444 i++;
cristybb503372010-05-27 20:51:26 +00005445 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005446 ThrowMogrifyException(OptionError,"MissingArgument",option);
5447 if (IsGeometry(argv[i]) == MagickFalse)
5448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5449 break;
5450 }
5451 if (LocaleCompare("rotate",option+1) == 0)
5452 {
5453 i++;
cristybb503372010-05-27 20:51:26 +00005454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005455 ThrowMogrifyException(OptionError,"MissingArgument",option);
5456 if (IsGeometry(argv[i]) == MagickFalse)
5457 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5458 break;
5459 }
5460 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5461 }
5462 case 's':
5463 {
5464 if (LocaleCompare("sample",option+1) == 0)
5465 {
5466 if (*option == '+')
5467 break;
5468 i++;
cristybb503372010-05-27 20:51:26 +00005469 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005470 ThrowMogrifyException(OptionError,"MissingArgument",option);
5471 if (IsGeometry(argv[i]) == MagickFalse)
5472 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5473 break;
5474 }
5475 if (LocaleCompare("sampling-factor",option+1) == 0)
5476 {
5477 if (*option == '+')
5478 break;
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 if (LocaleCompare("scale",option+1) == 0)
5487 {
5488 if (*option == '+')
5489 break;
5490 i++;
cristybb503372010-05-27 20:51:26 +00005491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005492 ThrowMogrifyException(OptionError,"MissingArgument",option);
5493 if (IsGeometry(argv[i]) == MagickFalse)
5494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5495 break;
5496 }
5497 if (LocaleCompare("scene",option+1) == 0)
5498 {
5499 if (*option == '+')
5500 break;
5501 i++;
cristybb503372010-05-27 20:51:26 +00005502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005503 ThrowMogrifyException(OptionError,"MissingArgument",option);
5504 if (IsGeometry(argv[i]) == MagickFalse)
5505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5506 break;
5507 }
5508 if (LocaleCompare("seed",option+1) == 0)
5509 {
5510 if (*option == '+')
5511 break;
5512 i++;
cristybb503372010-05-27 20:51:26 +00005513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005514 ThrowMogrifyException(OptionError,"MissingArgument",option);
5515 if (IsGeometry(argv[i]) == MagickFalse)
5516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5517 break;
5518 }
5519 if (LocaleCompare("segment",option+1) == 0)
5520 {
5521 if (*option == '+')
5522 break;
5523 i++;
cristybb503372010-05-27 20:51:26 +00005524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005525 ThrowMogrifyException(OptionError,"MissingArgument",option);
5526 if (IsGeometry(argv[i]) == MagickFalse)
5527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5528 break;
5529 }
5530 if (LocaleCompare("selective-blur",option+1) == 0)
5531 {
5532 i++;
cristybb503372010-05-27 20:51:26 +00005533 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005534 ThrowMogrifyException(OptionError,"MissingArgument",option);
5535 if (IsGeometry(argv[i]) == MagickFalse)
5536 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5537 break;
5538 }
5539 if (LocaleCompare("separate",option+1) == 0)
5540 break;
5541 if (LocaleCompare("sepia-tone",option+1) == 0)
5542 {
5543 if (*option == '+')
5544 break;
5545 i++;
cristybb503372010-05-27 20:51:26 +00005546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005547 ThrowMogrifyException(OptionError,"MissingArgument",option);
5548 if (IsGeometry(argv[i]) == MagickFalse)
5549 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550 break;
5551 }
5552 if (LocaleCompare("set",option+1) == 0)
5553 {
5554 i++;
cristybb503372010-05-27 20:51:26 +00005555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005556 ThrowMogrifyException(OptionError,"MissingArgument",option);
5557 if (*option == '+')
5558 break;
5559 i++;
cristybb503372010-05-27 20:51:26 +00005560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005561 ThrowMogrifyException(OptionError,"MissingArgument",option);
5562 break;
5563 }
5564 if (LocaleCompare("shade",option+1) == 0)
5565 {
5566 i++;
cristybb503372010-05-27 20:51:26 +00005567 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005568 ThrowMogrifyException(OptionError,"MissingArgument",option);
5569 if (IsGeometry(argv[i]) == MagickFalse)
5570 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5571 break;
5572 }
5573 if (LocaleCompare("shadow",option+1) == 0)
5574 {
5575 if (*option == '+')
5576 break;
5577 i++;
cristybb503372010-05-27 20:51:26 +00005578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005579 ThrowMogrifyException(OptionError,"MissingArgument",option);
5580 if (IsGeometry(argv[i]) == MagickFalse)
5581 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582 break;
5583 }
5584 if (LocaleCompare("sharpen",option+1) == 0)
5585 {
5586 i++;
cristybb503372010-05-27 20:51:26 +00005587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005588 ThrowMogrifyException(OptionError,"MissingArgument",option);
5589 if (IsGeometry(argv[i]) == MagickFalse)
5590 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5591 break;
5592 }
5593 if (LocaleCompare("shave",option+1) == 0)
5594 {
5595 if (*option == '+')
5596 break;
5597 i++;
cristybb503372010-05-27 20:51:26 +00005598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005599 ThrowMogrifyException(OptionError,"MissingArgument",option);
5600 if (IsGeometry(argv[i]) == MagickFalse)
5601 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5602 break;
5603 }
5604 if (LocaleCompare("shear",option+1) == 0)
5605 {
5606 i++;
cristybb503372010-05-27 20:51:26 +00005607 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005608 ThrowMogrifyException(OptionError,"MissingArgument",option);
5609 if (IsGeometry(argv[i]) == MagickFalse)
5610 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5611 break;
5612 }
5613 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5614 {
5615 i++;
cristybb503372010-05-27 20:51:26 +00005616 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005617 ThrowMogrifyException(OptionError,"MissingArgument",option);
5618 if (IsGeometry(argv[i]) == MagickFalse)
5619 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5620 break;
5621 }
5622 if (LocaleCompare("size",option+1) == 0)
5623 {
5624 if (*option == '+')
5625 break;
5626 i++;
cristybb503372010-05-27 20:51:26 +00005627 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005628 ThrowMogrifyException(OptionError,"MissingArgument",option);
5629 if (IsGeometry(argv[i]) == MagickFalse)
5630 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5631 break;
5632 }
5633 if (LocaleCompare("sketch",option+1) == 0)
5634 {
5635 if (*option == '+')
5636 break;
5637 i++;
cristybb503372010-05-27 20:51:26 +00005638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 if (IsGeometry(argv[i]) == MagickFalse)
5641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5642 break;
5643 }
cristy4285d782011-02-09 20:12:28 +00005644 if (LocaleCompare("smush",option+1) == 0)
5645 {
cristy4285d782011-02-09 20:12:28 +00005646 i++;
5647 if (i == (ssize_t) argc)
5648 ThrowMogrifyException(OptionError,"MissingArgument",option);
5649 if (IsGeometry(argv[i]) == MagickFalse)
5650 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005651 i++;
5652 break;
5653 }
cristy3ed852e2009-09-05 21:47:34 +00005654 if (LocaleCompare("solarize",option+1) == 0)
5655 {
5656 if (*option == '+')
5657 break;
5658 i++;
cristybb503372010-05-27 20:51:26 +00005659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005660 ThrowMogrifyException(OptionError,"MissingArgument",option);
5661 if (IsGeometry(argv[i]) == MagickFalse)
5662 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5663 break;
5664 }
5665 if (LocaleCompare("sparse-color",option+1) == 0)
5666 {
cristybb503372010-05-27 20:51:26 +00005667 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005668 op;
5669
5670 i++;
cristybb503372010-05-27 20:51:26 +00005671 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005672 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005673 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005674 if (op < 0)
5675 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5676 argv[i]);
5677 i++;
cristybb503372010-05-27 20:51:26 +00005678 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005679 ThrowMogrifyException(OptionError,"MissingArgument",option);
5680 break;
5681 }
5682 if (LocaleCompare("spread",option+1) == 0)
5683 {
5684 if (*option == '+')
5685 break;
5686 i++;
cristybb503372010-05-27 20:51:26 +00005687 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005688 ThrowMogrifyException(OptionError,"MissingArgument",option);
5689 if (IsGeometry(argv[i]) == MagickFalse)
5690 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5691 break;
5692 }
cristy0834d642011-03-18 18:26:08 +00005693 if (LocaleCompare("statistic",option+1) == 0)
5694 {
5695 ssize_t
5696 op;
5697
5698 if (*option == '+')
5699 break;
5700 i++;
5701 if (i == (ssize_t) argc)
5702 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005703 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005704 if (op < 0)
5705 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5706 argv[i]);
5707 i++;
5708 if (i == (ssize_t) (argc-1))
5709 ThrowMogrifyException(OptionError,"MissingArgument",option);
5710 if (IsGeometry(argv[i]) == MagickFalse)
5711 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5712 break;
5713 }
cristy3ed852e2009-09-05 21:47:34 +00005714 if (LocaleCompare("stretch",option+1) == 0)
5715 {
cristybb503372010-05-27 20:51:26 +00005716 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005717 stretch;
5718
5719 if (*option == '+')
5720 break;
5721 i++;
cristybb503372010-05-27 20:51:26 +00005722 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005723 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005724 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005725 if (stretch < 0)
5726 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5727 argv[i]);
5728 break;
5729 }
5730 if (LocaleCompare("strip",option+1) == 0)
5731 break;
5732 if (LocaleCompare("stroke",option+1) == 0)
5733 {
5734 if (*option == '+')
5735 break;
5736 i++;
cristybb503372010-05-27 20:51:26 +00005737 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005738 ThrowMogrifyException(OptionError,"MissingArgument",option);
5739 break;
5740 }
5741 if (LocaleCompare("strokewidth",option+1) == 0)
5742 {
5743 if (*option == '+')
5744 break;
5745 i++;
cristybb503372010-05-27 20:51:26 +00005746 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005747 ThrowMogrifyException(OptionError,"MissingArgument",option);
5748 if (IsGeometry(argv[i]) == MagickFalse)
5749 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5750 break;
5751 }
5752 if (LocaleCompare("style",option+1) == 0)
5753 {
cristybb503372010-05-27 20:51:26 +00005754 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005755 style;
5756
5757 if (*option == '+')
5758 break;
5759 i++;
cristybb503372010-05-27 20:51:26 +00005760 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005761 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005762 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005763 if (style < 0)
5764 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5765 argv[i]);
5766 break;
5767 }
cristyecb10ff2011-03-22 13:14:03 +00005768 if (LocaleCompare("swap",option+1) == 0)
5769 {
5770 if (*option == '+')
5771 break;
5772 i++;
5773 if (i == (ssize_t) (argc-1))
5774 ThrowMogrifyException(OptionError,"MissingArgument",option);
5775 if (IsGeometry(argv[i]) == MagickFalse)
5776 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5777 break;
5778 }
cristy3ed852e2009-09-05 21:47:34 +00005779 if (LocaleCompare("swirl",option+1) == 0)
5780 {
5781 if (*option == '+')
5782 break;
5783 i++;
cristybb503372010-05-27 20:51:26 +00005784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005785 ThrowMogrifyException(OptionError,"MissingArgument",option);
5786 if (IsGeometry(argv[i]) == MagickFalse)
5787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5788 break;
5789 }
cristyd9a29192010-10-16 16:49:53 +00005790 if (LocaleCompare("synchronize",option+1) == 0)
5791 break;
cristy3ed852e2009-09-05 21:47:34 +00005792 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5793 }
5794 case 't':
5795 {
5796 if (LocaleCompare("taint",option+1) == 0)
5797 break;
5798 if (LocaleCompare("texture",option+1) == 0)
5799 {
5800 if (*option == '+')
5801 break;
5802 i++;
cristybb503372010-05-27 20:51:26 +00005803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005804 ThrowMogrifyException(OptionError,"MissingArgument",option);
5805 break;
5806 }
5807 if (LocaleCompare("tile",option+1) == 0)
5808 {
5809 if (*option == '+')
5810 break;
5811 i++;
cristybb503372010-05-27 20:51:26 +00005812 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005813 ThrowMogrifyException(OptionError,"MissingArgument",option);
5814 break;
5815 }
5816 if (LocaleCompare("tile-offset",option+1) == 0)
5817 {
5818 if (*option == '+')
5819 break;
5820 i++;
cristybb503372010-05-27 20:51:26 +00005821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005822 ThrowMogrifyException(OptionError,"MissingArgument",option);
5823 if (IsGeometry(argv[i]) == MagickFalse)
5824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5825 break;
5826 }
5827 if (LocaleCompare("tint",option+1) == 0)
5828 {
5829 if (*option == '+')
5830 break;
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 if (IsGeometry(argv[i]) == MagickFalse)
5835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5836 break;
5837 }
5838 if (LocaleCompare("transform",option+1) == 0)
5839 break;
5840 if (LocaleCompare("transpose",option+1) == 0)
5841 break;
5842 if (LocaleCompare("transverse",option+1) == 0)
5843 break;
5844 if (LocaleCompare("threshold",option+1) == 0)
5845 {
5846 if (*option == '+')
5847 break;
5848 i++;
cristybb503372010-05-27 20:51:26 +00005849 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005850 ThrowMogrifyException(OptionError,"MissingArgument",option);
5851 if (IsGeometry(argv[i]) == MagickFalse)
5852 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5853 break;
5854 }
5855 if (LocaleCompare("thumbnail",option+1) == 0)
5856 {
5857 if (*option == '+')
5858 break;
5859 i++;
cristybb503372010-05-27 20:51:26 +00005860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005861 ThrowMogrifyException(OptionError,"MissingArgument",option);
5862 if (IsGeometry(argv[i]) == MagickFalse)
5863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5864 break;
5865 }
5866 if (LocaleCompare("transparent",option+1) == 0)
5867 {
5868 i++;
cristybb503372010-05-27 20:51:26 +00005869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005870 ThrowMogrifyException(OptionError,"MissingArgument",option);
5871 break;
5872 }
5873 if (LocaleCompare("transparent-color",option+1) == 0)
5874 {
5875 if (*option == '+')
5876 break;
5877 i++;
cristybb503372010-05-27 20:51:26 +00005878 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005879 ThrowMogrifyException(OptionError,"MissingArgument",option);
5880 break;
5881 }
5882 if (LocaleCompare("treedepth",option+1) == 0)
5883 {
5884 if (*option == '+')
5885 break;
5886 i++;
cristybb503372010-05-27 20:51:26 +00005887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005888 ThrowMogrifyException(OptionError,"MissingArgument",option);
5889 if (IsGeometry(argv[i]) == MagickFalse)
5890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5891 break;
5892 }
5893 if (LocaleCompare("trim",option+1) == 0)
5894 break;
5895 if (LocaleCompare("type",option+1) == 0)
5896 {
cristybb503372010-05-27 20:51:26 +00005897 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005898 type;
5899
5900 if (*option == '+')
5901 break;
5902 i++;
cristybb503372010-05-27 20:51:26 +00005903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005904 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005905 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005906 if (type < 0)
5907 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5908 argv[i]);
5909 break;
5910 }
5911 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5912 }
5913 case 'u':
5914 {
5915 if (LocaleCompare("undercolor",option+1) == 0)
5916 {
5917 if (*option == '+')
5918 break;
5919 i++;
cristybb503372010-05-27 20:51:26 +00005920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005921 ThrowMogrifyException(OptionError,"MissingArgument",option);
5922 break;
5923 }
5924 if (LocaleCompare("unique-colors",option+1) == 0)
5925 break;
5926 if (LocaleCompare("units",option+1) == 0)
5927 {
cristybb503372010-05-27 20:51:26 +00005928 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005929 units;
5930
5931 if (*option == '+')
5932 break;
5933 i++;
cristybb503372010-05-27 20:51:26 +00005934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005935 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005936 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005937 argv[i]);
5938 if (units < 0)
5939 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5940 argv[i]);
5941 break;
5942 }
5943 if (LocaleCompare("unsharp",option+1) == 0)
5944 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5949 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5950 break;
5951 }
5952 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5953 }
5954 case 'v':
5955 {
5956 if (LocaleCompare("verbose",option+1) == 0)
5957 {
5958 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5959 break;
5960 }
5961 if ((LocaleCompare("version",option+1) == 0) ||
5962 (LocaleCompare("-version",option+1) == 0))
5963 {
cristyb51dff52011-05-19 16:55:47 +00005964 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005965 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005966 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5967 GetMagickCopyright());
5968 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5969 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005970 break;
5971 }
5972 if (LocaleCompare("view",option+1) == 0)
5973 {
5974 if (*option == '+')
5975 break;
5976 i++;
cristybb503372010-05-27 20:51:26 +00005977 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005978 ThrowMogrifyException(OptionError,"MissingArgument",option);
5979 break;
5980 }
5981 if (LocaleCompare("vignette",option+1) == 0)
5982 {
5983 if (*option == '+')
5984 break;
5985 i++;
cristybb503372010-05-27 20:51:26 +00005986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005987 ThrowMogrifyException(OptionError,"MissingArgument",option);
5988 if (IsGeometry(argv[i]) == MagickFalse)
5989 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5990 break;
5991 }
5992 if (LocaleCompare("virtual-pixel",option+1) == 0)
5993 {
cristybb503372010-05-27 20:51:26 +00005994 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005995 method;
5996
5997 if (*option == '+')
5998 break;
5999 i++;
cristybb503372010-05-27 20:51:26 +00006000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006001 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006002 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006003 argv[i]);
6004 if (method < 0)
6005 ThrowMogrifyException(OptionError,
6006 "UnrecognizedVirtualPixelMethod",argv[i]);
6007 break;
6008 }
6009 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6010 }
6011 case 'w':
6012 {
6013 if (LocaleCompare("wave",option+1) == 0)
6014 {
6015 i++;
cristybb503372010-05-27 20:51:26 +00006016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006017 ThrowMogrifyException(OptionError,"MissingArgument",option);
6018 if (IsGeometry(argv[i]) == MagickFalse)
6019 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6020 break;
6021 }
6022 if (LocaleCompare("weight",option+1) == 0)
6023 {
6024 if (*option == '+')
6025 break;
6026 i++;
cristybb503372010-05-27 20:51:26 +00006027 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006028 ThrowMogrifyException(OptionError,"MissingArgument",option);
6029 break;
6030 }
6031 if (LocaleCompare("white-point",option+1) == 0)
6032 {
6033 if (*option == '+')
6034 break;
6035 i++;
cristybb503372010-05-27 20:51:26 +00006036 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006037 ThrowMogrifyException(OptionError,"MissingArgument",option);
6038 if (IsGeometry(argv[i]) == MagickFalse)
6039 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6040 break;
6041 }
6042 if (LocaleCompare("white-threshold",option+1) == 0)
6043 {
6044 if (*option == '+')
6045 break;
6046 i++;
cristybb503372010-05-27 20:51:26 +00006047 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006048 ThrowMogrifyException(OptionError,"MissingArgument",option);
6049 if (IsGeometry(argv[i]) == MagickFalse)
6050 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6051 break;
6052 }
6053 if (LocaleCompare("write",option+1) == 0)
6054 {
6055 i++;
cristybb503372010-05-27 20:51:26 +00006056 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006057 ThrowMogrifyException(OptionError,"MissingArgument",option);
6058 break;
6059 }
6060 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6061 }
6062 case '?':
6063 break;
6064 default:
6065 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6066 }
cristy042ee782011-04-22 18:48:30 +00006067 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6068 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006069 if (fire != MagickFalse)
6070 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6071 }
6072 if (k != 0)
6073 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006074 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006075 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6076 DestroyMogrify();
6077 return(status != 0 ? MagickTrue : MagickFalse);
6078}
6079
6080/*
6081%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6082% %
6083% %
6084% %
6085+ M o g r i f y I m a g e I n f o %
6086% %
6087% %
6088% %
6089%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6090%
6091% MogrifyImageInfo() applies image processing settings to the image as
6092% prescribed by command line options.
6093%
6094% The format of the MogrifyImageInfo method is:
6095%
6096% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6097% const char **argv,ExceptionInfo *exception)
6098%
6099% A description of each parameter follows:
6100%
6101% o image_info: the image info..
6102%
6103% o argc: Specifies a pointer to an integer describing the number of
6104% elements in the argument vector.
6105%
6106% o argv: Specifies a pointer to a text array containing the command line
6107% arguments.
6108%
6109% o exception: return any errors or warnings in this structure.
6110%
6111*/
6112WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6113 const int argc,const char **argv,ExceptionInfo *exception)
6114{
6115 const char
6116 *option;
6117
6118 GeometryInfo
6119 geometry_info;
6120
cristybb503372010-05-27 20:51:26 +00006121 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006122 count;
6123
cristybb503372010-05-27 20:51:26 +00006124 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006125 i;
6126
6127 /*
6128 Initialize method variables.
6129 */
6130 assert(image_info != (ImageInfo *) NULL);
6131 assert(image_info->signature == MagickSignature);
6132 if (image_info->debug != MagickFalse)
6133 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6134 image_info->filename);
6135 if (argc < 0)
6136 return(MagickTrue);
6137 /*
6138 Set the image settings.
6139 */
cristybb503372010-05-27 20:51:26 +00006140 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006141 {
6142 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006143 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006144 continue;
cristy042ee782011-04-22 18:48:30 +00006145 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006146 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006147 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006148 break;
6149 switch (*(option+1))
6150 {
6151 case 'a':
6152 {
6153 if (LocaleCompare("adjoin",option+1) == 0)
6154 {
6155 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6156 break;
6157 }
6158 if (LocaleCompare("antialias",option+1) == 0)
6159 {
6160 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6161 break;
6162 }
cristy3ed852e2009-09-05 21:47:34 +00006163 if (LocaleCompare("authenticate",option+1) == 0)
6164 {
6165 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006166 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006167 else
anthony1afdc7a2011-10-05 11:54:28 +00006168 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006169 break;
6170 }
6171 break;
6172 }
6173 case 'b':
6174 {
6175 if (LocaleCompare("background",option+1) == 0)
6176 {
6177 if (*option == '+')
6178 {
6179 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006180 (void) QueryColorCompliance(MogrifyBackgroundColor,
6181 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006182 break;
6183 }
6184 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006185 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6186 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006187 break;
6188 }
6189 if (LocaleCompare("bias",option+1) == 0)
6190 {
6191 if (*option == '+')
6192 {
6193 (void) SetImageOption(image_info,option+1,"0.0");
6194 break;
6195 }
6196 (void) SetImageOption(image_info,option+1,argv[i+1]);
6197 break;
6198 }
6199 if (LocaleCompare("black-point-compensation",option+1) == 0)
6200 {
6201 if (*option == '+')
6202 {
6203 (void) SetImageOption(image_info,option+1,"false");
6204 break;
6205 }
6206 (void) SetImageOption(image_info,option+1,"true");
6207 break;
6208 }
6209 if (LocaleCompare("blue-primary",option+1) == 0)
6210 {
6211 if (*option == '+')
6212 {
6213 (void) SetImageOption(image_info,option+1,"0.0");
6214 break;
6215 }
6216 (void) SetImageOption(image_info,option+1,argv[i+1]);
6217 break;
6218 }
6219 if (LocaleCompare("bordercolor",option+1) == 0)
6220 {
6221 if (*option == '+')
6222 {
6223 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006224 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006225 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006226 break;
6227 }
cristy9950d572011-10-01 18:22:35 +00006228 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6229 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006230 (void) SetImageOption(image_info,option+1,argv[i+1]);
6231 break;
6232 }
6233 if (LocaleCompare("box",option+1) == 0)
6234 {
6235 if (*option == '+')
6236 {
6237 (void) SetImageOption(image_info,"undercolor","none");
6238 break;
6239 }
6240 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6241 break;
6242 }
6243 break;
6244 }
6245 case 'c':
6246 {
6247 if (LocaleCompare("cache",option+1) == 0)
6248 {
6249 MagickSizeType
6250 limit;
6251
6252 limit=MagickResourceInfinity;
6253 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006254 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6255 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006256 (void) SetMagickResourceLimit(MemoryResource,limit);
6257 (void) SetMagickResourceLimit(MapResource,2*limit);
6258 break;
6259 }
6260 if (LocaleCompare("caption",option+1) == 0)
6261 {
6262 if (*option == '+')
6263 {
6264 (void) DeleteImageOption(image_info,option+1);
6265 break;
6266 }
6267 (void) SetImageOption(image_info,option+1,argv[i+1]);
6268 break;
6269 }
6270 if (LocaleCompare("channel",option+1) == 0)
6271 {
6272 if (*option == '+')
6273 {
6274 image_info->channel=DefaultChannels;
6275 break;
6276 }
6277 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6278 break;
6279 }
cristy3ed852e2009-09-05 21:47:34 +00006280 if (LocaleCompare("colorspace",option+1) == 0)
6281 {
6282 if (*option == '+')
6283 {
6284 image_info->colorspace=UndefinedColorspace;
6285 (void) SetImageOption(image_info,option+1,"undefined");
6286 break;
6287 }
cristy042ee782011-04-22 18:48:30 +00006288 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006289 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6290 (void) SetImageOption(image_info,option+1,argv[i+1]);
6291 break;
6292 }
cristy3ed852e2009-09-05 21:47:34 +00006293 if (LocaleCompare("comment",option+1) == 0)
6294 {
6295 if (*option == '+')
6296 {
6297 (void) DeleteImageOption(image_info,option+1);
6298 break;
6299 }
6300 (void) SetImageOption(image_info,option+1,argv[i+1]);
6301 break;
6302 }
6303 if (LocaleCompare("compose",option+1) == 0)
6304 {
6305 if (*option == '+')
6306 {
6307 (void) SetImageOption(image_info,option+1,"undefined");
6308 break;
6309 }
6310 (void) SetImageOption(image_info,option+1,argv[i+1]);
6311 break;
6312 }
6313 if (LocaleCompare("compress",option+1) == 0)
6314 {
6315 if (*option == '+')
6316 {
6317 image_info->compression=UndefinedCompression;
6318 (void) SetImageOption(image_info,option+1,"undefined");
6319 break;
6320 }
cristy042ee782011-04-22 18:48:30 +00006321 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006322 MagickCompressOptions,MagickFalse,argv[i+1]);
6323 (void) SetImageOption(image_info,option+1,argv[i+1]);
6324 break;
6325 }
6326 break;
6327 }
6328 case 'd':
6329 {
6330 if (LocaleCompare("debug",option+1) == 0)
6331 {
6332 if (*option == '+')
6333 (void) SetLogEventMask("none");
6334 else
6335 (void) SetLogEventMask(argv[i+1]);
6336 image_info->debug=IsEventLogging();
6337 break;
6338 }
6339 if (LocaleCompare("define",option+1) == 0)
6340 {
6341 if (*option == '+')
6342 {
6343 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6344 (void) DeleteImageRegistry(argv[i+1]+9);
6345 else
6346 (void) DeleteImageOption(image_info,argv[i+1]);
6347 break;
6348 }
6349 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6350 {
6351 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6352 exception);
6353 break;
6354 }
6355 (void) DefineImageOption(image_info,argv[i+1]);
6356 break;
6357 }
6358 if (LocaleCompare("delay",option+1) == 0)
6359 {
6360 if (*option == '+')
6361 {
6362 (void) SetImageOption(image_info,option+1,"0");
6363 break;
6364 }
6365 (void) SetImageOption(image_info,option+1,argv[i+1]);
6366 break;
6367 }
6368 if (LocaleCompare("density",option+1) == 0)
6369 {
6370 /*
6371 Set image density.
6372 */
6373 if (*option == '+')
6374 {
6375 if (image_info->density != (char *) NULL)
6376 image_info->density=DestroyString(image_info->density);
6377 (void) SetImageOption(image_info,option+1,"72");
6378 break;
6379 }
6380 (void) CloneString(&image_info->density,argv[i+1]);
6381 (void) SetImageOption(image_info,option+1,argv[i+1]);
6382 break;
6383 }
6384 if (LocaleCompare("depth",option+1) == 0)
6385 {
6386 if (*option == '+')
6387 {
6388 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6389 break;
6390 }
cristye27293e2009-12-18 02:53:20 +00006391 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006392 break;
6393 }
cristyc9b12952010-03-28 01:12:28 +00006394 if (LocaleCompare("direction",option+1) == 0)
6395 {
6396 if (*option == '+')
6397 {
6398 (void) SetImageOption(image_info,option+1,"undefined");
6399 break;
6400 }
6401 (void) SetImageOption(image_info,option+1,argv[i+1]);
6402 break;
6403 }
cristy3ed852e2009-09-05 21:47:34 +00006404 if (LocaleCompare("display",option+1) == 0)
6405 {
6406 if (*option == '+')
6407 {
6408 if (image_info->server_name != (char *) NULL)
6409 image_info->server_name=DestroyString(
6410 image_info->server_name);
6411 break;
6412 }
6413 (void) CloneString(&image_info->server_name,argv[i+1]);
6414 break;
6415 }
6416 if (LocaleCompare("dispose",option+1) == 0)
6417 {
6418 if (*option == '+')
6419 {
6420 (void) SetImageOption(image_info,option+1,"undefined");
6421 break;
6422 }
6423 (void) SetImageOption(image_info,option+1,argv[i+1]);
6424 break;
6425 }
6426 if (LocaleCompare("dither",option+1) == 0)
6427 {
6428 if (*option == '+')
6429 {
6430 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006431 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006432 break;
6433 }
6434 (void) SetImageOption(image_info,option+1,argv[i+1]);
6435 image_info->dither=MagickTrue;
6436 break;
6437 }
6438 break;
6439 }
6440 case 'e':
6441 {
6442 if (LocaleCompare("encoding",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("endian",option+1) == 0)
6453 {
6454 if (*option == '+')
6455 {
6456 image_info->endian=UndefinedEndian;
6457 (void) SetImageOption(image_info,option+1,"undefined");
6458 break;
6459 }
cristy042ee782011-04-22 18:48:30 +00006460 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006461 MagickEndianOptions,MagickFalse,argv[i+1]);
6462 (void) SetImageOption(image_info,option+1,argv[i+1]);
6463 break;
6464 }
6465 if (LocaleCompare("extract",option+1) == 0)
6466 {
6467 /*
6468 Set image extract geometry.
6469 */
6470 if (*option == '+')
6471 {
6472 if (image_info->extract != (char *) NULL)
6473 image_info->extract=DestroyString(image_info->extract);
6474 break;
6475 }
6476 (void) CloneString(&image_info->extract,argv[i+1]);
6477 break;
6478 }
6479 break;
6480 }
6481 case 'f':
6482 {
6483 if (LocaleCompare("fill",option+1) == 0)
6484 {
6485 if (*option == '+')
6486 {
6487 (void) SetImageOption(image_info,option+1,"none");
6488 break;
6489 }
6490 (void) SetImageOption(image_info,option+1,argv[i+1]);
6491 break;
6492 }
6493 if (LocaleCompare("filter",option+1) == 0)
6494 {
6495 if (*option == '+')
6496 {
6497 (void) SetImageOption(image_info,option+1,"undefined");
6498 break;
6499 }
6500 (void) SetImageOption(image_info,option+1,argv[i+1]);
6501 break;
6502 }
6503 if (LocaleCompare("font",option+1) == 0)
6504 {
6505 if (*option == '+')
6506 {
6507 if (image_info->font != (char *) NULL)
6508 image_info->font=DestroyString(image_info->font);
6509 break;
6510 }
6511 (void) CloneString(&image_info->font,argv[i+1]);
6512 break;
6513 }
6514 if (LocaleCompare("format",option+1) == 0)
6515 {
6516 register const char
6517 *q;
6518
6519 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006520 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006521 image_info->ping=MagickFalse;
6522 (void) SetImageOption(image_info,option+1,argv[i+1]);
6523 break;
6524 }
6525 if (LocaleCompare("fuzz",option+1) == 0)
6526 {
6527 if (*option == '+')
6528 {
6529 image_info->fuzz=0.0;
6530 (void) SetImageOption(image_info,option+1,"0");
6531 break;
6532 }
cristydbdd0e32011-11-04 23:29:40 +00006533 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6534 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006535 (void) SetImageOption(image_info,option+1,argv[i+1]);
6536 break;
6537 }
6538 break;
6539 }
6540 case 'g':
6541 {
6542 if (LocaleCompare("gravity",option+1) == 0)
6543 {
6544 if (*option == '+')
6545 {
6546 (void) SetImageOption(image_info,option+1,"undefined");
6547 break;
6548 }
6549 (void) SetImageOption(image_info,option+1,argv[i+1]);
6550 break;
6551 }
6552 if (LocaleCompare("green-primary",option+1) == 0)
6553 {
6554 if (*option == '+')
6555 {
6556 (void) SetImageOption(image_info,option+1,"0.0");
6557 break;
6558 }
6559 (void) SetImageOption(image_info,option+1,argv[i+1]);
6560 break;
6561 }
6562 break;
6563 }
6564 case 'i':
6565 {
6566 if (LocaleCompare("intent",option+1) == 0)
6567 {
6568 if (*option == '+')
6569 {
6570 (void) SetImageOption(image_info,option+1,"undefined");
6571 break;
6572 }
6573 (void) SetImageOption(image_info,option+1,argv[i+1]);
6574 break;
6575 }
6576 if (LocaleCompare("interlace",option+1) == 0)
6577 {
6578 if (*option == '+')
6579 {
6580 image_info->interlace=UndefinedInterlace;
6581 (void) SetImageOption(image_info,option+1,"undefined");
6582 break;
6583 }
cristy042ee782011-04-22 18:48:30 +00006584 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006585 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6586 (void) SetImageOption(image_info,option+1,argv[i+1]);
6587 break;
6588 }
cristyb32b90a2009-09-07 21:45:48 +00006589 if (LocaleCompare("interline-spacing",option+1) == 0)
6590 {
6591 if (*option == '+')
6592 {
6593 (void) SetImageOption(image_info,option+1,"undefined");
6594 break;
6595 }
6596 (void) SetImageOption(image_info,option+1,argv[i+1]);
6597 break;
6598 }
cristy3ed852e2009-09-05 21:47:34 +00006599 if (LocaleCompare("interpolate",option+1) == 0)
6600 {
6601 if (*option == '+')
6602 {
6603 (void) SetImageOption(image_info,option+1,"undefined");
6604 break;
6605 }
6606 (void) SetImageOption(image_info,option+1,argv[i+1]);
6607 break;
6608 }
6609 if (LocaleCompare("interword-spacing",option+1) == 0)
6610 {
6611 if (*option == '+')
6612 {
6613 (void) SetImageOption(image_info,option+1,"undefined");
6614 break;
6615 }
6616 (void) SetImageOption(image_info,option+1,argv[i+1]);
6617 break;
6618 }
6619 break;
6620 }
6621 case 'k':
6622 {
6623 if (LocaleCompare("kerning",option+1) == 0)
6624 {
6625 if (*option == '+')
6626 {
6627 (void) SetImageOption(image_info,option+1,"undefined");
6628 break;
6629 }
6630 (void) SetImageOption(image_info,option+1,argv[i+1]);
6631 break;
6632 }
6633 break;
6634 }
6635 case 'l':
6636 {
6637 if (LocaleCompare("label",option+1) == 0)
6638 {
6639 if (*option == '+')
6640 {
6641 (void) DeleteImageOption(image_info,option+1);
6642 break;
6643 }
6644 (void) SetImageOption(image_info,option+1,argv[i+1]);
6645 break;
6646 }
6647 if (LocaleCompare("limit",option+1) == 0)
6648 {
6649 MagickSizeType
6650 limit;
6651
6652 ResourceType
6653 type;
6654
6655 if (*option == '+')
6656 break;
cristy042ee782011-04-22 18:48:30 +00006657 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006658 MagickFalse,argv[i+1]);
6659 limit=MagickResourceInfinity;
6660 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006661 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],
6662 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006663 (void) SetMagickResourceLimit(type,limit);
6664 break;
6665 }
6666 if (LocaleCompare("list",option+1) == 0)
6667 {
cristybb503372010-05-27 20:51:26 +00006668 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006669 list;
6670
6671 /*
6672 Display configuration list.
6673 */
cristy042ee782011-04-22 18:48:30 +00006674 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006675 switch (list)
6676 {
6677 case MagickCoderOptions:
6678 {
6679 (void) ListCoderInfo((FILE *) NULL,exception);
6680 break;
6681 }
6682 case MagickColorOptions:
6683 {
6684 (void) ListColorInfo((FILE *) NULL,exception);
6685 break;
6686 }
6687 case MagickConfigureOptions:
6688 {
6689 (void) ListConfigureInfo((FILE *) NULL,exception);
6690 break;
6691 }
6692 case MagickDelegateOptions:
6693 {
6694 (void) ListDelegateInfo((FILE *) NULL,exception);
6695 break;
6696 }
6697 case MagickFontOptions:
6698 {
6699 (void) ListTypeInfo((FILE *) NULL,exception);
6700 break;
6701 }
6702 case MagickFormatOptions:
6703 {
6704 (void) ListMagickInfo((FILE *) NULL,exception);
6705 break;
6706 }
6707 case MagickLocaleOptions:
6708 {
6709 (void) ListLocaleInfo((FILE *) NULL,exception);
6710 break;
6711 }
6712 case MagickLogOptions:
6713 {
6714 (void) ListLogInfo((FILE *) NULL,exception);
6715 break;
6716 }
6717 case MagickMagicOptions:
6718 {
6719 (void) ListMagicInfo((FILE *) NULL,exception);
6720 break;
6721 }
6722 case MagickMimeOptions:
6723 {
6724 (void) ListMimeInfo((FILE *) NULL,exception);
6725 break;
6726 }
6727 case MagickModuleOptions:
6728 {
6729 (void) ListModuleInfo((FILE *) NULL,exception);
6730 break;
6731 }
6732 case MagickPolicyOptions:
6733 {
6734 (void) ListPolicyInfo((FILE *) NULL,exception);
6735 break;
6736 }
6737 case MagickResourceOptions:
6738 {
6739 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6740 break;
6741 }
6742 case MagickThresholdOptions:
6743 {
6744 (void) ListThresholdMaps((FILE *) NULL,exception);
6745 break;
6746 }
6747 default:
6748 {
cristy042ee782011-04-22 18:48:30 +00006749 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006750 exception);
6751 break;
6752 }
6753 }
cristyaeb2cbc2010-05-07 13:28:58 +00006754 break;
cristy3ed852e2009-09-05 21:47:34 +00006755 }
6756 if (LocaleCompare("log",option+1) == 0)
6757 {
6758 if (*option == '+')
6759 break;
6760 (void) SetLogFormat(argv[i+1]);
6761 break;
6762 }
6763 if (LocaleCompare("loop",option+1) == 0)
6764 {
6765 if (*option == '+')
6766 {
6767 (void) SetImageOption(image_info,option+1,"0");
6768 break;
6769 }
6770 (void) SetImageOption(image_info,option+1,argv[i+1]);
6771 break;
6772 }
6773 break;
6774 }
6775 case 'm':
6776 {
6777 if (LocaleCompare("matte",option+1) == 0)
6778 {
6779 if (*option == '+')
6780 {
6781 (void) SetImageOption(image_info,option+1,"false");
6782 break;
6783 }
6784 (void) SetImageOption(image_info,option+1,"true");
6785 break;
6786 }
6787 if (LocaleCompare("mattecolor",option+1) == 0)
6788 {
6789 if (*option == '+')
6790 {
6791 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006792 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006793 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006794 break;
6795 }
6796 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006797 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6798 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006799 break;
6800 }
6801 if (LocaleCompare("monitor",option+1) == 0)
6802 {
6803 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6804 (void *) NULL);
6805 break;
6806 }
6807 if (LocaleCompare("monochrome",option+1) == 0)
6808 {
6809 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6810 break;
6811 }
6812 break;
6813 }
6814 case 'o':
6815 {
6816 if (LocaleCompare("orient",option+1) == 0)
6817 {
6818 if (*option == '+')
6819 {
6820 image_info->orientation=UndefinedOrientation;
6821 (void) SetImageOption(image_info,option+1,"undefined");
6822 break;
6823 }
cristy042ee782011-04-22 18:48:30 +00006824 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006825 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006826 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006827 break;
6828 }
6829 }
6830 case 'p':
6831 {
6832 if (LocaleCompare("page",option+1) == 0)
6833 {
6834 char
6835 *canonical_page,
6836 page[MaxTextExtent];
6837
6838 const char
6839 *image_option;
6840
6841 MagickStatusType
6842 flags;
6843
6844 RectangleInfo
6845 geometry;
6846
6847 if (*option == '+')
6848 {
6849 (void) DeleteImageOption(image_info,option+1);
6850 (void) CloneString(&image_info->page,(char *) NULL);
6851 break;
6852 }
6853 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6854 image_option=GetImageOption(image_info,"page");
6855 if (image_option != (const char *) NULL)
6856 flags=ParseAbsoluteGeometry(image_option,&geometry);
6857 canonical_page=GetPageGeometry(argv[i+1]);
6858 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6859 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006860 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006861 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006862 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006863 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006864 (unsigned long) geometry.width,(unsigned long) geometry.height,
6865 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006866 (void) SetImageOption(image_info,option+1,page);
6867 (void) CloneString(&image_info->page,page);
6868 break;
6869 }
6870 if (LocaleCompare("pen",option+1) == 0)
6871 {
6872 if (*option == '+')
6873 {
6874 (void) SetImageOption(image_info,option+1,"none");
6875 break;
6876 }
6877 (void) SetImageOption(image_info,option+1,argv[i+1]);
6878 break;
6879 }
6880 if (LocaleCompare("ping",option+1) == 0)
6881 {
6882 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6883 break;
6884 }
6885 if (LocaleCompare("pointsize",option+1) == 0)
6886 {
6887 if (*option == '+')
6888 geometry_info.rho=0.0;
6889 else
6890 (void) ParseGeometry(argv[i+1],&geometry_info);
6891 image_info->pointsize=geometry_info.rho;
6892 break;
6893 }
cristye7f51092010-01-17 00:39:37 +00006894 if (LocaleCompare("precision",option+1) == 0)
6895 {
cristybf2766a2010-01-17 03:33:23 +00006896 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006897 break;
6898 }
cristy3ed852e2009-09-05 21:47:34 +00006899 if (LocaleCompare("preview",option+1) == 0)
6900 {
6901 /*
6902 Preview image.
6903 */
6904 if (*option == '+')
6905 {
6906 image_info->preview_type=UndefinedPreview;
6907 break;
6908 }
cristy042ee782011-04-22 18:48:30 +00006909 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006910 MagickPreviewOptions,MagickFalse,argv[i+1]);
6911 break;
6912 }
6913 break;
6914 }
6915 case 'q':
6916 {
6917 if (LocaleCompare("quality",option+1) == 0)
6918 {
6919 /*
6920 Set image compression quality.
6921 */
6922 if (*option == '+')
6923 {
6924 image_info->quality=UndefinedCompressionQuality;
6925 (void) SetImageOption(image_info,option+1,"0");
6926 break;
6927 }
cristye27293e2009-12-18 02:53:20 +00006928 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006929 (void) SetImageOption(image_info,option+1,argv[i+1]);
6930 break;
6931 }
6932 if (LocaleCompare("quiet",option+1) == 0)
6933 {
6934 static WarningHandler
6935 warning_handler = (WarningHandler) NULL;
6936
6937 if (*option == '+')
6938 {
6939 /*
6940 Restore error or warning messages.
6941 */
6942 warning_handler=SetWarningHandler(warning_handler);
6943 break;
6944 }
6945 /*
6946 Suppress error or warning messages.
6947 */
6948 warning_handler=SetWarningHandler((WarningHandler) NULL);
6949 break;
6950 }
6951 break;
6952 }
6953 case 'r':
6954 {
6955 if (LocaleCompare("red-primary",option+1) == 0)
6956 {
6957 if (*option == '+')
6958 {
6959 (void) SetImageOption(image_info,option+1,"0.0");
6960 break;
6961 }
6962 (void) SetImageOption(image_info,option+1,argv[i+1]);
6963 break;
6964 }
6965 break;
6966 }
6967 case 's':
6968 {
6969 if (LocaleCompare("sampling-factor",option+1) == 0)
6970 {
6971 /*
6972 Set image sampling factor.
6973 */
6974 if (*option == '+')
6975 {
6976 if (image_info->sampling_factor != (char *) NULL)
6977 image_info->sampling_factor=DestroyString(
6978 image_info->sampling_factor);
6979 break;
6980 }
6981 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6982 break;
6983 }
6984 if (LocaleCompare("scene",option+1) == 0)
6985 {
6986 /*
6987 Set image scene.
6988 */
6989 if (*option == '+')
6990 {
6991 image_info->scene=0;
6992 (void) SetImageOption(image_info,option+1,"0");
6993 break;
6994 }
cristye27293e2009-12-18 02:53:20 +00006995 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006996 (void) SetImageOption(image_info,option+1,argv[i+1]);
6997 break;
6998 }
6999 if (LocaleCompare("seed",option+1) == 0)
7000 {
cristybb503372010-05-27 20:51:26 +00007001 size_t
cristy3ed852e2009-09-05 21:47:34 +00007002 seed;
7003
7004 if (*option == '+')
7005 {
cristybb503372010-05-27 20:51:26 +00007006 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007007 SeedPseudoRandomGenerator(seed);
7008 break;
7009 }
cristye27293e2009-12-18 02:53:20 +00007010 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007011 SeedPseudoRandomGenerator(seed);
7012 break;
7013 }
7014 if (LocaleCompare("size",option+1) == 0)
7015 {
7016 if (*option == '+')
7017 {
7018 if (image_info->size != (char *) NULL)
7019 image_info->size=DestroyString(image_info->size);
7020 break;
7021 }
7022 (void) CloneString(&image_info->size,argv[i+1]);
7023 break;
7024 }
7025 if (LocaleCompare("stroke",option+1) == 0)
7026 {
7027 if (*option == '+')
7028 {
7029 (void) SetImageOption(image_info,option+1,"none");
7030 break;
7031 }
7032 (void) SetImageOption(image_info,option+1,argv[i+1]);
7033 break;
7034 }
7035 if (LocaleCompare("strokewidth",option+1) == 0)
7036 {
7037 if (*option == '+')
7038 {
7039 (void) SetImageOption(image_info,option+1,"0");
7040 break;
7041 }
7042 (void) SetImageOption(image_info,option+1,argv[i+1]);
7043 break;
7044 }
cristyd9a29192010-10-16 16:49:53 +00007045 if (LocaleCompare("synchronize",option+1) == 0)
7046 {
7047 if (*option == '+')
7048 {
7049 image_info->synchronize=MagickFalse;
7050 break;
7051 }
7052 image_info->synchronize=MagickTrue;
7053 break;
7054 }
cristy3ed852e2009-09-05 21:47:34 +00007055 break;
7056 }
7057 case 't':
7058 {
7059 if (LocaleCompare("taint",option+1) == 0)
7060 {
7061 if (*option == '+')
7062 {
7063 (void) SetImageOption(image_info,option+1,"false");
7064 break;
7065 }
7066 (void) SetImageOption(image_info,option+1,"true");
7067 break;
7068 }
7069 if (LocaleCompare("texture",option+1) == 0)
7070 {
7071 if (*option == '+')
7072 {
7073 if (image_info->texture != (char *) NULL)
7074 image_info->texture=DestroyString(image_info->texture);
7075 break;
7076 }
7077 (void) CloneString(&image_info->texture,argv[i+1]);
7078 break;
7079 }
7080 if (LocaleCompare("tile-offset",option+1) == 0)
7081 {
7082 if (*option == '+')
7083 {
7084 (void) SetImageOption(image_info,option+1,"0");
7085 break;
7086 }
7087 (void) SetImageOption(image_info,option+1,argv[i+1]);
7088 break;
7089 }
7090 if (LocaleCompare("transparent-color",option+1) == 0)
7091 {
7092 if (*option == '+')
7093 {
cristy9950d572011-10-01 18:22:35 +00007094 (void) QueryColorCompliance("none",AllCompliance,
7095 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007096 (void) SetImageOption(image_info,option+1,"none");
7097 break;
7098 }
cristy9950d572011-10-01 18:22:35 +00007099 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7100 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007101 (void) SetImageOption(image_info,option+1,argv[i+1]);
7102 break;
7103 }
7104 if (LocaleCompare("type",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
cristy5f1c1ff2010-12-23 21:38:06 +00007108 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007109 (void) SetImageOption(image_info,option+1,"undefined");
7110 break;
7111 }
cristy042ee782011-04-22 18:48:30 +00007112 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007113 MagickFalse,argv[i+1]);
7114 (void) SetImageOption(image_info,option+1,argv[i+1]);
7115 break;
7116 }
7117 break;
7118 }
7119 case 'u':
7120 {
7121 if (LocaleCompare("undercolor",option+1) == 0)
7122 {
7123 if (*option == '+')
7124 {
7125 (void) DeleteImageOption(image_info,option+1);
7126 break;
7127 }
7128 (void) SetImageOption(image_info,option+1,argv[i+1]);
7129 break;
7130 }
7131 if (LocaleCompare("units",option+1) == 0)
7132 {
7133 if (*option == '+')
7134 {
7135 image_info->units=UndefinedResolution;
7136 (void) SetImageOption(image_info,option+1,"undefined");
7137 break;
7138 }
cristy042ee782011-04-22 18:48:30 +00007139 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007140 MagickResolutionOptions,MagickFalse,argv[i+1]);
7141 (void) SetImageOption(image_info,option+1,argv[i+1]);
7142 break;
7143 }
7144 break;
7145 }
7146 case 'v':
7147 {
7148 if (LocaleCompare("verbose",option+1) == 0)
7149 {
7150 if (*option == '+')
7151 {
7152 image_info->verbose=MagickFalse;
7153 break;
7154 }
7155 image_info->verbose=MagickTrue;
7156 image_info->ping=MagickFalse;
7157 break;
7158 }
7159 if (LocaleCompare("view",option+1) == 0)
7160 {
7161 if (*option == '+')
7162 {
7163 if (image_info->view != (char *) NULL)
7164 image_info->view=DestroyString(image_info->view);
7165 break;
7166 }
7167 (void) CloneString(&image_info->view,argv[i+1]);
7168 break;
7169 }
7170 if (LocaleCompare("virtual-pixel",option+1) == 0)
7171 {
7172 if (*option == '+')
7173 {
7174 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7175 (void) SetImageOption(image_info,option+1,"undefined");
7176 break;
7177 }
7178 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007179 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007180 argv[i+1]);
7181 (void) SetImageOption(image_info,option+1,argv[i+1]);
7182 break;
7183 }
7184 break;
7185 }
7186 case 'w':
7187 {
7188 if (LocaleCompare("white-point",option+1) == 0)
7189 {
7190 if (*option == '+')
7191 {
7192 (void) SetImageOption(image_info,option+1,"0.0");
7193 break;
7194 }
7195 (void) SetImageOption(image_info,option+1,argv[i+1]);
7196 break;
7197 }
7198 break;
7199 }
7200 default:
7201 break;
7202 }
7203 i+=count;
7204 }
7205 return(MagickTrue);
7206}
7207
7208/*
7209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7210% %
7211% %
7212% %
7213+ M o g r i f y I m a g e L i s t %
7214% %
7215% %
7216% %
7217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7218%
7219% MogrifyImageList() applies any command line options that might affect the
7220% entire image list (e.g. -append, -coalesce, etc.).
7221%
7222% The format of the MogrifyImage method is:
7223%
7224% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7225% const char **argv,Image **images,ExceptionInfo *exception)
7226%
7227% A description of each parameter follows:
7228%
7229% o image_info: the image info..
7230%
7231% o argc: Specifies a pointer to an integer describing the number of
7232% elements in the argument vector.
7233%
7234% o argv: Specifies a pointer to a text array containing the command line
7235% arguments.
7236%
anthonye9c27192011-03-27 08:07:06 +00007237% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007238%
7239% o exception: return any errors or warnings in this structure.
7240%
7241*/
7242WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7243 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7244{
cristy3ed852e2009-09-05 21:47:34 +00007245 const char
7246 *option;
7247
cristy6b3da3a2010-06-20 02:21:46 +00007248 ImageInfo
7249 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007250
7251 MagickStatusType
7252 status;
7253
cristy28474bf2011-09-11 23:32:52 +00007254 PixelInterpolateMethod
7255 interpolate_method;
7256
cristy3ed852e2009-09-05 21:47:34 +00007257 QuantizeInfo
7258 *quantize_info;
7259
cristybb503372010-05-27 20:51:26 +00007260 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007261 i;
7262
cristy6b3da3a2010-06-20 02:21:46 +00007263 ssize_t
7264 count,
7265 index;
7266
cristy3ed852e2009-09-05 21:47:34 +00007267 /*
7268 Apply options to the image list.
7269 */
7270 assert(image_info != (ImageInfo *) NULL);
7271 assert(image_info->signature == MagickSignature);
7272 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007273 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007274 assert((*images)->signature == MagickSignature);
7275 if ((*images)->debug != MagickFalse)
7276 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7277 (*images)->filename);
7278 if ((argc <= 0) || (*argv == (char *) NULL))
7279 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007280 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007281 mogrify_info=CloneImageInfo(image_info);
7282 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007283 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007284 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007285 {
cristy74fe8f12009-10-03 19:09:01 +00007286 if (*images == (Image *) NULL)
7287 break;
cristy3ed852e2009-09-05 21:47:34 +00007288 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007289 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007290 continue;
cristy042ee782011-04-22 18:48:30 +00007291 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007292 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007293 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007294 break;
cristy6b3da3a2010-06-20 02:21:46 +00007295 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007296 switch (*(option+1))
7297 {
7298 case 'a':
7299 {
7300 if (LocaleCompare("affinity",option+1) == 0)
7301 {
cristy6fccee12011-10-20 18:43:18 +00007302 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007303 if (*option == '+')
7304 {
cristy018f07f2011-09-04 21:15:19 +00007305 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7306 exception);
cristy3ed852e2009-09-05 21:47:34 +00007307 break;
7308 }
7309 i++;
7310 break;
7311 }
7312 if (LocaleCompare("append",option+1) == 0)
7313 {
7314 Image
7315 *append_image;
7316
cristy6fccee12011-10-20 18:43:18 +00007317 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007318 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7319 MagickFalse,exception);
7320 if (append_image == (Image *) NULL)
7321 {
7322 status=MagickFalse;
7323 break;
7324 }
7325 *images=DestroyImageList(*images);
7326 *images=append_image;
7327 break;
7328 }
7329 if (LocaleCompare("average",option+1) == 0)
7330 {
7331 Image
7332 *average_image;
7333
cristyd18ae7c2010-03-07 17:39:52 +00007334 /*
7335 Average an image sequence (deprecated).
7336 */
cristy6fccee12011-10-20 18:43:18 +00007337 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007338 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7339 exception);
cristy3ed852e2009-09-05 21:47:34 +00007340 if (average_image == (Image *) NULL)
7341 {
7342 status=MagickFalse;
7343 break;
7344 }
7345 *images=DestroyImageList(*images);
7346 *images=average_image;
7347 break;
7348 }
7349 break;
7350 }
7351 case 'c':
7352 {
7353 if (LocaleCompare("channel",option+1) == 0)
7354 {
cristyf4ad9df2011-07-08 16:49:03 +00007355 ChannelType
7356 channel;
7357
cristy3ed852e2009-09-05 21:47:34 +00007358 if (*option == '+')
7359 {
7360 channel=DefaultChannels;
7361 break;
7362 }
7363 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007364 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007365 break;
7366 }
7367 if (LocaleCompare("clut",option+1) == 0)
7368 {
7369 Image
7370 *clut_image,
7371 *image;
7372
cristy6fccee12011-10-20 18:43:18 +00007373 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007374 image=RemoveFirstImageFromList(images);
7375 clut_image=RemoveFirstImageFromList(images);
7376 if (clut_image == (Image *) NULL)
7377 {
7378 status=MagickFalse;
7379 break;
7380 }
cristy28474bf2011-09-11 23:32:52 +00007381 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007382 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007383 *images=DestroyImageList(*images);
7384 *images=image;
7385 break;
7386 }
7387 if (LocaleCompare("coalesce",option+1) == 0)
7388 {
7389 Image
7390 *coalesce_image;
7391
cristy6fccee12011-10-20 18:43:18 +00007392 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007393 coalesce_image=CoalesceImages(*images,exception);
7394 if (coalesce_image == (Image *) NULL)
7395 {
7396 status=MagickFalse;
7397 break;
7398 }
7399 *images=DestroyImageList(*images);
7400 *images=coalesce_image;
7401 break;
7402 }
7403 if (LocaleCompare("combine",option+1) == 0)
7404 {
7405 Image
7406 *combine_image;
7407
cristy6fccee12011-10-20 18:43:18 +00007408 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007409 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007410 if (combine_image == (Image *) NULL)
7411 {
7412 status=MagickFalse;
7413 break;
7414 }
7415 *images=DestroyImageList(*images);
7416 *images=combine_image;
7417 break;
7418 }
7419 if (LocaleCompare("composite",option+1) == 0)
7420 {
7421 Image
7422 *mask_image,
7423 *composite_image,
7424 *image;
7425
7426 RectangleInfo
7427 geometry;
7428
cristy6fccee12011-10-20 18:43:18 +00007429 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007430 image=RemoveFirstImageFromList(images);
7431 composite_image=RemoveFirstImageFromList(images);
7432 if (composite_image == (Image *) NULL)
7433 {
7434 status=MagickFalse;
7435 break;
7436 }
7437 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007438 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007439 SetGeometry(composite_image,&geometry);
7440 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7441 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7442 &geometry);
7443 mask_image=RemoveFirstImageFromList(images);
7444 if (mask_image != (Image *) NULL)
7445 {
7446 if ((image->compose == DisplaceCompositeOp) ||
7447 (image->compose == DistortCompositeOp))
7448 {
7449 /*
7450 Merge Y displacement into X displacement image.
7451 */
7452 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007453 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007454 mask_image=DestroyImage(mask_image);
7455 }
7456 else
7457 {
7458 /*
7459 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007460 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007461 */
7462 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007463 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007464 }
7465 }
cristyf4ad9df2011-07-08 16:49:03 +00007466 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007467 geometry.x,geometry.y,exception);
anthonya129f702011-04-14 01:08:48 +00007468 if (mask_image != (Image *) NULL)
7469 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007470 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007471 *images=DestroyImageList(*images);
7472 *images=image;
7473 break;
7474 }
cristy3ed852e2009-09-05 21:47:34 +00007475 break;
7476 }
7477 case 'd':
7478 {
7479 if (LocaleCompare("deconstruct",option+1) == 0)
7480 {
7481 Image
7482 *deconstruct_image;
7483
cristy6fccee12011-10-20 18:43:18 +00007484 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007485 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007486 exception);
cristy3ed852e2009-09-05 21:47:34 +00007487 if (deconstruct_image == (Image *) NULL)
7488 {
7489 status=MagickFalse;
7490 break;
7491 }
7492 *images=DestroyImageList(*images);
7493 *images=deconstruct_image;
7494 break;
7495 }
7496 if (LocaleCompare("delete",option+1) == 0)
7497 {
7498 if (*option == '+')
7499 DeleteImages(images,"-1",exception);
7500 else
7501 DeleteImages(images,argv[i+1],exception);
7502 break;
7503 }
7504 if (LocaleCompare("dither",option+1) == 0)
7505 {
7506 if (*option == '+')
7507 {
7508 quantize_info->dither=MagickFalse;
7509 break;
7510 }
7511 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007512 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007513 MagickDitherOptions,MagickFalse,argv[i+1]);
7514 break;
7515 }
cristyecb10ff2011-03-22 13:14:03 +00007516 if (LocaleCompare("duplicate",option+1) == 0)
7517 {
cristy72988482011-03-29 16:34:38 +00007518 Image
7519 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007520
anthony2b6bcae2011-03-23 13:05:34 +00007521 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007522 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7523 else
7524 {
7525 const char
7526 *p;
7527
anthony2b6bcae2011-03-23 13:05:34 +00007528 size_t
7529 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007530
anthony2b6bcae2011-03-23 13:05:34 +00007531 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007532 p=strchr(argv[i+1],',');
7533 if (p == (const char *) NULL)
7534 duplicate_images=DuplicateImages(*images,number_duplicates,
7535 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007536 else
cristy72988482011-03-29 16:34:38 +00007537 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7538 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007539 }
7540 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007541 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007542 break;
7543 }
cristy3ed852e2009-09-05 21:47:34 +00007544 break;
7545 }
cristyd18ae7c2010-03-07 17:39:52 +00007546 case 'e':
7547 {
7548 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7549 {
7550 Image
7551 *evaluate_image;
7552
7553 MagickEvaluateOperator
7554 op;
7555
cristy6fccee12011-10-20 18:43:18 +00007556 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007557 op=(MagickEvaluateOperator) ParseCommandOption(
7558 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007559 evaluate_image=EvaluateImages(*images,op,exception);
7560 if (evaluate_image == (Image *) NULL)
7561 {
7562 status=MagickFalse;
7563 break;
7564 }
7565 *images=DestroyImageList(*images);
7566 *images=evaluate_image;
7567 break;
7568 }
7569 break;
7570 }
cristy3ed852e2009-09-05 21:47:34 +00007571 case 'f':
7572 {
cristyf0a247f2009-10-04 00:20:03 +00007573 if (LocaleCompare("fft",option+1) == 0)
7574 {
7575 Image
7576 *fourier_image;
7577
7578 /*
7579 Implements the discrete Fourier transform (DFT).
7580 */
cristy6fccee12011-10-20 18:43:18 +00007581 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007582 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7583 MagickTrue : MagickFalse,exception);
7584 if (fourier_image == (Image *) NULL)
7585 break;
7586 *images=DestroyImage(*images);
7587 *images=fourier_image;
7588 break;
7589 }
cristy3ed852e2009-09-05 21:47:34 +00007590 if (LocaleCompare("flatten",option+1) == 0)
7591 {
7592 Image
7593 *flatten_image;
7594
cristy6fccee12011-10-20 18:43:18 +00007595 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007596 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7597 if (flatten_image == (Image *) NULL)
7598 break;
7599 *images=DestroyImageList(*images);
7600 *images=flatten_image;
7601 break;
7602 }
7603 if (LocaleCompare("fx",option+1) == 0)
7604 {
7605 Image
7606 *fx_image;
7607
cristy6fccee12011-10-20 18:43:18 +00007608 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007609 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007610 if (fx_image == (Image *) NULL)
7611 {
7612 status=MagickFalse;
7613 break;
7614 }
7615 *images=DestroyImageList(*images);
7616 *images=fx_image;
7617 break;
7618 }
7619 break;
7620 }
7621 case 'h':
7622 {
7623 if (LocaleCompare("hald-clut",option+1) == 0)
7624 {
7625 Image
7626 *hald_image,
7627 *image;
7628
cristy6fccee12011-10-20 18:43:18 +00007629 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007630 image=RemoveFirstImageFromList(images);
7631 hald_image=RemoveFirstImageFromList(images);
7632 if (hald_image == (Image *) NULL)
7633 {
7634 status=MagickFalse;
7635 break;
7636 }
cristy7c0a0a42011-08-23 17:57:25 +00007637 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007638 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007639 if (*images != (Image *) NULL)
7640 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007641 *images=image;
7642 break;
7643 }
7644 break;
7645 }
7646 case 'i':
7647 {
7648 if (LocaleCompare("ift",option+1) == 0)
7649 {
7650 Image
cristy8587f882009-11-13 20:28:49 +00007651 *fourier_image,
7652 *magnitude_image,
7653 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007654
7655 /*
7656 Implements the inverse fourier discrete Fourier transform (DFT).
7657 */
cristy6fccee12011-10-20 18:43:18 +00007658 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007659 magnitude_image=RemoveFirstImageFromList(images);
7660 phase_image=RemoveFirstImageFromList(images);
7661 if (phase_image == (Image *) NULL)
7662 {
7663 status=MagickFalse;
7664 break;
7665 }
7666 fourier_image=InverseFourierTransformImage(magnitude_image,
7667 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007668 if (fourier_image == (Image *) NULL)
7669 break;
cristy0aff6ea2009-11-14 01:40:53 +00007670 if (*images != (Image *) NULL)
7671 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007672 *images=fourier_image;
7673 break;
7674 }
7675 if (LocaleCompare("insert",option+1) == 0)
7676 {
7677 Image
7678 *p,
7679 *q;
7680
7681 index=0;
7682 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007683 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007684 p=RemoveLastImageFromList(images);
7685 if (p == (Image *) NULL)
7686 {
7687 (void) ThrowMagickException(exception,GetMagickModule(),
7688 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7689 status=MagickFalse;
7690 break;
7691 }
7692 q=p;
7693 if (index == 0)
7694 PrependImageToList(images,q);
7695 else
cristybb503372010-05-27 20:51:26 +00007696 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007697 AppendImageToList(images,q);
7698 else
7699 {
7700 q=GetImageFromList(*images,index-1);
7701 if (q == (Image *) NULL)
7702 {
7703 (void) ThrowMagickException(exception,GetMagickModule(),
7704 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7705 status=MagickFalse;
7706 break;
7707 }
7708 InsertImageInList(&q,p);
7709 }
7710 *images=GetFirstImageInList(q);
7711 break;
7712 }
cristy28474bf2011-09-11 23:32:52 +00007713 if (LocaleCompare("interpolate",option+1) == 0)
7714 {
7715 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7716 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7717 break;
7718 }
cristy3ed852e2009-09-05 21:47:34 +00007719 break;
7720 }
7721 case 'l':
7722 {
7723 if (LocaleCompare("layers",option+1) == 0)
7724 {
7725 Image
7726 *layers;
7727
7728 ImageLayerMethod
7729 method;
7730
cristy6fccee12011-10-20 18:43:18 +00007731 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007732 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007733 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007734 MagickFalse,argv[i+1]);
7735 switch (method)
7736 {
7737 case CoalesceLayer:
7738 {
7739 layers=CoalesceImages(*images,exception);
7740 break;
7741 }
7742 case CompareAnyLayer:
7743 case CompareClearLayer:
7744 case CompareOverlayLayer:
7745 default:
7746 {
cristy8a9106f2011-07-05 14:39:26 +00007747 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007748 break;
7749 }
7750 case MergeLayer:
7751 case FlattenLayer:
7752 case MosaicLayer:
7753 case TrimBoundsLayer:
7754 {
7755 layers=MergeImageLayers(*images,method,exception);
7756 break;
7757 }
7758 case DisposeLayer:
7759 {
7760 layers=DisposeImages(*images,exception);
7761 break;
7762 }
7763 case OptimizeImageLayer:
7764 {
7765 layers=OptimizeImageLayers(*images,exception);
7766 break;
7767 }
7768 case OptimizePlusLayer:
7769 {
7770 layers=OptimizePlusImageLayers(*images,exception);
7771 break;
7772 }
7773 case OptimizeTransLayer:
7774 {
7775 OptimizeImageTransparency(*images,exception);
7776 break;
7777 }
7778 case RemoveDupsLayer:
7779 {
7780 RemoveDuplicateLayers(images,exception);
7781 break;
7782 }
7783 case RemoveZeroLayer:
7784 {
7785 RemoveZeroDelayLayers(images,exception);
7786 break;
7787 }
7788 case OptimizeLayer:
7789 {
7790 /*
7791 General Purpose, GIF Animation Optimizer.
7792 */
7793 layers=CoalesceImages(*images,exception);
7794 if (layers == (Image *) NULL)
7795 {
7796 status=MagickFalse;
7797 break;
7798 }
cristy3ed852e2009-09-05 21:47:34 +00007799 *images=DestroyImageList(*images);
7800 *images=layers;
7801 layers=OptimizeImageLayers(*images,exception);
7802 if (layers == (Image *) NULL)
7803 {
7804 status=MagickFalse;
7805 break;
7806 }
cristy3ed852e2009-09-05 21:47:34 +00007807 *images=DestroyImageList(*images);
7808 *images=layers;
7809 layers=(Image *) NULL;
7810 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007811 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7812 exception);
cristy3ed852e2009-09-05 21:47:34 +00007813 break;
7814 }
7815 case CompositeLayer:
7816 {
7817 CompositeOperator
7818 compose;
7819
7820 Image
7821 *source;
7822
7823 RectangleInfo
7824 geometry;
7825
7826 /*
7827 Split image sequence at the first 'NULL:' image.
7828 */
7829 source=(*images);
7830 while (source != (Image *) NULL)
7831 {
7832 source=GetNextImageInList(source);
7833 if ((source != (Image *) NULL) &&
7834 (LocaleCompare(source->magick,"NULL") == 0))
7835 break;
7836 }
7837 if (source != (Image *) NULL)
7838 {
7839 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7840 (GetNextImageInList(source) == (Image *) NULL))
7841 source=(Image *) NULL;
7842 else
7843 {
7844 /*
7845 Separate the two lists, junk the null: image.
7846 */
7847 source=SplitImageList(source->previous);
7848 DeleteImageFromList(&source);
7849 }
7850 }
7851 if (source == (Image *) NULL)
7852 {
7853 (void) ThrowMagickException(exception,GetMagickModule(),
7854 OptionError,"MissingNullSeparator","layers Composite");
7855 status=MagickFalse;
7856 break;
7857 }
7858 /*
7859 Adjust offset with gravity and virtual canvas.
7860 */
7861 SetGeometry(*images,&geometry);
7862 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7863 geometry.width=source->page.width != 0 ?
7864 source->page.width : source->columns;
7865 geometry.height=source->page.height != 0 ?
7866 source->page.height : source->rows;
7867 GravityAdjustGeometry((*images)->page.width != 0 ?
7868 (*images)->page.width : (*images)->columns,
7869 (*images)->page.height != 0 ? (*images)->page.height :
7870 (*images)->rows,(*images)->gravity,&geometry);
7871 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007872 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007873 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007874 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007875 MagickComposeOptions,MagickFalse,option);
7876 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7877 exception);
7878 source=DestroyImageList(source);
7879 break;
7880 }
7881 }
7882 if (layers == (Image *) NULL)
7883 break;
cristy3ed852e2009-09-05 21:47:34 +00007884 *images=DestroyImageList(*images);
7885 *images=layers;
7886 break;
7887 }
7888 break;
7889 }
7890 case 'm':
7891 {
7892 if (LocaleCompare("map",option+1) == 0)
7893 {
cristy6fccee12011-10-20 18:43:18 +00007894 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007895 if (*option == '+')
7896 {
cristy018f07f2011-09-04 21:15:19 +00007897 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7898 exception);
cristy3ed852e2009-09-05 21:47:34 +00007899 break;
7900 }
7901 i++;
7902 break;
7903 }
cristyf40785b2010-03-06 02:27:27 +00007904 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007905 {
7906 Image
cristyf40785b2010-03-06 02:27:27 +00007907 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007908
cristyd18ae7c2010-03-07 17:39:52 +00007909 /*
7910 Maximum image sequence (deprecated).
7911 */
cristy6fccee12011-10-20 18:43:18 +00007912 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007913 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007914 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007915 {
7916 status=MagickFalse;
7917 break;
7918 }
7919 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007920 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007921 break;
7922 }
cristyf40785b2010-03-06 02:27:27 +00007923 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007924 {
7925 Image
cristyf40785b2010-03-06 02:27:27 +00007926 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007927
cristyd18ae7c2010-03-07 17:39:52 +00007928 /*
7929 Minimum image sequence (deprecated).
7930 */
cristy6fccee12011-10-20 18:43:18 +00007931 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007932 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007933 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007934 {
7935 status=MagickFalse;
7936 break;
7937 }
7938 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007939 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007940 break;
7941 }
cristy3ed852e2009-09-05 21:47:34 +00007942 if (LocaleCompare("morph",option+1) == 0)
7943 {
7944 Image
7945 *morph_image;
7946
cristy6fccee12011-10-20 18:43:18 +00007947 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007948 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007949 exception);
7950 if (morph_image == (Image *) NULL)
7951 {
7952 status=MagickFalse;
7953 break;
7954 }
7955 *images=DestroyImageList(*images);
7956 *images=morph_image;
7957 break;
7958 }
7959 if (LocaleCompare("mosaic",option+1) == 0)
7960 {
7961 Image
7962 *mosaic_image;
7963
cristy6fccee12011-10-20 18:43:18 +00007964 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007965 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7966 if (mosaic_image == (Image *) NULL)
7967 {
7968 status=MagickFalse;
7969 break;
7970 }
7971 *images=DestroyImageList(*images);
7972 *images=mosaic_image;
7973 break;
7974 }
7975 break;
7976 }
7977 case 'p':
7978 {
7979 if (LocaleCompare("print",option+1) == 0)
7980 {
7981 char
7982 *string;
7983
cristy6fccee12011-10-20 18:43:18 +00007984 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007985 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7986 exception);
cristy3ed852e2009-09-05 21:47:34 +00007987 if (string == (char *) NULL)
7988 break;
cristyb51dff52011-05-19 16:55:47 +00007989 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007990 string=DestroyString(string);
7991 }
7992 if (LocaleCompare("process",option+1) == 0)
7993 {
7994 char
7995 **arguments;
7996
7997 int
7998 j,
7999 number_arguments;
8000
cristy6fccee12011-10-20 18:43:18 +00008001 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008002 arguments=StringToArgv(argv[i+1],&number_arguments);
8003 if (arguments == (char **) NULL)
8004 break;
8005 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8006 {
8007 char
8008 breaker,
8009 quote,
8010 *token;
8011
8012 const char
8013 *arguments;
8014
8015 int
8016 next,
8017 status;
8018
8019 size_t
8020 length;
8021
8022 TokenInfo
8023 *token_info;
8024
8025 /*
8026 Support old style syntax, filter="-option arg".
8027 */
8028 length=strlen(argv[i+1]);
8029 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008030 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008031 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8032 sizeof(*token));
8033 if (token == (char *) NULL)
8034 break;
8035 next=0;
8036 arguments=argv[i+1];
8037 token_info=AcquireTokenInfo();
8038 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8039 "\"",'\0',&breaker,&next,&quote);
8040 token_info=DestroyTokenInfo(token_info);
8041 if (status == 0)
8042 {
8043 const char
8044 *argv;
8045
8046 argv=(&(arguments[next]));
8047 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8048 exception);
8049 }
8050 token=DestroyString(token);
8051 break;
8052 }
cristy91c0da22010-05-02 01:44:07 +00008053 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008054 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8055 number_arguments-2,(const char **) arguments+2,exception);
8056 for (j=0; j < number_arguments; j++)
8057 arguments[j]=DestroyString(arguments[j]);
8058 arguments=(char **) RelinquishMagickMemory(arguments);
8059 break;
8060 }
8061 break;
8062 }
8063 case 'r':
8064 {
8065 if (LocaleCompare("reverse",option+1) == 0)
8066 {
8067 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008068 break;
8069 }
8070 break;
8071 }
8072 case 's':
8073 {
cristy4285d782011-02-09 20:12:28 +00008074 if (LocaleCompare("smush",option+1) == 0)
8075 {
8076 Image
8077 *smush_image;
8078
8079 ssize_t
8080 offset;
8081
cristy6fccee12011-10-20 18:43:18 +00008082 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008083 offset=(ssize_t) StringToLong(argv[i+1]);
8084 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8085 MagickFalse,offset,exception);
8086 if (smush_image == (Image *) NULL)
8087 {
8088 status=MagickFalse;
8089 break;
8090 }
8091 *images=DestroyImageList(*images);
8092 *images=smush_image;
8093 break;
8094 }
cristy3ed852e2009-09-05 21:47:34 +00008095 if (LocaleCompare("swap",option+1) == 0)
8096 {
8097 Image
8098 *p,
8099 *q,
8100 *swap;
8101
cristybb503372010-05-27 20:51:26 +00008102 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008103 swap_index;
8104
8105 index=(-1);
8106 swap_index=(-2);
8107 if (*option != '+')
8108 {
8109 GeometryInfo
8110 geometry_info;
8111
8112 MagickStatusType
8113 flags;
8114
8115 swap_index=(-1);
8116 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008117 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008118 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008119 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008120 }
8121 p=GetImageFromList(*images,index);
8122 q=GetImageFromList(*images,swap_index);
8123 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8124 {
8125 (void) ThrowMagickException(exception,GetMagickModule(),
8126 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8127 status=MagickFalse;
8128 break;
8129 }
8130 if (p == q)
8131 break;
8132 swap=CloneImage(p,0,0,MagickTrue,exception);
8133 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8134 ReplaceImageInList(&q,swap);
8135 *images=GetFirstImageInList(q);
8136 break;
8137 }
8138 break;
8139 }
8140 case 'w':
8141 {
8142 if (LocaleCompare("write",option+1) == 0)
8143 {
cristy071dd7b2010-04-09 13:04:54 +00008144 char
cristy06609ee2010-03-17 20:21:27 +00008145 key[MaxTextExtent];
8146
cristy3ed852e2009-09-05 21:47:34 +00008147 Image
8148 *write_images;
8149
8150 ImageInfo
8151 *write_info;
8152
cristy6fccee12011-10-20 18:43:18 +00008153 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008154 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008155 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008156 write_images=(*images);
8157 if (*option == '+')
8158 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008159 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008160 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8161 write_info=DestroyImageInfo(write_info);
8162 if (*option == '+')
8163 write_images=DestroyImageList(write_images);
8164 break;
8165 }
8166 break;
8167 }
8168 default:
8169 break;
8170 }
8171 i+=count;
8172 }
8173 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008174 mogrify_info=DestroyImageInfo(mogrify_info);
8175 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008176 return(status != 0 ? MagickTrue : MagickFalse);
8177}
8178
8179/*
8180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8181% %
8182% %
8183% %
8184+ M o g r i f y I m a g e s %
8185% %
8186% %
8187% %
8188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8189%
8190% MogrifyImages() applies image processing options to a sequence of images as
8191% prescribed by command line options.
8192%
8193% The format of the MogrifyImage method is:
8194%
8195% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8196% const MagickBooleanType post,const int argc,const char **argv,
8197% Image **images,Exceptioninfo *exception)
8198%
8199% A description of each parameter follows:
8200%
8201% o image_info: the image info..
8202%
8203% o post: If true, post process image list operators otherwise pre-process.
8204%
8205% o argc: Specifies a pointer to an integer describing the number of
8206% elements in the argument vector.
8207%
8208% o argv: Specifies a pointer to a text array containing the command line
8209% arguments.
8210%
anthonye9c27192011-03-27 08:07:06 +00008211% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008212%
8213% o exception: return any errors or warnings in this structure.
8214%
8215*/
8216WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8217 const MagickBooleanType post,const int argc,const char **argv,
8218 Image **images,ExceptionInfo *exception)
8219{
8220#define MogrifyImageTag "Mogrify/Image"
8221
anthonye9c27192011-03-27 08:07:06 +00008222 MagickStatusType
8223 status;
cristy3ed852e2009-09-05 21:47:34 +00008224
cristy0e9f9c12010-02-11 03:00:47 +00008225 MagickBooleanType
8226 proceed;
8227
anthonye9c27192011-03-27 08:07:06 +00008228 size_t
8229 n;
cristy3ed852e2009-09-05 21:47:34 +00008230
cristybb503372010-05-27 20:51:26 +00008231 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008232 i;
8233
cristy3ed852e2009-09-05 21:47:34 +00008234 assert(image_info != (ImageInfo *) NULL);
8235 assert(image_info->signature == MagickSignature);
8236 if (images == (Image **) NULL)
8237 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008238 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008239 assert((*images)->signature == MagickSignature);
8240 if ((*images)->debug != MagickFalse)
8241 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8242 (*images)->filename);
8243 if ((argc <= 0) || (*argv == (char *) NULL))
8244 return(MagickTrue);
8245 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8246 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008247 status=0;
anthonye9c27192011-03-27 08:07:06 +00008248
anthonyce2716b2011-04-22 09:51:34 +00008249#if 0
cristy1e604812011-05-19 18:07:50 +00008250 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8251 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008252#endif
8253
anthonye9c27192011-03-27 08:07:06 +00008254 /*
8255 Pre-process multi-image sequence operators
8256 */
cristy3ed852e2009-09-05 21:47:34 +00008257 if (post == MagickFalse)
8258 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008259 /*
8260 For each image, process simple single image operators
8261 */
8262 i=0;
8263 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008264 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008265 {
anthonyce2716b2011-04-22 09:51:34 +00008266#if 0
cristy1e604812011-05-19 18:07:50 +00008267 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8268 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008269#endif
anthonye9c27192011-03-27 08:07:06 +00008270 status&=MogrifyImage(image_info,argc,argv,images,exception);
8271 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008272 if (proceed == MagickFalse)
8273 break;
anthonye9c27192011-03-27 08:07:06 +00008274 if ( (*images)->next == (Image *) NULL )
8275 break;
8276 *images=(*images)->next;
8277 i++;
cristy3ed852e2009-09-05 21:47:34 +00008278 }
anthonye9c27192011-03-27 08:07:06 +00008279 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008280#if 0
cristy1e604812011-05-19 18:07:50 +00008281 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8282 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008283#endif
anthonye9c27192011-03-27 08:07:06 +00008284
8285 /*
8286 Post-process, multi-image sequence operators
8287 */
8288 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008289 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008290 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008291 return(status != 0 ? MagickTrue : MagickFalse);
8292}