blob: 0167c379053f8375c9a5fc5b6d29c34fa698689e [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"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-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)
cristyc1acd842011-05-19 23:05:47 +0000156 duration=InterpretLocaleValue(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
cristy4c08aed2011-07-01 19:47:50 +0000300/*
301** GetImageCache() will read an image into a image cache if not already
302** present then return the image that is in the cache under that filename.
303*/
anthonydf8ebac2011-04-27 09:03:19 +0000304static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
305 ExceptionInfo *exception)
306{
307 char
308 key[MaxTextExtent];
309
310 ExceptionInfo
311 *sans_exception;
312
313 Image
314 *image;
315
316 ImageInfo
317 *read_info;
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
cristy28474bf2011-09-11 23:32:52 +0000417 /*
418 SparseColorOption() parses the complex -sparse-color argument into an
419 an array of floating point values then calls SparseColorImage().
420 Argument is a complex mix of floating-point pixel coodinates, and color
421 specifications (or direct floating point numbers). The number of floats
422 needed to represent a color varies depending on the current channel
423 setting.
424 */
anthonydf8ebac2011-04-27 09:03:19 +0000425 assert(image != (Image *) NULL);
426 assert(image->signature == MagickSignature);
427 if (image->debug != MagickFalse)
428 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
429 assert(exception != (ExceptionInfo *) NULL);
430 assert(exception->signature == MagickSignature);
431 /*
432 Limit channels according to image - and add up number of color channel.
433 */
anthonydf8ebac2011-04-27 09:03:19 +0000434 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000435 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000436 number_colors++;
cristyed231572011-07-14 02:18:59 +0000437 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000438 number_colors++;
cristyed231572011-07-14 02:18:59 +0000439 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000440 number_colors++;
cristyed231572011-07-14 02:18:59 +0000441 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000442 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000443 number_colors++;
cristyed231572011-07-14 02:18:59 +0000444 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000445 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000446 number_colors++;
447
448 /*
449 Read string, to determine number of arguments needed,
450 */
451 p=arguments;
452 x=0;
453 while( *p != '\0' )
454 {
455 GetMagickToken(p,&p,token);
456 if ( token[0] == ',' ) continue;
457 if ( isalpha((int) token[0]) || token[0] == '#' ) {
458 if ( color_from_image ) {
459 (void) ThrowMagickException(exception,GetMagickModule(),
460 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
461 "Color arg given, when colors are coming from image");
462 return( (Image *)NULL);
463 }
464 x += number_colors; /* color argument */
465 }
466 else {
467 x++; /* floating point argument */
468 }
469 }
470 error=MagickTrue;
471 if ( color_from_image ) {
472 /* just the control points are being given */
473 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
474 number_arguments=(x/2)*(2+number_colors);
475 }
476 else {
477 /* control points and color values */
478 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
479 number_arguments=x;
480 }
481 if ( error ) {
482 (void) ThrowMagickException(exception,GetMagickModule(),
483 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
484 "Invalid number of Arguments");
485 return( (Image *)NULL);
486 }
487
488 /* Allocate and fill in the floating point arguments */
489 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
490 sizeof(*sparse_arguments));
491 if (sparse_arguments == (double *) NULL) {
492 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
493 "MemoryAllocationFailed","%s","SparseColorOption");
494 return( (Image *)NULL);
495 }
496 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
497 sizeof(*sparse_arguments));
498 p=arguments;
499 x=0;
500 while( *p != '\0' && x < number_arguments ) {
501 /* X coordinate */
502 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
503 if ( token[0] == '\0' ) break;
504 if ( isalpha((int) token[0]) || token[0] == '#' ) {
505 (void) ThrowMagickException(exception,GetMagickModule(),
506 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
507 "Color found, instead of X-coord");
508 error = MagickTrue;
509 break;
510 }
cristyc1acd842011-05-19 23:05:47 +0000511 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000512 /* Y coordinate */
513 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
514 if ( token[0] == '\0' ) break;
515 if ( isalpha((int) token[0]) || token[0] == '#' ) {
516 (void) ThrowMagickException(exception,GetMagickModule(),
517 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
518 "Color found, instead of Y-coord");
519 error = MagickTrue;
520 break;
521 }
cristyc1acd842011-05-19 23:05:47 +0000522 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000523 /* color values for this control point */
524#if 0
525 if ( (color_from_image ) {
526 /* get color from image */
527 /* HOW??? */
528 }
529 else
530#endif
531 {
532 /* color name or function given in string argument */
533 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
534 if ( token[0] == '\0' ) break;
535 if ( isalpha((int) token[0]) || token[0] == '#' ) {
536 /* Color string given */
537 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000538 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000539 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000540 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000541 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000542 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000543 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000544 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000545 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000546 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000547 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000548 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000549 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000550 }
551 else {
552 /* Colors given as a set of floating point values - experimental */
553 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000554 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000555 {
anthonydf8ebac2011-04-27 09:03:19 +0000556 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
557 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
558 break;
cristyc1acd842011-05-19 23:05:47 +0000559 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000560 token[0] = ','; /* used this token - get another */
561 }
cristyed231572011-07-14 02:18:59 +0000562 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000563 {
anthonydf8ebac2011-04-27 09:03:19 +0000564 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
565 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
566 break;
cristyc1acd842011-05-19 23:05:47 +0000567 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000568 token[0] = ','; /* used this token - get another */
569 }
cristyed231572011-07-14 02:18:59 +0000570 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000571 {
anthonydf8ebac2011-04-27 09:03:19 +0000572 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
573 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
574 break;
cristyc1acd842011-05-19 23:05:47 +0000575 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000576 token[0] = ','; /* used this token - get another */
577 }
cristyed231572011-07-14 02:18:59 +0000578 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000579 (image->colorspace == CMYKColorspace))
580 {
anthonydf8ebac2011-04-27 09:03:19 +0000581 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
582 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
583 break;
cristyc1acd842011-05-19 23:05:47 +0000584 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000585 token[0] = ','; /* used this token - get another */
586 }
cristyed231572011-07-14 02:18:59 +0000587 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000588 (image->matte != MagickFalse))
589 {
anthonydf8ebac2011-04-27 09:03:19 +0000590 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
591 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
592 break;
cristyc1acd842011-05-19 23:05:47 +0000593 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000594 token[0] = ','; /* used this token - get another */
595 }
596 }
597 }
598 }
599 if ( number_arguments != x && !error ) {
600 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
601 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
602 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
603 return( (Image *)NULL);
604 }
605 if ( error )
606 return( (Image *)NULL);
607
608 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000609 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
610 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000611 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
612 return( sparse_image );
613}
614
cristy3ed852e2009-09-05 21:47:34 +0000615WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
616 const char **argv,Image **image,ExceptionInfo *exception)
617{
anthonydf8ebac2011-04-27 09:03:19 +0000618 ChannelType
619 channel;
620
cristy633f0c62011-09-15 13:27:36 +0000621 CompositeOperator
622 compose;
623
anthonydf8ebac2011-04-27 09:03:19 +0000624 const char
625 *format,
626 *option;
627
628 DrawInfo
629 *draw_info;
630
631 GeometryInfo
632 geometry_info;
633
cristy3ed852e2009-09-05 21:47:34 +0000634 Image
635 *region_image;
636
anthonydf8ebac2011-04-27 09:03:19 +0000637 ImageInfo
638 *mogrify_info;
639
cristyebbcfea2011-02-25 02:43:54 +0000640 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000641 status;
642
cristy4c08aed2011-07-01 19:47:50 +0000643 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000644 fill;
cristy3ed852e2009-09-05 21:47:34 +0000645
anthonydf8ebac2011-04-27 09:03:19 +0000646 MagickStatusType
647 flags;
648
cristy28474bf2011-09-11 23:32:52 +0000649 PixelInterpolateMethod
650 interpolate_method;
651
anthonydf8ebac2011-04-27 09:03:19 +0000652 QuantizeInfo
653 *quantize_info;
654
655 RectangleInfo
656 geometry,
657 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000658
cristybb503372010-05-27 20:51:26 +0000659 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000660 i;
661
662 /*
663 Initialize method variables.
664 */
665 assert(image_info != (const ImageInfo *) NULL);
666 assert(image_info->signature == MagickSignature);
667 assert(image != (Image **) NULL);
668 assert((*image)->signature == MagickSignature);
669 if ((*image)->debug != MagickFalse)
670 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
671 if (argc < 0)
672 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000673 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000674 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
675 quantize_info=AcquireQuantizeInfo(mogrify_info);
676 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000677 GetPixelInfo(*image,&fill);
678 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
cristy633f0c62011-09-15 13:27:36 +0000679 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000680 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000681 channel=mogrify_info->channel;
682 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000683 SetGeometry(*image,&region_geometry);
684 region_image=NewImageList();
685 /*
686 Transmogrify the image.
687 */
cristybb503372010-05-27 20:51:26 +0000688 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000689 {
anthonydf8ebac2011-04-27 09:03:19 +0000690 Image
691 *mogrify_image;
692
anthonye9c27192011-03-27 08:07:06 +0000693 ssize_t
694 count;
695
anthonydf8ebac2011-04-27 09:03:19 +0000696 option=argv[i];
697 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000698 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000699 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
700 0L);
cristycee97112010-05-28 00:44:52 +0000701 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000702 break;
cristy6b3da3a2010-06-20 02:21:46 +0000703 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000704 mogrify_image=(Image *)NULL;
705 switch (*(option+1))
706 {
707 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000708 {
anthonydf8ebac2011-04-27 09:03:19 +0000709 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000710 {
anthonydf8ebac2011-04-27 09:03:19 +0000711 /*
712 Adaptive blur image.
713 */
714 (void) SyncImageSettings(mogrify_info,*image);
715 flags=ParseGeometry(argv[i+1],&geometry_info);
716 if ((flags & SigmaValue) == 0)
717 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000718 if ((flags & XiValue) == 0)
719 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000720 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000721 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000722 break;
cristy3ed852e2009-09-05 21:47:34 +0000723 }
anthonydf8ebac2011-04-27 09:03:19 +0000724 if (LocaleCompare("adaptive-resize",option+1) == 0)
725 {
726 /*
727 Adaptive resize image.
728 */
729 (void) SyncImageSettings(mogrify_info,*image);
730 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
731 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000732 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000733 break;
734 }
735 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
736 {
737 /*
738 Adaptive sharpen image.
739 */
740 (void) SyncImageSettings(mogrify_info,*image);
741 flags=ParseGeometry(argv[i+1],&geometry_info);
742 if ((flags & SigmaValue) == 0)
743 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000744 if ((flags & XiValue) == 0)
745 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000746 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000747 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000748 break;
749 }
750 if (LocaleCompare("affine",option+1) == 0)
751 {
752 /*
753 Affine matrix.
754 */
755 if (*option == '+')
756 {
757 GetAffineMatrix(&draw_info->affine);
758 break;
759 }
760 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
761 break;
762 }
763 if (LocaleCompare("alpha",option+1) == 0)
764 {
765 AlphaChannelType
766 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000767
anthonydf8ebac2011-04-27 09:03:19 +0000768 (void) SyncImageSettings(mogrify_info,*image);
769 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
770 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000771 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000772 break;
773 }
774 if (LocaleCompare("annotate",option+1) == 0)
775 {
776 char
777 *text,
778 geometry[MaxTextExtent];
779
780 /*
781 Annotate image.
782 */
783 (void) SyncImageSettings(mogrify_info,*image);
784 SetGeometryInfo(&geometry_info);
785 flags=ParseGeometry(argv[i+1],&geometry_info);
786 if ((flags & SigmaValue) == 0)
787 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000788 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
789 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000790 if (text == (char *) NULL)
791 break;
792 (void) CloneString(&draw_info->text,text);
793 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000794 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000795 geometry_info.xi,geometry_info.psi);
796 (void) CloneString(&draw_info->geometry,geometry);
797 draw_info->affine.sx=cos(DegreesToRadians(
798 fmod(geometry_info.rho,360.0)));
799 draw_info->affine.rx=sin(DegreesToRadians(
800 fmod(geometry_info.rho,360.0)));
801 draw_info->affine.ry=(-sin(DegreesToRadians(
802 fmod(geometry_info.sigma,360.0))));
803 draw_info->affine.sy=cos(DegreesToRadians(
804 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000805 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000806 break;
807 }
808 if (LocaleCompare("antialias",option+1) == 0)
809 {
810 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
811 MagickFalse;
812 draw_info->text_antialias=(*option == '-') ? MagickTrue :
813 MagickFalse;
814 break;
815 }
816 if (LocaleCompare("auto-gamma",option+1) == 0)
817 {
818 /*
819 Auto Adjust Gamma of image based on its mean
820 */
821 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000822 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000823 break;
824 }
825 if (LocaleCompare("auto-level",option+1) == 0)
826 {
827 /*
828 Perfectly Normalize (max/min stretch) the image
829 */
830 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000831 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000832 break;
833 }
834 if (LocaleCompare("auto-orient",option+1) == 0)
835 {
836 (void) SyncImageSettings(mogrify_info,*image);
837 switch ((*image)->orientation)
838 {
839 case TopRightOrientation:
840 {
841 mogrify_image=FlopImage(*image,exception);
842 break;
843 }
844 case BottomRightOrientation:
845 {
846 mogrify_image=RotateImage(*image,180.0,exception);
847 break;
848 }
849 case BottomLeftOrientation:
850 {
851 mogrify_image=FlipImage(*image,exception);
852 break;
853 }
854 case LeftTopOrientation:
855 {
856 mogrify_image=TransposeImage(*image,exception);
857 break;
858 }
859 case RightTopOrientation:
860 {
861 mogrify_image=RotateImage(*image,90.0,exception);
862 break;
863 }
864 case RightBottomOrientation:
865 {
866 mogrify_image=TransverseImage(*image,exception);
867 break;
868 }
869 case LeftBottomOrientation:
870 {
871 mogrify_image=RotateImage(*image,270.0,exception);
872 break;
873 }
874 default:
875 break;
876 }
877 if (mogrify_image != (Image *) NULL)
878 mogrify_image->orientation=TopLeftOrientation;
879 break;
880 }
881 break;
882 }
883 case 'b':
884 {
885 if (LocaleCompare("black-threshold",option+1) == 0)
886 {
887 /*
888 Black threshold image.
889 */
890 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000891 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000892 InheritException(exception,&(*image)->exception);
893 break;
894 }
895 if (LocaleCompare("blue-shift",option+1) == 0)
896 {
897 /*
898 Blue shift image.
899 */
900 (void) SyncImageSettings(mogrify_info,*image);
901 geometry_info.rho=1.5;
902 if (*option == '-')
903 flags=ParseGeometry(argv[i+1],&geometry_info);
904 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
905 break;
906 }
907 if (LocaleCompare("blur",option+1) == 0)
908 {
909 /*
910 Gaussian blur image.
911 */
912 (void) SyncImageSettings(mogrify_info,*image);
913 flags=ParseGeometry(argv[i+1],&geometry_info);
914 if ((flags & SigmaValue) == 0)
915 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000916 if ((flags & XiValue) == 0)
917 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000918 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000919 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000920 break;
921 }
922 if (LocaleCompare("border",option+1) == 0)
923 {
924 /*
925 Surround image with a border of solid color.
926 */
927 (void) SyncImageSettings(mogrify_info,*image);
928 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
929 if ((flags & SigmaValue) == 0)
930 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000931 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000932 break;
933 }
934 if (LocaleCompare("bordercolor",option+1) == 0)
935 {
936 if (*option == '+')
937 {
cristy05c0c9a2011-09-05 23:16:13 +0000938 (void) QueryColorDatabase(MogrifyBorderColor,
939 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000940 break;
941 }
942 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
943 exception);
944 break;
945 }
946 if (LocaleCompare("box",option+1) == 0)
947 {
948 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
949 exception);
950 break;
951 }
952 if (LocaleCompare("brightness-contrast",option+1) == 0)
953 {
954 double
955 brightness,
956 contrast;
957
958 GeometryInfo
959 geometry_info;
960
961 MagickStatusType
962 flags;
963
964 /*
965 Brightness / contrast image.
966 */
967 (void) SyncImageSettings(mogrify_info,*image);
968 flags=ParseGeometry(argv[i+1],&geometry_info);
969 brightness=geometry_info.rho;
970 contrast=0.0;
971 if ((flags & SigmaValue) != 0)
972 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000973 (void) BrightnessContrastImage(*image,brightness,contrast,
974 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000975 InheritException(exception,&(*image)->exception);
976 break;
977 }
978 break;
979 }
980 case 'c':
981 {
982 if (LocaleCompare("cdl",option+1) == 0)
983 {
984 char
985 *color_correction_collection;
986
987 /*
988 Color correct with a color decision list.
989 */
990 (void) SyncImageSettings(mogrify_info,*image);
991 color_correction_collection=FileToString(argv[i+1],~0,exception);
992 if (color_correction_collection == (char *) NULL)
993 break;
cristy1bfa9f02011-08-11 02:35:43 +0000994 (void) ColorDecisionListImage(*image,color_correction_collection,
995 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000996 InheritException(exception,&(*image)->exception);
997 break;
998 }
999 if (LocaleCompare("channel",option+1) == 0)
1000 {
1001 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001002 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001003 else
cristyfa806a72011-07-04 02:06:13 +00001004 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00001005 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001006 break;
1007 }
1008 if (LocaleCompare("charcoal",option+1) == 0)
1009 {
1010 /*
1011 Charcoal image.
1012 */
1013 (void) SyncImageSettings(mogrify_info,*image);
1014 flags=ParseGeometry(argv[i+1],&geometry_info);
1015 if ((flags & SigmaValue) == 0)
1016 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001017 if ((flags & XiValue) == 0)
1018 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001019 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001020 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001021 break;
1022 }
1023 if (LocaleCompare("chop",option+1) == 0)
1024 {
1025 /*
1026 Chop the image.
1027 */
1028 (void) SyncImageSettings(mogrify_info,*image);
1029 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1030 mogrify_image=ChopImage(*image,&geometry,exception);
1031 break;
1032 }
1033 if (LocaleCompare("clamp",option+1) == 0)
1034 {
1035 /*
1036 Clamp image.
1037 */
1038 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001039 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001040 InheritException(exception,&(*image)->exception);
1041 break;
1042 }
1043 if (LocaleCompare("clip",option+1) == 0)
1044 {
1045 (void) SyncImageSettings(mogrify_info,*image);
1046 if (*option == '+')
1047 {
cristy018f07f2011-09-04 21:15:19 +00001048 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001049 break;
1050 }
cristy018f07f2011-09-04 21:15:19 +00001051 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001052 break;
1053 }
1054 if (LocaleCompare("clip-mask",option+1) == 0)
1055 {
1056 CacheView
1057 *mask_view;
1058
1059 Image
1060 *mask_image;
1061
cristy4c08aed2011-07-01 19:47:50 +00001062 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001063 *restrict q;
1064
1065 register ssize_t
1066 x;
1067
1068 ssize_t
1069 y;
1070
1071 (void) SyncImageSettings(mogrify_info,*image);
1072 if (*option == '+')
1073 {
1074 /*
1075 Remove a mask.
1076 */
cristy018f07f2011-09-04 21:15:19 +00001077 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001078 break;
1079 }
1080 /*
1081 Set the image mask.
1082 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1083 */
1084 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1085 if (mask_image == (Image *) NULL)
1086 break;
cristy574cc262011-08-05 01:23:58 +00001087 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001088 return(MagickFalse);
1089 mask_view=AcquireCacheView(mask_image);
1090 for (y=0; y < (ssize_t) mask_image->rows; y++)
1091 {
1092 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1093 exception);
cristyacd2ed22011-08-30 01:44:23 +00001094 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001095 break;
1096 for (x=0; x < (ssize_t) mask_image->columns; x++)
1097 {
1098 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001099 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1100 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1101 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1102 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001103 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001104 }
1105 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1106 break;
1107 }
1108 mask_view=DestroyCacheView(mask_view);
1109 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001110 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001111 InheritException(exception,&(*image)->exception);
1112 break;
1113 }
1114 if (LocaleCompare("clip-path",option+1) == 0)
1115 {
1116 (void) SyncImageSettings(mogrify_info,*image);
1117 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001118 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001119 break;
1120 }
1121 if (LocaleCompare("colorize",option+1) == 0)
1122 {
1123 /*
1124 Colorize the image.
1125 */
1126 (void) SyncImageSettings(mogrify_info,*image);
1127 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1128 exception);
1129 break;
1130 }
1131 if (LocaleCompare("color-matrix",option+1) == 0)
1132 {
1133 KernelInfo
1134 *kernel;
1135
1136 (void) SyncImageSettings(mogrify_info,*image);
1137 kernel=AcquireKernelInfo(argv[i+1]);
1138 if (kernel == (KernelInfo *) NULL)
1139 break;
1140 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1141 kernel=DestroyKernelInfo(kernel);
1142 break;
1143 }
1144 if (LocaleCompare("colors",option+1) == 0)
1145 {
1146 /*
1147 Reduce the number of colors in the image.
1148 */
1149 (void) SyncImageSettings(mogrify_info,*image);
1150 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1151 if (quantize_info->number_colors == 0)
1152 break;
1153 if (((*image)->storage_class == DirectClass) ||
1154 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001155 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001156 else
cristy018f07f2011-09-04 21:15:19 +00001157 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001158 break;
1159 }
1160 if (LocaleCompare("colorspace",option+1) == 0)
1161 {
1162 ColorspaceType
1163 colorspace;
1164
1165 (void) SyncImageSettings(mogrify_info,*image);
1166 if (*option == '+')
1167 {
1168 (void) TransformImageColorspace(*image,RGBColorspace);
1169 InheritException(exception,&(*image)->exception);
1170 break;
1171 }
1172 colorspace=(ColorspaceType) ParseCommandOption(
1173 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1174 (void) TransformImageColorspace(*image,colorspace);
1175 InheritException(exception,&(*image)->exception);
1176 break;
1177 }
cristy633f0c62011-09-15 13:27:36 +00001178 if (LocaleCompare("compose",option+1) == 0)
1179 {
1180 (void) SyncImageSettings(mogrify_info,*image);
1181 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1182 MagickFalse,argv[i+1]);
1183 break;
1184 }
anthonydf8ebac2011-04-27 09:03:19 +00001185 if (LocaleCompare("contrast",option+1) == 0)
1186 {
1187 (void) SyncImageSettings(mogrify_info,*image);
1188 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001189 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001190 break;
1191 }
1192 if (LocaleCompare("contrast-stretch",option+1) == 0)
1193 {
1194 double
1195 black_point,
1196 white_point;
1197
1198 MagickStatusType
1199 flags;
1200
1201 /*
1202 Contrast stretch image.
1203 */
1204 (void) SyncImageSettings(mogrify_info,*image);
1205 flags=ParseGeometry(argv[i+1],&geometry_info);
1206 black_point=geometry_info.rho;
1207 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1208 black_point;
1209 if ((flags & PercentValue) != 0)
1210 {
1211 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1212 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1213 }
1214 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1215 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001216 (void) ContrastStretchImage(*image,black_point,white_point,
1217 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001218 InheritException(exception,&(*image)->exception);
1219 break;
1220 }
1221 if (LocaleCompare("convolve",option+1) == 0)
1222 {
anthonydf8ebac2011-04-27 09:03:19 +00001223 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001224 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001225
anthonydf8ebac2011-04-27 09:03:19 +00001226 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001227 kernel_info=AcquireKernelInfo(argv[i+1]);
1228 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001229 break;
cristy0a922382011-07-16 15:30:34 +00001230 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001231 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001232 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001233 break;
1234 }
1235 if (LocaleCompare("crop",option+1) == 0)
1236 {
1237 /*
1238 Crop a image to a smaller size
1239 */
1240 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001241 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001242 break;
1243 }
1244 if (LocaleCompare("cycle",option+1) == 0)
1245 {
1246 /*
1247 Cycle an image colormap.
1248 */
1249 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001250 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1251 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001252 break;
1253 }
1254 break;
1255 }
1256 case 'd':
1257 {
1258 if (LocaleCompare("decipher",option+1) == 0)
1259 {
1260 StringInfo
1261 *passkey;
1262
1263 /*
1264 Decipher pixels.
1265 */
1266 (void) SyncImageSettings(mogrify_info,*image);
1267 passkey=FileToStringInfo(argv[i+1],~0,exception);
1268 if (passkey != (StringInfo *) NULL)
1269 {
1270 (void) PasskeyDecipherImage(*image,passkey,exception);
1271 passkey=DestroyStringInfo(passkey);
1272 }
1273 break;
1274 }
1275 if (LocaleCompare("density",option+1) == 0)
1276 {
1277 /*
1278 Set image density.
1279 */
1280 (void) CloneString(&draw_info->density,argv[i+1]);
1281 break;
1282 }
1283 if (LocaleCompare("depth",option+1) == 0)
1284 {
1285 (void) SyncImageSettings(mogrify_info,*image);
1286 if (*option == '+')
1287 {
1288 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1289 break;
1290 }
1291 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1292 break;
1293 }
1294 if (LocaleCompare("deskew",option+1) == 0)
1295 {
1296 double
1297 threshold;
1298
1299 /*
1300 Straighten the image.
1301 */
1302 (void) SyncImageSettings(mogrify_info,*image);
1303 if (*option == '+')
1304 threshold=40.0*QuantumRange/100.0;
1305 else
1306 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1307 mogrify_image=DeskewImage(*image,threshold,exception);
1308 break;
1309 }
1310 if (LocaleCompare("despeckle",option+1) == 0)
1311 {
1312 /*
1313 Reduce the speckles within an image.
1314 */
1315 (void) SyncImageSettings(mogrify_info,*image);
1316 mogrify_image=DespeckleImage(*image,exception);
1317 break;
1318 }
1319 if (LocaleCompare("display",option+1) == 0)
1320 {
1321 (void) CloneString(&draw_info->server_name,argv[i+1]);
1322 break;
1323 }
1324 if (LocaleCompare("distort",option+1) == 0)
1325 {
1326 char
1327 *args,
1328 token[MaxTextExtent];
1329
1330 const char
1331 *p;
1332
1333 DistortImageMethod
1334 method;
1335
1336 double
1337 *arguments;
1338
1339 register ssize_t
1340 x;
1341
1342 size_t
1343 number_arguments;
1344
1345 /*
1346 Distort image.
1347 */
1348 (void) SyncImageSettings(mogrify_info,*image);
1349 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1350 MagickFalse,argv[i+1]);
1351 if ( method == ResizeDistortion )
1352 {
1353 /* Special Case - Argument is actually a resize geometry!
1354 ** Convert that to an appropriate distortion argument array.
1355 */
1356 double
1357 resize_args[2];
1358 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1359 exception);
1360 resize_args[0]=(double)geometry.width;
1361 resize_args[1]=(double)geometry.height;
1362 mogrify_image=DistortImage(*image,method,(size_t)2,
1363 resize_args,MagickTrue,exception);
1364 break;
1365 }
cristy018f07f2011-09-04 21:15:19 +00001366 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1367 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001368 if (args == (char *) NULL)
1369 break;
1370 p=(char *) args;
1371 for (x=0; *p != '\0'; x++)
1372 {
1373 GetMagickToken(p,&p,token);
1374 if (*token == ',')
1375 GetMagickToken(p,&p,token);
1376 }
1377 number_arguments=(size_t) x;
1378 arguments=(double *) AcquireQuantumMemory(number_arguments,
1379 sizeof(*arguments));
1380 if (arguments == (double *) NULL)
1381 ThrowWandFatalException(ResourceLimitFatalError,
1382 "MemoryAllocationFailed",(*image)->filename);
1383 (void) ResetMagickMemory(arguments,0,number_arguments*
1384 sizeof(*arguments));
1385 p=(char *) args;
1386 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1387 {
1388 GetMagickToken(p,&p,token);
1389 if (*token == ',')
1390 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001391 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001392 }
1393 args=DestroyString(args);
1394 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1395 (*option == '+') ? MagickTrue : MagickFalse,exception);
1396 arguments=(double *) RelinquishMagickMemory(arguments);
1397 break;
1398 }
1399 if (LocaleCompare("dither",option+1) == 0)
1400 {
1401 if (*option == '+')
1402 {
1403 quantize_info->dither=MagickFalse;
1404 break;
1405 }
1406 quantize_info->dither=MagickTrue;
1407 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1408 MagickDitherOptions,MagickFalse,argv[i+1]);
1409 if (quantize_info->dither_method == NoDitherMethod)
1410 quantize_info->dither=MagickFalse;
1411 break;
1412 }
1413 if (LocaleCompare("draw",option+1) == 0)
1414 {
1415 /*
1416 Draw image.
1417 */
1418 (void) SyncImageSettings(mogrify_info,*image);
1419 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001420 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001421 break;
1422 }
1423 break;
1424 }
1425 case 'e':
1426 {
1427 if (LocaleCompare("edge",option+1) == 0)
1428 {
1429 /*
1430 Enhance edges in the image.
1431 */
1432 (void) SyncImageSettings(mogrify_info,*image);
1433 flags=ParseGeometry(argv[i+1],&geometry_info);
1434 if ((flags & SigmaValue) == 0)
1435 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001436 mogrify_image=EdgeImage(*image,geometry_info.rho,
1437 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001438 break;
1439 }
1440 if (LocaleCompare("emboss",option+1) == 0)
1441 {
1442 /*
1443 Gaussian embossen image.
1444 */
1445 (void) SyncImageSettings(mogrify_info,*image);
1446 flags=ParseGeometry(argv[i+1],&geometry_info);
1447 if ((flags & SigmaValue) == 0)
1448 geometry_info.sigma=1.0;
1449 mogrify_image=EmbossImage(*image,geometry_info.rho,
1450 geometry_info.sigma,exception);
1451 break;
1452 }
1453 if (LocaleCompare("encipher",option+1) == 0)
1454 {
1455 StringInfo
1456 *passkey;
1457
1458 /*
1459 Encipher pixels.
1460 */
1461 (void) SyncImageSettings(mogrify_info,*image);
1462 passkey=FileToStringInfo(argv[i+1],~0,exception);
1463 if (passkey != (StringInfo *) NULL)
1464 {
1465 (void) PasskeyEncipherImage(*image,passkey,exception);
1466 passkey=DestroyStringInfo(passkey);
1467 }
1468 break;
1469 }
1470 if (LocaleCompare("encoding",option+1) == 0)
1471 {
1472 (void) CloneString(&draw_info->encoding,argv[i+1]);
1473 break;
1474 }
1475 if (LocaleCompare("enhance",option+1) == 0)
1476 {
1477 /*
1478 Enhance image.
1479 */
1480 (void) SyncImageSettings(mogrify_info,*image);
1481 mogrify_image=EnhanceImage(*image,exception);
1482 break;
1483 }
1484 if (LocaleCompare("equalize",option+1) == 0)
1485 {
1486 /*
1487 Equalize image.
1488 */
1489 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001490 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001491 break;
1492 }
1493 if (LocaleCompare("evaluate",option+1) == 0)
1494 {
1495 double
1496 constant;
1497
1498 MagickEvaluateOperator
1499 op;
1500
1501 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001502 op=(MagickEvaluateOperator) ParseCommandOption(
1503 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001504 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001505 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001506 break;
1507 }
1508 if (LocaleCompare("extent",option+1) == 0)
1509 {
1510 /*
1511 Set the image extent.
1512 */
1513 (void) SyncImageSettings(mogrify_info,*image);
1514 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1515 if (geometry.width == 0)
1516 geometry.width=(*image)->columns;
1517 if (geometry.height == 0)
1518 geometry.height=(*image)->rows;
1519 mogrify_image=ExtentImage(*image,&geometry,exception);
1520 break;
1521 }
1522 break;
1523 }
1524 case 'f':
1525 {
1526 if (LocaleCompare("family",option+1) == 0)
1527 {
1528 if (*option == '+')
1529 {
1530 if (draw_info->family != (char *) NULL)
1531 draw_info->family=DestroyString(draw_info->family);
1532 break;
1533 }
1534 (void) CloneString(&draw_info->family,argv[i+1]);
1535 break;
1536 }
1537 if (LocaleCompare("features",option+1) == 0)
1538 {
1539 if (*option == '+')
1540 {
1541 (void) DeleteImageArtifact(*image,"identify:features");
1542 break;
1543 }
1544 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1545 break;
1546 }
1547 if (LocaleCompare("fill",option+1) == 0)
1548 {
1549 ExceptionInfo
1550 *sans;
1551
cristy4c08aed2011-07-01 19:47:50 +00001552 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001553 if (*option == '+')
1554 {
1555 (void) QueryMagickColor("none",&fill,exception);
1556 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1557 if (draw_info->fill_pattern != (Image *) NULL)
1558 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1559 break;
1560 }
1561 sans=AcquireExceptionInfo();
1562 (void) QueryMagickColor(argv[i+1],&fill,sans);
1563 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1564 sans=DestroyExceptionInfo(sans);
1565 if (status == MagickFalse)
1566 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1567 exception);
1568 break;
1569 }
1570 if (LocaleCompare("flip",option+1) == 0)
1571 {
1572 /*
1573 Flip image scanlines.
1574 */
1575 (void) SyncImageSettings(mogrify_info,*image);
1576 mogrify_image=FlipImage(*image,exception);
1577 break;
1578 }
anthonydf8ebac2011-04-27 09:03:19 +00001579 if (LocaleCompare("floodfill",option+1) == 0)
1580 {
cristy4c08aed2011-07-01 19:47:50 +00001581 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001582 target;
1583
1584 /*
1585 Floodfill image.
1586 */
1587 (void) SyncImageSettings(mogrify_info,*image);
1588 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1589 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001590 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001591 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001592 break;
1593 }
anthony3d2f4862011-05-01 13:48:16 +00001594 if (LocaleCompare("flop",option+1) == 0)
1595 {
1596 /*
1597 Flop image scanlines.
1598 */
1599 (void) SyncImageSettings(mogrify_info,*image);
1600 mogrify_image=FlopImage(*image,exception);
1601 break;
1602 }
anthonydf8ebac2011-04-27 09:03:19 +00001603 if (LocaleCompare("font",option+1) == 0)
1604 {
1605 if (*option == '+')
1606 {
1607 if (draw_info->font != (char *) NULL)
1608 draw_info->font=DestroyString(draw_info->font);
1609 break;
1610 }
1611 (void) CloneString(&draw_info->font,argv[i+1]);
1612 break;
1613 }
1614 if (LocaleCompare("format",option+1) == 0)
1615 {
1616 format=argv[i+1];
1617 break;
1618 }
1619 if (LocaleCompare("frame",option+1) == 0)
1620 {
1621 FrameInfo
1622 frame_info;
1623
1624 /*
1625 Surround image with an ornamental border.
1626 */
1627 (void) SyncImageSettings(mogrify_info,*image);
1628 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1629 frame_info.width=geometry.width;
1630 frame_info.height=geometry.height;
1631 if ((flags & HeightValue) == 0)
1632 frame_info.height=geometry.width;
1633 frame_info.outer_bevel=geometry.x;
1634 frame_info.inner_bevel=geometry.y;
1635 frame_info.x=(ssize_t) frame_info.width;
1636 frame_info.y=(ssize_t) frame_info.height;
1637 frame_info.width=(*image)->columns+2*frame_info.width;
1638 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001639 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001640 break;
1641 }
1642 if (LocaleCompare("function",option+1) == 0)
1643 {
1644 char
1645 *arguments,
1646 token[MaxTextExtent];
1647
1648 const char
1649 *p;
1650
1651 double
1652 *parameters;
1653
1654 MagickFunction
1655 function;
1656
1657 register ssize_t
1658 x;
1659
1660 size_t
1661 number_parameters;
1662
1663 /*
1664 Function Modify Image Values
1665 */
1666 (void) SyncImageSettings(mogrify_info,*image);
1667 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1668 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001669 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1670 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001671 if (arguments == (char *) NULL)
1672 break;
1673 p=(char *) arguments;
1674 for (x=0; *p != '\0'; x++)
1675 {
1676 GetMagickToken(p,&p,token);
1677 if (*token == ',')
1678 GetMagickToken(p,&p,token);
1679 }
1680 number_parameters=(size_t) x;
1681 parameters=(double *) AcquireQuantumMemory(number_parameters,
1682 sizeof(*parameters));
1683 if (parameters == (double *) NULL)
1684 ThrowWandFatalException(ResourceLimitFatalError,
1685 "MemoryAllocationFailed",(*image)->filename);
1686 (void) ResetMagickMemory(parameters,0,number_parameters*
1687 sizeof(*parameters));
1688 p=(char *) arguments;
1689 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1690 {
1691 GetMagickToken(p,&p,token);
1692 if (*token == ',')
1693 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001694 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001695 }
1696 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001697 (void) FunctionImage(*image,function,number_parameters,parameters,
1698 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001699 parameters=(double *) RelinquishMagickMemory(parameters);
1700 break;
1701 }
1702 break;
1703 }
1704 case 'g':
1705 {
1706 if (LocaleCompare("gamma",option+1) == 0)
1707 {
1708 /*
1709 Gamma image.
1710 */
1711 (void) SyncImageSettings(mogrify_info,*image);
1712 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001713 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001714 else
cristyb3e7c6c2011-07-24 01:43:55 +00001715 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1716 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001717 break;
1718 }
1719 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1720 (LocaleCompare("gaussian",option+1) == 0))
1721 {
1722 /*
1723 Gaussian blur image.
1724 */
1725 (void) SyncImageSettings(mogrify_info,*image);
1726 flags=ParseGeometry(argv[i+1],&geometry_info);
1727 if ((flags & SigmaValue) == 0)
1728 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001729 if ((flags & XiValue) == 0)
1730 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001731 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001732 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001733 break;
1734 }
1735 if (LocaleCompare("geometry",option+1) == 0)
1736 {
1737 /*
1738 Record Image offset, Resize last image.
1739 */
1740 (void) SyncImageSettings(mogrify_info,*image);
1741 if (*option == '+')
1742 {
1743 if ((*image)->geometry != (char *) NULL)
1744 (*image)->geometry=DestroyString((*image)->geometry);
1745 break;
1746 }
1747 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1748 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1749 (void) CloneString(&(*image)->geometry,argv[i+1]);
1750 else
1751 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1752 (*image)->filter,(*image)->blur,exception);
1753 break;
1754 }
1755 if (LocaleCompare("gravity",option+1) == 0)
1756 {
1757 if (*option == '+')
1758 {
1759 draw_info->gravity=UndefinedGravity;
1760 break;
1761 }
1762 draw_info->gravity=(GravityType) ParseCommandOption(
1763 MagickGravityOptions,MagickFalse,argv[i+1]);
1764 break;
1765 }
1766 break;
1767 }
1768 case 'h':
1769 {
1770 if (LocaleCompare("highlight-color",option+1) == 0)
1771 {
1772 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1773 break;
1774 }
1775 break;
1776 }
1777 case 'i':
1778 {
1779 if (LocaleCompare("identify",option+1) == 0)
1780 {
1781 char
1782 *text;
1783
1784 (void) SyncImageSettings(mogrify_info,*image);
1785 if (format == (char *) NULL)
1786 {
cristya4037272011-08-28 15:11:39 +00001787 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1788 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001789 break;
1790 }
cristy018f07f2011-09-04 21:15:19 +00001791 text=InterpretImageProperties(mogrify_info,*image,format,
1792 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001793 if (text == (char *) NULL)
1794 break;
1795 (void) fputs(text,stdout);
1796 (void) fputc('\n',stdout);
1797 text=DestroyString(text);
1798 break;
1799 }
1800 if (LocaleCompare("implode",option+1) == 0)
1801 {
1802 /*
1803 Implode image.
1804 */
1805 (void) SyncImageSettings(mogrify_info,*image);
1806 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001807 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1808 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001809 break;
1810 }
1811 if (LocaleCompare("interline-spacing",option+1) == 0)
1812 {
1813 if (*option == '+')
1814 (void) ParseGeometry("0",&geometry_info);
1815 else
1816 (void) ParseGeometry(argv[i+1],&geometry_info);
1817 draw_info->interline_spacing=geometry_info.rho;
1818 break;
1819 }
cristy28474bf2011-09-11 23:32:52 +00001820 if (LocaleCompare("interpolate",option+1) == 0)
1821 {
1822 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1823 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1824 break;
1825 }
anthonydf8ebac2011-04-27 09:03:19 +00001826 if (LocaleCompare("interword-spacing",option+1) == 0)
1827 {
1828 if (*option == '+')
1829 (void) ParseGeometry("0",&geometry_info);
1830 else
1831 (void) ParseGeometry(argv[i+1],&geometry_info);
1832 draw_info->interword_spacing=geometry_info.rho;
1833 break;
1834 }
1835 break;
1836 }
1837 case 'k':
1838 {
1839 if (LocaleCompare("kerning",option+1) == 0)
1840 {
1841 if (*option == '+')
1842 (void) ParseGeometry("0",&geometry_info);
1843 else
1844 (void) ParseGeometry(argv[i+1],&geometry_info);
1845 draw_info->kerning=geometry_info.rho;
1846 break;
1847 }
1848 break;
1849 }
1850 case 'l':
1851 {
1852 if (LocaleCompare("lat",option+1) == 0)
1853 {
1854 /*
1855 Local adaptive threshold image.
1856 */
1857 (void) SyncImageSettings(mogrify_info,*image);
1858 flags=ParseGeometry(argv[i+1],&geometry_info);
1859 if ((flags & PercentValue) != 0)
1860 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1861 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001862 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001863 geometry_info.xi,exception);
1864 break;
1865 }
1866 if (LocaleCompare("level",option+1) == 0)
1867 {
1868 MagickRealType
1869 black_point,
1870 gamma,
1871 white_point;
1872
1873 MagickStatusType
1874 flags;
1875
1876 /*
1877 Parse levels.
1878 */
1879 (void) SyncImageSettings(mogrify_info,*image);
1880 flags=ParseGeometry(argv[i+1],&geometry_info);
1881 black_point=geometry_info.rho;
1882 white_point=(MagickRealType) QuantumRange;
1883 if ((flags & SigmaValue) != 0)
1884 white_point=geometry_info.sigma;
1885 gamma=1.0;
1886 if ((flags & XiValue) != 0)
1887 gamma=geometry_info.xi;
1888 if ((flags & PercentValue) != 0)
1889 {
1890 black_point*=(MagickRealType) (QuantumRange/100.0);
1891 white_point*=(MagickRealType) (QuantumRange/100.0);
1892 }
1893 if ((flags & SigmaValue) == 0)
1894 white_point=(MagickRealType) QuantumRange-black_point;
1895 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001896 (void) LevelizeImage(*image,black_point,white_point,gamma,
1897 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001898 else
cristy01e9afd2011-08-10 17:38:41 +00001899 (void) LevelImage(*image,black_point,white_point,gamma,
1900 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001901 InheritException(exception,&(*image)->exception);
1902 break;
1903 }
1904 if (LocaleCompare("level-colors",option+1) == 0)
1905 {
1906 char
1907 token[MaxTextExtent];
1908
1909 const char
1910 *p;
1911
cristy4c08aed2011-07-01 19:47:50 +00001912 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001913 black_point,
1914 white_point;
1915
1916 p=(const char *) argv[i+1];
1917 GetMagickToken(p,&p,token); /* get black point color */
1918 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1919 (void) QueryMagickColor(token,&black_point,exception);
1920 else
1921 (void) QueryMagickColor("#000000",&black_point,exception);
1922 if (isalpha((int) token[0]) || (token[0] == '#'))
1923 GetMagickToken(p,&p,token);
1924 if (*token == '\0')
1925 white_point=black_point; /* set everything to that color */
1926 else
1927 {
1928 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1929 GetMagickToken(p,&p,token); /* Get white point color. */
1930 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1931 (void) QueryMagickColor(token,&white_point,exception);
1932 else
1933 (void) QueryMagickColor("#ffffff",&white_point,exception);
1934 }
cristy490408a2011-07-07 14:42:05 +00001935 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001936 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001937 break;
1938 }
1939 if (LocaleCompare("linear-stretch",option+1) == 0)
1940 {
1941 double
1942 black_point,
1943 white_point;
1944
1945 MagickStatusType
1946 flags;
1947
1948 (void) SyncImageSettings(mogrify_info,*image);
1949 flags=ParseGeometry(argv[i+1],&geometry_info);
1950 black_point=geometry_info.rho;
1951 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1952 if ((flags & SigmaValue) != 0)
1953 white_point=geometry_info.sigma;
1954 if ((flags & PercentValue) != 0)
1955 {
1956 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1957 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1958 }
1959 if ((flags & SigmaValue) == 0)
1960 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1961 black_point;
cristy33bd5152011-08-24 01:42:24 +00001962 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001963 InheritException(exception,&(*image)->exception);
1964 break;
1965 }
1966 if (LocaleCompare("linewidth",option+1) == 0)
1967 {
cristyc1acd842011-05-19 23:05:47 +00001968 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1969 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001970 break;
1971 }
1972 if (LocaleCompare("liquid-rescale",option+1) == 0)
1973 {
1974 /*
1975 Liquid rescale image.
1976 */
1977 (void) SyncImageSettings(mogrify_info,*image);
1978 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1979 if ((flags & XValue) == 0)
1980 geometry.x=1;
1981 if ((flags & YValue) == 0)
1982 geometry.y=0;
1983 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1984 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1985 break;
1986 }
1987 if (LocaleCompare("lowlight-color",option+1) == 0)
1988 {
1989 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1990 break;
1991 }
1992 break;
1993 }
1994 case 'm':
1995 {
1996 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001997 {
cristy3ed852e2009-09-05 21:47:34 +00001998 Image
anthonydf8ebac2011-04-27 09:03:19 +00001999 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002000
anthonydf8ebac2011-04-27 09:03:19 +00002001 /*
2002 Transform image colors to match this set of colors.
2003 */
2004 (void) SyncImageSettings(mogrify_info,*image);
2005 if (*option == '+')
2006 break;
2007 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2008 if (remap_image == (Image *) NULL)
2009 break;
cristy018f07f2011-09-04 21:15:19 +00002010 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002011 remap_image=DestroyImage(remap_image);
2012 break;
2013 }
2014 if (LocaleCompare("mask",option+1) == 0)
2015 {
2016 Image
2017 *mask;
2018
2019 (void) SyncImageSettings(mogrify_info,*image);
2020 if (*option == '+')
2021 {
2022 /*
2023 Remove a mask.
2024 */
cristy018f07f2011-09-04 21:15:19 +00002025 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002026 break;
2027 }
2028 /*
2029 Set the image mask.
2030 */
2031 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2032 if (mask == (Image *) NULL)
2033 break;
cristy018f07f2011-09-04 21:15:19 +00002034 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002035 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002036 break;
2037 }
2038 if (LocaleCompare("matte",option+1) == 0)
2039 {
2040 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002041 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002042 break;
2043 }
2044 if (LocaleCompare("median",option+1) == 0)
2045 {
2046 /*
2047 Median filter image.
2048 */
2049 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002050 flags=ParseGeometry(argv[i+1],&geometry_info);
2051 if ((flags & SigmaValue) == 0)
2052 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002053 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002054 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002055 break;
2056 }
2057 if (LocaleCompare("mode",option+1) == 0)
2058 {
2059 /*
2060 Mode image.
2061 */
2062 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002063 flags=ParseGeometry(argv[i+1],&geometry_info);
2064 if ((flags & SigmaValue) == 0)
2065 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002066 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002067 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002068 break;
2069 }
2070 if (LocaleCompare("modulate",option+1) == 0)
2071 {
2072 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002073 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002074 break;
2075 }
2076 if (LocaleCompare("monitor",option+1) == 0)
2077 {
2078 if (*option == '+')
2079 {
2080 (void) SetImageProgressMonitor(*image,
2081 (MagickProgressMonitor) NULL,(void *) NULL);
2082 break;
2083 }
2084 (void) SetImageProgressMonitor(*image,MonitorProgress,
2085 (void *) NULL);
2086 break;
2087 }
2088 if (LocaleCompare("monochrome",option+1) == 0)
2089 {
2090 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002091 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002092 break;
2093 }
2094 if (LocaleCompare("morphology",option+1) == 0)
2095 {
2096 char
2097 token[MaxTextExtent];
2098
2099 const char
2100 *p;
2101
2102 KernelInfo
2103 *kernel;
2104
2105 MorphologyMethod
2106 method;
2107
2108 ssize_t
2109 iterations;
2110
2111 /*
2112 Morphological Image Operation
2113 */
2114 (void) SyncImageSettings(mogrify_info,*image);
2115 p=argv[i+1];
2116 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002117 method=(MorphologyMethod) ParseCommandOption(
2118 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002119 iterations=1L;
2120 GetMagickToken(p,&p,token);
2121 if ((*p == ':') || (*p == ','))
2122 GetMagickToken(p,&p,token);
2123 if ((*p != '\0'))
2124 iterations=(ssize_t) StringToLong(p);
2125 kernel=AcquireKernelInfo(argv[i+2]);
2126 if (kernel == (KernelInfo *) NULL)
2127 {
2128 (void) ThrowMagickException(exception,GetMagickModule(),
2129 OptionError,"UnabletoParseKernel","morphology");
2130 status=MagickFalse;
2131 break;
2132 }
cristyf4ad9df2011-07-08 16:49:03 +00002133 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2134 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002135 kernel=DestroyKernelInfo(kernel);
2136 break;
2137 }
2138 if (LocaleCompare("motion-blur",option+1) == 0)
2139 {
2140 /*
2141 Motion blur image.
2142 */
2143 (void) SyncImageSettings(mogrify_info,*image);
2144 flags=ParseGeometry(argv[i+1],&geometry_info);
2145 if ((flags & SigmaValue) == 0)
2146 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002147 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002148 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2149 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002150 break;
2151 }
2152 break;
2153 }
2154 case 'n':
2155 {
2156 if (LocaleCompare("negate",option+1) == 0)
2157 {
2158 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002159 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002160 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002161 break;
2162 }
2163 if (LocaleCompare("noise",option+1) == 0)
2164 {
2165 (void) SyncImageSettings(mogrify_info,*image);
2166 if (*option == '-')
2167 {
cristyf36cbcb2011-09-07 13:28:22 +00002168 flags=ParseGeometry(argv[i+1],&geometry_info);
2169 if ((flags & SigmaValue) == 0)
2170 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002171 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002172 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002173 }
2174 else
2175 {
2176 NoiseType
2177 noise;
2178
2179 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2180 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002181 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002182 }
2183 break;
2184 }
2185 if (LocaleCompare("normalize",option+1) == 0)
2186 {
2187 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002188 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002189 break;
2190 }
2191 break;
2192 }
2193 case 'o':
2194 {
2195 if (LocaleCompare("opaque",option+1) == 0)
2196 {
cristy4c08aed2011-07-01 19:47:50 +00002197 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002198 target;
2199
2200 (void) SyncImageSettings(mogrify_info,*image);
2201 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002202 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002203 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002204 break;
2205 }
2206 if (LocaleCompare("ordered-dither",option+1) == 0)
2207 {
2208 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002209 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002210 break;
2211 }
2212 break;
2213 }
2214 case 'p':
2215 {
2216 if (LocaleCompare("paint",option+1) == 0)
2217 {
anthonydf8ebac2011-04-27 09:03:19 +00002218 (void) SyncImageSettings(mogrify_info,*image);
2219 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002220 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2221 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002222 break;
2223 }
2224 if (LocaleCompare("pen",option+1) == 0)
2225 {
2226 if (*option == '+')
2227 {
2228 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2229 break;
2230 }
2231 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2232 break;
2233 }
2234 if (LocaleCompare("pointsize",option+1) == 0)
2235 {
2236 if (*option == '+')
2237 (void) ParseGeometry("12",&geometry_info);
2238 else
2239 (void) ParseGeometry(argv[i+1],&geometry_info);
2240 draw_info->pointsize=geometry_info.rho;
2241 break;
2242 }
2243 if (LocaleCompare("polaroid",option+1) == 0)
2244 {
2245 double
2246 angle;
2247
2248 RandomInfo
2249 *random_info;
2250
2251 /*
2252 Simulate a Polaroid picture.
2253 */
2254 (void) SyncImageSettings(mogrify_info,*image);
2255 random_info=AcquireRandomInfo();
2256 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2257 random_info=DestroyRandomInfo(random_info);
2258 if (*option == '-')
2259 {
2260 SetGeometryInfo(&geometry_info);
2261 flags=ParseGeometry(argv[i+1],&geometry_info);
2262 angle=geometry_info.rho;
2263 }
cristy5c4e2582011-09-11 19:21:03 +00002264 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002265 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002266 break;
2267 }
2268 if (LocaleCompare("posterize",option+1) == 0)
2269 {
2270 /*
2271 Posterize image.
2272 */
2273 (void) SyncImageSettings(mogrify_info,*image);
2274 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002275 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002276 break;
2277 }
2278 if (LocaleCompare("preview",option+1) == 0)
2279 {
2280 PreviewType
2281 preview_type;
2282
2283 /*
2284 Preview image.
2285 */
2286 (void) SyncImageSettings(mogrify_info,*image);
2287 if (*option == '+')
2288 preview_type=UndefinedPreview;
2289 else
cristy28474bf2011-09-11 23:32:52 +00002290 preview_type=(PreviewType) ParseCommandOption(
2291 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002292 mogrify_image=PreviewImage(*image,preview_type,exception);
2293 break;
2294 }
2295 if (LocaleCompare("profile",option+1) == 0)
2296 {
2297 const char
2298 *name;
2299
2300 const StringInfo
2301 *profile;
2302
2303 Image
2304 *profile_image;
2305
2306 ImageInfo
2307 *profile_info;
2308
2309 (void) SyncImageSettings(mogrify_info,*image);
2310 if (*option == '+')
2311 {
2312 /*
2313 Remove a profile from the image.
2314 */
2315 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2316 NULL,0,MagickTrue);
2317 InheritException(exception,&(*image)->exception);
2318 break;
2319 }
2320 /*
2321 Associate a profile with the image.
2322 */
2323 profile_info=CloneImageInfo(mogrify_info);
2324 profile=GetImageProfile(*image,"iptc");
2325 if (profile != (StringInfo *) NULL)
2326 profile_info->profile=(void *) CloneStringInfo(profile);
2327 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2328 profile_info=DestroyImageInfo(profile_info);
2329 if (profile_image == (Image *) NULL)
2330 {
2331 StringInfo
2332 *profile;
2333
2334 profile_info=CloneImageInfo(mogrify_info);
2335 (void) CopyMagickString(profile_info->filename,argv[i+1],
2336 MaxTextExtent);
2337 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2338 if (profile != (StringInfo *) NULL)
2339 {
2340 (void) ProfileImage(*image,profile_info->magick,
2341 GetStringInfoDatum(profile),(size_t)
2342 GetStringInfoLength(profile),MagickFalse);
2343 profile=DestroyStringInfo(profile);
2344 }
2345 profile_info=DestroyImageInfo(profile_info);
2346 break;
2347 }
2348 ResetImageProfileIterator(profile_image);
2349 name=GetNextImageProfile(profile_image);
2350 while (name != (const char *) NULL)
2351 {
2352 profile=GetImageProfile(profile_image,name);
2353 if (profile != (StringInfo *) NULL)
2354 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2355 (size_t) GetStringInfoLength(profile),MagickFalse);
2356 name=GetNextImageProfile(profile_image);
2357 }
2358 profile_image=DestroyImage(profile_image);
2359 break;
2360 }
2361 break;
2362 }
2363 case 'q':
2364 {
2365 if (LocaleCompare("quantize",option+1) == 0)
2366 {
2367 if (*option == '+')
2368 {
2369 quantize_info->colorspace=UndefinedColorspace;
2370 break;
2371 }
2372 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2373 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2374 break;
2375 }
2376 break;
2377 }
2378 case 'r':
2379 {
2380 if (LocaleCompare("radial-blur",option+1) == 0)
2381 {
2382 /*
2383 Radial blur image.
2384 */
2385 (void) SyncImageSettings(mogrify_info,*image);
cristy6435bd92011-09-10 02:10:07 +00002386 flags=ParseGeometry(argv[i+1],&geometry_info);
2387 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2388 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002389 break;
2390 }
2391 if (LocaleCompare("raise",option+1) == 0)
2392 {
2393 /*
2394 Surround image with a raise of solid color.
2395 */
2396 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2397 if ((flags & SigmaValue) == 0)
2398 geometry.height=geometry.width;
2399 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002400 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002401 break;
2402 }
2403 if (LocaleCompare("random-threshold",option+1) == 0)
2404 {
2405 /*
2406 Threshold image.
2407 */
2408 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002409 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002410 break;
2411 }
2412 if (LocaleCompare("recolor",option+1) == 0)
2413 {
2414 KernelInfo
2415 *kernel;
2416
2417 (void) SyncImageSettings(mogrify_info,*image);
2418 kernel=AcquireKernelInfo(argv[i+1]);
2419 if (kernel == (KernelInfo *) NULL)
2420 break;
2421 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2422 kernel=DestroyKernelInfo(kernel);
2423 break;
2424 }
2425 if (LocaleCompare("region",option+1) == 0)
2426 {
2427 (void) SyncImageSettings(mogrify_info,*image);
2428 if (region_image != (Image *) NULL)
2429 {
2430 /*
2431 Composite region.
2432 */
2433 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002434 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2435 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002436 InheritException(exception,&region_image->exception);
2437 *image=DestroyImage(*image);
2438 *image=region_image;
2439 region_image = (Image *) NULL;
2440 }
2441 if (*option == '+')
2442 break;
2443 /*
2444 Apply transformations to a selected region of the image.
2445 */
cristy3ed852e2009-09-05 21:47:34 +00002446 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2447 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002448 mogrify_image=CropImage(*image,&region_geometry,exception);
2449 if (mogrify_image == (Image *) NULL)
2450 break;
2451 region_image=(*image);
2452 *image=mogrify_image;
2453 mogrify_image=(Image *) NULL;
2454 break;
cristy3ed852e2009-09-05 21:47:34 +00002455 }
anthonydf8ebac2011-04-27 09:03:19 +00002456 if (LocaleCompare("render",option+1) == 0)
2457 {
2458 (void) SyncImageSettings(mogrify_info,*image);
2459 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2460 break;
2461 }
2462 if (LocaleCompare("remap",option+1) == 0)
2463 {
2464 Image
2465 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002466
anthonydf8ebac2011-04-27 09:03:19 +00002467 /*
2468 Transform image colors to match this set of colors.
2469 */
2470 (void) SyncImageSettings(mogrify_info,*image);
2471 if (*option == '+')
2472 break;
2473 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2474 if (remap_image == (Image *) NULL)
2475 break;
cristy018f07f2011-09-04 21:15:19 +00002476 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002477 remap_image=DestroyImage(remap_image);
2478 break;
2479 }
2480 if (LocaleCompare("repage",option+1) == 0)
2481 {
2482 if (*option == '+')
2483 {
2484 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2485 break;
2486 }
2487 (void) ResetImagePage(*image,argv[i+1]);
2488 InheritException(exception,&(*image)->exception);
2489 break;
2490 }
2491 if (LocaleCompare("resample",option+1) == 0)
2492 {
2493 /*
2494 Resample image.
2495 */
2496 (void) SyncImageSettings(mogrify_info,*image);
2497 flags=ParseGeometry(argv[i+1],&geometry_info);
2498 if ((flags & SigmaValue) == 0)
2499 geometry_info.sigma=geometry_info.rho;
2500 mogrify_image=ResampleImage(*image,geometry_info.rho,
2501 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2502 break;
2503 }
2504 if (LocaleCompare("resize",option+1) == 0)
2505 {
2506 /*
2507 Resize image.
2508 */
2509 (void) SyncImageSettings(mogrify_info,*image);
2510 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2511 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2512 (*image)->filter,(*image)->blur,exception);
2513 break;
2514 }
2515 if (LocaleCompare("roll",option+1) == 0)
2516 {
2517 /*
2518 Roll image.
2519 */
2520 (void) SyncImageSettings(mogrify_info,*image);
2521 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2522 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2523 break;
2524 }
2525 if (LocaleCompare("rotate",option+1) == 0)
2526 {
2527 char
2528 *geometry;
2529
2530 /*
2531 Check for conditional image rotation.
2532 */
2533 (void) SyncImageSettings(mogrify_info,*image);
2534 if (strchr(argv[i+1],'>') != (char *) NULL)
2535 if ((*image)->columns <= (*image)->rows)
2536 break;
2537 if (strchr(argv[i+1],'<') != (char *) NULL)
2538 if ((*image)->columns >= (*image)->rows)
2539 break;
2540 /*
2541 Rotate image.
2542 */
2543 geometry=ConstantString(argv[i+1]);
2544 (void) SubstituteString(&geometry,">","");
2545 (void) SubstituteString(&geometry,"<","");
2546 (void) ParseGeometry(geometry,&geometry_info);
2547 geometry=DestroyString(geometry);
2548 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2549 break;
2550 }
2551 break;
2552 }
2553 case 's':
2554 {
2555 if (LocaleCompare("sample",option+1) == 0)
2556 {
2557 /*
2558 Sample image with pixel replication.
2559 */
2560 (void) SyncImageSettings(mogrify_info,*image);
2561 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2562 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2563 exception);
2564 break;
2565 }
2566 if (LocaleCompare("scale",option+1) == 0)
2567 {
2568 /*
2569 Resize image.
2570 */
2571 (void) SyncImageSettings(mogrify_info,*image);
2572 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2573 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2574 exception);
2575 break;
2576 }
2577 if (LocaleCompare("selective-blur",option+1) == 0)
2578 {
2579 /*
2580 Selectively blur pixels within a contrast threshold.
2581 */
2582 (void) SyncImageSettings(mogrify_info,*image);
2583 flags=ParseGeometry(argv[i+1],&geometry_info);
2584 if ((flags & PercentValue) != 0)
2585 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002586 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002587 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002588 break;
2589 }
2590 if (LocaleCompare("separate",option+1) == 0)
2591 {
2592 /*
2593 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002594 */
2595 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002596 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002597 break;
2598 }
2599 if (LocaleCompare("sepia-tone",option+1) == 0)
2600 {
2601 double
2602 threshold;
2603
2604 /*
2605 Sepia-tone image.
2606 */
2607 (void) SyncImageSettings(mogrify_info,*image);
2608 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2609 mogrify_image=SepiaToneImage(*image,threshold,exception);
2610 break;
2611 }
2612 if (LocaleCompare("segment",option+1) == 0)
2613 {
2614 /*
2615 Segment image.
2616 */
2617 (void) SyncImageSettings(mogrify_info,*image);
2618 flags=ParseGeometry(argv[i+1],&geometry_info);
2619 if ((flags & SigmaValue) == 0)
2620 geometry_info.sigma=1.0;
2621 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002622 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2623 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002624 break;
2625 }
2626 if (LocaleCompare("set",option+1) == 0)
2627 {
2628 char
2629 *value;
2630
2631 /*
2632 Set image option.
2633 */
2634 if (*option == '+')
2635 {
2636 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2637 (void) DeleteImageRegistry(argv[i+1]+9);
2638 else
2639 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2640 {
2641 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2642 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2643 }
2644 else
2645 (void) DeleteImageProperty(*image,argv[i+1]);
2646 break;
2647 }
cristy018f07f2011-09-04 21:15:19 +00002648 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2649 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002650 if (value == (char *) NULL)
2651 break;
2652 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2653 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2654 exception);
2655 else
2656 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2657 {
2658 (void) SetImageOption(image_info,argv[i+1]+7,value);
2659 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2660 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2661 }
2662 else
2663 (void) SetImageProperty(*image,argv[i+1],value);
2664 value=DestroyString(value);
2665 break;
2666 }
2667 if (LocaleCompare("shade",option+1) == 0)
2668 {
2669 /*
2670 Shade image.
2671 */
2672 (void) SyncImageSettings(mogrify_info,*image);
2673 flags=ParseGeometry(argv[i+1],&geometry_info);
2674 if ((flags & SigmaValue) == 0)
2675 geometry_info.sigma=1.0;
2676 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2677 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2678 break;
2679 }
2680 if (LocaleCompare("shadow",option+1) == 0)
2681 {
2682 /*
2683 Shadow image.
2684 */
2685 (void) SyncImageSettings(mogrify_info,*image);
2686 flags=ParseGeometry(argv[i+1],&geometry_info);
2687 if ((flags & SigmaValue) == 0)
2688 geometry_info.sigma=1.0;
2689 if ((flags & XiValue) == 0)
2690 geometry_info.xi=4.0;
2691 if ((flags & PsiValue) == 0)
2692 geometry_info.psi=4.0;
2693 mogrify_image=ShadowImage(*image,geometry_info.rho,
2694 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2695 ceil(geometry_info.psi-0.5),exception);
2696 break;
2697 }
2698 if (LocaleCompare("sharpen",option+1) == 0)
2699 {
2700 /*
2701 Sharpen image.
2702 */
2703 (void) SyncImageSettings(mogrify_info,*image);
2704 flags=ParseGeometry(argv[i+1],&geometry_info);
2705 if ((flags & SigmaValue) == 0)
2706 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002707 if ((flags & XiValue) == 0)
2708 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002709 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002710 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002711 break;
2712 }
2713 if (LocaleCompare("shave",option+1) == 0)
2714 {
2715 /*
2716 Shave the image edges.
2717 */
2718 (void) SyncImageSettings(mogrify_info,*image);
2719 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2720 mogrify_image=ShaveImage(*image,&geometry,exception);
2721 break;
2722 }
2723 if (LocaleCompare("shear",option+1) == 0)
2724 {
2725 /*
2726 Shear image.
2727 */
2728 (void) SyncImageSettings(mogrify_info,*image);
2729 flags=ParseGeometry(argv[i+1],&geometry_info);
2730 if ((flags & SigmaValue) == 0)
2731 geometry_info.sigma=geometry_info.rho;
2732 mogrify_image=ShearImage(*image,geometry_info.rho,
2733 geometry_info.sigma,exception);
2734 break;
2735 }
2736 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2737 {
2738 /*
2739 Sigmoidal non-linearity contrast control.
2740 */
2741 (void) SyncImageSettings(mogrify_info,*image);
2742 flags=ParseGeometry(argv[i+1],&geometry_info);
2743 if ((flags & SigmaValue) == 0)
2744 geometry_info.sigma=(double) QuantumRange/2.0;
2745 if ((flags & PercentValue) != 0)
2746 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2747 100.0;
cristy9ee60942011-07-06 14:54:38 +00002748 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002749 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2750 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002751 break;
2752 }
2753 if (LocaleCompare("sketch",option+1) == 0)
2754 {
2755 /*
2756 Sketch image.
2757 */
2758 (void) SyncImageSettings(mogrify_info,*image);
2759 flags=ParseGeometry(argv[i+1],&geometry_info);
2760 if ((flags & SigmaValue) == 0)
2761 geometry_info.sigma=1.0;
2762 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002763 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002764 break;
2765 }
2766 if (LocaleCompare("solarize",option+1) == 0)
2767 {
2768 double
2769 threshold;
2770
2771 (void) SyncImageSettings(mogrify_info,*image);
2772 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002773 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002774 break;
2775 }
2776 if (LocaleCompare("sparse-color",option+1) == 0)
2777 {
2778 SparseColorMethod
2779 method;
2780
2781 char
2782 *arguments;
2783
2784 /*
2785 Sparse Color Interpolated Gradient
2786 */
2787 (void) SyncImageSettings(mogrify_info,*image);
2788 method=(SparseColorMethod) ParseCommandOption(
2789 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002790 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2791 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002792 if (arguments == (char *) NULL)
2793 break;
cristy3884f692011-07-08 18:00:18 +00002794 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002795 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2796 arguments=DestroyString(arguments);
2797 break;
2798 }
2799 if (LocaleCompare("splice",option+1) == 0)
2800 {
2801 /*
2802 Splice a solid color into the image.
2803 */
2804 (void) SyncImageSettings(mogrify_info,*image);
2805 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2806 mogrify_image=SpliceImage(*image,&geometry,exception);
2807 break;
2808 }
2809 if (LocaleCompare("spread",option+1) == 0)
2810 {
2811 /*
2812 Spread an image.
2813 */
2814 (void) SyncImageSettings(mogrify_info,*image);
2815 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002816 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002817 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002818 break;
2819 }
2820 if (LocaleCompare("statistic",option+1) == 0)
2821 {
2822 StatisticType
2823 type;
2824
2825 (void) SyncImageSettings(mogrify_info,*image);
2826 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2827 MagickFalse,argv[i+1]);
2828 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002829 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2830 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002831 break;
2832 }
2833 if (LocaleCompare("stretch",option+1) == 0)
2834 {
2835 if (*option == '+')
2836 {
2837 draw_info->stretch=UndefinedStretch;
2838 break;
2839 }
2840 draw_info->stretch=(StretchType) ParseCommandOption(
2841 MagickStretchOptions,MagickFalse,argv[i+1]);
2842 break;
2843 }
2844 if (LocaleCompare("strip",option+1) == 0)
2845 {
2846 /*
2847 Strip image of profiles and comments.
2848 */
2849 (void) SyncImageSettings(mogrify_info,*image);
2850 (void) StripImage(*image);
2851 InheritException(exception,&(*image)->exception);
2852 break;
2853 }
2854 if (LocaleCompare("stroke",option+1) == 0)
2855 {
2856 ExceptionInfo
2857 *sans;
2858
2859 if (*option == '+')
2860 {
2861 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2862 if (draw_info->stroke_pattern != (Image *) NULL)
2863 draw_info->stroke_pattern=DestroyImage(
2864 draw_info->stroke_pattern);
2865 break;
2866 }
2867 sans=AcquireExceptionInfo();
2868 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2869 sans=DestroyExceptionInfo(sans);
2870 if (status == MagickFalse)
2871 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2872 exception);
2873 break;
2874 }
2875 if (LocaleCompare("strokewidth",option+1) == 0)
2876 {
cristyc1acd842011-05-19 23:05:47 +00002877 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2878 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002879 break;
2880 }
2881 if (LocaleCompare("style",option+1) == 0)
2882 {
2883 if (*option == '+')
2884 {
2885 draw_info->style=UndefinedStyle;
2886 break;
2887 }
2888 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2889 MagickFalse,argv[i+1]);
2890 break;
2891 }
2892 if (LocaleCompare("swirl",option+1) == 0)
2893 {
2894 /*
2895 Swirl image.
2896 */
2897 (void) SyncImageSettings(mogrify_info,*image);
2898 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002899 mogrify_image=SwirlImage(*image,geometry_info.rho,
2900 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002901 break;
2902 }
2903 break;
2904 }
2905 case 't':
2906 {
2907 if (LocaleCompare("threshold",option+1) == 0)
2908 {
2909 double
2910 threshold;
2911
2912 /*
2913 Threshold image.
2914 */
2915 (void) SyncImageSettings(mogrify_info,*image);
2916 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002917 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002918 else
2919 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002920 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002921 InheritException(exception,&(*image)->exception);
2922 break;
2923 }
2924 if (LocaleCompare("thumbnail",option+1) == 0)
2925 {
2926 /*
2927 Thumbnail image.
2928 */
2929 (void) SyncImageSettings(mogrify_info,*image);
2930 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2931 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2932 exception);
2933 break;
2934 }
2935 if (LocaleCompare("tile",option+1) == 0)
2936 {
2937 if (*option == '+')
2938 {
2939 if (draw_info->fill_pattern != (Image *) NULL)
2940 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2941 break;
2942 }
2943 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2944 exception);
2945 break;
2946 }
2947 if (LocaleCompare("tint",option+1) == 0)
2948 {
2949 /*
2950 Tint the image.
2951 */
2952 (void) SyncImageSettings(mogrify_info,*image);
cristy28474bf2011-09-11 23:32:52 +00002953 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002954 break;
2955 }
2956 if (LocaleCompare("transform",option+1) == 0)
2957 {
2958 /*
2959 Affine transform image.
2960 */
2961 (void) SyncImageSettings(mogrify_info,*image);
2962 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2963 exception);
2964 break;
2965 }
2966 if (LocaleCompare("transparent",option+1) == 0)
2967 {
cristy4c08aed2011-07-01 19:47:50 +00002968 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002969 target;
2970
2971 (void) SyncImageSettings(mogrify_info,*image);
2972 (void) QueryMagickColor(argv[i+1],&target,exception);
2973 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002974 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2975 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002976 break;
2977 }
2978 if (LocaleCompare("transpose",option+1) == 0)
2979 {
2980 /*
2981 Transpose image scanlines.
2982 */
2983 (void) SyncImageSettings(mogrify_info,*image);
2984 mogrify_image=TransposeImage(*image,exception);
2985 break;
2986 }
2987 if (LocaleCompare("transverse",option+1) == 0)
2988 {
2989 /*
2990 Transverse image scanlines.
2991 */
2992 (void) SyncImageSettings(mogrify_info,*image);
2993 mogrify_image=TransverseImage(*image,exception);
2994 break;
2995 }
2996 if (LocaleCompare("treedepth",option+1) == 0)
2997 {
2998 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2999 break;
3000 }
3001 if (LocaleCompare("trim",option+1) == 0)
3002 {
3003 /*
3004 Trim image.
3005 */
3006 (void) SyncImageSettings(mogrify_info,*image);
3007 mogrify_image=TrimImage(*image,exception);
3008 break;
3009 }
3010 if (LocaleCompare("type",option+1) == 0)
3011 {
3012 ImageType
3013 type;
3014
3015 (void) SyncImageSettings(mogrify_info,*image);
3016 if (*option == '+')
3017 type=UndefinedType;
3018 else
3019 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3020 argv[i+1]);
3021 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003022 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003023 break;
3024 }
3025 break;
3026 }
3027 case 'u':
3028 {
3029 if (LocaleCompare("undercolor",option+1) == 0)
3030 {
3031 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3032 exception);
3033 break;
3034 }
3035 if (LocaleCompare("unique",option+1) == 0)
3036 {
3037 if (*option == '+')
3038 {
3039 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3040 break;
3041 }
3042 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3043 (void) SetImageArtifact(*image,"verbose","true");
3044 break;
3045 }
3046 if (LocaleCompare("unique-colors",option+1) == 0)
3047 {
3048 /*
3049 Unique image colors.
3050 */
3051 (void) SyncImageSettings(mogrify_info,*image);
3052 mogrify_image=UniqueImageColors(*image,exception);
3053 break;
3054 }
3055 if (LocaleCompare("unsharp",option+1) == 0)
3056 {
3057 /*
3058 Unsharp mask image.
3059 */
3060 (void) SyncImageSettings(mogrify_info,*image);
3061 flags=ParseGeometry(argv[i+1],&geometry_info);
3062 if ((flags & SigmaValue) == 0)
3063 geometry_info.sigma=1.0;
3064 if ((flags & XiValue) == 0)
3065 geometry_info.xi=1.0;
3066 if ((flags & PsiValue) == 0)
3067 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003068 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3069 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003070 break;
3071 }
3072 break;
3073 }
3074 case 'v':
3075 {
3076 if (LocaleCompare("verbose",option+1) == 0)
3077 {
3078 (void) SetImageArtifact(*image,option+1,
3079 *option == '+' ? "false" : "true");
3080 break;
3081 }
3082 if (LocaleCompare("vignette",option+1) == 0)
3083 {
3084 /*
3085 Vignette image.
3086 */
3087 (void) SyncImageSettings(mogrify_info,*image);
3088 flags=ParseGeometry(argv[i+1],&geometry_info);
3089 if ((flags & SigmaValue) == 0)
3090 geometry_info.sigma=1.0;
3091 if ((flags & XiValue) == 0)
3092 geometry_info.xi=0.1*(*image)->columns;
3093 if ((flags & PsiValue) == 0)
3094 geometry_info.psi=0.1*(*image)->rows;
3095 mogrify_image=VignetteImage(*image,geometry_info.rho,
3096 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3097 ceil(geometry_info.psi-0.5),exception);
3098 break;
3099 }
3100 if (LocaleCompare("virtual-pixel",option+1) == 0)
3101 {
3102 if (*option == '+')
3103 {
3104 (void) SetImageVirtualPixelMethod(*image,
3105 UndefinedVirtualPixelMethod);
3106 break;
3107 }
3108 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3109 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3110 argv[i+1]));
3111 break;
3112 }
3113 break;
3114 }
3115 case 'w':
3116 {
3117 if (LocaleCompare("wave",option+1) == 0)
3118 {
3119 /*
3120 Wave image.
3121 */
3122 (void) SyncImageSettings(mogrify_info,*image);
3123 flags=ParseGeometry(argv[i+1],&geometry_info);
3124 if ((flags & SigmaValue) == 0)
3125 geometry_info.sigma=1.0;
3126 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003127 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003128 break;
3129 }
3130 if (LocaleCompare("weight",option+1) == 0)
3131 {
3132 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3133 if (LocaleCompare(argv[i+1],"all") == 0)
3134 draw_info->weight=0;
3135 if (LocaleCompare(argv[i+1],"bold") == 0)
3136 draw_info->weight=700;
3137 if (LocaleCompare(argv[i+1],"bolder") == 0)
3138 if (draw_info->weight <= 800)
3139 draw_info->weight+=100;
3140 if (LocaleCompare(argv[i+1],"lighter") == 0)
3141 if (draw_info->weight >= 100)
3142 draw_info->weight-=100;
3143 if (LocaleCompare(argv[i+1],"normal") == 0)
3144 draw_info->weight=400;
3145 break;
3146 }
3147 if (LocaleCompare("white-threshold",option+1) == 0)
3148 {
3149 /*
3150 White threshold image.
3151 */
3152 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003153 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003154 InheritException(exception,&(*image)->exception);
3155 break;
3156 }
3157 break;
3158 }
3159 default:
3160 break;
3161 }
3162 /*
3163 Replace current image with any image that was generated
3164 */
3165 if (mogrify_image != (Image *) NULL)
3166 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003167 i+=count;
3168 }
3169 if (region_image != (Image *) NULL)
3170 {
anthonydf8ebac2011-04-27 09:03:19 +00003171 /*
3172 Composite transformed region onto image.
3173 */
cristy6b3da3a2010-06-20 02:21:46 +00003174 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003175 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003176 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3177 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003178 InheritException(exception,&region_image->exception);
3179 *image=DestroyImage(*image);
3180 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003181 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003182 }
3183 /*
3184 Free resources.
3185 */
anthonydf8ebac2011-04-27 09:03:19 +00003186 quantize_info=DestroyQuantizeInfo(quantize_info);
3187 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003188 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003189 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003190 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003191 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003192}
3193
3194/*
3195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3196% %
3197% %
3198% %
cristy5063d812010-10-19 16:28:10 +00003199+ 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 +00003200% %
3201% %
3202% %
3203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3204%
3205% MogrifyImageCommand() transforms an image or a sequence of images. These
3206% transforms include image scaling, image rotation, color reduction, and
3207% others. The transmogrified image overwrites the original image.
3208%
3209% The format of the MogrifyImageCommand method is:
3210%
3211% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3212% const char **argv,char **metadata,ExceptionInfo *exception)
3213%
3214% A description of each parameter follows:
3215%
3216% o image_info: the image info.
3217%
3218% o argc: the number of elements in the argument vector.
3219%
3220% o argv: A text array containing the command line arguments.
3221%
3222% o metadata: any metadata is returned here.
3223%
3224% o exception: return any errors or warnings in this structure.
3225%
3226*/
3227
3228static MagickBooleanType MogrifyUsage(void)
3229{
3230 static const char
3231 *miscellaneous[]=
3232 {
3233 "-debug events display copious debugging information",
3234 "-help print program options",
3235 "-list type print a list of supported option arguments",
3236 "-log format format of debugging information",
3237 "-version print version information",
3238 (char *) NULL
3239 },
3240 *operators[]=
3241 {
3242 "-adaptive-blur geometry",
3243 " adaptively blur pixels; decrease effect near edges",
3244 "-adaptive-resize geometry",
3245 " adaptively resize image using 'mesh' interpolation",
3246 "-adaptive-sharpen geometry",
3247 " adaptively sharpen pixels; increase effect near edges",
3248 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3249 " transparent, extract, background, or shape",
3250 "-annotate geometry text",
3251 " annotate the image with text",
3252 "-auto-gamma automagically adjust gamma level of image",
3253 "-auto-level automagically adjust color levels of image",
3254 "-auto-orient automagically orient (rotate) image",
3255 "-bench iterations measure performance",
3256 "-black-threshold value",
3257 " force all pixels below the threshold into black",
3258 "-blue-shift simulate a scene at nighttime in the moonlight",
3259 "-blur geometry reduce image noise and reduce detail levels",
3260 "-border geometry surround image with a border of color",
3261 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003262 "-brightness-contrast geometry",
3263 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003264 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003265 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003266 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003267 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003268 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003269 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003270 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003271 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003272 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003273 "-contrast enhance or reduce the image contrast",
3274 "-contrast-stretch geometry",
3275 " improve contrast by `stretching' the intensity range",
3276 "-convolve coefficients",
3277 " apply a convolution kernel to the image",
3278 "-cycle amount cycle the image colormap",
3279 "-decipher filename convert cipher pixels to plain pixels",
3280 "-deskew threshold straighten an image",
3281 "-despeckle reduce the speckles within an image",
3282 "-distort method args",
3283 " distort images according to given method ad args",
3284 "-draw string annotate the image with a graphic primitive",
3285 "-edge radius apply a filter to detect edges in the image",
3286 "-encipher filename convert plain pixels to cipher pixels",
3287 "-emboss radius emboss an image",
3288 "-enhance apply a digital filter to enhance a noisy image",
3289 "-equalize perform histogram equalization to an image",
3290 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003291 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003292 "-extent geometry set the image size",
3293 "-extract geometry extract area from image",
3294 "-fft implements the discrete Fourier transform (DFT)",
3295 "-flip flip image vertically",
3296 "-floodfill geometry color",
3297 " floodfill the image with color",
3298 "-flop flop image horizontally",
3299 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003300 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003301 " apply function over image values",
3302 "-gamma value level of gamma correction",
3303 "-gaussian-blur geometry",
3304 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003305 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-identify identify the format and characteristics of the image",
3307 "-ift implements the inverse discrete Fourier transform (DFT)",
3308 "-implode amount implode image pixels about the center",
3309 "-lat geometry local adaptive thresholding",
3310 "-layers method optimize, merge, or compare image layers",
3311 "-level value adjust the level of image contrast",
3312 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003313 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003314 "-linear-stretch geometry",
3315 " improve contrast by `stretching with saturation'",
3316 "-liquid-rescale geometry",
3317 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003318 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003319 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003320 "-modulate value vary the brightness, saturation, and hue",
3321 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003322 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003323 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003324 "-motion-blur geometry",
3325 " simulate motion blur",
3326 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003327 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003328 "-normalize transform image to span the full range of colors",
3329 "-opaque color change this color to the fill color",
3330 "-ordered-dither NxN",
3331 " add a noise pattern to the image with specific",
3332 " amplitudes",
3333 "-paint radius simulate an oil painting",
3334 "-polaroid angle simulate a Polaroid picture",
3335 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003336 "-profile filename add, delete, or apply an image profile",
3337 "-quantize colorspace reduce colors in this colorspace",
3338 "-radial-blur angle radial blur the image",
3339 "-raise value lighten/darken image edges to create a 3-D effect",
3340 "-random-threshold low,high",
3341 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003342 "-region geometry apply options to a portion of the image",
3343 "-render render vector graphics",
3344 "-repage geometry size and location of an image canvas",
3345 "-resample geometry change the resolution of an image",
3346 "-resize geometry resize the image",
3347 "-roll geometry roll an image vertically or horizontally",
3348 "-rotate degrees apply Paeth rotation to the image",
3349 "-sample geometry scale image with pixel sampling",
3350 "-scale geometry scale the image",
3351 "-segment values segment an image",
3352 "-selective-blur geometry",
3353 " selectively blur pixels within a contrast threshold",
3354 "-sepia-tone threshold",
3355 " simulate a sepia-toned photo",
3356 "-set property value set an image property",
3357 "-shade degrees shade the image using a distant light source",
3358 "-shadow geometry simulate an image shadow",
3359 "-sharpen geometry sharpen the image",
3360 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003361 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003362 "-sigmoidal-contrast geometry",
3363 " increase the contrast without saturating highlights or shadows",
3364 "-sketch geometry simulate a pencil sketch",
3365 "-solarize threshold negate all pixels above the threshold level",
3366 "-sparse-color method args",
3367 " fill in a image based on a few color points",
3368 "-splice geometry splice the background color into the image",
3369 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003370 "-statistic type radius",
3371 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003372 "-strip strip image of all profiles and comments",
3373 "-swirl degrees swirl image pixels about the center",
3374 "-threshold value threshold the image",
3375 "-thumbnail geometry create a thumbnail of the image",
3376 "-tile filename tile image when filling a graphic primitive",
3377 "-tint value tint the image with the fill color",
3378 "-transform affine transform image",
3379 "-transparent color make this color transparent within the image",
3380 "-transpose flip image vertically and rotate 90 degrees",
3381 "-transverse flop image horizontally and rotate 270 degrees",
3382 "-trim trim image edges",
3383 "-type type image type",
3384 "-unique-colors discard all but one of any pixel color",
3385 "-unsharp geometry sharpen the image",
3386 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003387 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003388 "-white-threshold value",
3389 " force all pixels above the threshold into white",
3390 (char *) NULL
3391 },
3392 *sequence_operators[]=
3393 {
cristy4285d782011-02-09 20:12:28 +00003394 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003395 "-clut apply a color lookup table to the image",
3396 "-coalesce merge a sequence of images",
3397 "-combine combine a sequence of images",
3398 "-composite composite image",
3399 "-crop geometry cut out a rectangular region of the image",
3400 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003401 "-evaluate-sequence operator",
3402 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003403 "-flatten flatten a sequence of images",
3404 "-fx expression apply mathematical expression to an image channel(s)",
3405 "-hald-clut apply a Hald color lookup table to the image",
3406 "-morph value morph an image sequence",
3407 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003408 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003409 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003410 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003411 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003412 "-write filename write images to this file",
3413 (char *) NULL
3414 },
3415 *settings[]=
3416 {
3417 "-adjoin join images into a single multi-image file",
3418 "-affine matrix affine transform matrix",
3419 "-alpha option activate, deactivate, reset, or set the alpha channel",
3420 "-antialias remove pixel-aliasing",
3421 "-authenticate password",
3422 " decipher image with this password",
3423 "-attenuate value lessen (or intensify) when adding noise to an image",
3424 "-background color background color",
3425 "-bias value add bias when convolving an image",
3426 "-black-point-compensation",
3427 " use black point compensation",
3428 "-blue-primary point chromaticity blue primary point",
3429 "-bordercolor color border color",
3430 "-caption string assign a caption to an image",
3431 "-channel type apply option to select image channels",
3432 "-colors value preferred number of colors in the image",
3433 "-colorspace type alternate image colorspace",
3434 "-comment string annotate image with comment",
3435 "-compose operator set image composite operator",
3436 "-compress type type of pixel compression when writing the image",
3437 "-define format:option",
3438 " define one or more image format options",
3439 "-delay value display the next image after pausing",
3440 "-density geometry horizontal and vertical density of the image",
3441 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003442 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003443 "-display server get image or font from this X server",
3444 "-dispose method layer disposal method",
3445 "-dither method apply error diffusion to image",
3446 "-encoding type text encoding type",
3447 "-endian type endianness (MSB or LSB) of the image",
3448 "-family name render text with this font family",
3449 "-fill color color to use when filling a graphic primitive",
3450 "-filter type use this filter when resizing an image",
3451 "-font name render text with this font",
3452 "-format \"string\" output formatted image characteristics",
3453 "-fuzz distance colors within this distance are considered equal",
3454 "-gravity type horizontal and vertical text placement",
3455 "-green-primary point chromaticity green primary point",
3456 "-intent type type of rendering intent when managing the image color",
3457 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003458 "-interline-spacing value",
3459 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003460 "-interpolate method pixel color interpolation method",
3461 "-interword-spacing value",
3462 " set the space between two words",
3463 "-kerning value set the space between two letters",
3464 "-label string assign a label to an image",
3465 "-limit type value pixel cache resource limit",
3466 "-loop iterations add Netscape loop extension to your GIF animation",
3467 "-mask filename associate a mask with the image",
3468 "-mattecolor color frame color",
3469 "-monitor monitor progress",
3470 "-orient type image orientation",
3471 "-page geometry size and location of an image canvas (setting)",
3472 "-ping efficiently determine image attributes",
3473 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003474 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003475 "-preview type image preview type",
3476 "-quality value JPEG/MIFF/PNG compression level",
3477 "-quiet suppress all warning messages",
3478 "-red-primary point chromaticity red primary point",
3479 "-regard-warnings pay attention to warning messages",
3480 "-remap filename transform image colors to match this set of colors",
3481 "-respect-parentheses settings remain in effect until parenthesis boundary",
3482 "-sampling-factor geometry",
3483 " horizontal and vertical sampling factor",
3484 "-scene value image scene number",
3485 "-seed value seed a new sequence of pseudo-random numbers",
3486 "-size geometry width and height of image",
3487 "-stretch type render text with this font stretch",
3488 "-stroke color graphic primitive stroke color",
3489 "-strokewidth value graphic primitive stroke width",
3490 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003491 "-synchronize synchronize image to storage device",
3492 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003493 "-texture filename name of texture to tile onto the image background",
3494 "-tile-offset geometry",
3495 " tile offset",
3496 "-treedepth value color tree depth",
3497 "-transparent-color color",
3498 " transparent color",
3499 "-undercolor color annotation bounding box color",
3500 "-units type the units of image resolution",
3501 "-verbose print detailed information about the image",
3502 "-view FlashPix viewing transforms",
3503 "-virtual-pixel method",
3504 " virtual pixel access method",
3505 "-weight type render text with this font weight",
3506 "-white-point point chromaticity white point",
3507 (char *) NULL
3508 },
3509 *stack_operators[]=
3510 {
anthonyb69c4b32011-03-23 04:37:44 +00003511 "-delete indexes delete the image from the image sequence",
3512 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003513 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003514 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003515 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003516 "-swap indexes swap two images in the image sequence",
3517 (char *) NULL
3518 };
3519
3520 const char
3521 **p;
3522
cristybb503372010-05-27 20:51:26 +00003523 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003524 (void) printf("Copyright: %s\n",GetMagickCopyright());
3525 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003526 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3527 GetClientName());
3528 (void) printf("\nImage Settings:\n");
3529 for (p=settings; *p != (char *) NULL; p++)
3530 (void) printf(" %s\n",*p);
3531 (void) printf("\nImage Operators:\n");
3532 for (p=operators; *p != (char *) NULL; p++)
3533 (void) printf(" %s\n",*p);
3534 (void) printf("\nImage Sequence Operators:\n");
3535 for (p=sequence_operators; *p != (char *) NULL; p++)
3536 (void) printf(" %s\n",*p);
3537 (void) printf("\nImage Stack Operators:\n");
3538 for (p=stack_operators; *p != (char *) NULL; p++)
3539 (void) printf(" %s\n",*p);
3540 (void) printf("\nMiscellaneous Options:\n");
3541 for (p=miscellaneous; *p != (char *) NULL; p++)
3542 (void) printf(" %s\n",*p);
3543 (void) printf(
3544 "\nBy default, the image format of `file' is determined by its magic\n");
3545 (void) printf(
3546 "number. To specify a particular image format, precede the filename\n");
3547 (void) printf(
3548 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3549 (void) printf(
3550 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3551 (void) printf("'-' for standard input or output.\n");
3552 return(MagickFalse);
3553}
3554
3555WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3556 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3557{
3558#define DestroyMogrify() \
3559{ \
3560 if (format != (char *) NULL) \
3561 format=DestroyString(format); \
3562 if (path != (char *) NULL) \
3563 path=DestroyString(path); \
3564 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003565 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003566 argv[i]=DestroyString(argv[i]); \
3567 argv=(char **) RelinquishMagickMemory(argv); \
3568}
3569#define ThrowMogrifyException(asperity,tag,option) \
3570{ \
3571 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3572 option); \
3573 DestroyMogrify(); \
3574 return(MagickFalse); \
3575}
3576#define ThrowMogrifyInvalidArgumentException(option,argument) \
3577{ \
3578 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3579 "InvalidArgument","`%s': %s",argument,option); \
3580 DestroyMogrify(); \
3581 return(MagickFalse); \
3582}
3583
3584 char
3585 *format,
3586 *option,
3587 *path;
3588
3589 Image
3590 *image;
3591
3592 ImageStack
3593 image_stack[MaxImageStackDepth+1];
3594
cristy3ed852e2009-09-05 21:47:34 +00003595 MagickBooleanType
3596 global_colormap;
3597
3598 MagickBooleanType
3599 fire,
cristyebbcfea2011-02-25 02:43:54 +00003600 pend,
3601 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003602
3603 MagickStatusType
3604 status;
3605
cristyebbcfea2011-02-25 02:43:54 +00003606 register ssize_t
3607 i;
3608
3609 ssize_t
3610 j,
3611 k;
3612
cristy3ed852e2009-09-05 21:47:34 +00003613 /*
3614 Set defaults.
3615 */
3616 assert(image_info != (ImageInfo *) NULL);
3617 assert(image_info->signature == MagickSignature);
3618 if (image_info->debug != MagickFalse)
3619 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3620 assert(exception != (ExceptionInfo *) NULL);
3621 if (argc == 2)
3622 {
3623 option=argv[1];
3624 if ((LocaleCompare("version",option+1) == 0) ||
3625 (LocaleCompare("-version",option+1) == 0))
3626 {
cristyb51dff52011-05-19 16:55:47 +00003627 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003628 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003629 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3630 GetMagickCopyright());
3631 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3632 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003633 return(MagickFalse);
3634 }
3635 }
3636 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003637 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003638 format=(char *) NULL;
3639 path=(char *) NULL;
3640 global_colormap=MagickFalse;
3641 k=0;
3642 j=1;
3643 NewImageStack();
3644 option=(char *) NULL;
3645 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003646 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003647 status=MagickTrue;
3648 /*
3649 Parse command line.
3650 */
3651 ReadCommandlLine(argc,&argv);
3652 status=ExpandFilenames(&argc,&argv);
3653 if (status == MagickFalse)
3654 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3655 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003656 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003657 {
3658 option=argv[i];
3659 if (LocaleCompare(option,"(") == 0)
3660 {
3661 FireImageStack(MagickFalse,MagickTrue,pend);
3662 if (k == MaxImageStackDepth)
3663 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3664 option);
3665 PushImageStack();
3666 continue;
3667 }
3668 if (LocaleCompare(option,")") == 0)
3669 {
3670 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3671 if (k == 0)
3672 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3673 PopImageStack();
3674 continue;
3675 }
cristy042ee782011-04-22 18:48:30 +00003676 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003677 {
3678 char
3679 backup_filename[MaxTextExtent],
3680 *filename;
3681
3682 Image
3683 *images;
3684
3685 /*
3686 Option is a file name: begin by reading image from specified file.
3687 */
3688 FireImageStack(MagickFalse,MagickFalse,pend);
3689 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003690 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003691 filename=argv[++i];
3692 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3693 images=ReadImages(image_info,exception);
3694 status&=(images != (Image *) NULL) &&
3695 (exception->severity < ErrorException);
3696 if (images == (Image *) NULL)
3697 continue;
cristydaa76602010-06-30 13:05:11 +00003698 if (format != (char *) NULL)
3699 (void) CopyMagickString(images->filename,images->magick_filename,
3700 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003701 if (path != (char *) NULL)
3702 {
3703 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003704 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003705 path,*DirectorySeparator,filename);
3706 }
3707 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003708 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003709 AppendImageStack(images);
3710 FinalizeImageSettings(image_info,image,MagickFalse);
3711 if (global_colormap != MagickFalse)
3712 {
3713 QuantizeInfo
3714 *quantize_info;
3715
3716 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003717 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003718 quantize_info=DestroyQuantizeInfo(quantize_info);
3719 }
3720 *backup_filename='\0';
3721 if ((LocaleCompare(image->filename,"-") != 0) &&
3722 (IsPathWritable(image->filename) != MagickFalse))
3723 {
cristybb503372010-05-27 20:51:26 +00003724 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003725 i;
3726
3727 /*
3728 Rename image file as backup.
3729 */
3730 (void) CopyMagickString(backup_filename,image->filename,
3731 MaxTextExtent);
3732 for (i=0; i < 6; i++)
3733 {
3734 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3735 if (IsPathAccessible(backup_filename) == MagickFalse)
3736 break;
3737 }
3738 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3739 (rename(image->filename,backup_filename) != 0))
3740 *backup_filename='\0';
3741 }
3742 /*
3743 Write transmogrified image to disk.
3744 */
3745 image_info->synchronize=MagickTrue;
3746 status&=WriteImages(image_info,image,image->filename,exception);
3747 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003748 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003749 RemoveAllImageStack();
3750 continue;
3751 }
3752 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3753 switch (*(option+1))
3754 {
3755 case 'a':
3756 {
3757 if (LocaleCompare("adaptive-blur",option+1) == 0)
3758 {
3759 i++;
cristybb503372010-05-27 20:51:26 +00003760 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003761 ThrowMogrifyException(OptionError,"MissingArgument",option);
3762 if (IsGeometry(argv[i]) == MagickFalse)
3763 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3764 break;
3765 }
3766 if (LocaleCompare("adaptive-resize",option+1) == 0)
3767 {
3768 i++;
cristybb503372010-05-27 20:51:26 +00003769 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003770 ThrowMogrifyException(OptionError,"MissingArgument",option);
3771 if (IsGeometry(argv[i]) == MagickFalse)
3772 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3773 break;
3774 }
3775 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3776 {
3777 i++;
cristybb503372010-05-27 20:51:26 +00003778 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003779 ThrowMogrifyException(OptionError,"MissingArgument",option);
3780 if (IsGeometry(argv[i]) == MagickFalse)
3781 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3782 break;
3783 }
3784 if (LocaleCompare("affine",option+1) == 0)
3785 {
3786 if (*option == '+')
3787 break;
3788 i++;
cristybb503372010-05-27 20:51:26 +00003789 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003790 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003791 break;
3792 }
3793 if (LocaleCompare("alpha",option+1) == 0)
3794 {
cristybb503372010-05-27 20:51:26 +00003795 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003796 type;
3797
3798 if (*option == '+')
3799 break;
3800 i++;
cristybb503372010-05-27 20:51:26 +00003801 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003802 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003803 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003804 if (type < 0)
3805 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3806 argv[i]);
3807 break;
3808 }
3809 if (LocaleCompare("annotate",option+1) == 0)
3810 {
3811 if (*option == '+')
3812 break;
3813 i++;
cristybb503372010-05-27 20:51:26 +00003814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003815 ThrowMogrifyException(OptionError,"MissingArgument",option);
3816 if (IsGeometry(argv[i]) == MagickFalse)
3817 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003819 ThrowMogrifyException(OptionError,"MissingArgument",option);
3820 i++;
3821 break;
3822 }
3823 if (LocaleCompare("antialias",option+1) == 0)
3824 break;
3825 if (LocaleCompare("append",option+1) == 0)
3826 break;
3827 if (LocaleCompare("attenuate",option+1) == 0)
3828 {
3829 if (*option == '+')
3830 break;
3831 i++;
cristybb503372010-05-27 20:51:26 +00003832 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003833 ThrowMogrifyException(OptionError,"MissingArgument",option);
3834 if (IsGeometry(argv[i]) == MagickFalse)
3835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3836 break;
3837 }
3838 if (LocaleCompare("authenticate",option+1) == 0)
3839 {
3840 if (*option == '+')
3841 break;
3842 i++;
cristybb503372010-05-27 20:51:26 +00003843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003844 ThrowMogrifyException(OptionError,"MissingArgument",option);
3845 break;
3846 }
3847 if (LocaleCompare("auto-gamma",option+1) == 0)
3848 break;
3849 if (LocaleCompare("auto-level",option+1) == 0)
3850 break;
3851 if (LocaleCompare("auto-orient",option+1) == 0)
3852 break;
3853 if (LocaleCompare("average",option+1) == 0)
3854 break;
3855 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3856 }
3857 case 'b':
3858 {
3859 if (LocaleCompare("background",option+1) == 0)
3860 {
3861 if (*option == '+')
3862 break;
3863 i++;
cristybb503372010-05-27 20:51:26 +00003864 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003865 ThrowMogrifyException(OptionError,"MissingArgument",option);
3866 break;
3867 }
3868 if (LocaleCompare("bias",option+1) == 0)
3869 {
3870 if (*option == '+')
3871 break;
3872 i++;
cristybb503372010-05-27 20:51:26 +00003873 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003874 ThrowMogrifyException(OptionError,"MissingArgument",option);
3875 if (IsGeometry(argv[i]) == MagickFalse)
3876 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3877 break;
3878 }
3879 if (LocaleCompare("black-point-compensation",option+1) == 0)
3880 break;
3881 if (LocaleCompare("black-threshold",option+1) == 0)
3882 {
3883 if (*option == '+')
3884 break;
3885 i++;
cristybb503372010-05-27 20:51:26 +00003886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003887 ThrowMogrifyException(OptionError,"MissingArgument",option);
3888 if (IsGeometry(argv[i]) == MagickFalse)
3889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3890 break;
3891 }
3892 if (LocaleCompare("blue-primary",option+1) == 0)
3893 {
3894 if (*option == '+')
3895 break;
3896 i++;
cristybb503372010-05-27 20:51:26 +00003897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003898 ThrowMogrifyException(OptionError,"MissingArgument",option);
3899 if (IsGeometry(argv[i]) == MagickFalse)
3900 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3901 break;
3902 }
3903 if (LocaleCompare("blue-shift",option+1) == 0)
3904 {
3905 i++;
cristybb503372010-05-27 20:51:26 +00003906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003907 ThrowMogrifyException(OptionError,"MissingArgument",option);
3908 if (IsGeometry(argv[i]) == MagickFalse)
3909 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3910 break;
3911 }
3912 if (LocaleCompare("blur",option+1) == 0)
3913 {
3914 i++;
cristybb503372010-05-27 20:51:26 +00003915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003916 ThrowMogrifyException(OptionError,"MissingArgument",option);
3917 if (IsGeometry(argv[i]) == MagickFalse)
3918 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3919 break;
3920 }
3921 if (LocaleCompare("border",option+1) == 0)
3922 {
3923 if (*option == '+')
3924 break;
3925 i++;
cristybb503372010-05-27 20:51:26 +00003926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003927 ThrowMogrifyException(OptionError,"MissingArgument",option);
3928 if (IsGeometry(argv[i]) == MagickFalse)
3929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3930 break;
3931 }
3932 if (LocaleCompare("bordercolor",option+1) == 0)
3933 {
3934 if (*option == '+')
3935 break;
3936 i++;
cristybb503372010-05-27 20:51:26 +00003937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003938 ThrowMogrifyException(OptionError,"MissingArgument",option);
3939 break;
3940 }
3941 if (LocaleCompare("box",option+1) == 0)
3942 {
3943 if (*option == '+')
3944 break;
3945 i++;
cristybb503372010-05-27 20:51:26 +00003946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003947 ThrowMogrifyException(OptionError,"MissingArgument",option);
3948 break;
3949 }
cristya28d6b82010-01-11 20:03:47 +00003950 if (LocaleCompare("brightness-contrast",option+1) == 0)
3951 {
3952 i++;
cristybb503372010-05-27 20:51:26 +00003953 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003954 ThrowMogrifyException(OptionError,"MissingArgument",option);
3955 if (IsGeometry(argv[i]) == MagickFalse)
3956 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3957 break;
3958 }
cristy3ed852e2009-09-05 21:47:34 +00003959 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3960 }
3961 case 'c':
3962 {
3963 if (LocaleCompare("cache",option+1) == 0)
3964 {
3965 if (*option == '+')
3966 break;
3967 i++;
cristybb503372010-05-27 20:51:26 +00003968 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003969 ThrowMogrifyException(OptionError,"MissingArgument",option);
3970 if (IsGeometry(argv[i]) == MagickFalse)
3971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3972 break;
3973 }
3974 if (LocaleCompare("caption",option+1) == 0)
3975 {
3976 if (*option == '+')
3977 break;
3978 i++;
cristybb503372010-05-27 20:51:26 +00003979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003980 ThrowMogrifyException(OptionError,"MissingArgument",option);
3981 break;
3982 }
3983 if (LocaleCompare("channel",option+1) == 0)
3984 {
cristybb503372010-05-27 20:51:26 +00003985 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003986 channel;
3987
3988 if (*option == '+')
3989 break;
3990 i++;
cristybb503372010-05-27 20:51:26 +00003991 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003992 ThrowMogrifyException(OptionError,"MissingArgument",option);
3993 channel=ParseChannelOption(argv[i]);
3994 if (channel < 0)
3995 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3996 argv[i]);
3997 break;
3998 }
3999 if (LocaleCompare("cdl",option+1) == 0)
4000 {
4001 if (*option == '+')
4002 break;
4003 i++;
cristybb503372010-05-27 20:51:26 +00004004 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004005 ThrowMogrifyException(OptionError,"MissingArgument",option);
4006 break;
4007 }
4008 if (LocaleCompare("charcoal",option+1) == 0)
4009 {
4010 if (*option == '+')
4011 break;
4012 i++;
cristybb503372010-05-27 20:51:26 +00004013 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004014 ThrowMogrifyException(OptionError,"MissingArgument",option);
4015 if (IsGeometry(argv[i]) == MagickFalse)
4016 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4017 break;
4018 }
4019 if (LocaleCompare("chop",option+1) == 0)
4020 {
4021 if (*option == '+')
4022 break;
4023 i++;
cristybb503372010-05-27 20:51:26 +00004024 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004025 ThrowMogrifyException(OptionError,"MissingArgument",option);
4026 if (IsGeometry(argv[i]) == MagickFalse)
4027 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4028 break;
4029 }
cristy1eb45dd2009-09-25 16:38:06 +00004030 if (LocaleCompare("clamp",option+1) == 0)
4031 break;
4032 if (LocaleCompare("clip",option+1) == 0)
4033 break;
cristy3ed852e2009-09-05 21:47:34 +00004034 if (LocaleCompare("clip-mask",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 break;
4042 }
4043 if (LocaleCompare("clut",option+1) == 0)
4044 break;
4045 if (LocaleCompare("coalesce",option+1) == 0)
4046 break;
4047 if (LocaleCompare("colorize",option+1) == 0)
4048 {
4049 if (*option == '+')
4050 break;
4051 i++;
cristybb503372010-05-27 20:51:26 +00004052 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004053 ThrowMogrifyException(OptionError,"MissingArgument",option);
4054 if (IsGeometry(argv[i]) == MagickFalse)
4055 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4056 break;
4057 }
cristye6365592010-04-02 17:31:23 +00004058 if (LocaleCompare("color-matrix",option+1) == 0)
4059 {
cristyb6bd4ad2010-08-08 01:12:27 +00004060 KernelInfo
4061 *kernel_info;
4062
cristye6365592010-04-02 17:31:23 +00004063 if (*option == '+')
4064 break;
4065 i++;
cristybb503372010-05-27 20:51:26 +00004066 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004067 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004068 kernel_info=AcquireKernelInfo(argv[i]);
4069 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004070 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004071 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004072 break;
4073 }
cristy3ed852e2009-09-05 21:47:34 +00004074 if (LocaleCompare("colors",option+1) == 0)
4075 {
4076 if (*option == '+')
4077 break;
4078 i++;
cristybb503372010-05-27 20:51:26 +00004079 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004080 ThrowMogrifyException(OptionError,"MissingArgument",option);
4081 if (IsGeometry(argv[i]) == MagickFalse)
4082 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4083 break;
4084 }
4085 if (LocaleCompare("colorspace",option+1) == 0)
4086 {
cristybb503372010-05-27 20:51:26 +00004087 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004088 colorspace;
4089
4090 if (*option == '+')
4091 break;
4092 i++;
cristybb503372010-05-27 20:51:26 +00004093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004094 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004095 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004096 argv[i]);
4097 if (colorspace < 0)
4098 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4099 argv[i]);
4100 break;
4101 }
4102 if (LocaleCompare("combine",option+1) == 0)
4103 break;
4104 if (LocaleCompare("comment",option+1) == 0)
4105 {
4106 if (*option == '+')
4107 break;
4108 i++;
cristybb503372010-05-27 20:51:26 +00004109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004110 ThrowMogrifyException(OptionError,"MissingArgument",option);
4111 break;
4112 }
4113 if (LocaleCompare("composite",option+1) == 0)
4114 break;
4115 if (LocaleCompare("compress",option+1) == 0)
4116 {
cristybb503372010-05-27 20:51:26 +00004117 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004118 compress;
4119
4120 if (*option == '+')
4121 break;
4122 i++;
cristybb503372010-05-27 20:51:26 +00004123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004124 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004125 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004126 argv[i]);
4127 if (compress < 0)
4128 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4129 argv[i]);
4130 break;
4131 }
cristy22879752009-10-25 23:55:40 +00004132 if (LocaleCompare("concurrent",option+1) == 0)
4133 break;
cristy3ed852e2009-09-05 21:47:34 +00004134 if (LocaleCompare("contrast",option+1) == 0)
4135 break;
4136 if (LocaleCompare("contrast-stretch",option+1) == 0)
4137 {
4138 i++;
cristybb503372010-05-27 20:51:26 +00004139 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004140 ThrowMogrifyException(OptionError,"MissingArgument",option);
4141 if (IsGeometry(argv[i]) == MagickFalse)
4142 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4143 break;
4144 }
4145 if (LocaleCompare("convolve",option+1) == 0)
4146 {
cristyb6bd4ad2010-08-08 01:12:27 +00004147 KernelInfo
4148 *kernel_info;
4149
cristy3ed852e2009-09-05 21:47:34 +00004150 if (*option == '+')
4151 break;
4152 i++;
cristybb503372010-05-27 20:51:26 +00004153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004154 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004155 kernel_info=AcquireKernelInfo(argv[i]);
4156 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004157 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004158 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004159 break;
4160 }
4161 if (LocaleCompare("crop",option+1) == 0)
4162 {
4163 if (*option == '+')
4164 break;
4165 i++;
cristybb503372010-05-27 20:51:26 +00004166 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004167 ThrowMogrifyException(OptionError,"MissingArgument",option);
4168 if (IsGeometry(argv[i]) == MagickFalse)
4169 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4170 break;
4171 }
4172 if (LocaleCompare("cycle",option+1) == 0)
4173 {
4174 if (*option == '+')
4175 break;
4176 i++;
cristybb503372010-05-27 20:51:26 +00004177 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004178 ThrowMogrifyException(OptionError,"MissingArgument",option);
4179 if (IsGeometry(argv[i]) == MagickFalse)
4180 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4181 break;
4182 }
4183 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4184 }
4185 case 'd':
4186 {
4187 if (LocaleCompare("decipher",option+1) == 0)
4188 {
4189 if (*option == '+')
4190 break;
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
4194 break;
4195 }
4196 if (LocaleCompare("deconstruct",option+1) == 0)
4197 break;
4198 if (LocaleCompare("debug",option+1) == 0)
4199 {
cristybb503372010-05-27 20:51:26 +00004200 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004201 event;
4202
4203 if (*option == '+')
4204 break;
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004208 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004209 if (event < 0)
4210 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4211 argv[i]);
4212 (void) SetLogEventMask(argv[i]);
4213 break;
4214 }
4215 if (LocaleCompare("define",option+1) == 0)
4216 {
4217 i++;
cristybb503372010-05-27 20:51:26 +00004218 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004219 ThrowMogrifyException(OptionError,"MissingArgument",option);
4220 if (*option == '+')
4221 {
4222 const char
4223 *define;
4224
4225 define=GetImageOption(image_info,argv[i]);
4226 if (define == (const char *) NULL)
4227 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4228 break;
4229 }
4230 break;
4231 }
4232 if (LocaleCompare("delay",option+1) == 0)
4233 {
4234 if (*option == '+')
4235 break;
4236 i++;
cristybb503372010-05-27 20:51:26 +00004237 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004238 ThrowMogrifyException(OptionError,"MissingArgument",option);
4239 if (IsGeometry(argv[i]) == MagickFalse)
4240 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4241 break;
4242 }
cristyecb10ff2011-03-22 13:14:03 +00004243 if (LocaleCompare("delete",option+1) == 0)
4244 {
4245 if (*option == '+')
4246 break;
4247 i++;
4248 if (i == (ssize_t) (argc-1))
4249 ThrowMogrifyException(OptionError,"MissingArgument",option);
4250 if (IsGeometry(argv[i]) == MagickFalse)
4251 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4252 break;
4253 }
cristy3ed852e2009-09-05 21:47:34 +00004254 if (LocaleCompare("density",option+1) == 0)
4255 {
4256 if (*option == '+')
4257 break;
4258 i++;
cristybb503372010-05-27 20:51:26 +00004259 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004260 ThrowMogrifyException(OptionError,"MissingArgument",option);
4261 if (IsGeometry(argv[i]) == MagickFalse)
4262 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4263 break;
4264 }
4265 if (LocaleCompare("depth",option+1) == 0)
4266 {
4267 if (*option == '+')
4268 break;
4269 i++;
cristybb503372010-05-27 20:51:26 +00004270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004271 ThrowMogrifyException(OptionError,"MissingArgument",option);
4272 if (IsGeometry(argv[i]) == MagickFalse)
4273 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4274 break;
4275 }
4276 if (LocaleCompare("deskew",option+1) == 0)
4277 {
4278 if (*option == '+')
4279 break;
4280 i++;
cristybb503372010-05-27 20:51:26 +00004281 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004282 ThrowMogrifyException(OptionError,"MissingArgument",option);
4283 if (IsGeometry(argv[i]) == MagickFalse)
4284 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4285 break;
4286 }
4287 if (LocaleCompare("despeckle",option+1) == 0)
4288 break;
4289 if (LocaleCompare("dft",option+1) == 0)
4290 break;
cristyc9b12952010-03-28 01:12:28 +00004291 if (LocaleCompare("direction",option+1) == 0)
4292 {
cristybb503372010-05-27 20:51:26 +00004293 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004294 direction;
4295
4296 if (*option == '+')
4297 break;
4298 i++;
cristybb503372010-05-27 20:51:26 +00004299 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004300 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004301 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004302 argv[i]);
4303 if (direction < 0)
4304 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4305 argv[i]);
4306 break;
4307 }
cristy3ed852e2009-09-05 21:47:34 +00004308 if (LocaleCompare("display",option+1) == 0)
4309 {
4310 if (*option == '+')
4311 break;
4312 i++;
cristybb503372010-05-27 20:51:26 +00004313 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004314 ThrowMogrifyException(OptionError,"MissingArgument",option);
4315 break;
4316 }
4317 if (LocaleCompare("dispose",option+1) == 0)
4318 {
cristybb503372010-05-27 20:51:26 +00004319 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004320 dispose;
4321
4322 if (*option == '+')
4323 break;
4324 i++;
cristybb503372010-05-27 20:51:26 +00004325 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004326 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004327 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004328 if (dispose < 0)
4329 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4330 argv[i]);
4331 break;
4332 }
4333 if (LocaleCompare("distort",option+1) == 0)
4334 {
cristybb503372010-05-27 20:51:26 +00004335 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004336 op;
4337
4338 i++;
cristybb503372010-05-27 20:51:26 +00004339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004340 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004341 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004342 if (op < 0)
4343 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4344 argv[i]);
4345 i++;
cristybb503372010-05-27 20:51:26 +00004346 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004347 ThrowMogrifyException(OptionError,"MissingArgument",option);
4348 break;
4349 }
4350 if (LocaleCompare("dither",option+1) == 0)
4351 {
cristybb503372010-05-27 20:51:26 +00004352 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004353 method;
4354
4355 if (*option == '+')
4356 break;
4357 i++;
cristybb503372010-05-27 20:51:26 +00004358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004359 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004360 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004361 if (method < 0)
4362 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4363 argv[i]);
4364 break;
4365 }
4366 if (LocaleCompare("draw",option+1) == 0)
4367 {
4368 if (*option == '+')
4369 break;
4370 i++;
cristybb503372010-05-27 20:51:26 +00004371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004372 ThrowMogrifyException(OptionError,"MissingArgument",option);
4373 break;
4374 }
cristyecb10ff2011-03-22 13:14:03 +00004375 if (LocaleCompare("duplicate",option+1) == 0)
4376 {
4377 if (*option == '+')
4378 break;
4379 i++;
4380 if (i == (ssize_t) (argc-1))
4381 ThrowMogrifyException(OptionError,"MissingArgument",option);
4382 if (IsGeometry(argv[i]) == MagickFalse)
4383 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4384 break;
4385 }
cristy22879752009-10-25 23:55:40 +00004386 if (LocaleCompare("duration",option+1) == 0)
4387 {
4388 if (*option == '+')
4389 break;
4390 i++;
cristybb503372010-05-27 20:51:26 +00004391 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004392 ThrowMogrifyException(OptionError,"MissingArgument",option);
4393 if (IsGeometry(argv[i]) == MagickFalse)
4394 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4395 break;
4396 }
cristy3ed852e2009-09-05 21:47:34 +00004397 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4398 }
4399 case 'e':
4400 {
4401 if (LocaleCompare("edge",option+1) == 0)
4402 {
4403 if (*option == '+')
4404 break;
4405 i++;
cristybb503372010-05-27 20:51:26 +00004406 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004407 ThrowMogrifyException(OptionError,"MissingArgument",option);
4408 if (IsGeometry(argv[i]) == MagickFalse)
4409 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4410 break;
4411 }
4412 if (LocaleCompare("emboss",option+1) == 0)
4413 {
4414 if (*option == '+')
4415 break;
4416 i++;
cristybb503372010-05-27 20:51:26 +00004417 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004418 ThrowMogrifyException(OptionError,"MissingArgument",option);
4419 if (IsGeometry(argv[i]) == MagickFalse)
4420 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4421 break;
4422 }
4423 if (LocaleCompare("encipher",option+1) == 0)
4424 {
4425 if (*option == '+')
4426 break;
4427 i++;
cristybb503372010-05-27 20:51:26 +00004428 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004429 ThrowMogrifyException(OptionError,"MissingArgument",option);
4430 break;
4431 }
4432 if (LocaleCompare("encoding",option+1) == 0)
4433 {
4434 if (*option == '+')
4435 break;
4436 i++;
cristybb503372010-05-27 20:51:26 +00004437 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004438 ThrowMogrifyException(OptionError,"MissingArgument",option);
4439 break;
4440 }
4441 if (LocaleCompare("endian",option+1) == 0)
4442 {
cristybb503372010-05-27 20:51:26 +00004443 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004444 endian;
4445
4446 if (*option == '+')
4447 break;
4448 i++;
cristybb503372010-05-27 20:51:26 +00004449 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004450 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004451 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004452 if (endian < 0)
4453 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4454 argv[i]);
4455 break;
4456 }
4457 if (LocaleCompare("enhance",option+1) == 0)
4458 break;
4459 if (LocaleCompare("equalize",option+1) == 0)
4460 break;
4461 if (LocaleCompare("evaluate",option+1) == 0)
4462 {
cristybb503372010-05-27 20:51:26 +00004463 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004464 op;
4465
4466 if (*option == '+')
4467 break;
4468 i++;
cristybb503372010-05-27 20:51:26 +00004469 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004470 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004471 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004472 if (op < 0)
4473 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4474 argv[i]);
4475 i++;
cristybb503372010-05-27 20:51:26 +00004476 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004477 ThrowMogrifyException(OptionError,"MissingArgument",option);
4478 if (IsGeometry(argv[i]) == MagickFalse)
4479 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4480 break;
4481 }
cristyd18ae7c2010-03-07 17:39:52 +00004482 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4483 {
cristybb503372010-05-27 20:51:26 +00004484 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004485 op;
4486
4487 if (*option == '+')
4488 break;
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004492 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004493 if (op < 0)
4494 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4495 argv[i]);
4496 break;
4497 }
cristy3ed852e2009-09-05 21:47:34 +00004498 if (LocaleCompare("extent",option+1) == 0)
4499 {
4500 if (*option == '+')
4501 break;
4502 i++;
cristybb503372010-05-27 20:51:26 +00004503 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004504 ThrowMogrifyException(OptionError,"MissingArgument",option);
4505 if (IsGeometry(argv[i]) == MagickFalse)
4506 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4507 break;
4508 }
4509 if (LocaleCompare("extract",option+1) == 0)
4510 {
4511 if (*option == '+')
4512 break;
4513 i++;
cristybb503372010-05-27 20:51:26 +00004514 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004515 ThrowMogrifyException(OptionError,"MissingArgument",option);
4516 if (IsGeometry(argv[i]) == MagickFalse)
4517 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4518 break;
4519 }
4520 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4521 }
4522 case 'f':
4523 {
4524 if (LocaleCompare("family",option+1) == 0)
4525 {
4526 if (*option == '+')
4527 break;
4528 i++;
cristybb503372010-05-27 20:51:26 +00004529 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004530 ThrowMogrifyException(OptionError,"MissingArgument",option);
4531 break;
4532 }
4533 if (LocaleCompare("fill",option+1) == 0)
4534 {
4535 if (*option == '+')
4536 break;
4537 i++;
cristybb503372010-05-27 20:51:26 +00004538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004539 ThrowMogrifyException(OptionError,"MissingArgument",option);
4540 break;
4541 }
4542 if (LocaleCompare("filter",option+1) == 0)
4543 {
cristybb503372010-05-27 20:51:26 +00004544 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004545 filter;
4546
4547 if (*option == '+')
4548 break;
4549 i++;
cristybb503372010-05-27 20:51:26 +00004550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004551 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004552 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004553 if (filter < 0)
4554 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4555 argv[i]);
4556 break;
4557 }
4558 if (LocaleCompare("flatten",option+1) == 0)
4559 break;
4560 if (LocaleCompare("flip",option+1) == 0)
4561 break;
4562 if (LocaleCompare("flop",option+1) == 0)
4563 break;
4564 if (LocaleCompare("floodfill",option+1) == 0)
4565 {
4566 if (*option == '+')
4567 break;
4568 i++;
cristybb503372010-05-27 20:51:26 +00004569 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004570 ThrowMogrifyException(OptionError,"MissingArgument",option);
4571 if (IsGeometry(argv[i]) == MagickFalse)
4572 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4573 i++;
cristybb503372010-05-27 20:51:26 +00004574 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004575 ThrowMogrifyException(OptionError,"MissingArgument",option);
4576 break;
4577 }
4578 if (LocaleCompare("font",option+1) == 0)
4579 {
4580 if (*option == '+')
4581 break;
4582 i++;
cristybb503372010-05-27 20:51:26 +00004583 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004584 ThrowMogrifyException(OptionError,"MissingArgument",option);
4585 break;
4586 }
4587 if (LocaleCompare("format",option+1) == 0)
4588 {
4589 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4590 (void) CloneString(&format,(char *) NULL);
4591 if (*option == '+')
4592 break;
4593 i++;
cristybb503372010-05-27 20:51:26 +00004594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004595 ThrowMogrifyException(OptionError,"MissingArgument",option);
4596 (void) CloneString(&format,argv[i]);
4597 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4598 (void) ConcatenateMagickString(image_info->filename,":",
4599 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004600 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004601 if (*image_info->magick == '\0')
4602 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4603 format);
4604 break;
4605 }
4606 if (LocaleCompare("frame",option+1) == 0)
4607 {
4608 if (*option == '+')
4609 break;
4610 i++;
cristybb503372010-05-27 20:51:26 +00004611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004612 ThrowMogrifyException(OptionError,"MissingArgument",option);
4613 if (IsGeometry(argv[i]) == MagickFalse)
4614 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4615 break;
4616 }
4617 if (LocaleCompare("function",option+1) == 0)
4618 {
cristybb503372010-05-27 20:51:26 +00004619 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004620 op;
4621
4622 if (*option == '+')
4623 break;
4624 i++;
cristybb503372010-05-27 20:51:26 +00004625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004626 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004627 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004628 if (op < 0)
4629 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4630 i++;
cristybb503372010-05-27 20:51:26 +00004631 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004632 ThrowMogrifyException(OptionError,"MissingArgument",option);
4633 break;
4634 }
4635 if (LocaleCompare("fuzz",option+1) == 0)
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);
4642 if (IsGeometry(argv[i]) == MagickFalse)
4643 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4644 break;
4645 }
4646 if (LocaleCompare("fx",option+1) == 0)
4647 {
4648 if (*option == '+')
4649 break;
4650 i++;
cristybb503372010-05-27 20:51:26 +00004651 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004652 ThrowMogrifyException(OptionError,"MissingArgument",option);
4653 break;
4654 }
4655 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4656 }
4657 case 'g':
4658 {
4659 if (LocaleCompare("gamma",option+1) == 0)
4660 {
4661 i++;
cristybb503372010-05-27 20:51:26 +00004662 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004663 ThrowMogrifyException(OptionError,"MissingArgument",option);
4664 if (IsGeometry(argv[i]) == MagickFalse)
4665 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4666 break;
4667 }
4668 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4669 (LocaleCompare("gaussian",option+1) == 0))
4670 {
4671 i++;
cristybb503372010-05-27 20:51:26 +00004672 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 if (IsGeometry(argv[i]) == MagickFalse)
4675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676 break;
4677 }
4678 if (LocaleCompare("geometry",option+1) == 0)
4679 {
4680 if (*option == '+')
4681 break;
4682 i++;
cristybb503372010-05-27 20:51:26 +00004683 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004684 ThrowMogrifyException(OptionError,"MissingArgument",option);
4685 if (IsGeometry(argv[i]) == MagickFalse)
4686 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4687 break;
4688 }
4689 if (LocaleCompare("gravity",option+1) == 0)
4690 {
cristybb503372010-05-27 20:51:26 +00004691 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004692 gravity;
4693
4694 if (*option == '+')
4695 break;
4696 i++;
cristybb503372010-05-27 20:51:26 +00004697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004698 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004699 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004700 if (gravity < 0)
4701 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4702 argv[i]);
4703 break;
4704 }
4705 if (LocaleCompare("green-primary",option+1) == 0)
4706 {
4707 if (*option == '+')
4708 break;
4709 i++;
cristybb503372010-05-27 20:51:26 +00004710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004711 ThrowMogrifyException(OptionError,"MissingArgument",option);
4712 if (IsGeometry(argv[i]) == MagickFalse)
4713 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4714 break;
4715 }
4716 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4717 }
4718 case 'h':
4719 {
4720 if (LocaleCompare("hald-clut",option+1) == 0)
4721 break;
4722 if ((LocaleCompare("help",option+1) == 0) ||
4723 (LocaleCompare("-help",option+1) == 0))
4724 return(MogrifyUsage());
4725 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4726 }
4727 case 'i':
4728 {
4729 if (LocaleCompare("identify",option+1) == 0)
4730 break;
4731 if (LocaleCompare("idft",option+1) == 0)
4732 break;
4733 if (LocaleCompare("implode",option+1) == 0)
4734 {
4735 if (*option == '+')
4736 break;
4737 i++;
cristybb503372010-05-27 20:51:26 +00004738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004739 ThrowMogrifyException(OptionError,"MissingArgument",option);
4740 if (IsGeometry(argv[i]) == MagickFalse)
4741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4742 break;
4743 }
4744 if (LocaleCompare("intent",option+1) == 0)
4745 {
cristybb503372010-05-27 20:51:26 +00004746 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004747 intent;
4748
4749 if (*option == '+')
4750 break;
4751 i++;
cristybb503372010-05-27 20:51:26 +00004752 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004753 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004754 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004755 if (intent < 0)
4756 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4757 argv[i]);
4758 break;
4759 }
4760 if (LocaleCompare("interlace",option+1) == 0)
4761 {
cristybb503372010-05-27 20:51:26 +00004762 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004763 interlace;
4764
4765 if (*option == '+')
4766 break;
4767 i++;
cristybb503372010-05-27 20:51:26 +00004768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004769 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004770 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004771 argv[i]);
4772 if (interlace < 0)
4773 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4774 argv[i]);
4775 break;
4776 }
cristyb32b90a2009-09-07 21:45:48 +00004777 if (LocaleCompare("interline-spacing",option+1) == 0)
4778 {
4779 if (*option == '+')
4780 break;
4781 i++;
cristybb503372010-05-27 20:51:26 +00004782 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004783 ThrowMogrifyException(OptionError,"MissingArgument",option);
4784 if (IsGeometry(argv[i]) == MagickFalse)
4785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4786 break;
4787 }
cristy3ed852e2009-09-05 21:47:34 +00004788 if (LocaleCompare("interpolate",option+1) == 0)
4789 {
cristybb503372010-05-27 20:51:26 +00004790 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004791 interpolate;
4792
4793 if (*option == '+')
4794 break;
4795 i++;
cristybb503372010-05-27 20:51:26 +00004796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004797 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004798 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004799 argv[i]);
4800 if (interpolate < 0)
4801 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4802 argv[i]);
4803 break;
4804 }
4805 if (LocaleCompare("interword-spacing",option+1) == 0)
4806 {
4807 if (*option == '+')
4808 break;
4809 i++;
cristybb503372010-05-27 20:51:26 +00004810 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004811 ThrowMogrifyException(OptionError,"MissingArgument",option);
4812 if (IsGeometry(argv[i]) == MagickFalse)
4813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4814 break;
4815 }
4816 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4817 }
4818 case 'k':
4819 {
4820 if (LocaleCompare("kerning",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 'l':
4834 {
4835 if (LocaleCompare("label",option+1) == 0)
4836 {
4837 if (*option == '+')
4838 break;
4839 i++;
cristybb503372010-05-27 20:51:26 +00004840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004841 ThrowMogrifyException(OptionError,"MissingArgument",option);
4842 break;
4843 }
4844 if (LocaleCompare("lat",option+1) == 0)
4845 {
4846 if (*option == '+')
4847 break;
4848 i++;
cristybb503372010-05-27 20:51:26 +00004849 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004850 ThrowMogrifyException(OptionError,"MissingArgument",option);
4851 if (IsGeometry(argv[i]) == MagickFalse)
4852 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4853 }
4854 if (LocaleCompare("layers",option+1) == 0)
4855 {
cristybb503372010-05-27 20:51:26 +00004856 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004857 type;
4858
4859 if (*option == '+')
4860 break;
4861 i++;
cristybb503372010-05-27 20:51:26 +00004862 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004863 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004864 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004865 if (type < 0)
4866 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4867 argv[i]);
4868 break;
4869 }
4870 if (LocaleCompare("level",option+1) == 0)
4871 {
4872 i++;
cristybb503372010-05-27 20:51:26 +00004873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004874 ThrowMogrifyException(OptionError,"MissingArgument",option);
4875 if (IsGeometry(argv[i]) == MagickFalse)
4876 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4877 break;
4878 }
4879 if (LocaleCompare("level-colors",option+1) == 0)
4880 {
4881 i++;
cristybb503372010-05-27 20:51:26 +00004882 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004883 ThrowMogrifyException(OptionError,"MissingArgument",option);
4884 break;
4885 }
4886 if (LocaleCompare("linewidth",option+1) == 0)
4887 {
4888 if (*option == '+')
4889 break;
4890 i++;
cristybb503372010-05-27 20:51:26 +00004891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004892 ThrowMogrifyException(OptionError,"MissingArgument",option);
4893 if (IsGeometry(argv[i]) == MagickFalse)
4894 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4895 break;
4896 }
4897 if (LocaleCompare("limit",option+1) == 0)
4898 {
4899 char
4900 *p;
4901
4902 double
4903 value;
4904
cristybb503372010-05-27 20:51:26 +00004905 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004906 resource;
4907
4908 if (*option == '+')
4909 break;
4910 i++;
cristybb503372010-05-27 20:51:26 +00004911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004912 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004913 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004914 argv[i]);
4915 if (resource < 0)
4916 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4917 argv[i]);
4918 i++;
cristybb503372010-05-27 20:51:26 +00004919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004920 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004921 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004922 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004923 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4925 break;
4926 }
4927 if (LocaleCompare("liquid-rescale",option+1) == 0)
4928 {
4929 i++;
cristybb503372010-05-27 20:51:26 +00004930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004931 ThrowMogrifyException(OptionError,"MissingArgument",option);
4932 if (IsGeometry(argv[i]) == MagickFalse)
4933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4934 break;
4935 }
4936 if (LocaleCompare("list",option+1) == 0)
4937 {
cristybb503372010-05-27 20:51:26 +00004938 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004939 list;
4940
4941 if (*option == '+')
4942 break;
4943 i++;
cristybb503372010-05-27 20:51:26 +00004944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004945 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004946 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004947 if (list < 0)
4948 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004949 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004950 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004951 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004952 }
4953 if (LocaleCompare("log",option+1) == 0)
4954 {
4955 if (*option == '+')
4956 break;
4957 i++;
cristybb503372010-05-27 20:51:26 +00004958 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004959 (strchr(argv[i],'%') == (char *) NULL))
4960 ThrowMogrifyException(OptionError,"MissingArgument",option);
4961 break;
4962 }
4963 if (LocaleCompare("loop",option+1) == 0)
4964 {
4965 if (*option == '+')
4966 break;
4967 i++;
cristybb503372010-05-27 20:51:26 +00004968 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004969 ThrowMogrifyException(OptionError,"MissingArgument",option);
4970 if (IsGeometry(argv[i]) == MagickFalse)
4971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4972 break;
4973 }
4974 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4975 }
4976 case 'm':
4977 {
4978 if (LocaleCompare("map",option+1) == 0)
4979 {
4980 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4981 if (*option == '+')
4982 break;
4983 i++;
cristybb503372010-05-27 20:51:26 +00004984 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004985 ThrowMogrifyException(OptionError,"MissingArgument",option);
4986 break;
4987 }
4988 if (LocaleCompare("mask",option+1) == 0)
4989 {
4990 if (*option == '+')
4991 break;
4992 i++;
cristybb503372010-05-27 20:51:26 +00004993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004994 ThrowMogrifyException(OptionError,"MissingArgument",option);
4995 break;
4996 }
4997 if (LocaleCompare("matte",option+1) == 0)
4998 break;
4999 if (LocaleCompare("mattecolor",option+1) == 0)
5000 {
5001 if (*option == '+')
5002 break;
5003 i++;
cristybb503372010-05-27 20:51:26 +00005004 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005005 ThrowMogrifyException(OptionError,"MissingArgument",option);
5006 break;
5007 }
cristyf40785b2010-03-06 02:27:27 +00005008 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005009 break;
cristyf40785b2010-03-06 02:27:27 +00005010 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005011 break;
cristy3ed852e2009-09-05 21:47:34 +00005012 if (LocaleCompare("modulate",option+1) == 0)
5013 {
5014 if (*option == '+')
5015 break;
5016 i++;
cristybb503372010-05-27 20:51:26 +00005017 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005018 ThrowMogrifyException(OptionError,"MissingArgument",option);
5019 if (IsGeometry(argv[i]) == MagickFalse)
5020 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5021 break;
5022 }
5023 if (LocaleCompare("median",option+1) == 0)
5024 {
5025 if (*option == '+')
5026 break;
5027 i++;
cristybb503372010-05-27 20:51:26 +00005028 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005029 ThrowMogrifyException(OptionError,"MissingArgument",option);
5030 if (IsGeometry(argv[i]) == MagickFalse)
5031 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5032 break;
5033 }
cristy69ec32d2011-02-27 23:57:09 +00005034 if (LocaleCompare("mode",option+1) == 0)
5035 {
5036 if (*option == '+')
5037 break;
5038 i++;
5039 if (i == (ssize_t) argc)
5040 ThrowMogrifyException(OptionError,"MissingArgument",option);
5041 if (IsGeometry(argv[i]) == MagickFalse)
5042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5043 break;
5044 }
cristy3ed852e2009-09-05 21:47:34 +00005045 if (LocaleCompare("monitor",option+1) == 0)
5046 break;
5047 if (LocaleCompare("monochrome",option+1) == 0)
5048 break;
5049 if (LocaleCompare("morph",option+1) == 0)
5050 {
5051 if (*option == '+')
5052 break;
5053 i++;
cristybb503372010-05-27 20:51:26 +00005054 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005055 ThrowMogrifyException(OptionError,"MissingArgument",option);
5056 if (IsGeometry(argv[i]) == MagickFalse)
5057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5058 break;
5059 }
anthony29188a82010-01-22 10:12:34 +00005060 if (LocaleCompare("morphology",option+1) == 0)
5061 {
anthony29188a82010-01-22 10:12:34 +00005062 char
5063 token[MaxTextExtent];
5064
cristyb6bd4ad2010-08-08 01:12:27 +00005065 KernelInfo
5066 *kernel_info;
5067
5068 ssize_t
5069 op;
5070
anthony29188a82010-01-22 10:12:34 +00005071 i++;
cristybb503372010-05-27 20:51:26 +00005072 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005073 ThrowMogrifyException(OptionError,"MissingArgument",option);
5074 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005075 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005076 if (op < 0)
5077 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005078 token);
anthony29188a82010-01-22 10:12:34 +00005079 i++;
cristybb503372010-05-27 20:51:26 +00005080 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005081 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005082 kernel_info=AcquireKernelInfo(argv[i]);
5083 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005084 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005085 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005086 break;
5087 }
cristy3ed852e2009-09-05 21:47:34 +00005088 if (LocaleCompare("mosaic",option+1) == 0)
5089 break;
5090 if (LocaleCompare("motion-blur",option+1) == 0)
5091 {
5092 if (*option == '+')
5093 break;
5094 i++;
cristybb503372010-05-27 20:51:26 +00005095 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005096 ThrowMogrifyException(OptionError,"MissingArgument",option);
5097 if (IsGeometry(argv[i]) == MagickFalse)
5098 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5099 break;
5100 }
5101 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5102 }
5103 case 'n':
5104 {
5105 if (LocaleCompare("negate",option+1) == 0)
5106 break;
5107 if (LocaleCompare("noise",option+1) == 0)
5108 {
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 (*option == '+')
5113 {
cristybb503372010-05-27 20:51:26 +00005114 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005115 noise;
5116
cristy042ee782011-04-22 18:48:30 +00005117 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005118 if (noise < 0)
5119 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5120 argv[i]);
5121 break;
5122 }
5123 if (IsGeometry(argv[i]) == MagickFalse)
5124 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5125 break;
5126 }
5127 if (LocaleCompare("noop",option+1) == 0)
5128 break;
5129 if (LocaleCompare("normalize",option+1) == 0)
5130 break;
5131 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5132 }
5133 case 'o':
5134 {
5135 if (LocaleCompare("opaque",option+1) == 0)
5136 {
cristy3ed852e2009-09-05 21:47:34 +00005137 i++;
cristybb503372010-05-27 20:51:26 +00005138 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005139 ThrowMogrifyException(OptionError,"MissingArgument",option);
5140 break;
5141 }
5142 if (LocaleCompare("ordered-dither",option+1) == 0)
5143 {
5144 if (*option == '+')
5145 break;
5146 i++;
cristybb503372010-05-27 20:51:26 +00005147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005148 ThrowMogrifyException(OptionError,"MissingArgument",option);
5149 break;
5150 }
5151 if (LocaleCompare("orient",option+1) == 0)
5152 {
cristybb503372010-05-27 20:51:26 +00005153 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005154 orientation;
5155
5156 orientation=UndefinedOrientation;
5157 if (*option == '+')
5158 break;
5159 i++;
cristybb503372010-05-27 20:51:26 +00005160 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005161 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005162 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005163 argv[i]);
5164 if (orientation < 0)
5165 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5166 argv[i]);
5167 break;
5168 }
5169 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5170 }
5171 case 'p':
5172 {
5173 if (LocaleCompare("page",option+1) == 0)
5174 {
5175 if (*option == '+')
5176 break;
5177 i++;
cristybb503372010-05-27 20:51:26 +00005178 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005179 ThrowMogrifyException(OptionError,"MissingArgument",option);
5180 break;
5181 }
5182 if (LocaleCompare("paint",option+1) == 0)
5183 {
5184 if (*option == '+')
5185 break;
5186 i++;
cristybb503372010-05-27 20:51:26 +00005187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005188 ThrowMogrifyException(OptionError,"MissingArgument",option);
5189 if (IsGeometry(argv[i]) == MagickFalse)
5190 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5191 break;
5192 }
5193 if (LocaleCompare("path",option+1) == 0)
5194 {
5195 (void) CloneString(&path,(char *) NULL);
5196 if (*option == '+')
5197 break;
5198 i++;
cristybb503372010-05-27 20:51:26 +00005199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005200 ThrowMogrifyException(OptionError,"MissingArgument",option);
5201 (void) CloneString(&path,argv[i]);
5202 break;
5203 }
5204 if (LocaleCompare("pointsize",option+1) == 0)
5205 {
5206 if (*option == '+')
5207 break;
5208 i++;
cristybb503372010-05-27 20:51:26 +00005209 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005210 ThrowMogrifyException(OptionError,"MissingArgument",option);
5211 if (IsGeometry(argv[i]) == MagickFalse)
5212 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5213 break;
5214 }
5215 if (LocaleCompare("polaroid",option+1) == 0)
5216 {
5217 if (*option == '+')
5218 break;
5219 i++;
cristybb503372010-05-27 20:51:26 +00005220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005221 ThrowMogrifyException(OptionError,"MissingArgument",option);
5222 if (IsGeometry(argv[i]) == MagickFalse)
5223 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5224 break;
5225 }
5226 if (LocaleCompare("posterize",option+1) == 0)
5227 {
5228 if (*option == '+')
5229 break;
5230 i++;
cristybb503372010-05-27 20:51:26 +00005231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005232 ThrowMogrifyException(OptionError,"MissingArgument",option);
5233 if (IsGeometry(argv[i]) == MagickFalse)
5234 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5235 break;
5236 }
cristye7f51092010-01-17 00:39:37 +00005237 if (LocaleCompare("precision",option+1) == 0)
5238 {
5239 if (*option == '+')
5240 break;
5241 i++;
cristybb503372010-05-27 20:51:26 +00005242 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005243 ThrowMogrifyException(OptionError,"MissingArgument",option);
5244 if (IsGeometry(argv[i]) == MagickFalse)
5245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5246 break;
5247 }
cristy3ed852e2009-09-05 21:47:34 +00005248 if (LocaleCompare("print",option+1) == 0)
5249 {
5250 if (*option == '+')
5251 break;
5252 i++;
cristybb503372010-05-27 20:51:26 +00005253 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005254 ThrowMogrifyException(OptionError,"MissingArgument",option);
5255 break;
5256 }
5257 if (LocaleCompare("process",option+1) == 0)
5258 {
5259 if (*option == '+')
5260 break;
5261 i++;
cristybb503372010-05-27 20:51:26 +00005262 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005263 ThrowMogrifyException(OptionError,"MissingArgument",option);
5264 break;
5265 }
5266 if (LocaleCompare("profile",option+1) == 0)
5267 {
5268 i++;
cristybb503372010-05-27 20:51:26 +00005269 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005270 ThrowMogrifyException(OptionError,"MissingArgument",option);
5271 break;
5272 }
5273 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5274 }
5275 case 'q':
5276 {
5277 if (LocaleCompare("quality",option+1) == 0)
5278 {
5279 if (*option == '+')
5280 break;
5281 i++;
cristybb503372010-05-27 20:51:26 +00005282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005283 ThrowMogrifyException(OptionError,"MissingArgument",option);
5284 if (IsGeometry(argv[i]) == MagickFalse)
5285 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5286 break;
5287 }
5288 if (LocaleCompare("quantize",option+1) == 0)
5289 {
cristybb503372010-05-27 20:51:26 +00005290 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005291 colorspace;
5292
5293 if (*option == '+')
5294 break;
5295 i++;
cristybb503372010-05-27 20:51:26 +00005296 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005297 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005298 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005299 argv[i]);
5300 if (colorspace < 0)
5301 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5302 argv[i]);
5303 break;
5304 }
5305 if (LocaleCompare("quiet",option+1) == 0)
5306 break;
5307 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5308 }
5309 case 'r':
5310 {
5311 if (LocaleCompare("radial-blur",option+1) == 0)
5312 {
5313 i++;
cristybb503372010-05-27 20:51:26 +00005314 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005315 ThrowMogrifyException(OptionError,"MissingArgument",option);
5316 if (IsGeometry(argv[i]) == MagickFalse)
5317 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5318 break;
5319 }
5320 if (LocaleCompare("raise",option+1) == 0)
5321 {
5322 i++;
cristybb503372010-05-27 20:51:26 +00005323 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005324 ThrowMogrifyException(OptionError,"MissingArgument",option);
5325 if (IsGeometry(argv[i]) == MagickFalse)
5326 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5327 break;
5328 }
5329 if (LocaleCompare("random-threshold",option+1) == 0)
5330 {
5331 if (*option == '+')
5332 break;
5333 i++;
cristybb503372010-05-27 20:51:26 +00005334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005335 ThrowMogrifyException(OptionError,"MissingArgument",option);
5336 if (IsGeometry(argv[i]) == MagickFalse)
5337 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5338 break;
5339 }
cristye6365592010-04-02 17:31:23 +00005340 if (LocaleCompare("recolor",option+1) == 0)
5341 {
5342 if (*option == '+')
5343 break;
5344 i++;
cristybb503372010-05-27 20:51:26 +00005345 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005346 ThrowMogrifyException(OptionError,"MissingArgument",option);
5347 if (IsGeometry(argv[i]) == MagickFalse)
5348 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5349 break;
5350 }
cristy3ed852e2009-09-05 21:47:34 +00005351 if (LocaleCompare("red-primary",option+1) == 0)
5352 {
5353 if (*option == '+')
5354 break;
5355 i++;
cristybb503372010-05-27 20:51:26 +00005356 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005357 ThrowMogrifyException(OptionError,"MissingArgument",option);
5358 if (IsGeometry(argv[i]) == MagickFalse)
5359 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5360 }
cristy9f2083a2010-04-22 19:48:05 +00005361 if (LocaleCompare("regard-warnings",option+1) == 0)
5362 break;
cristy3ed852e2009-09-05 21:47:34 +00005363 if (LocaleCompare("region",option+1) == 0)
5364 {
5365 if (*option == '+')
5366 break;
5367 i++;
cristybb503372010-05-27 20:51:26 +00005368 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005369 ThrowMogrifyException(OptionError,"MissingArgument",option);
5370 if (IsGeometry(argv[i]) == MagickFalse)
5371 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5372 break;
5373 }
cristyf0c78232010-03-15 12:53:40 +00005374 if (LocaleCompare("remap",option+1) == 0)
5375 {
5376 if (*option == '+')
5377 break;
5378 i++;
cristybb503372010-05-27 20:51:26 +00005379 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005380 ThrowMogrifyException(OptionError,"MissingArgument",option);
5381 break;
5382 }
cristy3ed852e2009-09-05 21:47:34 +00005383 if (LocaleCompare("render",option+1) == 0)
5384 break;
5385 if (LocaleCompare("repage",option+1) == 0)
5386 {
5387 if (*option == '+')
5388 break;
5389 i++;
cristybb503372010-05-27 20:51:26 +00005390 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005391 ThrowMogrifyException(OptionError,"MissingArgument",option);
5392 if (IsGeometry(argv[i]) == MagickFalse)
5393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5394 break;
5395 }
5396 if (LocaleCompare("resample",option+1) == 0)
5397 {
5398 if (*option == '+')
5399 break;
5400 i++;
cristybb503372010-05-27 20:51:26 +00005401 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005402 ThrowMogrifyException(OptionError,"MissingArgument",option);
5403 if (IsGeometry(argv[i]) == MagickFalse)
5404 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5405 break;
5406 }
5407 if (LocaleCompare("resize",option+1) == 0)
5408 {
5409 if (*option == '+')
5410 break;
5411 i++;
cristybb503372010-05-27 20:51:26 +00005412 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005413 ThrowMogrifyException(OptionError,"MissingArgument",option);
5414 if (IsGeometry(argv[i]) == MagickFalse)
5415 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5416 break;
5417 }
cristyebbcfea2011-02-25 02:43:54 +00005418 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5419 {
5420 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5421 break;
5422 }
cristy3ed852e2009-09-05 21:47:34 +00005423 if (LocaleCompare("reverse",option+1) == 0)
5424 break;
5425 if (LocaleCompare("roll",option+1) == 0)
5426 {
5427 if (*option == '+')
5428 break;
5429 i++;
cristybb503372010-05-27 20:51:26 +00005430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005431 ThrowMogrifyException(OptionError,"MissingArgument",option);
5432 if (IsGeometry(argv[i]) == MagickFalse)
5433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5434 break;
5435 }
5436 if (LocaleCompare("rotate",option+1) == 0)
5437 {
5438 i++;
cristybb503372010-05-27 20:51:26 +00005439 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005440 ThrowMogrifyException(OptionError,"MissingArgument",option);
5441 if (IsGeometry(argv[i]) == MagickFalse)
5442 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5443 break;
5444 }
5445 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5446 }
5447 case 's':
5448 {
5449 if (LocaleCompare("sample",option+1) == 0)
5450 {
5451 if (*option == '+')
5452 break;
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 if (LocaleCompare("sampling-factor",option+1) == 0)
5461 {
5462 if (*option == '+')
5463 break;
5464 i++;
cristybb503372010-05-27 20:51:26 +00005465 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005466 ThrowMogrifyException(OptionError,"MissingArgument",option);
5467 if (IsGeometry(argv[i]) == MagickFalse)
5468 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5469 break;
5470 }
5471 if (LocaleCompare("scale",option+1) == 0)
5472 {
5473 if (*option == '+')
5474 break;
5475 i++;
cristybb503372010-05-27 20:51:26 +00005476 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005477 ThrowMogrifyException(OptionError,"MissingArgument",option);
5478 if (IsGeometry(argv[i]) == MagickFalse)
5479 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5480 break;
5481 }
5482 if (LocaleCompare("scene",option+1) == 0)
5483 {
5484 if (*option == '+')
5485 break;
5486 i++;
cristybb503372010-05-27 20:51:26 +00005487 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005488 ThrowMogrifyException(OptionError,"MissingArgument",option);
5489 if (IsGeometry(argv[i]) == MagickFalse)
5490 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5491 break;
5492 }
5493 if (LocaleCompare("seed",option+1) == 0)
5494 {
5495 if (*option == '+')
5496 break;
5497 i++;
cristybb503372010-05-27 20:51:26 +00005498 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005499 ThrowMogrifyException(OptionError,"MissingArgument",option);
5500 if (IsGeometry(argv[i]) == MagickFalse)
5501 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5502 break;
5503 }
5504 if (LocaleCompare("segment",option+1) == 0)
5505 {
5506 if (*option == '+')
5507 break;
5508 i++;
cristybb503372010-05-27 20:51:26 +00005509 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005510 ThrowMogrifyException(OptionError,"MissingArgument",option);
5511 if (IsGeometry(argv[i]) == MagickFalse)
5512 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5513 break;
5514 }
5515 if (LocaleCompare("selective-blur",option+1) == 0)
5516 {
5517 i++;
cristybb503372010-05-27 20:51:26 +00005518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 if (IsGeometry(argv[i]) == MagickFalse)
5521 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5522 break;
5523 }
5524 if (LocaleCompare("separate",option+1) == 0)
5525 break;
5526 if (LocaleCompare("sepia-tone",option+1) == 0)
5527 {
5528 if (*option == '+')
5529 break;
5530 i++;
cristybb503372010-05-27 20:51:26 +00005531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005532 ThrowMogrifyException(OptionError,"MissingArgument",option);
5533 if (IsGeometry(argv[i]) == MagickFalse)
5534 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5535 break;
5536 }
5537 if (LocaleCompare("set",option+1) == 0)
5538 {
5539 i++;
cristybb503372010-05-27 20:51:26 +00005540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005541 ThrowMogrifyException(OptionError,"MissingArgument",option);
5542 if (*option == '+')
5543 break;
5544 i++;
cristybb503372010-05-27 20:51:26 +00005545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 break;
5548 }
5549 if (LocaleCompare("shade",option+1) == 0)
5550 {
5551 i++;
cristybb503372010-05-27 20:51:26 +00005552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005553 ThrowMogrifyException(OptionError,"MissingArgument",option);
5554 if (IsGeometry(argv[i]) == MagickFalse)
5555 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5556 break;
5557 }
5558 if (LocaleCompare("shadow",option+1) == 0)
5559 {
5560 if (*option == '+')
5561 break;
5562 i++;
cristybb503372010-05-27 20:51:26 +00005563 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005564 ThrowMogrifyException(OptionError,"MissingArgument",option);
5565 if (IsGeometry(argv[i]) == MagickFalse)
5566 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5567 break;
5568 }
5569 if (LocaleCompare("sharpen",option+1) == 0)
5570 {
5571 i++;
cristybb503372010-05-27 20:51:26 +00005572 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005573 ThrowMogrifyException(OptionError,"MissingArgument",option);
5574 if (IsGeometry(argv[i]) == MagickFalse)
5575 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5576 break;
5577 }
5578 if (LocaleCompare("shave",option+1) == 0)
5579 {
5580 if (*option == '+')
5581 break;
5582 i++;
cristybb503372010-05-27 20:51:26 +00005583 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005584 ThrowMogrifyException(OptionError,"MissingArgument",option);
5585 if (IsGeometry(argv[i]) == MagickFalse)
5586 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5587 break;
5588 }
5589 if (LocaleCompare("shear",option+1) == 0)
5590 {
5591 i++;
cristybb503372010-05-27 20:51:26 +00005592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005593 ThrowMogrifyException(OptionError,"MissingArgument",option);
5594 if (IsGeometry(argv[i]) == MagickFalse)
5595 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5596 break;
5597 }
5598 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5599 {
5600 i++;
cristybb503372010-05-27 20:51:26 +00005601 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005602 ThrowMogrifyException(OptionError,"MissingArgument",option);
5603 if (IsGeometry(argv[i]) == MagickFalse)
5604 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5605 break;
5606 }
5607 if (LocaleCompare("size",option+1) == 0)
5608 {
5609 if (*option == '+')
5610 break;
5611 i++;
cristybb503372010-05-27 20:51:26 +00005612 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005613 ThrowMogrifyException(OptionError,"MissingArgument",option);
5614 if (IsGeometry(argv[i]) == MagickFalse)
5615 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5616 break;
5617 }
5618 if (LocaleCompare("sketch",option+1) == 0)
5619 {
5620 if (*option == '+')
5621 break;
5622 i++;
cristybb503372010-05-27 20:51:26 +00005623 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005624 ThrowMogrifyException(OptionError,"MissingArgument",option);
5625 if (IsGeometry(argv[i]) == MagickFalse)
5626 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5627 break;
5628 }
cristy4285d782011-02-09 20:12:28 +00005629 if (LocaleCompare("smush",option+1) == 0)
5630 {
cristy4285d782011-02-09 20:12:28 +00005631 i++;
5632 if (i == (ssize_t) argc)
5633 ThrowMogrifyException(OptionError,"MissingArgument",option);
5634 if (IsGeometry(argv[i]) == MagickFalse)
5635 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005636 i++;
5637 break;
5638 }
cristy3ed852e2009-09-05 21:47:34 +00005639 if (LocaleCompare("solarize",option+1) == 0)
5640 {
5641 if (*option == '+')
5642 break;
5643 i++;
cristybb503372010-05-27 20:51:26 +00005644 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005645 ThrowMogrifyException(OptionError,"MissingArgument",option);
5646 if (IsGeometry(argv[i]) == MagickFalse)
5647 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5648 break;
5649 }
5650 if (LocaleCompare("sparse-color",option+1) == 0)
5651 {
cristybb503372010-05-27 20:51:26 +00005652 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005653 op;
5654
5655 i++;
cristybb503372010-05-27 20:51:26 +00005656 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005657 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005658 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005659 if (op < 0)
5660 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5661 argv[i]);
5662 i++;
cristybb503372010-05-27 20:51:26 +00005663 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005664 ThrowMogrifyException(OptionError,"MissingArgument",option);
5665 break;
5666 }
5667 if (LocaleCompare("spread",option+1) == 0)
5668 {
5669 if (*option == '+')
5670 break;
5671 i++;
cristybb503372010-05-27 20:51:26 +00005672 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005673 ThrowMogrifyException(OptionError,"MissingArgument",option);
5674 if (IsGeometry(argv[i]) == MagickFalse)
5675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5676 break;
5677 }
cristy0834d642011-03-18 18:26:08 +00005678 if (LocaleCompare("statistic",option+1) == 0)
5679 {
5680 ssize_t
5681 op;
5682
5683 if (*option == '+')
5684 break;
5685 i++;
5686 if (i == (ssize_t) argc)
5687 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005688 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005689 if (op < 0)
5690 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5691 argv[i]);
5692 i++;
5693 if (i == (ssize_t) (argc-1))
5694 ThrowMogrifyException(OptionError,"MissingArgument",option);
5695 if (IsGeometry(argv[i]) == MagickFalse)
5696 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5697 break;
5698 }
cristy3ed852e2009-09-05 21:47:34 +00005699 if (LocaleCompare("stretch",option+1) == 0)
5700 {
cristybb503372010-05-27 20:51:26 +00005701 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005702 stretch;
5703
5704 if (*option == '+')
5705 break;
5706 i++;
cristybb503372010-05-27 20:51:26 +00005707 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005708 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005709 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005710 if (stretch < 0)
5711 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5712 argv[i]);
5713 break;
5714 }
5715 if (LocaleCompare("strip",option+1) == 0)
5716 break;
5717 if (LocaleCompare("stroke",option+1) == 0)
5718 {
5719 if (*option == '+')
5720 break;
5721 i++;
cristybb503372010-05-27 20:51:26 +00005722 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005723 ThrowMogrifyException(OptionError,"MissingArgument",option);
5724 break;
5725 }
5726 if (LocaleCompare("strokewidth",option+1) == 0)
5727 {
5728 if (*option == '+')
5729 break;
5730 i++;
cristybb503372010-05-27 20:51:26 +00005731 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005732 ThrowMogrifyException(OptionError,"MissingArgument",option);
5733 if (IsGeometry(argv[i]) == MagickFalse)
5734 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5735 break;
5736 }
5737 if (LocaleCompare("style",option+1) == 0)
5738 {
cristybb503372010-05-27 20:51:26 +00005739 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005740 style;
5741
5742 if (*option == '+')
5743 break;
5744 i++;
cristybb503372010-05-27 20:51:26 +00005745 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005746 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005747 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005748 if (style < 0)
5749 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5750 argv[i]);
5751 break;
5752 }
cristyecb10ff2011-03-22 13:14:03 +00005753 if (LocaleCompare("swap",option+1) == 0)
5754 {
5755 if (*option == '+')
5756 break;
5757 i++;
5758 if (i == (ssize_t) (argc-1))
5759 ThrowMogrifyException(OptionError,"MissingArgument",option);
5760 if (IsGeometry(argv[i]) == MagickFalse)
5761 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5762 break;
5763 }
cristy3ed852e2009-09-05 21:47:34 +00005764 if (LocaleCompare("swirl",option+1) == 0)
5765 {
5766 if (*option == '+')
5767 break;
5768 i++;
cristybb503372010-05-27 20:51:26 +00005769 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005770 ThrowMogrifyException(OptionError,"MissingArgument",option);
5771 if (IsGeometry(argv[i]) == MagickFalse)
5772 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5773 break;
5774 }
cristyd9a29192010-10-16 16:49:53 +00005775 if (LocaleCompare("synchronize",option+1) == 0)
5776 break;
cristy3ed852e2009-09-05 21:47:34 +00005777 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5778 }
5779 case 't':
5780 {
5781 if (LocaleCompare("taint",option+1) == 0)
5782 break;
5783 if (LocaleCompare("texture",option+1) == 0)
5784 {
5785 if (*option == '+')
5786 break;
5787 i++;
cristybb503372010-05-27 20:51:26 +00005788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005789 ThrowMogrifyException(OptionError,"MissingArgument",option);
5790 break;
5791 }
5792 if (LocaleCompare("tile",option+1) == 0)
5793 {
5794 if (*option == '+')
5795 break;
5796 i++;
cristybb503372010-05-27 20:51:26 +00005797 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005798 ThrowMogrifyException(OptionError,"MissingArgument",option);
5799 break;
5800 }
5801 if (LocaleCompare("tile-offset",option+1) == 0)
5802 {
5803 if (*option == '+')
5804 break;
5805 i++;
cristybb503372010-05-27 20:51:26 +00005806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005807 ThrowMogrifyException(OptionError,"MissingArgument",option);
5808 if (IsGeometry(argv[i]) == MagickFalse)
5809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5810 break;
5811 }
5812 if (LocaleCompare("tint",option+1) == 0)
5813 {
5814 if (*option == '+')
5815 break;
5816 i++;
cristybb503372010-05-27 20:51:26 +00005817 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005818 ThrowMogrifyException(OptionError,"MissingArgument",option);
5819 if (IsGeometry(argv[i]) == MagickFalse)
5820 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5821 break;
5822 }
5823 if (LocaleCompare("transform",option+1) == 0)
5824 break;
5825 if (LocaleCompare("transpose",option+1) == 0)
5826 break;
5827 if (LocaleCompare("transverse",option+1) == 0)
5828 break;
5829 if (LocaleCompare("threshold",option+1) == 0)
5830 {
5831 if (*option == '+')
5832 break;
5833 i++;
cristybb503372010-05-27 20:51:26 +00005834 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005835 ThrowMogrifyException(OptionError,"MissingArgument",option);
5836 if (IsGeometry(argv[i]) == MagickFalse)
5837 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5838 break;
5839 }
5840 if (LocaleCompare("thumbnail",option+1) == 0)
5841 {
5842 if (*option == '+')
5843 break;
5844 i++;
cristybb503372010-05-27 20:51:26 +00005845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005846 ThrowMogrifyException(OptionError,"MissingArgument",option);
5847 if (IsGeometry(argv[i]) == MagickFalse)
5848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5849 break;
5850 }
5851 if (LocaleCompare("transparent",option+1) == 0)
5852 {
5853 i++;
cristybb503372010-05-27 20:51:26 +00005854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005855 ThrowMogrifyException(OptionError,"MissingArgument",option);
5856 break;
5857 }
5858 if (LocaleCompare("transparent-color",option+1) == 0)
5859 {
5860 if (*option == '+')
5861 break;
5862 i++;
cristybb503372010-05-27 20:51:26 +00005863 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005864 ThrowMogrifyException(OptionError,"MissingArgument",option);
5865 break;
5866 }
5867 if (LocaleCompare("treedepth",option+1) == 0)
5868 {
5869 if (*option == '+')
5870 break;
5871 i++;
cristybb503372010-05-27 20:51:26 +00005872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005873 ThrowMogrifyException(OptionError,"MissingArgument",option);
5874 if (IsGeometry(argv[i]) == MagickFalse)
5875 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5876 break;
5877 }
5878 if (LocaleCompare("trim",option+1) == 0)
5879 break;
5880 if (LocaleCompare("type",option+1) == 0)
5881 {
cristybb503372010-05-27 20:51:26 +00005882 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005883 type;
5884
5885 if (*option == '+')
5886 break;
5887 i++;
cristybb503372010-05-27 20:51:26 +00005888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005889 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005890 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005891 if (type < 0)
5892 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5893 argv[i]);
5894 break;
5895 }
5896 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5897 }
5898 case 'u':
5899 {
5900 if (LocaleCompare("undercolor",option+1) == 0)
5901 {
5902 if (*option == '+')
5903 break;
5904 i++;
cristybb503372010-05-27 20:51:26 +00005905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005906 ThrowMogrifyException(OptionError,"MissingArgument",option);
5907 break;
5908 }
5909 if (LocaleCompare("unique-colors",option+1) == 0)
5910 break;
5911 if (LocaleCompare("units",option+1) == 0)
5912 {
cristybb503372010-05-27 20:51:26 +00005913 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005914 units;
5915
5916 if (*option == '+')
5917 break;
5918 i++;
cristybb503372010-05-27 20:51:26 +00005919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005920 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005921 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005922 argv[i]);
5923 if (units < 0)
5924 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5925 argv[i]);
5926 break;
5927 }
5928 if (LocaleCompare("unsharp",option+1) == 0)
5929 {
5930 i++;
cristybb503372010-05-27 20:51:26 +00005931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 if (IsGeometry(argv[i]) == MagickFalse)
5934 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5935 break;
5936 }
5937 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5938 }
5939 case 'v':
5940 {
5941 if (LocaleCompare("verbose",option+1) == 0)
5942 {
5943 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5944 break;
5945 }
5946 if ((LocaleCompare("version",option+1) == 0) ||
5947 (LocaleCompare("-version",option+1) == 0))
5948 {
cristyb51dff52011-05-19 16:55:47 +00005949 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005950 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005951 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5952 GetMagickCopyright());
5953 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5954 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005955 break;
5956 }
5957 if (LocaleCompare("view",option+1) == 0)
5958 {
5959 if (*option == '+')
5960 break;
5961 i++;
cristybb503372010-05-27 20:51:26 +00005962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005963 ThrowMogrifyException(OptionError,"MissingArgument",option);
5964 break;
5965 }
5966 if (LocaleCompare("vignette",option+1) == 0)
5967 {
5968 if (*option == '+')
5969 break;
5970 i++;
cristybb503372010-05-27 20:51:26 +00005971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005972 ThrowMogrifyException(OptionError,"MissingArgument",option);
5973 if (IsGeometry(argv[i]) == MagickFalse)
5974 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5975 break;
5976 }
5977 if (LocaleCompare("virtual-pixel",option+1) == 0)
5978 {
cristybb503372010-05-27 20:51:26 +00005979 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005980 method;
5981
5982 if (*option == '+')
5983 break;
5984 i++;
cristybb503372010-05-27 20:51:26 +00005985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005986 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005987 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005988 argv[i]);
5989 if (method < 0)
5990 ThrowMogrifyException(OptionError,
5991 "UnrecognizedVirtualPixelMethod",argv[i]);
5992 break;
5993 }
5994 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5995 }
5996 case 'w':
5997 {
5998 if (LocaleCompare("wave",option+1) == 0)
5999 {
6000 i++;
cristybb503372010-05-27 20:51:26 +00006001 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006002 ThrowMogrifyException(OptionError,"MissingArgument",option);
6003 if (IsGeometry(argv[i]) == MagickFalse)
6004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6005 break;
6006 }
6007 if (LocaleCompare("weight",option+1) == 0)
6008 {
6009 if (*option == '+')
6010 break;
6011 i++;
cristybb503372010-05-27 20:51:26 +00006012 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006013 ThrowMogrifyException(OptionError,"MissingArgument",option);
6014 break;
6015 }
6016 if (LocaleCompare("white-point",option+1) == 0)
6017 {
6018 if (*option == '+')
6019 break;
6020 i++;
cristybb503372010-05-27 20:51:26 +00006021 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006022 ThrowMogrifyException(OptionError,"MissingArgument",option);
6023 if (IsGeometry(argv[i]) == MagickFalse)
6024 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6025 break;
6026 }
6027 if (LocaleCompare("white-threshold",option+1) == 0)
6028 {
6029 if (*option == '+')
6030 break;
6031 i++;
cristybb503372010-05-27 20:51:26 +00006032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006033 ThrowMogrifyException(OptionError,"MissingArgument",option);
6034 if (IsGeometry(argv[i]) == MagickFalse)
6035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036 break;
6037 }
6038 if (LocaleCompare("write",option+1) == 0)
6039 {
6040 i++;
cristybb503372010-05-27 20:51:26 +00006041 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006042 ThrowMogrifyException(OptionError,"MissingArgument",option);
6043 break;
6044 }
6045 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6046 }
6047 case '?':
6048 break;
6049 default:
6050 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6051 }
cristy042ee782011-04-22 18:48:30 +00006052 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6053 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006054 if (fire != MagickFalse)
6055 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6056 }
6057 if (k != 0)
6058 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006059 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006060 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6061 DestroyMogrify();
6062 return(status != 0 ? MagickTrue : MagickFalse);
6063}
6064
6065/*
6066%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6067% %
6068% %
6069% %
6070+ M o g r i f y I m a g e I n f o %
6071% %
6072% %
6073% %
6074%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6075%
6076% MogrifyImageInfo() applies image processing settings to the image as
6077% prescribed by command line options.
6078%
6079% The format of the MogrifyImageInfo method is:
6080%
6081% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6082% const char **argv,ExceptionInfo *exception)
6083%
6084% A description of each parameter follows:
6085%
6086% o image_info: the image info..
6087%
6088% o argc: Specifies a pointer to an integer describing the number of
6089% elements in the argument vector.
6090%
6091% o argv: Specifies a pointer to a text array containing the command line
6092% arguments.
6093%
6094% o exception: return any errors or warnings in this structure.
6095%
6096*/
6097WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6098 const int argc,const char **argv,ExceptionInfo *exception)
6099{
6100 const char
6101 *option;
6102
6103 GeometryInfo
6104 geometry_info;
6105
cristybb503372010-05-27 20:51:26 +00006106 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006107 count;
6108
cristybb503372010-05-27 20:51:26 +00006109 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006110 i;
6111
6112 /*
6113 Initialize method variables.
6114 */
6115 assert(image_info != (ImageInfo *) NULL);
6116 assert(image_info->signature == MagickSignature);
6117 if (image_info->debug != MagickFalse)
6118 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6119 image_info->filename);
6120 if (argc < 0)
6121 return(MagickTrue);
6122 /*
6123 Set the image settings.
6124 */
cristybb503372010-05-27 20:51:26 +00006125 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006126 {
6127 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006128 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006129 continue;
cristy042ee782011-04-22 18:48:30 +00006130 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006131 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006132 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006133 break;
6134 switch (*(option+1))
6135 {
6136 case 'a':
6137 {
6138 if (LocaleCompare("adjoin",option+1) == 0)
6139 {
6140 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6141 break;
6142 }
6143 if (LocaleCompare("antialias",option+1) == 0)
6144 {
6145 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6146 break;
6147 }
6148 if (LocaleCompare("attenuate",option+1) == 0)
6149 {
6150 if (*option == '+')
6151 {
6152 (void) DeleteImageOption(image_info,option+1);
6153 break;
6154 }
6155 (void) SetImageOption(image_info,option+1,argv[i+1]);
6156 break;
6157 }
6158 if (LocaleCompare("authenticate",option+1) == 0)
6159 {
6160 if (*option == '+')
6161 (void) CloneString(&image_info->authenticate,(char *) NULL);
6162 else
6163 (void) CloneString(&image_info->authenticate,argv[i+1]);
6164 break;
6165 }
6166 break;
6167 }
6168 case 'b':
6169 {
6170 if (LocaleCompare("background",option+1) == 0)
6171 {
6172 if (*option == '+')
6173 {
6174 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006175 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006176 &image_info->background_color,exception);
6177 break;
6178 }
6179 (void) SetImageOption(image_info,option+1,argv[i+1]);
6180 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6181 exception);
6182 break;
6183 }
6184 if (LocaleCompare("bias",option+1) == 0)
6185 {
6186 if (*option == '+')
6187 {
6188 (void) SetImageOption(image_info,option+1,"0.0");
6189 break;
6190 }
6191 (void) SetImageOption(image_info,option+1,argv[i+1]);
6192 break;
6193 }
6194 if (LocaleCompare("black-point-compensation",option+1) == 0)
6195 {
6196 if (*option == '+')
6197 {
6198 (void) SetImageOption(image_info,option+1,"false");
6199 break;
6200 }
6201 (void) SetImageOption(image_info,option+1,"true");
6202 break;
6203 }
6204 if (LocaleCompare("blue-primary",option+1) == 0)
6205 {
6206 if (*option == '+')
6207 {
6208 (void) SetImageOption(image_info,option+1,"0.0");
6209 break;
6210 }
6211 (void) SetImageOption(image_info,option+1,argv[i+1]);
6212 break;
6213 }
6214 if (LocaleCompare("bordercolor",option+1) == 0)
6215 {
6216 if (*option == '+')
6217 {
6218 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006219 (void) QueryColorDatabase(MogrifyBorderColor,
6220 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006221 break;
6222 }
6223 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6224 exception);
6225 (void) SetImageOption(image_info,option+1,argv[i+1]);
6226 break;
6227 }
6228 if (LocaleCompare("box",option+1) == 0)
6229 {
6230 if (*option == '+')
6231 {
6232 (void) SetImageOption(image_info,"undercolor","none");
6233 break;
6234 }
6235 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6236 break;
6237 }
6238 break;
6239 }
6240 case 'c':
6241 {
6242 if (LocaleCompare("cache",option+1) == 0)
6243 {
6244 MagickSizeType
6245 limit;
6246
6247 limit=MagickResourceInfinity;
6248 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006249 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006250 (void) SetMagickResourceLimit(MemoryResource,limit);
6251 (void) SetMagickResourceLimit(MapResource,2*limit);
6252 break;
6253 }
6254 if (LocaleCompare("caption",option+1) == 0)
6255 {
6256 if (*option == '+')
6257 {
6258 (void) DeleteImageOption(image_info,option+1);
6259 break;
6260 }
6261 (void) SetImageOption(image_info,option+1,argv[i+1]);
6262 break;
6263 }
6264 if (LocaleCompare("channel",option+1) == 0)
6265 {
6266 if (*option == '+')
6267 {
6268 image_info->channel=DefaultChannels;
6269 break;
6270 }
6271 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6272 break;
6273 }
6274 if (LocaleCompare("colors",option+1) == 0)
6275 {
cristye27293e2009-12-18 02:53:20 +00006276 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006277 break;
6278 }
6279 if (LocaleCompare("colorspace",option+1) == 0)
6280 {
6281 if (*option == '+')
6282 {
6283 image_info->colorspace=UndefinedColorspace;
6284 (void) SetImageOption(image_info,option+1,"undefined");
6285 break;
6286 }
cristy042ee782011-04-22 18:48:30 +00006287 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006288 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6289 (void) SetImageOption(image_info,option+1,argv[i+1]);
6290 break;
6291 }
cristy3ed852e2009-09-05 21:47:34 +00006292 if (LocaleCompare("comment",option+1) == 0)
6293 {
6294 if (*option == '+')
6295 {
6296 (void) DeleteImageOption(image_info,option+1);
6297 break;
6298 }
6299 (void) SetImageOption(image_info,option+1,argv[i+1]);
6300 break;
6301 }
6302 if (LocaleCompare("compose",option+1) == 0)
6303 {
6304 if (*option == '+')
6305 {
6306 (void) SetImageOption(image_info,option+1,"undefined");
6307 break;
6308 }
6309 (void) SetImageOption(image_info,option+1,argv[i+1]);
6310 break;
6311 }
6312 if (LocaleCompare("compress",option+1) == 0)
6313 {
6314 if (*option == '+')
6315 {
6316 image_info->compression=UndefinedCompression;
6317 (void) SetImageOption(image_info,option+1,"undefined");
6318 break;
6319 }
cristy042ee782011-04-22 18:48:30 +00006320 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006321 MagickCompressOptions,MagickFalse,argv[i+1]);
6322 (void) SetImageOption(image_info,option+1,argv[i+1]);
6323 break;
6324 }
6325 break;
6326 }
6327 case 'd':
6328 {
6329 if (LocaleCompare("debug",option+1) == 0)
6330 {
6331 if (*option == '+')
6332 (void) SetLogEventMask("none");
6333 else
6334 (void) SetLogEventMask(argv[i+1]);
6335 image_info->debug=IsEventLogging();
6336 break;
6337 }
6338 if (LocaleCompare("define",option+1) == 0)
6339 {
6340 if (*option == '+')
6341 {
6342 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6343 (void) DeleteImageRegistry(argv[i+1]+9);
6344 else
6345 (void) DeleteImageOption(image_info,argv[i+1]);
6346 break;
6347 }
6348 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6349 {
6350 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6351 exception);
6352 break;
6353 }
6354 (void) DefineImageOption(image_info,argv[i+1]);
6355 break;
6356 }
6357 if (LocaleCompare("delay",option+1) == 0)
6358 {
6359 if (*option == '+')
6360 {
6361 (void) SetImageOption(image_info,option+1,"0");
6362 break;
6363 }
6364 (void) SetImageOption(image_info,option+1,argv[i+1]);
6365 break;
6366 }
6367 if (LocaleCompare("density",option+1) == 0)
6368 {
6369 /*
6370 Set image density.
6371 */
6372 if (*option == '+')
6373 {
6374 if (image_info->density != (char *) NULL)
6375 image_info->density=DestroyString(image_info->density);
6376 (void) SetImageOption(image_info,option+1,"72");
6377 break;
6378 }
6379 (void) CloneString(&image_info->density,argv[i+1]);
6380 (void) SetImageOption(image_info,option+1,argv[i+1]);
6381 break;
6382 }
6383 if (LocaleCompare("depth",option+1) == 0)
6384 {
6385 if (*option == '+')
6386 {
6387 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6388 break;
6389 }
cristye27293e2009-12-18 02:53:20 +00006390 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006391 break;
6392 }
cristyc9b12952010-03-28 01:12:28 +00006393 if (LocaleCompare("direction",option+1) == 0)
6394 {
6395 if (*option == '+')
6396 {
6397 (void) SetImageOption(image_info,option+1,"undefined");
6398 break;
6399 }
6400 (void) SetImageOption(image_info,option+1,argv[i+1]);
6401 break;
6402 }
cristy3ed852e2009-09-05 21:47:34 +00006403 if (LocaleCompare("display",option+1) == 0)
6404 {
6405 if (*option == '+')
6406 {
6407 if (image_info->server_name != (char *) NULL)
6408 image_info->server_name=DestroyString(
6409 image_info->server_name);
6410 break;
6411 }
6412 (void) CloneString(&image_info->server_name,argv[i+1]);
6413 break;
6414 }
6415 if (LocaleCompare("dispose",option+1) == 0)
6416 {
6417 if (*option == '+')
6418 {
6419 (void) SetImageOption(image_info,option+1,"undefined");
6420 break;
6421 }
6422 (void) SetImageOption(image_info,option+1,argv[i+1]);
6423 break;
6424 }
6425 if (LocaleCompare("dither",option+1) == 0)
6426 {
6427 if (*option == '+')
6428 {
6429 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006430 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006431 break;
6432 }
6433 (void) SetImageOption(image_info,option+1,argv[i+1]);
6434 image_info->dither=MagickTrue;
6435 break;
6436 }
6437 break;
6438 }
6439 case 'e':
6440 {
6441 if (LocaleCompare("encoding",option+1) == 0)
6442 {
6443 if (*option == '+')
6444 {
6445 (void) SetImageOption(image_info,option+1,"undefined");
6446 break;
6447 }
6448 (void) SetImageOption(image_info,option+1,argv[i+1]);
6449 break;
6450 }
6451 if (LocaleCompare("endian",option+1) == 0)
6452 {
6453 if (*option == '+')
6454 {
6455 image_info->endian=UndefinedEndian;
6456 (void) SetImageOption(image_info,option+1,"undefined");
6457 break;
6458 }
cristy042ee782011-04-22 18:48:30 +00006459 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006460 MagickEndianOptions,MagickFalse,argv[i+1]);
6461 (void) SetImageOption(image_info,option+1,argv[i+1]);
6462 break;
6463 }
6464 if (LocaleCompare("extract",option+1) == 0)
6465 {
6466 /*
6467 Set image extract geometry.
6468 */
6469 if (*option == '+')
6470 {
6471 if (image_info->extract != (char *) NULL)
6472 image_info->extract=DestroyString(image_info->extract);
6473 break;
6474 }
6475 (void) CloneString(&image_info->extract,argv[i+1]);
6476 break;
6477 }
6478 break;
6479 }
6480 case 'f':
6481 {
6482 if (LocaleCompare("fill",option+1) == 0)
6483 {
6484 if (*option == '+')
6485 {
6486 (void) SetImageOption(image_info,option+1,"none");
6487 break;
6488 }
6489 (void) SetImageOption(image_info,option+1,argv[i+1]);
6490 break;
6491 }
6492 if (LocaleCompare("filter",option+1) == 0)
6493 {
6494 if (*option == '+')
6495 {
6496 (void) SetImageOption(image_info,option+1,"undefined");
6497 break;
6498 }
6499 (void) SetImageOption(image_info,option+1,argv[i+1]);
6500 break;
6501 }
6502 if (LocaleCompare("font",option+1) == 0)
6503 {
6504 if (*option == '+')
6505 {
6506 if (image_info->font != (char *) NULL)
6507 image_info->font=DestroyString(image_info->font);
6508 break;
6509 }
6510 (void) CloneString(&image_info->font,argv[i+1]);
6511 break;
6512 }
6513 if (LocaleCompare("format",option+1) == 0)
6514 {
6515 register const char
6516 *q;
6517
6518 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006519 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006520 image_info->ping=MagickFalse;
6521 (void) SetImageOption(image_info,option+1,argv[i+1]);
6522 break;
6523 }
6524 if (LocaleCompare("fuzz",option+1) == 0)
6525 {
6526 if (*option == '+')
6527 {
6528 image_info->fuzz=0.0;
6529 (void) SetImageOption(image_info,option+1,"0");
6530 break;
6531 }
cristyf2f27272009-12-17 14:48:46 +00006532 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006533 1.0);
6534 (void) SetImageOption(image_info,option+1,argv[i+1]);
6535 break;
6536 }
6537 break;
6538 }
6539 case 'g':
6540 {
6541 if (LocaleCompare("gravity",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 (void) SetImageOption(image_info,option+1,"undefined");
6546 break;
6547 }
6548 (void) SetImageOption(image_info,option+1,argv[i+1]);
6549 break;
6550 }
6551 if (LocaleCompare("green-primary",option+1) == 0)
6552 {
6553 if (*option == '+')
6554 {
6555 (void) SetImageOption(image_info,option+1,"0.0");
6556 break;
6557 }
6558 (void) SetImageOption(image_info,option+1,argv[i+1]);
6559 break;
6560 }
6561 break;
6562 }
6563 case 'i':
6564 {
6565 if (LocaleCompare("intent",option+1) == 0)
6566 {
6567 if (*option == '+')
6568 {
6569 (void) SetImageOption(image_info,option+1,"undefined");
6570 break;
6571 }
6572 (void) SetImageOption(image_info,option+1,argv[i+1]);
6573 break;
6574 }
6575 if (LocaleCompare("interlace",option+1) == 0)
6576 {
6577 if (*option == '+')
6578 {
6579 image_info->interlace=UndefinedInterlace;
6580 (void) SetImageOption(image_info,option+1,"undefined");
6581 break;
6582 }
cristy042ee782011-04-22 18:48:30 +00006583 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006584 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6585 (void) SetImageOption(image_info,option+1,argv[i+1]);
6586 break;
6587 }
cristyb32b90a2009-09-07 21:45:48 +00006588 if (LocaleCompare("interline-spacing",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 (void) SetImageOption(image_info,option+1,"undefined");
6593 break;
6594 }
6595 (void) SetImageOption(image_info,option+1,argv[i+1]);
6596 break;
6597 }
cristy3ed852e2009-09-05 21:47:34 +00006598 if (LocaleCompare("interpolate",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 (void) SetImageOption(image_info,option+1,"undefined");
6603 break;
6604 }
6605 (void) SetImageOption(image_info,option+1,argv[i+1]);
6606 break;
6607 }
6608 if (LocaleCompare("interword-spacing",option+1) == 0)
6609 {
6610 if (*option == '+')
6611 {
6612 (void) SetImageOption(image_info,option+1,"undefined");
6613 break;
6614 }
6615 (void) SetImageOption(image_info,option+1,argv[i+1]);
6616 break;
6617 }
6618 break;
6619 }
6620 case 'k':
6621 {
6622 if (LocaleCompare("kerning",option+1) == 0)
6623 {
6624 if (*option == '+')
6625 {
6626 (void) SetImageOption(image_info,option+1,"undefined");
6627 break;
6628 }
6629 (void) SetImageOption(image_info,option+1,argv[i+1]);
6630 break;
6631 }
6632 break;
6633 }
6634 case 'l':
6635 {
6636 if (LocaleCompare("label",option+1) == 0)
6637 {
6638 if (*option == '+')
6639 {
6640 (void) DeleteImageOption(image_info,option+1);
6641 break;
6642 }
6643 (void) SetImageOption(image_info,option+1,argv[i+1]);
6644 break;
6645 }
6646 if (LocaleCompare("limit",option+1) == 0)
6647 {
6648 MagickSizeType
6649 limit;
6650
6651 ResourceType
6652 type;
6653
6654 if (*option == '+')
6655 break;
cristy042ee782011-04-22 18:48:30 +00006656 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006657 MagickFalse,argv[i+1]);
6658 limit=MagickResourceInfinity;
6659 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006660 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006661 (void) SetMagickResourceLimit(type,limit);
6662 break;
6663 }
6664 if (LocaleCompare("list",option+1) == 0)
6665 {
cristybb503372010-05-27 20:51:26 +00006666 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006667 list;
6668
6669 /*
6670 Display configuration list.
6671 */
cristy042ee782011-04-22 18:48:30 +00006672 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006673 switch (list)
6674 {
6675 case MagickCoderOptions:
6676 {
6677 (void) ListCoderInfo((FILE *) NULL,exception);
6678 break;
6679 }
6680 case MagickColorOptions:
6681 {
6682 (void) ListColorInfo((FILE *) NULL,exception);
6683 break;
6684 }
6685 case MagickConfigureOptions:
6686 {
6687 (void) ListConfigureInfo((FILE *) NULL,exception);
6688 break;
6689 }
6690 case MagickDelegateOptions:
6691 {
6692 (void) ListDelegateInfo((FILE *) NULL,exception);
6693 break;
6694 }
6695 case MagickFontOptions:
6696 {
6697 (void) ListTypeInfo((FILE *) NULL,exception);
6698 break;
6699 }
6700 case MagickFormatOptions:
6701 {
6702 (void) ListMagickInfo((FILE *) NULL,exception);
6703 break;
6704 }
6705 case MagickLocaleOptions:
6706 {
6707 (void) ListLocaleInfo((FILE *) NULL,exception);
6708 break;
6709 }
6710 case MagickLogOptions:
6711 {
6712 (void) ListLogInfo((FILE *) NULL,exception);
6713 break;
6714 }
6715 case MagickMagicOptions:
6716 {
6717 (void) ListMagicInfo((FILE *) NULL,exception);
6718 break;
6719 }
6720 case MagickMimeOptions:
6721 {
6722 (void) ListMimeInfo((FILE *) NULL,exception);
6723 break;
6724 }
6725 case MagickModuleOptions:
6726 {
6727 (void) ListModuleInfo((FILE *) NULL,exception);
6728 break;
6729 }
6730 case MagickPolicyOptions:
6731 {
6732 (void) ListPolicyInfo((FILE *) NULL,exception);
6733 break;
6734 }
6735 case MagickResourceOptions:
6736 {
6737 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6738 break;
6739 }
6740 case MagickThresholdOptions:
6741 {
6742 (void) ListThresholdMaps((FILE *) NULL,exception);
6743 break;
6744 }
6745 default:
6746 {
cristy042ee782011-04-22 18:48:30 +00006747 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006748 exception);
6749 break;
6750 }
6751 }
cristyaeb2cbc2010-05-07 13:28:58 +00006752 break;
cristy3ed852e2009-09-05 21:47:34 +00006753 }
6754 if (LocaleCompare("log",option+1) == 0)
6755 {
6756 if (*option == '+')
6757 break;
6758 (void) SetLogFormat(argv[i+1]);
6759 break;
6760 }
6761 if (LocaleCompare("loop",option+1) == 0)
6762 {
6763 if (*option == '+')
6764 {
6765 (void) SetImageOption(image_info,option+1,"0");
6766 break;
6767 }
6768 (void) SetImageOption(image_info,option+1,argv[i+1]);
6769 break;
6770 }
6771 break;
6772 }
6773 case 'm':
6774 {
6775 if (LocaleCompare("matte",option+1) == 0)
6776 {
6777 if (*option == '+')
6778 {
6779 (void) SetImageOption(image_info,option+1,"false");
6780 break;
6781 }
6782 (void) SetImageOption(image_info,option+1,"true");
6783 break;
6784 }
6785 if (LocaleCompare("mattecolor",option+1) == 0)
6786 {
6787 if (*option == '+')
6788 {
6789 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006790 (void) QueryColorDatabase(MogrifyMatteColor,
6791 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006792 break;
6793 }
6794 (void) SetImageOption(image_info,option+1,argv[i+1]);
6795 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6796 exception);
6797 break;
6798 }
6799 if (LocaleCompare("monitor",option+1) == 0)
6800 {
6801 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6802 (void *) NULL);
6803 break;
6804 }
6805 if (LocaleCompare("monochrome",option+1) == 0)
6806 {
6807 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6808 break;
6809 }
6810 break;
6811 }
6812 case 'o':
6813 {
6814 if (LocaleCompare("orient",option+1) == 0)
6815 {
6816 if (*option == '+')
6817 {
6818 image_info->orientation=UndefinedOrientation;
6819 (void) SetImageOption(image_info,option+1,"undefined");
6820 break;
6821 }
cristy042ee782011-04-22 18:48:30 +00006822 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006823 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006824 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006825 break;
6826 }
6827 }
6828 case 'p':
6829 {
6830 if (LocaleCompare("page",option+1) == 0)
6831 {
6832 char
6833 *canonical_page,
6834 page[MaxTextExtent];
6835
6836 const char
6837 *image_option;
6838
6839 MagickStatusType
6840 flags;
6841
6842 RectangleInfo
6843 geometry;
6844
6845 if (*option == '+')
6846 {
6847 (void) DeleteImageOption(image_info,option+1);
6848 (void) CloneString(&image_info->page,(char *) NULL);
6849 break;
6850 }
6851 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6852 image_option=GetImageOption(image_info,"page");
6853 if (image_option != (const char *) NULL)
6854 flags=ParseAbsoluteGeometry(image_option,&geometry);
6855 canonical_page=GetPageGeometry(argv[i+1]);
6856 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6857 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006858 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006859 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006860 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006861 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006862 (unsigned long) geometry.width,(unsigned long) geometry.height,
6863 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006864 (void) SetImageOption(image_info,option+1,page);
6865 (void) CloneString(&image_info->page,page);
6866 break;
6867 }
6868 if (LocaleCompare("pen",option+1) == 0)
6869 {
6870 if (*option == '+')
6871 {
6872 (void) SetImageOption(image_info,option+1,"none");
6873 break;
6874 }
6875 (void) SetImageOption(image_info,option+1,argv[i+1]);
6876 break;
6877 }
6878 if (LocaleCompare("ping",option+1) == 0)
6879 {
6880 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6881 break;
6882 }
6883 if (LocaleCompare("pointsize",option+1) == 0)
6884 {
6885 if (*option == '+')
6886 geometry_info.rho=0.0;
6887 else
6888 (void) ParseGeometry(argv[i+1],&geometry_info);
6889 image_info->pointsize=geometry_info.rho;
6890 break;
6891 }
cristye7f51092010-01-17 00:39:37 +00006892 if (LocaleCompare("precision",option+1) == 0)
6893 {
cristybf2766a2010-01-17 03:33:23 +00006894 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006895 break;
6896 }
cristy3ed852e2009-09-05 21:47:34 +00006897 if (LocaleCompare("preview",option+1) == 0)
6898 {
6899 /*
6900 Preview image.
6901 */
6902 if (*option == '+')
6903 {
6904 image_info->preview_type=UndefinedPreview;
6905 break;
6906 }
cristy042ee782011-04-22 18:48:30 +00006907 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006908 MagickPreviewOptions,MagickFalse,argv[i+1]);
6909 break;
6910 }
6911 break;
6912 }
6913 case 'q':
6914 {
6915 if (LocaleCompare("quality",option+1) == 0)
6916 {
6917 /*
6918 Set image compression quality.
6919 */
6920 if (*option == '+')
6921 {
6922 image_info->quality=UndefinedCompressionQuality;
6923 (void) SetImageOption(image_info,option+1,"0");
6924 break;
6925 }
cristye27293e2009-12-18 02:53:20 +00006926 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006927 (void) SetImageOption(image_info,option+1,argv[i+1]);
6928 break;
6929 }
6930 if (LocaleCompare("quiet",option+1) == 0)
6931 {
6932 static WarningHandler
6933 warning_handler = (WarningHandler) NULL;
6934
6935 if (*option == '+')
6936 {
6937 /*
6938 Restore error or warning messages.
6939 */
6940 warning_handler=SetWarningHandler(warning_handler);
6941 break;
6942 }
6943 /*
6944 Suppress error or warning messages.
6945 */
6946 warning_handler=SetWarningHandler((WarningHandler) NULL);
6947 break;
6948 }
6949 break;
6950 }
6951 case 'r':
6952 {
6953 if (LocaleCompare("red-primary",option+1) == 0)
6954 {
6955 if (*option == '+')
6956 {
6957 (void) SetImageOption(image_info,option+1,"0.0");
6958 break;
6959 }
6960 (void) SetImageOption(image_info,option+1,argv[i+1]);
6961 break;
6962 }
6963 break;
6964 }
6965 case 's':
6966 {
6967 if (LocaleCompare("sampling-factor",option+1) == 0)
6968 {
6969 /*
6970 Set image sampling factor.
6971 */
6972 if (*option == '+')
6973 {
6974 if (image_info->sampling_factor != (char *) NULL)
6975 image_info->sampling_factor=DestroyString(
6976 image_info->sampling_factor);
6977 break;
6978 }
6979 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6980 break;
6981 }
6982 if (LocaleCompare("scene",option+1) == 0)
6983 {
6984 /*
6985 Set image scene.
6986 */
6987 if (*option == '+')
6988 {
6989 image_info->scene=0;
6990 (void) SetImageOption(image_info,option+1,"0");
6991 break;
6992 }
cristye27293e2009-12-18 02:53:20 +00006993 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006994 (void) SetImageOption(image_info,option+1,argv[i+1]);
6995 break;
6996 }
6997 if (LocaleCompare("seed",option+1) == 0)
6998 {
cristybb503372010-05-27 20:51:26 +00006999 size_t
cristy3ed852e2009-09-05 21:47:34 +00007000 seed;
7001
7002 if (*option == '+')
7003 {
cristybb503372010-05-27 20:51:26 +00007004 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007005 SeedPseudoRandomGenerator(seed);
7006 break;
7007 }
cristye27293e2009-12-18 02:53:20 +00007008 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007009 SeedPseudoRandomGenerator(seed);
7010 break;
7011 }
7012 if (LocaleCompare("size",option+1) == 0)
7013 {
7014 if (*option == '+')
7015 {
7016 if (image_info->size != (char *) NULL)
7017 image_info->size=DestroyString(image_info->size);
7018 break;
7019 }
7020 (void) CloneString(&image_info->size,argv[i+1]);
7021 break;
7022 }
7023 if (LocaleCompare("stroke",option+1) == 0)
7024 {
7025 if (*option == '+')
7026 {
7027 (void) SetImageOption(image_info,option+1,"none");
7028 break;
7029 }
7030 (void) SetImageOption(image_info,option+1,argv[i+1]);
7031 break;
7032 }
7033 if (LocaleCompare("strokewidth",option+1) == 0)
7034 {
7035 if (*option == '+')
7036 {
7037 (void) SetImageOption(image_info,option+1,"0");
7038 break;
7039 }
7040 (void) SetImageOption(image_info,option+1,argv[i+1]);
7041 break;
7042 }
cristyd9a29192010-10-16 16:49:53 +00007043 if (LocaleCompare("synchronize",option+1) == 0)
7044 {
7045 if (*option == '+')
7046 {
7047 image_info->synchronize=MagickFalse;
7048 break;
7049 }
7050 image_info->synchronize=MagickTrue;
7051 break;
7052 }
cristy3ed852e2009-09-05 21:47:34 +00007053 break;
7054 }
7055 case 't':
7056 {
7057 if (LocaleCompare("taint",option+1) == 0)
7058 {
7059 if (*option == '+')
7060 {
7061 (void) SetImageOption(image_info,option+1,"false");
7062 break;
7063 }
7064 (void) SetImageOption(image_info,option+1,"true");
7065 break;
7066 }
7067 if (LocaleCompare("texture",option+1) == 0)
7068 {
7069 if (*option == '+')
7070 {
7071 if (image_info->texture != (char *) NULL)
7072 image_info->texture=DestroyString(image_info->texture);
7073 break;
7074 }
7075 (void) CloneString(&image_info->texture,argv[i+1]);
7076 break;
7077 }
7078 if (LocaleCompare("tile-offset",option+1) == 0)
7079 {
7080 if (*option == '+')
7081 {
7082 (void) SetImageOption(image_info,option+1,"0");
7083 break;
7084 }
7085 (void) SetImageOption(image_info,option+1,argv[i+1]);
7086 break;
7087 }
7088 if (LocaleCompare("transparent-color",option+1) == 0)
7089 {
7090 if (*option == '+')
7091 {
7092 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7093 (void) SetImageOption(image_info,option+1,"none");
7094 break;
7095 }
7096 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7097 exception);
7098 (void) SetImageOption(image_info,option+1,argv[i+1]);
7099 break;
7100 }
7101 if (LocaleCompare("type",option+1) == 0)
7102 {
7103 if (*option == '+')
7104 {
cristy5f1c1ff2010-12-23 21:38:06 +00007105 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007106 (void) SetImageOption(image_info,option+1,"undefined");
7107 break;
7108 }
cristy042ee782011-04-22 18:48:30 +00007109 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007110 MagickFalse,argv[i+1]);
7111 (void) SetImageOption(image_info,option+1,argv[i+1]);
7112 break;
7113 }
7114 break;
7115 }
7116 case 'u':
7117 {
7118 if (LocaleCompare("undercolor",option+1) == 0)
7119 {
7120 if (*option == '+')
7121 {
7122 (void) DeleteImageOption(image_info,option+1);
7123 break;
7124 }
7125 (void) SetImageOption(image_info,option+1,argv[i+1]);
7126 break;
7127 }
7128 if (LocaleCompare("units",option+1) == 0)
7129 {
7130 if (*option == '+')
7131 {
7132 image_info->units=UndefinedResolution;
7133 (void) SetImageOption(image_info,option+1,"undefined");
7134 break;
7135 }
cristy042ee782011-04-22 18:48:30 +00007136 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007137 MagickResolutionOptions,MagickFalse,argv[i+1]);
7138 (void) SetImageOption(image_info,option+1,argv[i+1]);
7139 break;
7140 }
7141 break;
7142 }
7143 case 'v':
7144 {
7145 if (LocaleCompare("verbose",option+1) == 0)
7146 {
7147 if (*option == '+')
7148 {
7149 image_info->verbose=MagickFalse;
7150 break;
7151 }
7152 image_info->verbose=MagickTrue;
7153 image_info->ping=MagickFalse;
7154 break;
7155 }
7156 if (LocaleCompare("view",option+1) == 0)
7157 {
7158 if (*option == '+')
7159 {
7160 if (image_info->view != (char *) NULL)
7161 image_info->view=DestroyString(image_info->view);
7162 break;
7163 }
7164 (void) CloneString(&image_info->view,argv[i+1]);
7165 break;
7166 }
7167 if (LocaleCompare("virtual-pixel",option+1) == 0)
7168 {
7169 if (*option == '+')
7170 {
7171 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7172 (void) SetImageOption(image_info,option+1,"undefined");
7173 break;
7174 }
7175 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007176 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007177 argv[i+1]);
7178 (void) SetImageOption(image_info,option+1,argv[i+1]);
7179 break;
7180 }
7181 break;
7182 }
7183 case 'w':
7184 {
7185 if (LocaleCompare("white-point",option+1) == 0)
7186 {
7187 if (*option == '+')
7188 {
7189 (void) SetImageOption(image_info,option+1,"0.0");
7190 break;
7191 }
7192 (void) SetImageOption(image_info,option+1,argv[i+1]);
7193 break;
7194 }
7195 break;
7196 }
7197 default:
7198 break;
7199 }
7200 i+=count;
7201 }
7202 return(MagickTrue);
7203}
7204
7205/*
7206%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7207% %
7208% %
7209% %
7210+ M o g r i f y I m a g e L i s t %
7211% %
7212% %
7213% %
7214%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7215%
7216% MogrifyImageList() applies any command line options that might affect the
7217% entire image list (e.g. -append, -coalesce, etc.).
7218%
7219% The format of the MogrifyImage method is:
7220%
7221% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7222% const char **argv,Image **images,ExceptionInfo *exception)
7223%
7224% A description of each parameter follows:
7225%
7226% o image_info: the image info..
7227%
7228% o argc: Specifies a pointer to an integer describing the number of
7229% elements in the argument vector.
7230%
7231% o argv: Specifies a pointer to a text array containing the command line
7232% arguments.
7233%
anthonye9c27192011-03-27 08:07:06 +00007234% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007235%
7236% o exception: return any errors or warnings in this structure.
7237%
7238*/
7239WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7240 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7241{
cristy3ed852e2009-09-05 21:47:34 +00007242 const char
7243 *option;
7244
cristy6b3da3a2010-06-20 02:21:46 +00007245 ImageInfo
7246 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007247
7248 MagickStatusType
7249 status;
7250
cristy28474bf2011-09-11 23:32:52 +00007251 PixelInterpolateMethod
7252 interpolate_method;
7253
cristy3ed852e2009-09-05 21:47:34 +00007254 QuantizeInfo
7255 *quantize_info;
7256
cristybb503372010-05-27 20:51:26 +00007257 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007258 i;
7259
cristy6b3da3a2010-06-20 02:21:46 +00007260 ssize_t
7261 count,
7262 index;
7263
cristy3ed852e2009-09-05 21:47:34 +00007264 /*
7265 Apply options to the image list.
7266 */
7267 assert(image_info != (ImageInfo *) NULL);
7268 assert(image_info->signature == MagickSignature);
7269 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007270 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007271 assert((*images)->signature == MagickSignature);
7272 if ((*images)->debug != MagickFalse)
7273 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7274 (*images)->filename);
7275 if ((argc <= 0) || (*argv == (char *) NULL))
7276 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007277 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007278 mogrify_info=CloneImageInfo(image_info);
7279 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007280 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007281 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007282 {
cristy74fe8f12009-10-03 19:09:01 +00007283 if (*images == (Image *) NULL)
7284 break;
cristy3ed852e2009-09-05 21:47:34 +00007285 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007286 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007287 continue;
cristy042ee782011-04-22 18:48:30 +00007288 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007289 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007290 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007291 break;
cristy6b3da3a2010-06-20 02:21:46 +00007292 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007293 switch (*(option+1))
7294 {
7295 case 'a':
7296 {
7297 if (LocaleCompare("affinity",option+1) == 0)
7298 {
cristy6b3da3a2010-06-20 02:21:46 +00007299 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007300 if (*option == '+')
7301 {
cristy018f07f2011-09-04 21:15:19 +00007302 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7303 exception);
cristy3ed852e2009-09-05 21:47:34 +00007304 break;
7305 }
7306 i++;
7307 break;
7308 }
7309 if (LocaleCompare("append",option+1) == 0)
7310 {
7311 Image
7312 *append_image;
7313
cristy6b3da3a2010-06-20 02:21:46 +00007314 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007315 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7316 MagickFalse,exception);
7317 if (append_image == (Image *) NULL)
7318 {
7319 status=MagickFalse;
7320 break;
7321 }
7322 *images=DestroyImageList(*images);
7323 *images=append_image;
7324 break;
7325 }
7326 if (LocaleCompare("average",option+1) == 0)
7327 {
7328 Image
7329 *average_image;
7330
cristyd18ae7c2010-03-07 17:39:52 +00007331 /*
7332 Average an image sequence (deprecated).
7333 */
cristy6b3da3a2010-06-20 02:21:46 +00007334 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007335 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7336 exception);
cristy3ed852e2009-09-05 21:47:34 +00007337 if (average_image == (Image *) NULL)
7338 {
7339 status=MagickFalse;
7340 break;
7341 }
7342 *images=DestroyImageList(*images);
7343 *images=average_image;
7344 break;
7345 }
7346 break;
7347 }
7348 case 'c':
7349 {
7350 if (LocaleCompare("channel",option+1) == 0)
7351 {
cristyf4ad9df2011-07-08 16:49:03 +00007352 ChannelType
7353 channel;
7354
cristy3ed852e2009-09-05 21:47:34 +00007355 if (*option == '+')
7356 {
7357 channel=DefaultChannels;
7358 break;
7359 }
7360 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007361 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007362 break;
7363 }
7364 if (LocaleCompare("clut",option+1) == 0)
7365 {
7366 Image
7367 *clut_image,
7368 *image;
7369
cristy6b3da3a2010-06-20 02:21:46 +00007370 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007371 image=RemoveFirstImageFromList(images);
7372 clut_image=RemoveFirstImageFromList(images);
7373 if (clut_image == (Image *) NULL)
7374 {
7375 status=MagickFalse;
7376 break;
7377 }
cristy28474bf2011-09-11 23:32:52 +00007378 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007379 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007380 *images=DestroyImageList(*images);
7381 *images=image;
7382 break;
7383 }
7384 if (LocaleCompare("coalesce",option+1) == 0)
7385 {
7386 Image
7387 *coalesce_image;
7388
cristy6b3da3a2010-06-20 02:21:46 +00007389 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007390 coalesce_image=CoalesceImages(*images,exception);
7391 if (coalesce_image == (Image *) NULL)
7392 {
7393 status=MagickFalse;
7394 break;
7395 }
7396 *images=DestroyImageList(*images);
7397 *images=coalesce_image;
7398 break;
7399 }
7400 if (LocaleCompare("combine",option+1) == 0)
7401 {
7402 Image
7403 *combine_image;
7404
cristy6b3da3a2010-06-20 02:21:46 +00007405 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007406 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007407 if (combine_image == (Image *) NULL)
7408 {
7409 status=MagickFalse;
7410 break;
7411 }
7412 *images=DestroyImageList(*images);
7413 *images=combine_image;
7414 break;
7415 }
7416 if (LocaleCompare("composite",option+1) == 0)
7417 {
7418 Image
7419 *mask_image,
7420 *composite_image,
7421 *image;
7422
7423 RectangleInfo
7424 geometry;
7425
cristy6b3da3a2010-06-20 02:21:46 +00007426 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007427 image=RemoveFirstImageFromList(images);
7428 composite_image=RemoveFirstImageFromList(images);
7429 if (composite_image == (Image *) NULL)
7430 {
7431 status=MagickFalse;
7432 break;
7433 }
7434 (void) TransformImage(&composite_image,(char *) NULL,
7435 composite_image->geometry);
7436 SetGeometry(composite_image,&geometry);
7437 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7438 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7439 &geometry);
7440 mask_image=RemoveFirstImageFromList(images);
7441 if (mask_image != (Image *) NULL)
7442 {
7443 if ((image->compose == DisplaceCompositeOp) ||
7444 (image->compose == DistortCompositeOp))
7445 {
7446 /*
7447 Merge Y displacement into X displacement image.
7448 */
7449 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7450 mask_image,0,0);
7451 mask_image=DestroyImage(mask_image);
7452 }
7453 else
7454 {
7455 /*
7456 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007457 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007458 */
7459 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007460 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007461 }
7462 }
cristyf4ad9df2011-07-08 16:49:03 +00007463 (void) CompositeImage(image,image->compose,composite_image,
7464 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007465 if (mask_image != (Image *) NULL)
7466 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007467 composite_image=DestroyImage(composite_image);
7468 InheritException(exception,&image->exception);
7469 *images=DestroyImageList(*images);
7470 *images=image;
7471 break;
7472 }
cristy3ed852e2009-09-05 21:47:34 +00007473 break;
7474 }
7475 case 'd':
7476 {
7477 if (LocaleCompare("deconstruct",option+1) == 0)
7478 {
7479 Image
7480 *deconstruct_image;
7481
cristy6b3da3a2010-06-20 02:21:46 +00007482 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007483 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007484 exception);
cristy3ed852e2009-09-05 21:47:34 +00007485 if (deconstruct_image == (Image *) NULL)
7486 {
7487 status=MagickFalse;
7488 break;
7489 }
7490 *images=DestroyImageList(*images);
7491 *images=deconstruct_image;
7492 break;
7493 }
7494 if (LocaleCompare("delete",option+1) == 0)
7495 {
7496 if (*option == '+')
7497 DeleteImages(images,"-1",exception);
7498 else
7499 DeleteImages(images,argv[i+1],exception);
7500 break;
7501 }
7502 if (LocaleCompare("dither",option+1) == 0)
7503 {
7504 if (*option == '+')
7505 {
7506 quantize_info->dither=MagickFalse;
7507 break;
7508 }
7509 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007510 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007511 MagickDitherOptions,MagickFalse,argv[i+1]);
7512 break;
7513 }
cristyecb10ff2011-03-22 13:14:03 +00007514 if (LocaleCompare("duplicate",option+1) == 0)
7515 {
cristy72988482011-03-29 16:34:38 +00007516 Image
7517 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007518
anthony2b6bcae2011-03-23 13:05:34 +00007519 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007520 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7521 else
7522 {
7523 const char
7524 *p;
7525
anthony2b6bcae2011-03-23 13:05:34 +00007526 size_t
7527 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007528
anthony2b6bcae2011-03-23 13:05:34 +00007529 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007530 p=strchr(argv[i+1],',');
7531 if (p == (const char *) NULL)
7532 duplicate_images=DuplicateImages(*images,number_duplicates,
7533 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007534 else
cristy72988482011-03-29 16:34:38 +00007535 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7536 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007537 }
7538 AppendImageToList(images, duplicate_images);
7539 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007540 break;
7541 }
cristy3ed852e2009-09-05 21:47:34 +00007542 break;
7543 }
cristyd18ae7c2010-03-07 17:39:52 +00007544 case 'e':
7545 {
7546 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7547 {
7548 Image
7549 *evaluate_image;
7550
7551 MagickEvaluateOperator
7552 op;
7553
cristy6b3da3a2010-06-20 02:21:46 +00007554 (void) SyncImageSettings(mogrify_info,*images);
cristy28474bf2011-09-11 23:32:52 +00007555 op=(MagickEvaluateOperator) ParseCommandOption(
7556 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007557 evaluate_image=EvaluateImages(*images,op,exception);
7558 if (evaluate_image == (Image *) NULL)
7559 {
7560 status=MagickFalse;
7561 break;
7562 }
7563 *images=DestroyImageList(*images);
7564 *images=evaluate_image;
7565 break;
7566 }
7567 break;
7568 }
cristy3ed852e2009-09-05 21:47:34 +00007569 case 'f':
7570 {
cristyf0a247f2009-10-04 00:20:03 +00007571 if (LocaleCompare("fft",option+1) == 0)
7572 {
7573 Image
7574 *fourier_image;
7575
7576 /*
7577 Implements the discrete Fourier transform (DFT).
7578 */
cristy6b3da3a2010-06-20 02:21:46 +00007579 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007580 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7581 MagickTrue : MagickFalse,exception);
7582 if (fourier_image == (Image *) NULL)
7583 break;
7584 *images=DestroyImage(*images);
7585 *images=fourier_image;
7586 break;
7587 }
cristy3ed852e2009-09-05 21:47:34 +00007588 if (LocaleCompare("flatten",option+1) == 0)
7589 {
7590 Image
7591 *flatten_image;
7592
cristy6b3da3a2010-06-20 02:21:46 +00007593 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007594 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7595 if (flatten_image == (Image *) NULL)
7596 break;
7597 *images=DestroyImageList(*images);
7598 *images=flatten_image;
7599 break;
7600 }
7601 if (LocaleCompare("fx",option+1) == 0)
7602 {
7603 Image
7604 *fx_image;
7605
cristy6b3da3a2010-06-20 02:21:46 +00007606 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007607 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007608 if (fx_image == (Image *) NULL)
7609 {
7610 status=MagickFalse;
7611 break;
7612 }
7613 *images=DestroyImageList(*images);
7614 *images=fx_image;
7615 break;
7616 }
7617 break;
7618 }
7619 case 'h':
7620 {
7621 if (LocaleCompare("hald-clut",option+1) == 0)
7622 {
7623 Image
7624 *hald_image,
7625 *image;
7626
cristy6b3da3a2010-06-20 02:21:46 +00007627 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007628 image=RemoveFirstImageFromList(images);
7629 hald_image=RemoveFirstImageFromList(images);
7630 if (hald_image == (Image *) NULL)
7631 {
7632 status=MagickFalse;
7633 break;
7634 }
cristy7c0a0a42011-08-23 17:57:25 +00007635 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007636 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007637 if (*images != (Image *) NULL)
7638 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007639 *images=image;
7640 break;
7641 }
7642 break;
7643 }
7644 case 'i':
7645 {
7646 if (LocaleCompare("ift",option+1) == 0)
7647 {
7648 Image
cristy8587f882009-11-13 20:28:49 +00007649 *fourier_image,
7650 *magnitude_image,
7651 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007652
7653 /*
7654 Implements the inverse fourier discrete Fourier transform (DFT).
7655 */
cristy6b3da3a2010-06-20 02:21:46 +00007656 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007657 magnitude_image=RemoveFirstImageFromList(images);
7658 phase_image=RemoveFirstImageFromList(images);
7659 if (phase_image == (Image *) NULL)
7660 {
7661 status=MagickFalse;
7662 break;
7663 }
7664 fourier_image=InverseFourierTransformImage(magnitude_image,
7665 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007666 if (fourier_image == (Image *) NULL)
7667 break;
cristy0aff6ea2009-11-14 01:40:53 +00007668 if (*images != (Image *) NULL)
7669 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007670 *images=fourier_image;
7671 break;
7672 }
7673 if (LocaleCompare("insert",option+1) == 0)
7674 {
7675 Image
7676 *p,
7677 *q;
7678
7679 index=0;
7680 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007681 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007682 p=RemoveLastImageFromList(images);
7683 if (p == (Image *) NULL)
7684 {
7685 (void) ThrowMagickException(exception,GetMagickModule(),
7686 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7687 status=MagickFalse;
7688 break;
7689 }
7690 q=p;
7691 if (index == 0)
7692 PrependImageToList(images,q);
7693 else
cristybb503372010-05-27 20:51:26 +00007694 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007695 AppendImageToList(images,q);
7696 else
7697 {
7698 q=GetImageFromList(*images,index-1);
7699 if (q == (Image *) NULL)
7700 {
7701 (void) ThrowMagickException(exception,GetMagickModule(),
7702 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7703 status=MagickFalse;
7704 break;
7705 }
7706 InsertImageInList(&q,p);
7707 }
7708 *images=GetFirstImageInList(q);
7709 break;
7710 }
cristy28474bf2011-09-11 23:32:52 +00007711 if (LocaleCompare("interpolate",option+1) == 0)
7712 {
7713 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7714 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7715 break;
7716 }
cristy3ed852e2009-09-05 21:47:34 +00007717 break;
7718 }
7719 case 'l':
7720 {
7721 if (LocaleCompare("layers",option+1) == 0)
7722 {
7723 Image
7724 *layers;
7725
7726 ImageLayerMethod
7727 method;
7728
cristy6b3da3a2010-06-20 02:21:46 +00007729 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007730 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007731 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007732 MagickFalse,argv[i+1]);
7733 switch (method)
7734 {
7735 case CoalesceLayer:
7736 {
7737 layers=CoalesceImages(*images,exception);
7738 break;
7739 }
7740 case CompareAnyLayer:
7741 case CompareClearLayer:
7742 case CompareOverlayLayer:
7743 default:
7744 {
cristy8a9106f2011-07-05 14:39:26 +00007745 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007746 break;
7747 }
7748 case MergeLayer:
7749 case FlattenLayer:
7750 case MosaicLayer:
7751 case TrimBoundsLayer:
7752 {
7753 layers=MergeImageLayers(*images,method,exception);
7754 break;
7755 }
7756 case DisposeLayer:
7757 {
7758 layers=DisposeImages(*images,exception);
7759 break;
7760 }
7761 case OptimizeImageLayer:
7762 {
7763 layers=OptimizeImageLayers(*images,exception);
7764 break;
7765 }
7766 case OptimizePlusLayer:
7767 {
7768 layers=OptimizePlusImageLayers(*images,exception);
7769 break;
7770 }
7771 case OptimizeTransLayer:
7772 {
7773 OptimizeImageTransparency(*images,exception);
7774 break;
7775 }
7776 case RemoveDupsLayer:
7777 {
7778 RemoveDuplicateLayers(images,exception);
7779 break;
7780 }
7781 case RemoveZeroLayer:
7782 {
7783 RemoveZeroDelayLayers(images,exception);
7784 break;
7785 }
7786 case OptimizeLayer:
7787 {
7788 /*
7789 General Purpose, GIF Animation Optimizer.
7790 */
7791 layers=CoalesceImages(*images,exception);
7792 if (layers == (Image *) NULL)
7793 {
7794 status=MagickFalse;
7795 break;
7796 }
cristy3ed852e2009-09-05 21:47:34 +00007797 *images=DestroyImageList(*images);
7798 *images=layers;
7799 layers=OptimizeImageLayers(*images,exception);
7800 if (layers == (Image *) NULL)
7801 {
7802 status=MagickFalse;
7803 break;
7804 }
cristy3ed852e2009-09-05 21:47:34 +00007805 *images=DestroyImageList(*images);
7806 *images=layers;
7807 layers=(Image *) NULL;
7808 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007809 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7810 exception);
cristy3ed852e2009-09-05 21:47:34 +00007811 break;
7812 }
7813 case CompositeLayer:
7814 {
7815 CompositeOperator
7816 compose;
7817
7818 Image
7819 *source;
7820
7821 RectangleInfo
7822 geometry;
7823
7824 /*
7825 Split image sequence at the first 'NULL:' image.
7826 */
7827 source=(*images);
7828 while (source != (Image *) NULL)
7829 {
7830 source=GetNextImageInList(source);
7831 if ((source != (Image *) NULL) &&
7832 (LocaleCompare(source->magick,"NULL") == 0))
7833 break;
7834 }
7835 if (source != (Image *) NULL)
7836 {
7837 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7838 (GetNextImageInList(source) == (Image *) NULL))
7839 source=(Image *) NULL;
7840 else
7841 {
7842 /*
7843 Separate the two lists, junk the null: image.
7844 */
7845 source=SplitImageList(source->previous);
7846 DeleteImageFromList(&source);
7847 }
7848 }
7849 if (source == (Image *) NULL)
7850 {
7851 (void) ThrowMagickException(exception,GetMagickModule(),
7852 OptionError,"MissingNullSeparator","layers Composite");
7853 status=MagickFalse;
7854 break;
7855 }
7856 /*
7857 Adjust offset with gravity and virtual canvas.
7858 */
7859 SetGeometry(*images,&geometry);
7860 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7861 geometry.width=source->page.width != 0 ?
7862 source->page.width : source->columns;
7863 geometry.height=source->page.height != 0 ?
7864 source->page.height : source->rows;
7865 GravityAdjustGeometry((*images)->page.width != 0 ?
7866 (*images)->page.width : (*images)->columns,
7867 (*images)->page.height != 0 ? (*images)->page.height :
7868 (*images)->rows,(*images)->gravity,&geometry);
7869 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007870 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007871 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007872 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007873 MagickComposeOptions,MagickFalse,option);
7874 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7875 exception);
7876 source=DestroyImageList(source);
7877 break;
7878 }
7879 }
7880 if (layers == (Image *) NULL)
7881 break;
7882 InheritException(exception,&layers->exception);
7883 *images=DestroyImageList(*images);
7884 *images=layers;
7885 break;
7886 }
7887 break;
7888 }
7889 case 'm':
7890 {
7891 if (LocaleCompare("map",option+1) == 0)
7892 {
cristy6b3da3a2010-06-20 02:21:46 +00007893 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007894 if (*option == '+')
7895 {
cristy018f07f2011-09-04 21:15:19 +00007896 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7897 exception);
cristy3ed852e2009-09-05 21:47:34 +00007898 break;
7899 }
7900 i++;
7901 break;
7902 }
cristyf40785b2010-03-06 02:27:27 +00007903 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007904 {
7905 Image
cristyf40785b2010-03-06 02:27:27 +00007906 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007907
cristyd18ae7c2010-03-07 17:39:52 +00007908 /*
7909 Maximum image sequence (deprecated).
7910 */
cristy6b3da3a2010-06-20 02:21:46 +00007911 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007912 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007913 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007914 {
7915 status=MagickFalse;
7916 break;
7917 }
7918 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007919 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007920 break;
7921 }
cristyf40785b2010-03-06 02:27:27 +00007922 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007923 {
7924 Image
cristyf40785b2010-03-06 02:27:27 +00007925 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007926
cristyd18ae7c2010-03-07 17:39:52 +00007927 /*
7928 Minimum image sequence (deprecated).
7929 */
cristy6b3da3a2010-06-20 02:21:46 +00007930 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007931 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007932 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007933 {
7934 status=MagickFalse;
7935 break;
7936 }
7937 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007938 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007939 break;
7940 }
cristy3ed852e2009-09-05 21:47:34 +00007941 if (LocaleCompare("morph",option+1) == 0)
7942 {
7943 Image
7944 *morph_image;
7945
cristy6b3da3a2010-06-20 02:21:46 +00007946 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007947 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007948 exception);
7949 if (morph_image == (Image *) NULL)
7950 {
7951 status=MagickFalse;
7952 break;
7953 }
7954 *images=DestroyImageList(*images);
7955 *images=morph_image;
7956 break;
7957 }
7958 if (LocaleCompare("mosaic",option+1) == 0)
7959 {
7960 Image
7961 *mosaic_image;
7962
cristy6b3da3a2010-06-20 02:21:46 +00007963 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007964 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7965 if (mosaic_image == (Image *) NULL)
7966 {
7967 status=MagickFalse;
7968 break;
7969 }
7970 *images=DestroyImageList(*images);
7971 *images=mosaic_image;
7972 break;
7973 }
7974 break;
7975 }
7976 case 'p':
7977 {
7978 if (LocaleCompare("print",option+1) == 0)
7979 {
7980 char
7981 *string;
7982
cristy6b3da3a2010-06-20 02:21:46 +00007983 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007984 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7985 exception);
cristy3ed852e2009-09-05 21:47:34 +00007986 if (string == (char *) NULL)
7987 break;
cristyb51dff52011-05-19 16:55:47 +00007988 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007989 string=DestroyString(string);
7990 }
7991 if (LocaleCompare("process",option+1) == 0)
7992 {
7993 char
7994 **arguments;
7995
7996 int
7997 j,
7998 number_arguments;
7999
cristy6b3da3a2010-06-20 02:21:46 +00008000 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008001 arguments=StringToArgv(argv[i+1],&number_arguments);
8002 if (arguments == (char **) NULL)
8003 break;
8004 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8005 {
8006 char
8007 breaker,
8008 quote,
8009 *token;
8010
8011 const char
8012 *arguments;
8013
8014 int
8015 next,
8016 status;
8017
8018 size_t
8019 length;
8020
8021 TokenInfo
8022 *token_info;
8023
8024 /*
8025 Support old style syntax, filter="-option arg".
8026 */
8027 length=strlen(argv[i+1]);
8028 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008029 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008030 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8031 sizeof(*token));
8032 if (token == (char *) NULL)
8033 break;
8034 next=0;
8035 arguments=argv[i+1];
8036 token_info=AcquireTokenInfo();
8037 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8038 "\"",'\0',&breaker,&next,&quote);
8039 token_info=DestroyTokenInfo(token_info);
8040 if (status == 0)
8041 {
8042 const char
8043 *argv;
8044
8045 argv=(&(arguments[next]));
8046 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8047 exception);
8048 }
8049 token=DestroyString(token);
8050 break;
8051 }
cristy91c0da22010-05-02 01:44:07 +00008052 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008053 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8054 number_arguments-2,(const char **) arguments+2,exception);
8055 for (j=0; j < number_arguments; j++)
8056 arguments[j]=DestroyString(arguments[j]);
8057 arguments=(char **) RelinquishMagickMemory(arguments);
8058 break;
8059 }
8060 break;
8061 }
8062 case 'r':
8063 {
8064 if (LocaleCompare("reverse",option+1) == 0)
8065 {
8066 ReverseImageList(images);
8067 InheritException(exception,&(*images)->exception);
8068 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
8082 (void) SyncImagesSettings(mogrify_info,*images);
8083 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
cristy6b3da3a2010-06-20 02:21:46 +00008153 (void) SyncImagesSettings(mogrify_info,*images);
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}