blob: 7d8e0fffcc1734ca3b02b2f8ee4c754d7d0f09e1 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
cristy4c08aed2011-07-01 19:47:50 +000054#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000055#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000056#include "MagickCore/utility-private.h"
cristy3ed852e2009-09-05 21:47:34 +000057
58/*
cristy154fa9d2011-08-05 14:25:15 +000059 Constant declaration.
60*/
cristy3a557c02011-08-06 19:48:02 +000061static const char
cristy638895a2011-08-06 23:19:14 +000062 MogrifyBackgroundColor[] = "#ffffff", /* white */
63 MogrifyBorderColor[] = "#dfdfdf", /* gray */
64 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000065
66/*
cristy3ed852e2009-09-05 21:47:34 +000067 Define declarations.
68*/
69#define UndefinedCompressionQuality 0UL
70
71/*
cristy3ed852e2009-09-05 21:47:34 +000072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
cristy5063d812010-10-19 16:28:10 +000076% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000077% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% MagickCommandGenesis() applies image processing options to an image as
83% prescribed by command line options.
84%
85% The format of the MagickCommandGenesis method is:
86%
87% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000088% MagickCommand command,int argc,char **argv,char **metadata,
89% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000090%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
cristy5063d812010-10-19 16:28:10 +000095% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000096% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000097% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000099%
100% o argc: Specifies a pointer to an integer describing the number of
101% elements in the argument vector.
102%
103% o argv: Specifies a pointer to a text array containing the command line
104% arguments.
105%
cristy5063d812010-10-19 16:28:10 +0000106% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000107%
108% o exception: return any errors or warnings in this structure.
109%
110*/
111WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
112 MagickCommand command,int argc,char **argv,char **metadata,
113 ExceptionInfo *exception)
114{
115 char
116 *option;
117
118 double
119 duration,
120 elapsed_time,
121 user_time;
122
cristy3980b0d2009-10-25 14:37:13 +0000123 MagickBooleanType
124 concurrent,
125 regard_warnings,
126 status;
127
cristybb503372010-05-27 20:51:26 +0000128 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000129 i;
130
131 TimerInfo
132 *timer;
133
cristybb503372010-05-27 20:51:26 +0000134 size_t
cristy3980b0d2009-10-25 14:37:13 +0000135 iterations;
136
cristyd0a94fa2010-03-12 14:18:11 +0000137 (void) setlocale(LC_ALL,"");
138 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000139 concurrent=MagickFalse;
140 duration=(-1.0);
141 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000142 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000143 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000144 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000145 {
146 option=argv[i];
147 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
148 continue;
149 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000150 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000151 if (LocaleCompare("concurrent",option+1) == 0)
152 concurrent=MagickTrue;
153 if (LocaleCompare("debug",option+1) == 0)
154 (void) SetLogEventMask(argv[++i]);
155 if (LocaleCompare("duration",option+1) == 0)
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/*
anthony0d0fd352011-10-04 11:09:07 +0000301 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.
cristy4c08aed2011-07-01 19:47:50 +0000303*/
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
anthony0d0fd352011-10-04 11:09:07 +0000388 /*
389 SparseColorOption() parses the complex -sparse-color argument into an
390 an array of floating point values then calls SparseColorImage().
391 Argument is a complex mix of floating-point pixel coodinates, and color
392 specifications (or direct floating point numbers). The number of floats
393 needed to represent a color varies depending on the current channel
394 setting.
395 */
cristy3884f692011-07-08 18:00:18 +0000396static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000397 const SparseColorMethod method,const char *arguments,
398 const MagickBooleanType color_from_image,ExceptionInfo *exception)
399{
anthonydf8ebac2011-04-27 09:03:19 +0000400 char
401 token[MaxTextExtent];
402
403 const char
404 *p;
405
406 double
407 *sparse_arguments;
408
anthonydf8ebac2011-04-27 09:03:19 +0000409 Image
410 *sparse_image;
411
cristy4c08aed2011-07-01 19:47:50 +0000412 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000413 color;
414
415 MagickBooleanType
416 error;
417
cristy5f09d852011-05-29 01:39:29 +0000418 register size_t
419 x;
420
421 size_t
422 number_arguments,
423 number_colors;
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 */
cristy269c9412011-10-13 23:41:15 +0000537 (void) QueryColorCompliance(token,AllCompliance,&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
cristy9ed1f812011-10-08 02:00:08 +0000628 double
629 attenuate;
630
anthonydf8ebac2011-04-27 09:03:19 +0000631 DrawInfo
632 *draw_info;
633
634 GeometryInfo
635 geometry_info;
636
cristy3ed852e2009-09-05 21:47:34 +0000637 Image
638 *region_image;
639
anthonydf8ebac2011-04-27 09:03:19 +0000640 ImageInfo
641 *mogrify_info;
642
cristyebbcfea2011-02-25 02:43:54 +0000643 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000644 status;
645
cristy4c08aed2011-07-01 19:47:50 +0000646 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000647 fill;
cristy3ed852e2009-09-05 21:47:34 +0000648
anthonydf8ebac2011-04-27 09:03:19 +0000649 MagickStatusType
650 flags;
651
cristy28474bf2011-09-11 23:32:52 +0000652 PixelInterpolateMethod
653 interpolate_method;
654
anthonydf8ebac2011-04-27 09:03:19 +0000655 QuantizeInfo
656 *quantize_info;
657
658 RectangleInfo
659 geometry,
660 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000661
cristybb503372010-05-27 20:51:26 +0000662 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000663 i;
664
665 /*
666 Initialize method variables.
667 */
668 assert(image_info != (const ImageInfo *) NULL);
669 assert(image_info->signature == MagickSignature);
670 assert(image != (Image **) NULL);
671 assert((*image)->signature == MagickSignature);
672 if ((*image)->debug != MagickFalse)
673 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
674 if (argc < 0)
675 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000676 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000677 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
678 quantize_info=AcquireQuantizeInfo(mogrify_info);
679 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000680 GetPixelInfo(*image,&fill);
681 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
cristy9ed1f812011-10-08 02:00:08 +0000682 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000683 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000684 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000685 channel=mogrify_info->channel;
686 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000687 SetGeometry(*image,&region_geometry);
688 region_image=NewImageList();
689 /*
690 Transmogrify the image.
691 */
cristybb503372010-05-27 20:51:26 +0000692 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000693 {
anthonydf8ebac2011-04-27 09:03:19 +0000694 Image
695 *mogrify_image;
696
anthonye9c27192011-03-27 08:07:06 +0000697 ssize_t
698 count;
699
anthonydf8ebac2011-04-27 09:03:19 +0000700 option=argv[i];
701 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000702 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000703 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
704 0L);
cristycee97112010-05-28 00:44:52 +0000705 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000706 break;
cristy6b3da3a2010-06-20 02:21:46 +0000707 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000708 mogrify_image=(Image *)NULL;
709 switch (*(option+1))
710 {
711 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000712 {
anthonydf8ebac2011-04-27 09:03:19 +0000713 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000714 {
anthonydf8ebac2011-04-27 09:03:19 +0000715 /*
716 Adaptive blur image.
717 */
718 (void) SyncImageSettings(mogrify_info,*image);
719 flags=ParseGeometry(argv[i+1],&geometry_info);
720 if ((flags & SigmaValue) == 0)
721 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000722 if ((flags & XiValue) == 0)
723 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000724 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000725 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000726 break;
cristy3ed852e2009-09-05 21:47:34 +0000727 }
anthonydf8ebac2011-04-27 09:03:19 +0000728 if (LocaleCompare("adaptive-resize",option+1) == 0)
729 {
730 /*
731 Adaptive resize image.
732 */
733 (void) SyncImageSettings(mogrify_info,*image);
734 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
735 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000736 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000737 break;
738 }
739 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
740 {
741 /*
742 Adaptive sharpen image.
743 */
744 (void) SyncImageSettings(mogrify_info,*image);
745 flags=ParseGeometry(argv[i+1],&geometry_info);
746 if ((flags & SigmaValue) == 0)
747 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000748 if ((flags & XiValue) == 0)
749 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000750 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000751 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000752 break;
753 }
754 if (LocaleCompare("affine",option+1) == 0)
755 {
756 /*
757 Affine matrix.
758 */
759 if (*option == '+')
760 {
761 GetAffineMatrix(&draw_info->affine);
762 break;
763 }
764 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
765 break;
766 }
767 if (LocaleCompare("alpha",option+1) == 0)
768 {
769 AlphaChannelType
770 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000771
anthonydf8ebac2011-04-27 09:03:19 +0000772 (void) SyncImageSettings(mogrify_info,*image);
773 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
774 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000775 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000776 break;
777 }
778 if (LocaleCompare("annotate",option+1) == 0)
779 {
780 char
781 *text,
782 geometry[MaxTextExtent];
783
784 /*
785 Annotate image.
786 */
787 (void) SyncImageSettings(mogrify_info,*image);
788 SetGeometryInfo(&geometry_info);
789 flags=ParseGeometry(argv[i+1],&geometry_info);
790 if ((flags & SigmaValue) == 0)
791 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000792 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
793 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000794 if (text == (char *) NULL)
795 break;
796 (void) CloneString(&draw_info->text,text);
797 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000798 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000799 geometry_info.xi,geometry_info.psi);
800 (void) CloneString(&draw_info->geometry,geometry);
801 draw_info->affine.sx=cos(DegreesToRadians(
802 fmod(geometry_info.rho,360.0)));
803 draw_info->affine.rx=sin(DegreesToRadians(
804 fmod(geometry_info.rho,360.0)));
805 draw_info->affine.ry=(-sin(DegreesToRadians(
806 fmod(geometry_info.sigma,360.0))));
807 draw_info->affine.sy=cos(DegreesToRadians(
808 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000809 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000810 break;
811 }
812 if (LocaleCompare("antialias",option+1) == 0)
813 {
814 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
815 MagickFalse;
816 draw_info->text_antialias=(*option == '-') ? MagickTrue :
817 MagickFalse;
818 break;
819 }
cristy9ed1f812011-10-08 02:00:08 +0000820 if (LocaleCompare("attenuate",option+1) == 0)
821 {
822 if (*option == '+')
823 {
824 attenuate=1.0;
825 break;
826 }
827 attenuate=InterpretLocaleValue(argv[i+1],(char **) NULL);
828 break;
829 }
anthonydf8ebac2011-04-27 09:03:19 +0000830 if (LocaleCompare("auto-gamma",option+1) == 0)
831 {
832 /*
833 Auto Adjust Gamma of image based on its mean
834 */
835 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000836 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000837 break;
838 }
839 if (LocaleCompare("auto-level",option+1) == 0)
840 {
841 /*
842 Perfectly Normalize (max/min stretch) the image
843 */
844 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000845 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000846 break;
847 }
848 if (LocaleCompare("auto-orient",option+1) == 0)
849 {
850 (void) SyncImageSettings(mogrify_info,*image);
851 switch ((*image)->orientation)
852 {
853 case TopRightOrientation:
854 {
855 mogrify_image=FlopImage(*image,exception);
856 break;
857 }
858 case BottomRightOrientation:
859 {
860 mogrify_image=RotateImage(*image,180.0,exception);
861 break;
862 }
863 case BottomLeftOrientation:
864 {
865 mogrify_image=FlipImage(*image,exception);
866 break;
867 }
868 case LeftTopOrientation:
869 {
870 mogrify_image=TransposeImage(*image,exception);
871 break;
872 }
873 case RightTopOrientation:
874 {
875 mogrify_image=RotateImage(*image,90.0,exception);
876 break;
877 }
878 case RightBottomOrientation:
879 {
880 mogrify_image=TransverseImage(*image,exception);
881 break;
882 }
883 case LeftBottomOrientation:
884 {
885 mogrify_image=RotateImage(*image,270.0,exception);
886 break;
887 }
888 default:
889 break;
890 }
891 if (mogrify_image != (Image *) NULL)
892 mogrify_image->orientation=TopLeftOrientation;
893 break;
894 }
895 break;
896 }
897 case 'b':
898 {
899 if (LocaleCompare("black-threshold",option+1) == 0)
900 {
901 /*
902 Black threshold image.
903 */
904 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000905 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000906 break;
907 }
908 if (LocaleCompare("blue-shift",option+1) == 0)
909 {
910 /*
911 Blue shift image.
912 */
913 (void) SyncImageSettings(mogrify_info,*image);
914 geometry_info.rho=1.5;
915 if (*option == '-')
916 flags=ParseGeometry(argv[i+1],&geometry_info);
917 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
918 break;
919 }
920 if (LocaleCompare("blur",option+1) == 0)
921 {
922 /*
923 Gaussian blur image.
924 */
925 (void) SyncImageSettings(mogrify_info,*image);
926 flags=ParseGeometry(argv[i+1],&geometry_info);
927 if ((flags & SigmaValue) == 0)
928 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000929 if ((flags & XiValue) == 0)
930 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000931 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000932 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000933 break;
934 }
935 if (LocaleCompare("border",option+1) == 0)
936 {
937 /*
938 Surround image with a border of solid color.
939 */
940 (void) SyncImageSettings(mogrify_info,*image);
941 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
942 if ((flags & SigmaValue) == 0)
943 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000944 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000945 break;
946 }
947 if (LocaleCompare("bordercolor",option+1) == 0)
948 {
949 if (*option == '+')
950 {
cristy9950d572011-10-01 18:22:35 +0000951 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000952 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000953 break;
954 }
cristy9950d572011-10-01 18:22:35 +0000955 (void) QueryColorCompliance(argv[i+1],AllCompliance,
956 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000957 break;
958 }
959 if (LocaleCompare("box",option+1) == 0)
960 {
cristy9950d572011-10-01 18:22:35 +0000961 (void) QueryColorCompliance(argv[i+1],AllCompliance,
962 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000963 break;
964 }
965 if (LocaleCompare("brightness-contrast",option+1) == 0)
966 {
967 double
968 brightness,
969 contrast;
970
971 GeometryInfo
972 geometry_info;
973
974 MagickStatusType
975 flags;
976
977 /*
978 Brightness / contrast image.
979 */
980 (void) SyncImageSettings(mogrify_info,*image);
981 flags=ParseGeometry(argv[i+1],&geometry_info);
982 brightness=geometry_info.rho;
983 contrast=0.0;
984 if ((flags & SigmaValue) != 0)
985 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000986 (void) BrightnessContrastImage(*image,brightness,contrast,
987 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000988 break;
989 }
990 break;
991 }
992 case 'c':
993 {
994 if (LocaleCompare("cdl",option+1) == 0)
995 {
996 char
997 *color_correction_collection;
998
999 /*
1000 Color correct with a color decision list.
1001 */
1002 (void) SyncImageSettings(mogrify_info,*image);
1003 color_correction_collection=FileToString(argv[i+1],~0,exception);
1004 if (color_correction_collection == (char *) NULL)
1005 break;
cristy1bfa9f02011-08-11 02:35:43 +00001006 (void) ColorDecisionListImage(*image,color_correction_collection,
1007 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001008 break;
1009 }
1010 if (LocaleCompare("channel",option+1) == 0)
1011 {
1012 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001013 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001014 else
cristyfa806a72011-07-04 02:06:13 +00001015 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00001016 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001017 break;
1018 }
1019 if (LocaleCompare("charcoal",option+1) == 0)
1020 {
1021 /*
1022 Charcoal image.
1023 */
1024 (void) SyncImageSettings(mogrify_info,*image);
1025 flags=ParseGeometry(argv[i+1],&geometry_info);
1026 if ((flags & SigmaValue) == 0)
1027 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001028 if ((flags & XiValue) == 0)
1029 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001030 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001031 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001032 break;
1033 }
1034 if (LocaleCompare("chop",option+1) == 0)
1035 {
1036 /*
1037 Chop the image.
1038 */
1039 (void) SyncImageSettings(mogrify_info,*image);
1040 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1041 mogrify_image=ChopImage(*image,&geometry,exception);
1042 break;
1043 }
1044 if (LocaleCompare("clamp",option+1) == 0)
1045 {
1046 /*
1047 Clamp image.
1048 */
1049 (void) SyncImageSettings(mogrify_info,*image);
cristy092d71c2011-10-14 18:01:29 +00001050 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001051 break;
1052 }
1053 if (LocaleCompare("clip",option+1) == 0)
1054 {
1055 (void) SyncImageSettings(mogrify_info,*image);
1056 if (*option == '+')
1057 {
cristy018f07f2011-09-04 21:15:19 +00001058 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001059 break;
1060 }
cristy018f07f2011-09-04 21:15:19 +00001061 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001062 break;
1063 }
1064 if (LocaleCompare("clip-mask",option+1) == 0)
1065 {
1066 CacheView
1067 *mask_view;
1068
1069 Image
1070 *mask_image;
1071
cristy4c08aed2011-07-01 19:47:50 +00001072 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001073 *restrict q;
1074
1075 register ssize_t
1076 x;
1077
1078 ssize_t
1079 y;
1080
1081 (void) SyncImageSettings(mogrify_info,*image);
1082 if (*option == '+')
1083 {
1084 /*
1085 Remove a mask.
1086 */
cristy018f07f2011-09-04 21:15:19 +00001087 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001088 break;
1089 }
1090 /*
1091 Set the image mask.
1092 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1093 */
1094 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1095 if (mask_image == (Image *) NULL)
1096 break;
cristy574cc262011-08-05 01:23:58 +00001097 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001098 return(MagickFalse);
1099 mask_view=AcquireCacheView(mask_image);
1100 for (y=0; y < (ssize_t) mask_image->rows; y++)
1101 {
1102 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1103 exception);
cristyacd2ed22011-08-30 01:44:23 +00001104 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001105 break;
1106 for (x=0; x < (ssize_t) mask_image->columns; x++)
1107 {
1108 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001109 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1110 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1111 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1112 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001113 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001114 }
1115 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1116 break;
1117 }
1118 mask_view=DestroyCacheView(mask_view);
1119 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001120 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001121 break;
1122 }
1123 if (LocaleCompare("clip-path",option+1) == 0)
1124 {
1125 (void) SyncImageSettings(mogrify_info,*image);
1126 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001127 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001128 break;
1129 }
1130 if (LocaleCompare("colorize",option+1) == 0)
1131 {
1132 /*
1133 Colorize the image.
1134 */
1135 (void) SyncImageSettings(mogrify_info,*image);
cristyc7e6ff62011-10-03 13:46:11 +00001136 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001137 break;
1138 }
1139 if (LocaleCompare("color-matrix",option+1) == 0)
1140 {
1141 KernelInfo
1142 *kernel;
1143
1144 (void) SyncImageSettings(mogrify_info,*image);
1145 kernel=AcquireKernelInfo(argv[i+1]);
1146 if (kernel == (KernelInfo *) NULL)
1147 break;
1148 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1149 kernel=DestroyKernelInfo(kernel);
1150 break;
1151 }
1152 if (LocaleCompare("colors",option+1) == 0)
1153 {
1154 /*
1155 Reduce the number of colors in the image.
1156 */
1157 (void) SyncImageSettings(mogrify_info,*image);
1158 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1159 if (quantize_info->number_colors == 0)
1160 break;
1161 if (((*image)->storage_class == DirectClass) ||
1162 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001163 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001164 else
cristy018f07f2011-09-04 21:15:19 +00001165 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001166 break;
1167 }
1168 if (LocaleCompare("colorspace",option+1) == 0)
1169 {
1170 ColorspaceType
1171 colorspace;
1172
1173 (void) SyncImageSettings(mogrify_info,*image);
1174 if (*option == '+')
1175 {
cristye941a752011-10-15 01:52:48 +00001176 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001177 break;
1178 }
1179 colorspace=(ColorspaceType) ParseCommandOption(
1180 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001181 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001182 break;
1183 }
cristy633f0c62011-09-15 13:27:36 +00001184 if (LocaleCompare("compose",option+1) == 0)
1185 {
1186 (void) SyncImageSettings(mogrify_info,*image);
1187 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1188 MagickFalse,argv[i+1]);
1189 break;
1190 }
anthonydf8ebac2011-04-27 09:03:19 +00001191 if (LocaleCompare("contrast",option+1) == 0)
1192 {
1193 (void) SyncImageSettings(mogrify_info,*image);
1194 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001195 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001196 break;
1197 }
1198 if (LocaleCompare("contrast-stretch",option+1) == 0)
1199 {
1200 double
1201 black_point,
1202 white_point;
1203
1204 MagickStatusType
1205 flags;
1206
1207 /*
1208 Contrast stretch image.
1209 */
1210 (void) SyncImageSettings(mogrify_info,*image);
1211 flags=ParseGeometry(argv[i+1],&geometry_info);
1212 black_point=geometry_info.rho;
1213 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1214 black_point;
1215 if ((flags & PercentValue) != 0)
1216 {
1217 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1218 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1219 }
1220 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1221 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001222 (void) ContrastStretchImage(*image,black_point,white_point,
1223 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001224 break;
1225 }
1226 if (LocaleCompare("convolve",option+1) == 0)
1227 {
anthonydf8ebac2011-04-27 09:03:19 +00001228 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001229 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001230
anthonydf8ebac2011-04-27 09:03:19 +00001231 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001232 kernel_info=AcquireKernelInfo(argv[i+1]);
1233 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001234 break;
cristy0a922382011-07-16 15:30:34 +00001235 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001236 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001237 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001238 break;
1239 }
1240 if (LocaleCompare("crop",option+1) == 0)
1241 {
1242 /*
1243 Crop a image to a smaller size
1244 */
1245 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001246 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001247 break;
1248 }
1249 if (LocaleCompare("cycle",option+1) == 0)
1250 {
1251 /*
1252 Cycle an image colormap.
1253 */
1254 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001255 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1256 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001257 break;
1258 }
1259 break;
1260 }
1261 case 'd':
1262 {
1263 if (LocaleCompare("decipher",option+1) == 0)
1264 {
1265 StringInfo
1266 *passkey;
1267
1268 /*
1269 Decipher pixels.
1270 */
1271 (void) SyncImageSettings(mogrify_info,*image);
1272 passkey=FileToStringInfo(argv[i+1],~0,exception);
1273 if (passkey != (StringInfo *) NULL)
1274 {
1275 (void) PasskeyDecipherImage(*image,passkey,exception);
1276 passkey=DestroyStringInfo(passkey);
1277 }
1278 break;
1279 }
1280 if (LocaleCompare("density",option+1) == 0)
1281 {
1282 /*
1283 Set image density.
1284 */
1285 (void) CloneString(&draw_info->density,argv[i+1]);
1286 break;
1287 }
1288 if (LocaleCompare("depth",option+1) == 0)
1289 {
1290 (void) SyncImageSettings(mogrify_info,*image);
1291 if (*option == '+')
1292 {
cristy8a11cb12011-10-19 23:53:34 +00001293 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001294 break;
1295 }
cristy8a11cb12011-10-19 23:53:34 +00001296 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1297 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001298 break;
1299 }
1300 if (LocaleCompare("deskew",option+1) == 0)
1301 {
1302 double
1303 threshold;
1304
1305 /*
1306 Straighten the image.
1307 */
1308 (void) SyncImageSettings(mogrify_info,*image);
1309 if (*option == '+')
1310 threshold=40.0*QuantumRange/100.0;
1311 else
1312 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1313 mogrify_image=DeskewImage(*image,threshold,exception);
1314 break;
1315 }
1316 if (LocaleCompare("despeckle",option+1) == 0)
1317 {
1318 /*
1319 Reduce the speckles within an image.
1320 */
1321 (void) SyncImageSettings(mogrify_info,*image);
1322 mogrify_image=DespeckleImage(*image,exception);
1323 break;
1324 }
1325 if (LocaleCompare("display",option+1) == 0)
1326 {
1327 (void) CloneString(&draw_info->server_name,argv[i+1]);
1328 break;
1329 }
1330 if (LocaleCompare("distort",option+1) == 0)
1331 {
1332 char
1333 *args,
1334 token[MaxTextExtent];
1335
1336 const char
1337 *p;
1338
1339 DistortImageMethod
1340 method;
1341
1342 double
1343 *arguments;
1344
1345 register ssize_t
1346 x;
1347
1348 size_t
1349 number_arguments;
1350
1351 /*
1352 Distort image.
1353 */
1354 (void) SyncImageSettings(mogrify_info,*image);
1355 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1356 MagickFalse,argv[i+1]);
1357 if ( method == ResizeDistortion )
1358 {
1359 /* Special Case - Argument is actually a resize geometry!
1360 ** Convert that to an appropriate distortion argument array.
1361 */
1362 double
1363 resize_args[2];
1364 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1365 exception);
1366 resize_args[0]=(double)geometry.width;
1367 resize_args[1]=(double)geometry.height;
1368 mogrify_image=DistortImage(*image,method,(size_t)2,
1369 resize_args,MagickTrue,exception);
1370 break;
1371 }
cristy018f07f2011-09-04 21:15:19 +00001372 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1373 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001374 if (args == (char *) NULL)
1375 break;
1376 p=(char *) args;
1377 for (x=0; *p != '\0'; x++)
1378 {
1379 GetMagickToken(p,&p,token);
1380 if (*token == ',')
1381 GetMagickToken(p,&p,token);
1382 }
1383 number_arguments=(size_t) x;
1384 arguments=(double *) AcquireQuantumMemory(number_arguments,
1385 sizeof(*arguments));
1386 if (arguments == (double *) NULL)
1387 ThrowWandFatalException(ResourceLimitFatalError,
1388 "MemoryAllocationFailed",(*image)->filename);
1389 (void) ResetMagickMemory(arguments,0,number_arguments*
1390 sizeof(*arguments));
1391 p=(char *) args;
1392 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1393 {
1394 GetMagickToken(p,&p,token);
1395 if (*token == ',')
1396 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001397 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001398 }
1399 args=DestroyString(args);
1400 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1401 (*option == '+') ? MagickTrue : MagickFalse,exception);
1402 arguments=(double *) RelinquishMagickMemory(arguments);
1403 break;
1404 }
1405 if (LocaleCompare("dither",option+1) == 0)
1406 {
1407 if (*option == '+')
1408 {
1409 quantize_info->dither=MagickFalse;
1410 break;
1411 }
1412 quantize_info->dither=MagickTrue;
1413 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1414 MagickDitherOptions,MagickFalse,argv[i+1]);
1415 if (quantize_info->dither_method == NoDitherMethod)
1416 quantize_info->dither=MagickFalse;
1417 break;
1418 }
1419 if (LocaleCompare("draw",option+1) == 0)
1420 {
1421 /*
1422 Draw image.
1423 */
1424 (void) SyncImageSettings(mogrify_info,*image);
1425 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001426 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001427 break;
1428 }
1429 break;
1430 }
1431 case 'e':
1432 {
1433 if (LocaleCompare("edge",option+1) == 0)
1434 {
1435 /*
1436 Enhance edges in the image.
1437 */
1438 (void) SyncImageSettings(mogrify_info,*image);
1439 flags=ParseGeometry(argv[i+1],&geometry_info);
1440 if ((flags & SigmaValue) == 0)
1441 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001442 mogrify_image=EdgeImage(*image,geometry_info.rho,
1443 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001444 break;
1445 }
1446 if (LocaleCompare("emboss",option+1) == 0)
1447 {
1448 /*
1449 Gaussian embossen image.
1450 */
1451 (void) SyncImageSettings(mogrify_info,*image);
1452 flags=ParseGeometry(argv[i+1],&geometry_info);
1453 if ((flags & SigmaValue) == 0)
1454 geometry_info.sigma=1.0;
1455 mogrify_image=EmbossImage(*image,geometry_info.rho,
1456 geometry_info.sigma,exception);
1457 break;
1458 }
1459 if (LocaleCompare("encipher",option+1) == 0)
1460 {
1461 StringInfo
1462 *passkey;
1463
1464 /*
1465 Encipher pixels.
1466 */
1467 (void) SyncImageSettings(mogrify_info,*image);
1468 passkey=FileToStringInfo(argv[i+1],~0,exception);
1469 if (passkey != (StringInfo *) NULL)
1470 {
1471 (void) PasskeyEncipherImage(*image,passkey,exception);
1472 passkey=DestroyStringInfo(passkey);
1473 }
1474 break;
1475 }
1476 if (LocaleCompare("encoding",option+1) == 0)
1477 {
1478 (void) CloneString(&draw_info->encoding,argv[i+1]);
1479 break;
1480 }
1481 if (LocaleCompare("enhance",option+1) == 0)
1482 {
1483 /*
1484 Enhance image.
1485 */
1486 (void) SyncImageSettings(mogrify_info,*image);
1487 mogrify_image=EnhanceImage(*image,exception);
1488 break;
1489 }
1490 if (LocaleCompare("equalize",option+1) == 0)
1491 {
1492 /*
1493 Equalize image.
1494 */
1495 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001496 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001497 break;
1498 }
1499 if (LocaleCompare("evaluate",option+1) == 0)
1500 {
1501 double
1502 constant;
1503
1504 MagickEvaluateOperator
1505 op;
1506
1507 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001508 op=(MagickEvaluateOperator) ParseCommandOption(
1509 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001510 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001511 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001512 break;
1513 }
1514 if (LocaleCompare("extent",option+1) == 0)
1515 {
1516 /*
1517 Set the image extent.
1518 */
1519 (void) SyncImageSettings(mogrify_info,*image);
1520 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1521 if (geometry.width == 0)
1522 geometry.width=(*image)->columns;
1523 if (geometry.height == 0)
1524 geometry.height=(*image)->rows;
1525 mogrify_image=ExtentImage(*image,&geometry,exception);
1526 break;
1527 }
1528 break;
1529 }
1530 case 'f':
1531 {
1532 if (LocaleCompare("family",option+1) == 0)
1533 {
1534 if (*option == '+')
1535 {
1536 if (draw_info->family != (char *) NULL)
1537 draw_info->family=DestroyString(draw_info->family);
1538 break;
1539 }
1540 (void) CloneString(&draw_info->family,argv[i+1]);
1541 break;
1542 }
1543 if (LocaleCompare("features",option+1) == 0)
1544 {
1545 if (*option == '+')
1546 {
1547 (void) DeleteImageArtifact(*image,"identify:features");
1548 break;
1549 }
1550 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1551 break;
1552 }
1553 if (LocaleCompare("fill",option+1) == 0)
1554 {
1555 ExceptionInfo
1556 *sans;
1557
cristy4c08aed2011-07-01 19:47:50 +00001558 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001559 if (*option == '+')
1560 {
cristy269c9412011-10-13 23:41:15 +00001561 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001562 exception);
1563 (void) QueryColorCompliance("none",AllCompliance,
1564 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001565 if (draw_info->fill_pattern != (Image *) NULL)
1566 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1567 break;
1568 }
1569 sans=AcquireExceptionInfo();
cristy269c9412011-10-13 23:41:15 +00001570 (void) QueryColorCompliance(argv[i+1],AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001571 sans);
1572 status=QueryColorCompliance(argv[i+1],AllCompliance,
1573 &draw_info->fill,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001574 sans=DestroyExceptionInfo(sans);
1575 if (status == MagickFalse)
1576 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1577 exception);
1578 break;
1579 }
1580 if (LocaleCompare("flip",option+1) == 0)
1581 {
1582 /*
1583 Flip image scanlines.
1584 */
1585 (void) SyncImageSettings(mogrify_info,*image);
1586 mogrify_image=FlipImage(*image,exception);
1587 break;
1588 }
anthonydf8ebac2011-04-27 09:03:19 +00001589 if (LocaleCompare("floodfill",option+1) == 0)
1590 {
cristy4c08aed2011-07-01 19:47:50 +00001591 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001592 target;
1593
1594 /*
1595 Floodfill image.
1596 */
1597 (void) SyncImageSettings(mogrify_info,*image);
1598 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001599 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001600 exception);
cristyd42d9952011-07-08 14:21:50 +00001601 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001602 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001603 break;
1604 }
anthony3d2f4862011-05-01 13:48:16 +00001605 if (LocaleCompare("flop",option+1) == 0)
1606 {
1607 /*
1608 Flop image scanlines.
1609 */
1610 (void) SyncImageSettings(mogrify_info,*image);
1611 mogrify_image=FlopImage(*image,exception);
1612 break;
1613 }
anthonydf8ebac2011-04-27 09:03:19 +00001614 if (LocaleCompare("font",option+1) == 0)
1615 {
1616 if (*option == '+')
1617 {
1618 if (draw_info->font != (char *) NULL)
1619 draw_info->font=DestroyString(draw_info->font);
1620 break;
1621 }
1622 (void) CloneString(&draw_info->font,argv[i+1]);
1623 break;
1624 }
1625 if (LocaleCompare("format",option+1) == 0)
1626 {
1627 format=argv[i+1];
1628 break;
1629 }
1630 if (LocaleCompare("frame",option+1) == 0)
1631 {
1632 FrameInfo
1633 frame_info;
1634
1635 /*
1636 Surround image with an ornamental border.
1637 */
1638 (void) SyncImageSettings(mogrify_info,*image);
1639 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1640 frame_info.width=geometry.width;
1641 frame_info.height=geometry.height;
1642 if ((flags & HeightValue) == 0)
1643 frame_info.height=geometry.width;
1644 frame_info.outer_bevel=geometry.x;
1645 frame_info.inner_bevel=geometry.y;
1646 frame_info.x=(ssize_t) frame_info.width;
1647 frame_info.y=(ssize_t) frame_info.height;
1648 frame_info.width=(*image)->columns+2*frame_info.width;
1649 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001650 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001651 break;
1652 }
1653 if (LocaleCompare("function",option+1) == 0)
1654 {
1655 char
1656 *arguments,
1657 token[MaxTextExtent];
1658
1659 const char
1660 *p;
1661
1662 double
1663 *parameters;
1664
1665 MagickFunction
1666 function;
1667
1668 register ssize_t
1669 x;
1670
1671 size_t
1672 number_parameters;
1673
1674 /*
1675 Function Modify Image Values
1676 */
1677 (void) SyncImageSettings(mogrify_info,*image);
1678 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1679 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001680 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1681 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001682 if (arguments == (char *) NULL)
1683 break;
1684 p=(char *) arguments;
1685 for (x=0; *p != '\0'; x++)
1686 {
1687 GetMagickToken(p,&p,token);
1688 if (*token == ',')
1689 GetMagickToken(p,&p,token);
1690 }
1691 number_parameters=(size_t) x;
1692 parameters=(double *) AcquireQuantumMemory(number_parameters,
1693 sizeof(*parameters));
1694 if (parameters == (double *) NULL)
1695 ThrowWandFatalException(ResourceLimitFatalError,
1696 "MemoryAllocationFailed",(*image)->filename);
1697 (void) ResetMagickMemory(parameters,0,number_parameters*
1698 sizeof(*parameters));
1699 p=(char *) arguments;
1700 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1701 {
1702 GetMagickToken(p,&p,token);
1703 if (*token == ',')
1704 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001705 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001706 }
1707 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001708 (void) FunctionImage(*image,function,number_parameters,parameters,
1709 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001710 parameters=(double *) RelinquishMagickMemory(parameters);
1711 break;
1712 }
1713 break;
1714 }
1715 case 'g':
1716 {
1717 if (LocaleCompare("gamma",option+1) == 0)
1718 {
1719 /*
1720 Gamma image.
1721 */
1722 (void) SyncImageSettings(mogrify_info,*image);
1723 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001724 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001725 else
cristyb3e7c6c2011-07-24 01:43:55 +00001726 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1727 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001728 break;
1729 }
1730 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1731 (LocaleCompare("gaussian",option+1) == 0))
1732 {
1733 /*
1734 Gaussian blur image.
1735 */
1736 (void) SyncImageSettings(mogrify_info,*image);
1737 flags=ParseGeometry(argv[i+1],&geometry_info);
1738 if ((flags & SigmaValue) == 0)
1739 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001740 if ((flags & XiValue) == 0)
1741 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001742 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001743 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001744 break;
1745 }
1746 if (LocaleCompare("geometry",option+1) == 0)
1747 {
1748 /*
1749 Record Image offset, Resize last image.
1750 */
1751 (void) SyncImageSettings(mogrify_info,*image);
1752 if (*option == '+')
1753 {
1754 if ((*image)->geometry != (char *) NULL)
1755 (*image)->geometry=DestroyString((*image)->geometry);
1756 break;
1757 }
1758 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1759 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1760 (void) CloneString(&(*image)->geometry,argv[i+1]);
1761 else
1762 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1763 (*image)->filter,(*image)->blur,exception);
1764 break;
1765 }
1766 if (LocaleCompare("gravity",option+1) == 0)
1767 {
1768 if (*option == '+')
1769 {
1770 draw_info->gravity=UndefinedGravity;
1771 break;
1772 }
1773 draw_info->gravity=(GravityType) ParseCommandOption(
1774 MagickGravityOptions,MagickFalse,argv[i+1]);
1775 break;
1776 }
1777 break;
1778 }
1779 case 'h':
1780 {
1781 if (LocaleCompare("highlight-color",option+1) == 0)
1782 {
1783 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1784 break;
1785 }
1786 break;
1787 }
1788 case 'i':
1789 {
1790 if (LocaleCompare("identify",option+1) == 0)
1791 {
1792 char
1793 *text;
1794
1795 (void) SyncImageSettings(mogrify_info,*image);
1796 if (format == (char *) NULL)
1797 {
cristya4037272011-08-28 15:11:39 +00001798 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1799 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001800 break;
1801 }
cristy018f07f2011-09-04 21:15:19 +00001802 text=InterpretImageProperties(mogrify_info,*image,format,
1803 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001804 if (text == (char *) NULL)
1805 break;
1806 (void) fputs(text,stdout);
1807 (void) fputc('\n',stdout);
1808 text=DestroyString(text);
1809 break;
1810 }
1811 if (LocaleCompare("implode",option+1) == 0)
1812 {
1813 /*
1814 Implode image.
1815 */
1816 (void) SyncImageSettings(mogrify_info,*image);
1817 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001818 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1819 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001820 break;
1821 }
1822 if (LocaleCompare("interline-spacing",option+1) == 0)
1823 {
1824 if (*option == '+')
1825 (void) ParseGeometry("0",&geometry_info);
1826 else
1827 (void) ParseGeometry(argv[i+1],&geometry_info);
1828 draw_info->interline_spacing=geometry_info.rho;
1829 break;
1830 }
cristy28474bf2011-09-11 23:32:52 +00001831 if (LocaleCompare("interpolate",option+1) == 0)
1832 {
1833 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1834 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1835 break;
1836 }
anthonydf8ebac2011-04-27 09:03:19 +00001837 if (LocaleCompare("interword-spacing",option+1) == 0)
1838 {
1839 if (*option == '+')
1840 (void) ParseGeometry("0",&geometry_info);
1841 else
1842 (void) ParseGeometry(argv[i+1],&geometry_info);
1843 draw_info->interword_spacing=geometry_info.rho;
1844 break;
1845 }
1846 break;
1847 }
1848 case 'k':
1849 {
1850 if (LocaleCompare("kerning",option+1) == 0)
1851 {
1852 if (*option == '+')
1853 (void) ParseGeometry("0",&geometry_info);
1854 else
1855 (void) ParseGeometry(argv[i+1],&geometry_info);
1856 draw_info->kerning=geometry_info.rho;
1857 break;
1858 }
1859 break;
1860 }
1861 case 'l':
1862 {
1863 if (LocaleCompare("lat",option+1) == 0)
1864 {
1865 /*
1866 Local adaptive threshold image.
1867 */
1868 (void) SyncImageSettings(mogrify_info,*image);
1869 flags=ParseGeometry(argv[i+1],&geometry_info);
1870 if ((flags & PercentValue) != 0)
1871 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1872 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001873 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001874 geometry_info.xi,exception);
1875 break;
1876 }
1877 if (LocaleCompare("level",option+1) == 0)
1878 {
1879 MagickRealType
1880 black_point,
1881 gamma,
1882 white_point;
1883
1884 MagickStatusType
1885 flags;
1886
1887 /*
1888 Parse levels.
1889 */
1890 (void) SyncImageSettings(mogrify_info,*image);
1891 flags=ParseGeometry(argv[i+1],&geometry_info);
1892 black_point=geometry_info.rho;
1893 white_point=(MagickRealType) QuantumRange;
1894 if ((flags & SigmaValue) != 0)
1895 white_point=geometry_info.sigma;
1896 gamma=1.0;
1897 if ((flags & XiValue) != 0)
1898 gamma=geometry_info.xi;
1899 if ((flags & PercentValue) != 0)
1900 {
1901 black_point*=(MagickRealType) (QuantumRange/100.0);
1902 white_point*=(MagickRealType) (QuantumRange/100.0);
1903 }
1904 if ((flags & SigmaValue) == 0)
1905 white_point=(MagickRealType) QuantumRange-black_point;
1906 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001907 (void) LevelizeImage(*image,black_point,white_point,gamma,
1908 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001909 else
cristy01e9afd2011-08-10 17:38:41 +00001910 (void) LevelImage(*image,black_point,white_point,gamma,
1911 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001912 break;
1913 }
1914 if (LocaleCompare("level-colors",option+1) == 0)
1915 {
1916 char
1917 token[MaxTextExtent];
1918
1919 const char
1920 *p;
1921
cristy4c08aed2011-07-01 19:47:50 +00001922 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001923 black_point,
1924 white_point;
1925
1926 p=(const char *) argv[i+1];
1927 GetMagickToken(p,&p,token); /* get black point color */
1928 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001929 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001930 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001931 else
cristy269c9412011-10-13 23:41:15 +00001932 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001933 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001934 if (isalpha((int) token[0]) || (token[0] == '#'))
1935 GetMagickToken(p,&p,token);
1936 if (*token == '\0')
1937 white_point=black_point; /* set everything to that color */
1938 else
1939 {
1940 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1941 GetMagickToken(p,&p,token); /* Get white point color. */
1942 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001943 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001944 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001945 else
cristy269c9412011-10-13 23:41:15 +00001946 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001947 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001948 }
cristy490408a2011-07-07 14:42:05 +00001949 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001950 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001951 break;
1952 }
1953 if (LocaleCompare("linear-stretch",option+1) == 0)
1954 {
1955 double
1956 black_point,
1957 white_point;
1958
1959 MagickStatusType
1960 flags;
1961
1962 (void) SyncImageSettings(mogrify_info,*image);
1963 flags=ParseGeometry(argv[i+1],&geometry_info);
1964 black_point=geometry_info.rho;
1965 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1966 if ((flags & SigmaValue) != 0)
1967 white_point=geometry_info.sigma;
1968 if ((flags & PercentValue) != 0)
1969 {
1970 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1971 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1972 }
1973 if ((flags & SigmaValue) == 0)
1974 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1975 black_point;
cristy33bd5152011-08-24 01:42:24 +00001976 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001977 break;
1978 }
1979 if (LocaleCompare("linewidth",option+1) == 0)
1980 {
cristyc1acd842011-05-19 23:05:47 +00001981 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1982 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001983 break;
1984 }
1985 if (LocaleCompare("liquid-rescale",option+1) == 0)
1986 {
1987 /*
1988 Liquid rescale image.
1989 */
1990 (void) SyncImageSettings(mogrify_info,*image);
1991 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1992 if ((flags & XValue) == 0)
1993 geometry.x=1;
1994 if ((flags & YValue) == 0)
1995 geometry.y=0;
1996 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1997 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1998 break;
1999 }
2000 if (LocaleCompare("lowlight-color",option+1) == 0)
2001 {
2002 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2003 break;
2004 }
2005 break;
2006 }
2007 case 'm':
2008 {
2009 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002010 {
cristy3ed852e2009-09-05 21:47:34 +00002011 Image
anthonydf8ebac2011-04-27 09:03:19 +00002012 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002013
anthonydf8ebac2011-04-27 09:03:19 +00002014 /*
2015 Transform image colors to match this set of colors.
2016 */
2017 (void) SyncImageSettings(mogrify_info,*image);
2018 if (*option == '+')
2019 break;
2020 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2021 if (remap_image == (Image *) NULL)
2022 break;
cristy018f07f2011-09-04 21:15:19 +00002023 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002024 remap_image=DestroyImage(remap_image);
2025 break;
2026 }
2027 if (LocaleCompare("mask",option+1) == 0)
2028 {
2029 Image
2030 *mask;
2031
2032 (void) SyncImageSettings(mogrify_info,*image);
2033 if (*option == '+')
2034 {
2035 /*
2036 Remove a mask.
2037 */
cristy018f07f2011-09-04 21:15:19 +00002038 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002039 break;
2040 }
2041 /*
2042 Set the image mask.
2043 */
2044 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2045 if (mask == (Image *) NULL)
2046 break;
cristy018f07f2011-09-04 21:15:19 +00002047 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002048 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002049 break;
2050 }
2051 if (LocaleCompare("matte",option+1) == 0)
2052 {
2053 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002054 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002055 break;
2056 }
2057 if (LocaleCompare("median",option+1) == 0)
2058 {
2059 /*
2060 Median filter 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,MedianStatistic,(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("mode",option+1) == 0)
2071 {
2072 /*
2073 Mode image.
2074 */
2075 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002076 flags=ParseGeometry(argv[i+1],&geometry_info);
2077 if ((flags & SigmaValue) == 0)
2078 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002079 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002080 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002081 break;
2082 }
2083 if (LocaleCompare("modulate",option+1) == 0)
2084 {
2085 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002086 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002087 break;
2088 }
2089 if (LocaleCompare("monitor",option+1) == 0)
2090 {
2091 if (*option == '+')
2092 {
2093 (void) SetImageProgressMonitor(*image,
2094 (MagickProgressMonitor) NULL,(void *) NULL);
2095 break;
2096 }
2097 (void) SetImageProgressMonitor(*image,MonitorProgress,
2098 (void *) NULL);
2099 break;
2100 }
2101 if (LocaleCompare("monochrome",option+1) == 0)
2102 {
2103 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002104 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002105 break;
2106 }
2107 if (LocaleCompare("morphology",option+1) == 0)
2108 {
2109 char
2110 token[MaxTextExtent];
2111
2112 const char
2113 *p;
2114
2115 KernelInfo
2116 *kernel;
2117
2118 MorphologyMethod
2119 method;
2120
2121 ssize_t
2122 iterations;
2123
2124 /*
2125 Morphological Image Operation
2126 */
2127 (void) SyncImageSettings(mogrify_info,*image);
2128 p=argv[i+1];
2129 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002130 method=(MorphologyMethod) ParseCommandOption(
2131 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002132 iterations=1L;
2133 GetMagickToken(p,&p,token);
2134 if ((*p == ':') || (*p == ','))
2135 GetMagickToken(p,&p,token);
2136 if ((*p != '\0'))
2137 iterations=(ssize_t) StringToLong(p);
2138 kernel=AcquireKernelInfo(argv[i+2]);
2139 if (kernel == (KernelInfo *) NULL)
2140 {
2141 (void) ThrowMagickException(exception,GetMagickModule(),
2142 OptionError,"UnabletoParseKernel","morphology");
2143 status=MagickFalse;
2144 break;
2145 }
cristyf4ad9df2011-07-08 16:49:03 +00002146 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2147 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002148 kernel=DestroyKernelInfo(kernel);
2149 break;
2150 }
2151 if (LocaleCompare("motion-blur",option+1) == 0)
2152 {
2153 /*
2154 Motion blur image.
2155 */
2156 (void) SyncImageSettings(mogrify_info,*image);
2157 flags=ParseGeometry(argv[i+1],&geometry_info);
2158 if ((flags & SigmaValue) == 0)
2159 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002160 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002161 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2162 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002163 break;
2164 }
2165 break;
2166 }
2167 case 'n':
2168 {
2169 if (LocaleCompare("negate",option+1) == 0)
2170 {
2171 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002172 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002173 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002174 break;
2175 }
2176 if (LocaleCompare("noise",option+1) == 0)
2177 {
2178 (void) SyncImageSettings(mogrify_info,*image);
2179 if (*option == '-')
2180 {
cristyf36cbcb2011-09-07 13:28:22 +00002181 flags=ParseGeometry(argv[i+1],&geometry_info);
2182 if ((flags & SigmaValue) == 0)
2183 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002184 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002185 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002186 }
2187 else
2188 {
2189 NoiseType
2190 noise;
2191
2192 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2193 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002194 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002195 }
2196 break;
2197 }
2198 if (LocaleCompare("normalize",option+1) == 0)
2199 {
2200 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002201 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002202 break;
2203 }
2204 break;
2205 }
2206 case 'o':
2207 {
2208 if (LocaleCompare("opaque",option+1) == 0)
2209 {
cristy4c08aed2011-07-01 19:47:50 +00002210 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002211 target;
2212
2213 (void) SyncImageSettings(mogrify_info,*image);
cristy269c9412011-10-13 23:41:15 +00002214 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002215 exception);
cristyd42d9952011-07-08 14:21:50 +00002216 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002217 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002218 break;
2219 }
2220 if (LocaleCompare("ordered-dither",option+1) == 0)
2221 {
2222 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002223 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002224 break;
2225 }
2226 break;
2227 }
2228 case 'p':
2229 {
2230 if (LocaleCompare("paint",option+1) == 0)
2231 {
anthonydf8ebac2011-04-27 09:03:19 +00002232 (void) SyncImageSettings(mogrify_info,*image);
2233 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002234 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2235 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002236 break;
2237 }
2238 if (LocaleCompare("pen",option+1) == 0)
2239 {
2240 if (*option == '+')
2241 {
cristy9950d572011-10-01 18:22:35 +00002242 (void) QueryColorCompliance("none",AllCompliance,
2243 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002244 break;
2245 }
cristy9950d572011-10-01 18:22:35 +00002246 (void) QueryColorCompliance(argv[i+1],AllCompliance,
2247 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002248 break;
2249 }
2250 if (LocaleCompare("pointsize",option+1) == 0)
2251 {
2252 if (*option == '+')
2253 (void) ParseGeometry("12",&geometry_info);
2254 else
2255 (void) ParseGeometry(argv[i+1],&geometry_info);
2256 draw_info->pointsize=geometry_info.rho;
2257 break;
2258 }
2259 if (LocaleCompare("polaroid",option+1) == 0)
2260 {
2261 double
2262 angle;
2263
2264 RandomInfo
2265 *random_info;
2266
2267 /*
2268 Simulate a Polaroid picture.
2269 */
2270 (void) SyncImageSettings(mogrify_info,*image);
2271 random_info=AcquireRandomInfo();
2272 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2273 random_info=DestroyRandomInfo(random_info);
2274 if (*option == '-')
2275 {
2276 SetGeometryInfo(&geometry_info);
2277 flags=ParseGeometry(argv[i+1],&geometry_info);
2278 angle=geometry_info.rho;
2279 }
cristy5c4e2582011-09-11 19:21:03 +00002280 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002281 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002282 break;
2283 }
2284 if (LocaleCompare("posterize",option+1) == 0)
2285 {
2286 /*
2287 Posterize image.
2288 */
2289 (void) SyncImageSettings(mogrify_info,*image);
2290 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002291 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002292 break;
2293 }
2294 if (LocaleCompare("preview",option+1) == 0)
2295 {
2296 PreviewType
2297 preview_type;
2298
2299 /*
2300 Preview image.
2301 */
2302 (void) SyncImageSettings(mogrify_info,*image);
2303 if (*option == '+')
2304 preview_type=UndefinedPreview;
2305 else
cristy28474bf2011-09-11 23:32:52 +00002306 preview_type=(PreviewType) ParseCommandOption(
2307 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002308 mogrify_image=PreviewImage(*image,preview_type,exception);
2309 break;
2310 }
2311 if (LocaleCompare("profile",option+1) == 0)
2312 {
2313 const char
2314 *name;
2315
2316 const StringInfo
2317 *profile;
2318
2319 Image
2320 *profile_image;
2321
2322 ImageInfo
2323 *profile_info;
2324
2325 (void) SyncImageSettings(mogrify_info,*image);
2326 if (*option == '+')
2327 {
2328 /*
2329 Remove a profile from the image.
2330 */
2331 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002332 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002333 break;
2334 }
2335 /*
2336 Associate a profile with the image.
2337 */
2338 profile_info=CloneImageInfo(mogrify_info);
2339 profile=GetImageProfile(*image,"iptc");
2340 if (profile != (StringInfo *) NULL)
2341 profile_info->profile=(void *) CloneStringInfo(profile);
2342 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2343 profile_info=DestroyImageInfo(profile_info);
2344 if (profile_image == (Image *) NULL)
2345 {
2346 StringInfo
2347 *profile;
2348
2349 profile_info=CloneImageInfo(mogrify_info);
2350 (void) CopyMagickString(profile_info->filename,argv[i+1],
2351 MaxTextExtent);
2352 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2353 if (profile != (StringInfo *) NULL)
2354 {
2355 (void) ProfileImage(*image,profile_info->magick,
2356 GetStringInfoDatum(profile),(size_t)
2357 GetStringInfoLength(profile),MagickFalse);
2358 profile=DestroyStringInfo(profile);
2359 }
2360 profile_info=DestroyImageInfo(profile_info);
2361 break;
2362 }
2363 ResetImageProfileIterator(profile_image);
2364 name=GetNextImageProfile(profile_image);
2365 while (name != (const char *) NULL)
2366 {
2367 profile=GetImageProfile(profile_image,name);
2368 if (profile != (StringInfo *) NULL)
2369 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2370 (size_t) GetStringInfoLength(profile),MagickFalse);
2371 name=GetNextImageProfile(profile_image);
2372 }
2373 profile_image=DestroyImage(profile_image);
2374 break;
2375 }
2376 break;
2377 }
2378 case 'q':
2379 {
2380 if (LocaleCompare("quantize",option+1) == 0)
2381 {
2382 if (*option == '+')
2383 {
2384 quantize_info->colorspace=UndefinedColorspace;
2385 break;
2386 }
2387 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2388 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2389 break;
2390 }
2391 break;
2392 }
2393 case 'r':
2394 {
2395 if (LocaleCompare("radial-blur",option+1) == 0)
2396 {
2397 /*
2398 Radial blur image.
2399 */
2400 (void) SyncImageSettings(mogrify_info,*image);
cristy6435bd92011-09-10 02:10:07 +00002401 flags=ParseGeometry(argv[i+1],&geometry_info);
2402 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2403 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002404 break;
2405 }
2406 if (LocaleCompare("raise",option+1) == 0)
2407 {
2408 /*
2409 Surround image with a raise of solid color.
2410 */
2411 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2412 if ((flags & SigmaValue) == 0)
2413 geometry.height=geometry.width;
2414 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002415 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002416 break;
2417 }
2418 if (LocaleCompare("random-threshold",option+1) == 0)
2419 {
2420 /*
2421 Threshold image.
2422 */
2423 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002424 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002425 break;
2426 }
2427 if (LocaleCompare("recolor",option+1) == 0)
2428 {
2429 KernelInfo
2430 *kernel;
2431
2432 (void) SyncImageSettings(mogrify_info,*image);
2433 kernel=AcquireKernelInfo(argv[i+1]);
2434 if (kernel == (KernelInfo *) NULL)
2435 break;
2436 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2437 kernel=DestroyKernelInfo(kernel);
2438 break;
2439 }
2440 if (LocaleCompare("region",option+1) == 0)
2441 {
2442 (void) SyncImageSettings(mogrify_info,*image);
2443 if (region_image != (Image *) NULL)
2444 {
2445 /*
2446 Composite region.
2447 */
2448 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002449 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002450 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002451 *image=DestroyImage(*image);
2452 *image=region_image;
2453 region_image = (Image *) NULL;
2454 }
2455 if (*option == '+')
2456 break;
2457 /*
2458 Apply transformations to a selected region of the image.
2459 */
cristy3ed852e2009-09-05 21:47:34 +00002460 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2461 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002462 mogrify_image=CropImage(*image,&region_geometry,exception);
2463 if (mogrify_image == (Image *) NULL)
2464 break;
2465 region_image=(*image);
2466 *image=mogrify_image;
2467 mogrify_image=(Image *) NULL;
2468 break;
cristy3ed852e2009-09-05 21:47:34 +00002469 }
anthonydf8ebac2011-04-27 09:03:19 +00002470 if (LocaleCompare("render",option+1) == 0)
2471 {
2472 (void) SyncImageSettings(mogrify_info,*image);
2473 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2474 break;
2475 }
2476 if (LocaleCompare("remap",option+1) == 0)
2477 {
2478 Image
2479 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002480
anthonydf8ebac2011-04-27 09:03:19 +00002481 /*
2482 Transform image colors to match this set of colors.
2483 */
2484 (void) SyncImageSettings(mogrify_info,*image);
2485 if (*option == '+')
2486 break;
2487 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2488 if (remap_image == (Image *) NULL)
2489 break;
cristy018f07f2011-09-04 21:15:19 +00002490 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002491 remap_image=DestroyImage(remap_image);
2492 break;
2493 }
2494 if (LocaleCompare("repage",option+1) == 0)
2495 {
2496 if (*option == '+')
2497 {
2498 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2499 break;
2500 }
2501 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002502 break;
2503 }
2504 if (LocaleCompare("resample",option+1) == 0)
2505 {
2506 /*
2507 Resample image.
2508 */
2509 (void) SyncImageSettings(mogrify_info,*image);
2510 flags=ParseGeometry(argv[i+1],&geometry_info);
2511 if ((flags & SigmaValue) == 0)
2512 geometry_info.sigma=geometry_info.rho;
2513 mogrify_image=ResampleImage(*image,geometry_info.rho,
2514 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2515 break;
2516 }
2517 if (LocaleCompare("resize",option+1) == 0)
2518 {
2519 /*
2520 Resize image.
2521 */
2522 (void) SyncImageSettings(mogrify_info,*image);
2523 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2524 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2525 (*image)->filter,(*image)->blur,exception);
2526 break;
2527 }
2528 if (LocaleCompare("roll",option+1) == 0)
2529 {
2530 /*
2531 Roll image.
2532 */
2533 (void) SyncImageSettings(mogrify_info,*image);
2534 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2535 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2536 break;
2537 }
2538 if (LocaleCompare("rotate",option+1) == 0)
2539 {
2540 char
2541 *geometry;
2542
2543 /*
2544 Check for conditional image rotation.
2545 */
2546 (void) SyncImageSettings(mogrify_info,*image);
2547 if (strchr(argv[i+1],'>') != (char *) NULL)
2548 if ((*image)->columns <= (*image)->rows)
2549 break;
2550 if (strchr(argv[i+1],'<') != (char *) NULL)
2551 if ((*image)->columns >= (*image)->rows)
2552 break;
2553 /*
2554 Rotate image.
2555 */
2556 geometry=ConstantString(argv[i+1]);
2557 (void) SubstituteString(&geometry,">","");
2558 (void) SubstituteString(&geometry,"<","");
2559 (void) ParseGeometry(geometry,&geometry_info);
2560 geometry=DestroyString(geometry);
2561 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2562 break;
2563 }
2564 break;
2565 }
2566 case 's':
2567 {
2568 if (LocaleCompare("sample",option+1) == 0)
2569 {
2570 /*
2571 Sample image with pixel replication.
2572 */
2573 (void) SyncImageSettings(mogrify_info,*image);
2574 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2575 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2576 exception);
2577 break;
2578 }
2579 if (LocaleCompare("scale",option+1) == 0)
2580 {
2581 /*
2582 Resize image.
2583 */
2584 (void) SyncImageSettings(mogrify_info,*image);
2585 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2586 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2587 exception);
2588 break;
2589 }
2590 if (LocaleCompare("selective-blur",option+1) == 0)
2591 {
2592 /*
2593 Selectively blur pixels within a contrast threshold.
2594 */
2595 (void) SyncImageSettings(mogrify_info,*image);
2596 flags=ParseGeometry(argv[i+1],&geometry_info);
2597 if ((flags & PercentValue) != 0)
2598 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002599 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002600 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002601 break;
2602 }
2603 if (LocaleCompare("separate",option+1) == 0)
2604 {
2605 /*
2606 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002607 */
2608 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002609 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002610 break;
2611 }
2612 if (LocaleCompare("sepia-tone",option+1) == 0)
2613 {
2614 double
2615 threshold;
2616
2617 /*
2618 Sepia-tone image.
2619 */
2620 (void) SyncImageSettings(mogrify_info,*image);
2621 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2622 mogrify_image=SepiaToneImage(*image,threshold,exception);
2623 break;
2624 }
2625 if (LocaleCompare("segment",option+1) == 0)
2626 {
2627 /*
2628 Segment image.
2629 */
2630 (void) SyncImageSettings(mogrify_info,*image);
2631 flags=ParseGeometry(argv[i+1],&geometry_info);
2632 if ((flags & SigmaValue) == 0)
2633 geometry_info.sigma=1.0;
2634 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002635 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2636 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002637 break;
2638 }
2639 if (LocaleCompare("set",option+1) == 0)
2640 {
2641 char
2642 *value;
2643
2644 /*
2645 Set image option.
2646 */
2647 if (*option == '+')
2648 {
2649 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2650 (void) DeleteImageRegistry(argv[i+1]+9);
2651 else
2652 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2653 {
2654 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2655 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2656 }
2657 else
2658 (void) DeleteImageProperty(*image,argv[i+1]);
2659 break;
2660 }
cristy018f07f2011-09-04 21:15:19 +00002661 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2662 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002663 if (value == (char *) NULL)
2664 break;
2665 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2666 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2667 exception);
2668 else
2669 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2670 {
2671 (void) SetImageOption(image_info,argv[i+1]+7,value);
2672 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2673 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2674 }
2675 else
cristyd15e6592011-10-15 00:13:06 +00002676 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002677 value=DestroyString(value);
2678 break;
2679 }
2680 if (LocaleCompare("shade",option+1) == 0)
2681 {
2682 /*
2683 Shade 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 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2690 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2691 break;
2692 }
2693 if (LocaleCompare("shadow",option+1) == 0)
2694 {
2695 /*
2696 Shadow image.
2697 */
2698 (void) SyncImageSettings(mogrify_info,*image);
2699 flags=ParseGeometry(argv[i+1],&geometry_info);
2700 if ((flags & SigmaValue) == 0)
2701 geometry_info.sigma=1.0;
2702 if ((flags & XiValue) == 0)
2703 geometry_info.xi=4.0;
2704 if ((flags & PsiValue) == 0)
2705 geometry_info.psi=4.0;
2706 mogrify_image=ShadowImage(*image,geometry_info.rho,
2707 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2708 ceil(geometry_info.psi-0.5),exception);
2709 break;
2710 }
2711 if (LocaleCompare("sharpen",option+1) == 0)
2712 {
2713 /*
2714 Sharpen image.
2715 */
2716 (void) SyncImageSettings(mogrify_info,*image);
2717 flags=ParseGeometry(argv[i+1],&geometry_info);
2718 if ((flags & SigmaValue) == 0)
2719 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002720 if ((flags & XiValue) == 0)
2721 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002722 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002723 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002724 break;
2725 }
2726 if (LocaleCompare("shave",option+1) == 0)
2727 {
2728 /*
2729 Shave the image edges.
2730 */
2731 (void) SyncImageSettings(mogrify_info,*image);
2732 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2733 mogrify_image=ShaveImage(*image,&geometry,exception);
2734 break;
2735 }
2736 if (LocaleCompare("shear",option+1) == 0)
2737 {
2738 /*
2739 Shear image.
2740 */
2741 (void) SyncImageSettings(mogrify_info,*image);
2742 flags=ParseGeometry(argv[i+1],&geometry_info);
2743 if ((flags & SigmaValue) == 0)
2744 geometry_info.sigma=geometry_info.rho;
2745 mogrify_image=ShearImage(*image,geometry_info.rho,
2746 geometry_info.sigma,exception);
2747 break;
2748 }
2749 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2750 {
2751 /*
2752 Sigmoidal non-linearity contrast control.
2753 */
2754 (void) SyncImageSettings(mogrify_info,*image);
2755 flags=ParseGeometry(argv[i+1],&geometry_info);
2756 if ((flags & SigmaValue) == 0)
2757 geometry_info.sigma=(double) QuantumRange/2.0;
2758 if ((flags & PercentValue) != 0)
2759 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2760 100.0;
cristy9ee60942011-07-06 14:54:38 +00002761 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002762 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2763 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002764 break;
2765 }
2766 if (LocaleCompare("sketch",option+1) == 0)
2767 {
2768 /*
2769 Sketch image.
2770 */
2771 (void) SyncImageSettings(mogrify_info,*image);
2772 flags=ParseGeometry(argv[i+1],&geometry_info);
2773 if ((flags & SigmaValue) == 0)
2774 geometry_info.sigma=1.0;
2775 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002776 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002777 break;
2778 }
2779 if (LocaleCompare("solarize",option+1) == 0)
2780 {
2781 double
2782 threshold;
2783
2784 (void) SyncImageSettings(mogrify_info,*image);
2785 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002786 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002787 break;
2788 }
2789 if (LocaleCompare("sparse-color",option+1) == 0)
2790 {
2791 SparseColorMethod
2792 method;
2793
2794 char
2795 *arguments;
2796
2797 /*
2798 Sparse Color Interpolated Gradient
2799 */
2800 (void) SyncImageSettings(mogrify_info,*image);
2801 method=(SparseColorMethod) ParseCommandOption(
2802 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002803 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2804 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002805 if (arguments == (char *) NULL)
2806 break;
cristy3884f692011-07-08 18:00:18 +00002807 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002808 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2809 arguments=DestroyString(arguments);
2810 break;
2811 }
2812 if (LocaleCompare("splice",option+1) == 0)
2813 {
2814 /*
2815 Splice a solid color into the image.
2816 */
2817 (void) SyncImageSettings(mogrify_info,*image);
2818 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2819 mogrify_image=SpliceImage(*image,&geometry,exception);
2820 break;
2821 }
2822 if (LocaleCompare("spread",option+1) == 0)
2823 {
2824 /*
2825 Spread an image.
2826 */
2827 (void) SyncImageSettings(mogrify_info,*image);
2828 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002829 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002830 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002831 break;
2832 }
2833 if (LocaleCompare("statistic",option+1) == 0)
2834 {
2835 StatisticType
2836 type;
2837
2838 (void) SyncImageSettings(mogrify_info,*image);
2839 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2840 MagickFalse,argv[i+1]);
2841 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002842 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2843 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002844 break;
2845 }
2846 if (LocaleCompare("stretch",option+1) == 0)
2847 {
2848 if (*option == '+')
2849 {
2850 draw_info->stretch=UndefinedStretch;
2851 break;
2852 }
2853 draw_info->stretch=(StretchType) ParseCommandOption(
2854 MagickStretchOptions,MagickFalse,argv[i+1]);
2855 break;
2856 }
2857 if (LocaleCompare("strip",option+1) == 0)
2858 {
2859 /*
2860 Strip image of profiles and comments.
2861 */
2862 (void) SyncImageSettings(mogrify_info,*image);
cristye941a752011-10-15 01:52:48 +00002863 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002864 break;
2865 }
2866 if (LocaleCompare("stroke",option+1) == 0)
2867 {
2868 ExceptionInfo
2869 *sans;
2870
2871 if (*option == '+')
2872 {
cristy9950d572011-10-01 18:22:35 +00002873 (void) QueryColorCompliance("none",AllCompliance,
2874 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002875 if (draw_info->stroke_pattern != (Image *) NULL)
2876 draw_info->stroke_pattern=DestroyImage(
2877 draw_info->stroke_pattern);
2878 break;
2879 }
2880 sans=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00002881 status=QueryColorCompliance(argv[i+1],AllCompliance,
2882 &draw_info->stroke,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002883 sans=DestroyExceptionInfo(sans);
2884 if (status == MagickFalse)
2885 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2886 exception);
2887 break;
2888 }
2889 if (LocaleCompare("strokewidth",option+1) == 0)
2890 {
cristyc1acd842011-05-19 23:05:47 +00002891 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2892 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002893 break;
2894 }
2895 if (LocaleCompare("style",option+1) == 0)
2896 {
2897 if (*option == '+')
2898 {
2899 draw_info->style=UndefinedStyle;
2900 break;
2901 }
2902 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2903 MagickFalse,argv[i+1]);
2904 break;
2905 }
2906 if (LocaleCompare("swirl",option+1) == 0)
2907 {
2908 /*
2909 Swirl image.
2910 */
2911 (void) SyncImageSettings(mogrify_info,*image);
2912 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002913 mogrify_image=SwirlImage(*image,geometry_info.rho,
2914 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002915 break;
2916 }
2917 break;
2918 }
2919 case 't':
2920 {
2921 if (LocaleCompare("threshold",option+1) == 0)
2922 {
2923 double
2924 threshold;
2925
2926 /*
2927 Threshold image.
2928 */
2929 (void) SyncImageSettings(mogrify_info,*image);
2930 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002931 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002932 else
2933 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristye941a752011-10-15 01:52:48 +00002934 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002935 break;
2936 }
2937 if (LocaleCompare("thumbnail",option+1) == 0)
2938 {
2939 /*
2940 Thumbnail image.
2941 */
2942 (void) SyncImageSettings(mogrify_info,*image);
2943 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2944 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2945 exception);
2946 break;
2947 }
2948 if (LocaleCompare("tile",option+1) == 0)
2949 {
2950 if (*option == '+')
2951 {
2952 if (draw_info->fill_pattern != (Image *) NULL)
2953 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2954 break;
2955 }
2956 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2957 exception);
2958 break;
2959 }
2960 if (LocaleCompare("tint",option+1) == 0)
2961 {
2962 /*
2963 Tint the image.
2964 */
2965 (void) SyncImageSettings(mogrify_info,*image);
cristy28474bf2011-09-11 23:32:52 +00002966 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002967 break;
2968 }
2969 if (LocaleCompare("transform",option+1) == 0)
2970 {
2971 /*
2972 Affine transform image.
2973 */
2974 (void) SyncImageSettings(mogrify_info,*image);
2975 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2976 exception);
2977 break;
2978 }
2979 if (LocaleCompare("transparent",option+1) == 0)
2980 {
cristy4c08aed2011-07-01 19:47:50 +00002981 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002982 target;
2983
2984 (void) SyncImageSettings(mogrify_info,*image);
cristy269c9412011-10-13 23:41:15 +00002985 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002986 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002987 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002988 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00002989 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002990 break;
2991 }
2992 if (LocaleCompare("transpose",option+1) == 0)
2993 {
2994 /*
2995 Transpose image scanlines.
2996 */
2997 (void) SyncImageSettings(mogrify_info,*image);
2998 mogrify_image=TransposeImage(*image,exception);
2999 break;
3000 }
3001 if (LocaleCompare("transverse",option+1) == 0)
3002 {
3003 /*
3004 Transverse image scanlines.
3005 */
3006 (void) SyncImageSettings(mogrify_info,*image);
3007 mogrify_image=TransverseImage(*image,exception);
3008 break;
3009 }
3010 if (LocaleCompare("treedepth",option+1) == 0)
3011 {
3012 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3013 break;
3014 }
3015 if (LocaleCompare("trim",option+1) == 0)
3016 {
3017 /*
3018 Trim image.
3019 */
3020 (void) SyncImageSettings(mogrify_info,*image);
3021 mogrify_image=TrimImage(*image,exception);
3022 break;
3023 }
3024 if (LocaleCompare("type",option+1) == 0)
3025 {
3026 ImageType
3027 type;
3028
3029 (void) SyncImageSettings(mogrify_info,*image);
3030 if (*option == '+')
3031 type=UndefinedType;
3032 else
3033 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3034 argv[i+1]);
3035 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003036 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003037 break;
3038 }
3039 break;
3040 }
3041 case 'u':
3042 {
3043 if (LocaleCompare("undercolor",option+1) == 0)
3044 {
cristy9950d572011-10-01 18:22:35 +00003045 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3046 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003047 break;
3048 }
3049 if (LocaleCompare("unique",option+1) == 0)
3050 {
3051 if (*option == '+')
3052 {
3053 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3054 break;
3055 }
3056 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3057 (void) SetImageArtifact(*image,"verbose","true");
3058 break;
3059 }
3060 if (LocaleCompare("unique-colors",option+1) == 0)
3061 {
3062 /*
3063 Unique image colors.
3064 */
3065 (void) SyncImageSettings(mogrify_info,*image);
3066 mogrify_image=UniqueImageColors(*image,exception);
3067 break;
3068 }
3069 if (LocaleCompare("unsharp",option+1) == 0)
3070 {
3071 /*
3072 Unsharp mask image.
3073 */
3074 (void) SyncImageSettings(mogrify_info,*image);
3075 flags=ParseGeometry(argv[i+1],&geometry_info);
3076 if ((flags & SigmaValue) == 0)
3077 geometry_info.sigma=1.0;
3078 if ((flags & XiValue) == 0)
3079 geometry_info.xi=1.0;
3080 if ((flags & PsiValue) == 0)
3081 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003082 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3083 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003084 break;
3085 }
3086 break;
3087 }
3088 case 'v':
3089 {
3090 if (LocaleCompare("verbose",option+1) == 0)
3091 {
3092 (void) SetImageArtifact(*image,option+1,
3093 *option == '+' ? "false" : "true");
3094 break;
3095 }
3096 if (LocaleCompare("vignette",option+1) == 0)
3097 {
3098 /*
3099 Vignette image.
3100 */
3101 (void) SyncImageSettings(mogrify_info,*image);
3102 flags=ParseGeometry(argv[i+1],&geometry_info);
3103 if ((flags & SigmaValue) == 0)
3104 geometry_info.sigma=1.0;
3105 if ((flags & XiValue) == 0)
3106 geometry_info.xi=0.1*(*image)->columns;
3107 if ((flags & PsiValue) == 0)
3108 geometry_info.psi=0.1*(*image)->rows;
3109 mogrify_image=VignetteImage(*image,geometry_info.rho,
3110 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3111 ceil(geometry_info.psi-0.5),exception);
3112 break;
3113 }
3114 if (LocaleCompare("virtual-pixel",option+1) == 0)
3115 {
3116 if (*option == '+')
3117 {
3118 (void) SetImageVirtualPixelMethod(*image,
3119 UndefinedVirtualPixelMethod);
3120 break;
3121 }
3122 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3123 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3124 argv[i+1]));
3125 break;
3126 }
3127 break;
3128 }
3129 case 'w':
3130 {
3131 if (LocaleCompare("wave",option+1) == 0)
3132 {
3133 /*
3134 Wave image.
3135 */
3136 (void) SyncImageSettings(mogrify_info,*image);
3137 flags=ParseGeometry(argv[i+1],&geometry_info);
3138 if ((flags & SigmaValue) == 0)
3139 geometry_info.sigma=1.0;
3140 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003141 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003142 break;
3143 }
3144 if (LocaleCompare("weight",option+1) == 0)
3145 {
3146 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3147 if (LocaleCompare(argv[i+1],"all") == 0)
3148 draw_info->weight=0;
3149 if (LocaleCompare(argv[i+1],"bold") == 0)
3150 draw_info->weight=700;
3151 if (LocaleCompare(argv[i+1],"bolder") == 0)
3152 if (draw_info->weight <= 800)
3153 draw_info->weight+=100;
3154 if (LocaleCompare(argv[i+1],"lighter") == 0)
3155 if (draw_info->weight >= 100)
3156 draw_info->weight-=100;
3157 if (LocaleCompare(argv[i+1],"normal") == 0)
3158 draw_info->weight=400;
3159 break;
3160 }
3161 if (LocaleCompare("white-threshold",option+1) == 0)
3162 {
3163 /*
3164 White threshold image.
3165 */
3166 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003167 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003168 break;
3169 }
3170 break;
3171 }
3172 default:
3173 break;
3174 }
3175 /*
3176 Replace current image with any image that was generated
3177 */
3178 if (mogrify_image != (Image *) NULL)
3179 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003180 i+=count;
3181 }
3182 if (region_image != (Image *) NULL)
3183 {
anthonydf8ebac2011-04-27 09:03:19 +00003184 /*
3185 Composite transformed region onto image.
3186 */
cristy6b3da3a2010-06-20 02:21:46 +00003187 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003188 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003189 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003190 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003191 *image=DestroyImage(*image);
3192 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003193 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003194 }
3195 /*
3196 Free resources.
3197 */
anthonydf8ebac2011-04-27 09:03:19 +00003198 quantize_info=DestroyQuantizeInfo(quantize_info);
3199 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003200 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003201 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003202 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003203}
3204
3205/*
3206%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3207% %
3208% %
3209% %
cristy5063d812010-10-19 16:28:10 +00003210+ 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 +00003211% %
3212% %
3213% %
3214%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3215%
3216% MogrifyImageCommand() transforms an image or a sequence of images. These
3217% transforms include image scaling, image rotation, color reduction, and
3218% others. The transmogrified image overwrites the original image.
3219%
3220% The format of the MogrifyImageCommand method is:
3221%
3222% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3223% const char **argv,char **metadata,ExceptionInfo *exception)
3224%
3225% A description of each parameter follows:
3226%
3227% o image_info: the image info.
3228%
3229% o argc: the number of elements in the argument vector.
3230%
3231% o argv: A text array containing the command line arguments.
3232%
3233% o metadata: any metadata is returned here.
3234%
3235% o exception: return any errors or warnings in this structure.
3236%
3237*/
3238
3239static MagickBooleanType MogrifyUsage(void)
3240{
3241 static const char
3242 *miscellaneous[]=
3243 {
3244 "-debug events display copious debugging information",
3245 "-help print program options",
3246 "-list type print a list of supported option arguments",
3247 "-log format format of debugging information",
3248 "-version print version information",
3249 (char *) NULL
3250 },
3251 *operators[]=
3252 {
3253 "-adaptive-blur geometry",
3254 " adaptively blur pixels; decrease effect near edges",
3255 "-adaptive-resize geometry",
3256 " adaptively resize image using 'mesh' interpolation",
3257 "-adaptive-sharpen geometry",
3258 " adaptively sharpen pixels; increase effect near edges",
3259 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3260 " transparent, extract, background, or shape",
3261 "-annotate geometry text",
3262 " annotate the image with text",
3263 "-auto-gamma automagically adjust gamma level of image",
3264 "-auto-level automagically adjust color levels of image",
3265 "-auto-orient automagically orient (rotate) image",
3266 "-bench iterations measure performance",
3267 "-black-threshold value",
3268 " force all pixels below the threshold into black",
3269 "-blue-shift simulate a scene at nighttime in the moonlight",
3270 "-blur geometry reduce image noise and reduce detail levels",
3271 "-border geometry surround image with a border of color",
3272 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003273 "-brightness-contrast geometry",
3274 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003275 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003276 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003277 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003278 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003279 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003281 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003282 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003283 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003284 "-contrast enhance or reduce the image contrast",
3285 "-contrast-stretch geometry",
3286 " improve contrast by `stretching' the intensity range",
3287 "-convolve coefficients",
3288 " apply a convolution kernel to the image",
3289 "-cycle amount cycle the image colormap",
3290 "-decipher filename convert cipher pixels to plain pixels",
3291 "-deskew threshold straighten an image",
3292 "-despeckle reduce the speckles within an image",
3293 "-distort method args",
3294 " distort images according to given method ad args",
3295 "-draw string annotate the image with a graphic primitive",
3296 "-edge radius apply a filter to detect edges in the image",
3297 "-encipher filename convert plain pixels to cipher pixels",
3298 "-emboss radius emboss an image",
3299 "-enhance apply a digital filter to enhance a noisy image",
3300 "-equalize perform histogram equalization to an image",
3301 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003302 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003303 "-extent geometry set the image size",
3304 "-extract geometry extract area from image",
3305 "-fft implements the discrete Fourier transform (DFT)",
3306 "-flip flip image vertically",
3307 "-floodfill geometry color",
3308 " floodfill the image with color",
3309 "-flop flop image horizontally",
3310 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003311 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003312 " apply function over image values",
3313 "-gamma value level of gamma correction",
3314 "-gaussian-blur geometry",
3315 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003316 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003317 "-identify identify the format and characteristics of the image",
3318 "-ift implements the inverse discrete Fourier transform (DFT)",
3319 "-implode amount implode image pixels about the center",
3320 "-lat geometry local adaptive thresholding",
3321 "-layers method optimize, merge, or compare image layers",
3322 "-level value adjust the level of image contrast",
3323 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003324 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003325 "-linear-stretch geometry",
3326 " improve contrast by `stretching with saturation'",
3327 "-liquid-rescale geometry",
3328 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003329 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003330 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003331 "-modulate value vary the brightness, saturation, and hue",
3332 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003333 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003334 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003335 "-motion-blur geometry",
3336 " simulate motion blur",
3337 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003338 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003339 "-normalize transform image to span the full range of colors",
3340 "-opaque color change this color to the fill color",
3341 "-ordered-dither NxN",
3342 " add a noise pattern to the image with specific",
3343 " amplitudes",
3344 "-paint radius simulate an oil painting",
3345 "-polaroid angle simulate a Polaroid picture",
3346 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003347 "-profile filename add, delete, or apply an image profile",
3348 "-quantize colorspace reduce colors in this colorspace",
3349 "-radial-blur angle radial blur the image",
3350 "-raise value lighten/darken image edges to create a 3-D effect",
3351 "-random-threshold low,high",
3352 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003353 "-region geometry apply options to a portion of the image",
3354 "-render render vector graphics",
3355 "-repage geometry size and location of an image canvas",
3356 "-resample geometry change the resolution of an image",
3357 "-resize geometry resize the image",
3358 "-roll geometry roll an image vertically or horizontally",
3359 "-rotate degrees apply Paeth rotation to the image",
3360 "-sample geometry scale image with pixel sampling",
3361 "-scale geometry scale the image",
3362 "-segment values segment an image",
3363 "-selective-blur geometry",
3364 " selectively blur pixels within a contrast threshold",
3365 "-sepia-tone threshold",
3366 " simulate a sepia-toned photo",
3367 "-set property value set an image property",
3368 "-shade degrees shade the image using a distant light source",
3369 "-shadow geometry simulate an image shadow",
3370 "-sharpen geometry sharpen the image",
3371 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003372 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003373 "-sigmoidal-contrast geometry",
3374 " increase the contrast without saturating highlights or shadows",
3375 "-sketch geometry simulate a pencil sketch",
3376 "-solarize threshold negate all pixels above the threshold level",
3377 "-sparse-color method args",
3378 " fill in a image based on a few color points",
3379 "-splice geometry splice the background color into the image",
3380 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003381 "-statistic type radius",
3382 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003383 "-strip strip image of all profiles and comments",
3384 "-swirl degrees swirl image pixels about the center",
3385 "-threshold value threshold the image",
3386 "-thumbnail geometry create a thumbnail of the image",
3387 "-tile filename tile image when filling a graphic primitive",
3388 "-tint value tint the image with the fill color",
3389 "-transform affine transform image",
3390 "-transparent color make this color transparent within the image",
3391 "-transpose flip image vertically and rotate 90 degrees",
3392 "-transverse flop image horizontally and rotate 270 degrees",
3393 "-trim trim image edges",
3394 "-type type image type",
3395 "-unique-colors discard all but one of any pixel color",
3396 "-unsharp geometry sharpen the image",
3397 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003398 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003399 "-white-threshold value",
3400 " force all pixels above the threshold into white",
3401 (char *) NULL
3402 },
3403 *sequence_operators[]=
3404 {
cristy4285d782011-02-09 20:12:28 +00003405 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003406 "-clut apply a color lookup table to the image",
3407 "-coalesce merge a sequence of images",
3408 "-combine combine a sequence of images",
3409 "-composite composite image",
3410 "-crop geometry cut out a rectangular region of the image",
3411 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003412 "-evaluate-sequence operator",
3413 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003414 "-flatten flatten a sequence of images",
3415 "-fx expression apply mathematical expression to an image channel(s)",
3416 "-hald-clut apply a Hald color lookup table to the image",
3417 "-morph value morph an image sequence",
3418 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003419 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003420 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003421 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003422 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003423 "-write filename write images to this file",
3424 (char *) NULL
3425 },
3426 *settings[]=
3427 {
3428 "-adjoin join images into a single multi-image file",
3429 "-affine matrix affine transform matrix",
3430 "-alpha option activate, deactivate, reset, or set the alpha channel",
3431 "-antialias remove pixel-aliasing",
3432 "-authenticate password",
3433 " decipher image with this password",
3434 "-attenuate value lessen (or intensify) when adding noise to an image",
3435 "-background color background color",
3436 "-bias value add bias when convolving an image",
3437 "-black-point-compensation",
3438 " use black point compensation",
3439 "-blue-primary point chromaticity blue primary point",
3440 "-bordercolor color border color",
3441 "-caption string assign a caption to an image",
3442 "-channel type apply option to select image channels",
3443 "-colors value preferred number of colors in the image",
3444 "-colorspace type alternate image colorspace",
3445 "-comment string annotate image with comment",
3446 "-compose operator set image composite operator",
3447 "-compress type type of pixel compression when writing the image",
3448 "-define format:option",
3449 " define one or more image format options",
3450 "-delay value display the next image after pausing",
3451 "-density geometry horizontal and vertical density of the image",
3452 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003453 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003454 "-display server get image or font from this X server",
3455 "-dispose method layer disposal method",
3456 "-dither method apply error diffusion to image",
3457 "-encoding type text encoding type",
3458 "-endian type endianness (MSB or LSB) of the image",
3459 "-family name render text with this font family",
3460 "-fill color color to use when filling a graphic primitive",
3461 "-filter type use this filter when resizing an image",
3462 "-font name render text with this font",
3463 "-format \"string\" output formatted image characteristics",
3464 "-fuzz distance colors within this distance are considered equal",
3465 "-gravity type horizontal and vertical text placement",
3466 "-green-primary point chromaticity green primary point",
3467 "-intent type type of rendering intent when managing the image color",
3468 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003469 "-interline-spacing value",
3470 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003471 "-interpolate method pixel color interpolation method",
3472 "-interword-spacing value",
3473 " set the space between two words",
3474 "-kerning value set the space between two letters",
3475 "-label string assign a label to an image",
3476 "-limit type value pixel cache resource limit",
3477 "-loop iterations add Netscape loop extension to your GIF animation",
3478 "-mask filename associate a mask with the image",
3479 "-mattecolor color frame color",
3480 "-monitor monitor progress",
3481 "-orient type image orientation",
3482 "-page geometry size and location of an image canvas (setting)",
3483 "-ping efficiently determine image attributes",
3484 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003485 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003486 "-preview type image preview type",
3487 "-quality value JPEG/MIFF/PNG compression level",
3488 "-quiet suppress all warning messages",
3489 "-red-primary point chromaticity red primary point",
3490 "-regard-warnings pay attention to warning messages",
3491 "-remap filename transform image colors to match this set of colors",
3492 "-respect-parentheses settings remain in effect until parenthesis boundary",
3493 "-sampling-factor geometry",
3494 " horizontal and vertical sampling factor",
3495 "-scene value image scene number",
3496 "-seed value seed a new sequence of pseudo-random numbers",
3497 "-size geometry width and height of image",
3498 "-stretch type render text with this font stretch",
3499 "-stroke color graphic primitive stroke color",
3500 "-strokewidth value graphic primitive stroke width",
3501 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003502 "-synchronize synchronize image to storage device",
3503 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003504 "-texture filename name of texture to tile onto the image background",
3505 "-tile-offset geometry",
3506 " tile offset",
3507 "-treedepth value color tree depth",
3508 "-transparent-color color",
3509 " transparent color",
3510 "-undercolor color annotation bounding box color",
3511 "-units type the units of image resolution",
3512 "-verbose print detailed information about the image",
3513 "-view FlashPix viewing transforms",
3514 "-virtual-pixel method",
3515 " virtual pixel access method",
3516 "-weight type render text with this font weight",
3517 "-white-point point chromaticity white point",
3518 (char *) NULL
3519 },
3520 *stack_operators[]=
3521 {
anthonyb69c4b32011-03-23 04:37:44 +00003522 "-delete indexes delete the image from the image sequence",
3523 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003524 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003525 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003526 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003527 "-swap indexes swap two images in the image sequence",
3528 (char *) NULL
3529 };
3530
3531 const char
3532 **p;
3533
cristybb503372010-05-27 20:51:26 +00003534 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003535 (void) printf("Copyright: %s\n",GetMagickCopyright());
3536 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003537 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3538 GetClientName());
3539 (void) printf("\nImage Settings:\n");
3540 for (p=settings; *p != (char *) NULL; p++)
3541 (void) printf(" %s\n",*p);
3542 (void) printf("\nImage Operators:\n");
3543 for (p=operators; *p != (char *) NULL; p++)
3544 (void) printf(" %s\n",*p);
3545 (void) printf("\nImage Sequence Operators:\n");
3546 for (p=sequence_operators; *p != (char *) NULL; p++)
3547 (void) printf(" %s\n",*p);
3548 (void) printf("\nImage Stack Operators:\n");
3549 for (p=stack_operators; *p != (char *) NULL; p++)
3550 (void) printf(" %s\n",*p);
3551 (void) printf("\nMiscellaneous Options:\n");
3552 for (p=miscellaneous; *p != (char *) NULL; p++)
3553 (void) printf(" %s\n",*p);
3554 (void) printf(
3555 "\nBy default, the image format of `file' is determined by its magic\n");
3556 (void) printf(
3557 "number. To specify a particular image format, precede the filename\n");
3558 (void) printf(
3559 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3560 (void) printf(
3561 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3562 (void) printf("'-' for standard input or output.\n");
3563 return(MagickFalse);
3564}
3565
3566WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3567 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3568{
3569#define DestroyMogrify() \
3570{ \
3571 if (format != (char *) NULL) \
3572 format=DestroyString(format); \
3573 if (path != (char *) NULL) \
3574 path=DestroyString(path); \
3575 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003576 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003577 argv[i]=DestroyString(argv[i]); \
3578 argv=(char **) RelinquishMagickMemory(argv); \
3579}
3580#define ThrowMogrifyException(asperity,tag,option) \
3581{ \
3582 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3583 option); \
3584 DestroyMogrify(); \
3585 return(MagickFalse); \
3586}
3587#define ThrowMogrifyInvalidArgumentException(option,argument) \
3588{ \
3589 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3590 "InvalidArgument","`%s': %s",argument,option); \
3591 DestroyMogrify(); \
3592 return(MagickFalse); \
3593}
3594
3595 char
3596 *format,
3597 *option,
3598 *path;
3599
3600 Image
3601 *image;
3602
3603 ImageStack
3604 image_stack[MaxImageStackDepth+1];
3605
cristy3ed852e2009-09-05 21:47:34 +00003606 MagickBooleanType
3607 global_colormap;
3608
3609 MagickBooleanType
3610 fire,
cristyebbcfea2011-02-25 02:43:54 +00003611 pend,
3612 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003613
3614 MagickStatusType
3615 status;
3616
cristyebbcfea2011-02-25 02:43:54 +00003617 register ssize_t
3618 i;
3619
3620 ssize_t
3621 j,
3622 k;
3623
cristy3ed852e2009-09-05 21:47:34 +00003624 /*
3625 Set defaults.
3626 */
3627 assert(image_info != (ImageInfo *) NULL);
3628 assert(image_info->signature == MagickSignature);
3629 if (image_info->debug != MagickFalse)
3630 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3631 assert(exception != (ExceptionInfo *) NULL);
3632 if (argc == 2)
3633 {
3634 option=argv[1];
3635 if ((LocaleCompare("version",option+1) == 0) ||
3636 (LocaleCompare("-version",option+1) == 0))
3637 {
cristyb51dff52011-05-19 16:55:47 +00003638 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003639 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003640 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3641 GetMagickCopyright());
3642 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3643 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003644 return(MagickFalse);
3645 }
3646 }
3647 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003648 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003649 format=(char *) NULL;
3650 path=(char *) NULL;
3651 global_colormap=MagickFalse;
3652 k=0;
3653 j=1;
3654 NewImageStack();
3655 option=(char *) NULL;
3656 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003657 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003658 status=MagickTrue;
3659 /*
3660 Parse command line.
3661 */
3662 ReadCommandlLine(argc,&argv);
3663 status=ExpandFilenames(&argc,&argv);
3664 if (status == MagickFalse)
3665 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3666 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003667 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003668 {
3669 option=argv[i];
3670 if (LocaleCompare(option,"(") == 0)
3671 {
3672 FireImageStack(MagickFalse,MagickTrue,pend);
3673 if (k == MaxImageStackDepth)
3674 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3675 option);
3676 PushImageStack();
3677 continue;
3678 }
3679 if (LocaleCompare(option,")") == 0)
3680 {
3681 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3682 if (k == 0)
3683 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3684 PopImageStack();
3685 continue;
3686 }
cristy042ee782011-04-22 18:48:30 +00003687 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003688 {
3689 char
3690 backup_filename[MaxTextExtent],
3691 *filename;
3692
3693 Image
3694 *images;
3695
3696 /*
3697 Option is a file name: begin by reading image from specified file.
3698 */
3699 FireImageStack(MagickFalse,MagickFalse,pend);
3700 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003701 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003702 filename=argv[++i];
3703 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3704 images=ReadImages(image_info,exception);
3705 status&=(images != (Image *) NULL) &&
3706 (exception->severity < ErrorException);
3707 if (images == (Image *) NULL)
3708 continue;
cristydaa76602010-06-30 13:05:11 +00003709 if (format != (char *) NULL)
3710 (void) CopyMagickString(images->filename,images->magick_filename,
3711 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003712 if (path != (char *) NULL)
3713 {
3714 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003715 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003716 path,*DirectorySeparator,filename);
3717 }
3718 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003719 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003720 AppendImageStack(images);
3721 FinalizeImageSettings(image_info,image,MagickFalse);
3722 if (global_colormap != MagickFalse)
3723 {
3724 QuantizeInfo
3725 *quantize_info;
3726
3727 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003728 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003729 quantize_info=DestroyQuantizeInfo(quantize_info);
3730 }
3731 *backup_filename='\0';
3732 if ((LocaleCompare(image->filename,"-") != 0) &&
3733 (IsPathWritable(image->filename) != MagickFalse))
3734 {
cristybb503372010-05-27 20:51:26 +00003735 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003736 i;
3737
3738 /*
3739 Rename image file as backup.
3740 */
3741 (void) CopyMagickString(backup_filename,image->filename,
3742 MaxTextExtent);
3743 for (i=0; i < 6; i++)
3744 {
3745 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3746 if (IsPathAccessible(backup_filename) == MagickFalse)
3747 break;
3748 }
3749 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003750 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003751 *backup_filename='\0';
3752 }
3753 /*
3754 Write transmogrified image to disk.
3755 */
3756 image_info->synchronize=MagickTrue;
3757 status&=WriteImages(image_info,image,image->filename,exception);
3758 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003759 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003760 RemoveAllImageStack();
3761 continue;
3762 }
3763 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3764 switch (*(option+1))
3765 {
3766 case 'a':
3767 {
3768 if (LocaleCompare("adaptive-blur",option+1) == 0)
3769 {
3770 i++;
cristybb503372010-05-27 20:51:26 +00003771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003772 ThrowMogrifyException(OptionError,"MissingArgument",option);
3773 if (IsGeometry(argv[i]) == MagickFalse)
3774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3775 break;
3776 }
3777 if (LocaleCompare("adaptive-resize",option+1) == 0)
3778 {
3779 i++;
cristybb503372010-05-27 20:51:26 +00003780 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003781 ThrowMogrifyException(OptionError,"MissingArgument",option);
3782 if (IsGeometry(argv[i]) == MagickFalse)
3783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3784 break;
3785 }
3786 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3787 {
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);
3791 if (IsGeometry(argv[i]) == MagickFalse)
3792 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3793 break;
3794 }
3795 if (LocaleCompare("affine",option+1) == 0)
3796 {
3797 if (*option == '+')
3798 break;
3799 i++;
cristybb503372010-05-27 20:51:26 +00003800 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003801 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003802 break;
3803 }
3804 if (LocaleCompare("alpha",option+1) == 0)
3805 {
cristybb503372010-05-27 20:51:26 +00003806 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003807 type;
3808
3809 if (*option == '+')
3810 break;
3811 i++;
cristybb503372010-05-27 20:51:26 +00003812 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003813 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003814 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003815 if (type < 0)
3816 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3817 argv[i]);
3818 break;
3819 }
3820 if (LocaleCompare("annotate",option+1) == 0)
3821 {
3822 if (*option == '+')
3823 break;
3824 i++;
cristybb503372010-05-27 20:51:26 +00003825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003826 ThrowMogrifyException(OptionError,"MissingArgument",option);
3827 if (IsGeometry(argv[i]) == MagickFalse)
3828 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003830 ThrowMogrifyException(OptionError,"MissingArgument",option);
3831 i++;
3832 break;
3833 }
3834 if (LocaleCompare("antialias",option+1) == 0)
3835 break;
3836 if (LocaleCompare("append",option+1) == 0)
3837 break;
3838 if (LocaleCompare("attenuate",option+1) == 0)
3839 {
3840 if (*option == '+')
3841 break;
3842 i++;
cristybb503372010-05-27 20:51:26 +00003843 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003844 ThrowMogrifyException(OptionError,"MissingArgument",option);
3845 if (IsGeometry(argv[i]) == MagickFalse)
3846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3847 break;
3848 }
3849 if (LocaleCompare("authenticate",option+1) == 0)
3850 {
3851 if (*option == '+')
3852 break;
3853 i++;
cristybb503372010-05-27 20:51:26 +00003854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003855 ThrowMogrifyException(OptionError,"MissingArgument",option);
3856 break;
3857 }
3858 if (LocaleCompare("auto-gamma",option+1) == 0)
3859 break;
3860 if (LocaleCompare("auto-level",option+1) == 0)
3861 break;
3862 if (LocaleCompare("auto-orient",option+1) == 0)
3863 break;
3864 if (LocaleCompare("average",option+1) == 0)
3865 break;
3866 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3867 }
3868 case 'b':
3869 {
3870 if (LocaleCompare("background",option+1) == 0)
3871 {
3872 if (*option == '+')
3873 break;
3874 i++;
cristybb503372010-05-27 20:51:26 +00003875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003876 ThrowMogrifyException(OptionError,"MissingArgument",option);
3877 break;
3878 }
3879 if (LocaleCompare("bias",option+1) == 0)
3880 {
3881 if (*option == '+')
3882 break;
3883 i++;
cristybb503372010-05-27 20:51:26 +00003884 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003885 ThrowMogrifyException(OptionError,"MissingArgument",option);
3886 if (IsGeometry(argv[i]) == MagickFalse)
3887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3888 break;
3889 }
3890 if (LocaleCompare("black-point-compensation",option+1) == 0)
3891 break;
3892 if (LocaleCompare("black-threshold",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-primary",option+1) == 0)
3904 {
3905 if (*option == '+')
3906 break;
3907 i++;
cristybb503372010-05-27 20:51:26 +00003908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003909 ThrowMogrifyException(OptionError,"MissingArgument",option);
3910 if (IsGeometry(argv[i]) == MagickFalse)
3911 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3912 break;
3913 }
3914 if (LocaleCompare("blue-shift",option+1) == 0)
3915 {
3916 i++;
cristybb503372010-05-27 20:51:26 +00003917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003918 ThrowMogrifyException(OptionError,"MissingArgument",option);
3919 if (IsGeometry(argv[i]) == MagickFalse)
3920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3921 break;
3922 }
3923 if (LocaleCompare("blur",option+1) == 0)
3924 {
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("border",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 if (IsGeometry(argv[i]) == MagickFalse)
3940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3941 break;
3942 }
3943 if (LocaleCompare("bordercolor",option+1) == 0)
3944 {
3945 if (*option == '+')
3946 break;
3947 i++;
cristybb503372010-05-27 20:51:26 +00003948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003949 ThrowMogrifyException(OptionError,"MissingArgument",option);
3950 break;
3951 }
3952 if (LocaleCompare("box",option+1) == 0)
3953 {
3954 if (*option == '+')
3955 break;
3956 i++;
cristybb503372010-05-27 20:51:26 +00003957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003958 ThrowMogrifyException(OptionError,"MissingArgument",option);
3959 break;
3960 }
cristya28d6b82010-01-11 20:03:47 +00003961 if (LocaleCompare("brightness-contrast",option+1) == 0)
3962 {
3963 i++;
cristybb503372010-05-27 20:51:26 +00003964 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003965 ThrowMogrifyException(OptionError,"MissingArgument",option);
3966 if (IsGeometry(argv[i]) == MagickFalse)
3967 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3968 break;
3969 }
cristy3ed852e2009-09-05 21:47:34 +00003970 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3971 }
3972 case 'c':
3973 {
3974 if (LocaleCompare("cache",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 if (IsGeometry(argv[i]) == MagickFalse)
3982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3983 break;
3984 }
3985 if (LocaleCompare("caption",option+1) == 0)
3986 {
3987 if (*option == '+')
3988 break;
3989 i++;
cristybb503372010-05-27 20:51:26 +00003990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003991 ThrowMogrifyException(OptionError,"MissingArgument",option);
3992 break;
3993 }
3994 if (LocaleCompare("channel",option+1) == 0)
3995 {
cristybb503372010-05-27 20:51:26 +00003996 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003997 channel;
3998
3999 if (*option == '+')
4000 break;
4001 i++;
cristybb503372010-05-27 20:51:26 +00004002 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004003 ThrowMogrifyException(OptionError,"MissingArgument",option);
4004 channel=ParseChannelOption(argv[i]);
4005 if (channel < 0)
4006 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4007 argv[i]);
4008 break;
4009 }
4010 if (LocaleCompare("cdl",option+1) == 0)
4011 {
4012 if (*option == '+')
4013 break;
4014 i++;
cristybb503372010-05-27 20:51:26 +00004015 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004016 ThrowMogrifyException(OptionError,"MissingArgument",option);
4017 break;
4018 }
4019 if (LocaleCompare("charcoal",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 }
4030 if (LocaleCompare("chop",option+1) == 0)
4031 {
4032 if (*option == '+')
4033 break;
4034 i++;
cristybb503372010-05-27 20:51:26 +00004035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004036 ThrowMogrifyException(OptionError,"MissingArgument",option);
4037 if (IsGeometry(argv[i]) == MagickFalse)
4038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4039 break;
4040 }
cristy1eb45dd2009-09-25 16:38:06 +00004041 if (LocaleCompare("clamp",option+1) == 0)
4042 break;
4043 if (LocaleCompare("clip",option+1) == 0)
4044 break;
cristy3ed852e2009-09-05 21:47:34 +00004045 if (LocaleCompare("clip-mask",option+1) == 0)
4046 {
4047 if (*option == '+')
4048 break;
4049 i++;
cristybb503372010-05-27 20:51:26 +00004050 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004051 ThrowMogrifyException(OptionError,"MissingArgument",option);
4052 break;
4053 }
4054 if (LocaleCompare("clut",option+1) == 0)
4055 break;
4056 if (LocaleCompare("coalesce",option+1) == 0)
4057 break;
4058 if (LocaleCompare("colorize",option+1) == 0)
4059 {
4060 if (*option == '+')
4061 break;
4062 i++;
cristybb503372010-05-27 20:51:26 +00004063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004064 ThrowMogrifyException(OptionError,"MissingArgument",option);
4065 if (IsGeometry(argv[i]) == MagickFalse)
4066 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4067 break;
4068 }
cristye6365592010-04-02 17:31:23 +00004069 if (LocaleCompare("color-matrix",option+1) == 0)
4070 {
cristyb6bd4ad2010-08-08 01:12:27 +00004071 KernelInfo
4072 *kernel_info;
4073
cristye6365592010-04-02 17:31:23 +00004074 if (*option == '+')
4075 break;
4076 i++;
cristybb503372010-05-27 20:51:26 +00004077 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004078 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004079 kernel_info=AcquireKernelInfo(argv[i]);
4080 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004081 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004082 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004083 break;
4084 }
cristy3ed852e2009-09-05 21:47:34 +00004085 if (LocaleCompare("colors",option+1) == 0)
4086 {
4087 if (*option == '+')
4088 break;
4089 i++;
cristybb503372010-05-27 20:51:26 +00004090 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004091 ThrowMogrifyException(OptionError,"MissingArgument",option);
4092 if (IsGeometry(argv[i]) == MagickFalse)
4093 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4094 break;
4095 }
4096 if (LocaleCompare("colorspace",option+1) == 0)
4097 {
cristybb503372010-05-27 20:51:26 +00004098 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004099 colorspace;
4100
4101 if (*option == '+')
4102 break;
4103 i++;
cristybb503372010-05-27 20:51:26 +00004104 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004105 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004106 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004107 argv[i]);
4108 if (colorspace < 0)
4109 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4110 argv[i]);
4111 break;
4112 }
4113 if (LocaleCompare("combine",option+1) == 0)
4114 break;
4115 if (LocaleCompare("comment",option+1) == 0)
4116 {
4117 if (*option == '+')
4118 break;
4119 i++;
cristybb503372010-05-27 20:51:26 +00004120 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004121 ThrowMogrifyException(OptionError,"MissingArgument",option);
4122 break;
4123 }
4124 if (LocaleCompare("composite",option+1) == 0)
4125 break;
4126 if (LocaleCompare("compress",option+1) == 0)
4127 {
cristybb503372010-05-27 20:51:26 +00004128 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004129 compress;
4130
4131 if (*option == '+')
4132 break;
4133 i++;
cristybb503372010-05-27 20:51:26 +00004134 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004135 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004136 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004137 argv[i]);
4138 if (compress < 0)
4139 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4140 argv[i]);
4141 break;
4142 }
cristy22879752009-10-25 23:55:40 +00004143 if (LocaleCompare("concurrent",option+1) == 0)
4144 break;
cristy3ed852e2009-09-05 21:47:34 +00004145 if (LocaleCompare("contrast",option+1) == 0)
4146 break;
4147 if (LocaleCompare("contrast-stretch",option+1) == 0)
4148 {
4149 i++;
cristybb503372010-05-27 20:51:26 +00004150 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004151 ThrowMogrifyException(OptionError,"MissingArgument",option);
4152 if (IsGeometry(argv[i]) == MagickFalse)
4153 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4154 break;
4155 }
4156 if (LocaleCompare("convolve",option+1) == 0)
4157 {
cristyb6bd4ad2010-08-08 01:12:27 +00004158 KernelInfo
4159 *kernel_info;
4160
cristy3ed852e2009-09-05 21:47:34 +00004161 if (*option == '+')
4162 break;
4163 i++;
cristybb503372010-05-27 20:51:26 +00004164 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004165 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004166 kernel_info=AcquireKernelInfo(argv[i]);
4167 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004168 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004169 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004170 break;
4171 }
4172 if (LocaleCompare("crop",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 if (LocaleCompare("cycle",option+1) == 0)
4184 {
4185 if (*option == '+')
4186 break;
4187 i++;
cristybb503372010-05-27 20:51:26 +00004188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004189 ThrowMogrifyException(OptionError,"MissingArgument",option);
4190 if (IsGeometry(argv[i]) == MagickFalse)
4191 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4192 break;
4193 }
4194 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4195 }
4196 case 'd':
4197 {
4198 if (LocaleCompare("decipher",option+1) == 0)
4199 {
4200 if (*option == '+')
4201 break;
4202 i++;
cristybb503372010-05-27 20:51:26 +00004203 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004204 ThrowMogrifyException(OptionError,"MissingArgument",option);
4205 break;
4206 }
4207 if (LocaleCompare("deconstruct",option+1) == 0)
4208 break;
4209 if (LocaleCompare("debug",option+1) == 0)
4210 {
cristybb503372010-05-27 20:51:26 +00004211 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004212 event;
4213
4214 if (*option == '+')
4215 break;
4216 i++;
cristybb503372010-05-27 20:51:26 +00004217 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004218 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004219 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004220 if (event < 0)
4221 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4222 argv[i]);
4223 (void) SetLogEventMask(argv[i]);
4224 break;
4225 }
4226 if (LocaleCompare("define",option+1) == 0)
4227 {
4228 i++;
cristybb503372010-05-27 20:51:26 +00004229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004230 ThrowMogrifyException(OptionError,"MissingArgument",option);
4231 if (*option == '+')
4232 {
4233 const char
4234 *define;
4235
4236 define=GetImageOption(image_info,argv[i]);
4237 if (define == (const char *) NULL)
4238 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4239 break;
4240 }
4241 break;
4242 }
4243 if (LocaleCompare("delay",option+1) == 0)
4244 {
4245 if (*option == '+')
4246 break;
4247 i++;
cristybb503372010-05-27 20:51:26 +00004248 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004249 ThrowMogrifyException(OptionError,"MissingArgument",option);
4250 if (IsGeometry(argv[i]) == MagickFalse)
4251 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4252 break;
4253 }
cristyecb10ff2011-03-22 13:14:03 +00004254 if (LocaleCompare("delete",option+1) == 0)
4255 {
4256 if (*option == '+')
4257 break;
4258 i++;
4259 if (i == (ssize_t) (argc-1))
4260 ThrowMogrifyException(OptionError,"MissingArgument",option);
4261 if (IsGeometry(argv[i]) == MagickFalse)
4262 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4263 break;
4264 }
cristy3ed852e2009-09-05 21:47:34 +00004265 if (LocaleCompare("density",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("depth",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("deskew",option+1) == 0)
4288 {
4289 if (*option == '+')
4290 break;
4291 i++;
cristybb503372010-05-27 20:51:26 +00004292 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004293 ThrowMogrifyException(OptionError,"MissingArgument",option);
4294 if (IsGeometry(argv[i]) == MagickFalse)
4295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4296 break;
4297 }
4298 if (LocaleCompare("despeckle",option+1) == 0)
4299 break;
4300 if (LocaleCompare("dft",option+1) == 0)
4301 break;
cristyc9b12952010-03-28 01:12:28 +00004302 if (LocaleCompare("direction",option+1) == 0)
4303 {
cristybb503372010-05-27 20:51:26 +00004304 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004305 direction;
4306
4307 if (*option == '+')
4308 break;
4309 i++;
cristybb503372010-05-27 20:51:26 +00004310 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004311 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004312 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004313 argv[i]);
4314 if (direction < 0)
4315 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4316 argv[i]);
4317 break;
4318 }
cristy3ed852e2009-09-05 21:47:34 +00004319 if (LocaleCompare("display",option+1) == 0)
4320 {
4321 if (*option == '+')
4322 break;
4323 i++;
cristybb503372010-05-27 20:51:26 +00004324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004325 ThrowMogrifyException(OptionError,"MissingArgument",option);
4326 break;
4327 }
4328 if (LocaleCompare("dispose",option+1) == 0)
4329 {
cristybb503372010-05-27 20:51:26 +00004330 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004331 dispose;
4332
4333 if (*option == '+')
4334 break;
4335 i++;
cristybb503372010-05-27 20:51:26 +00004336 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004337 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004338 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004339 if (dispose < 0)
4340 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4341 argv[i]);
4342 break;
4343 }
4344 if (LocaleCompare("distort",option+1) == 0)
4345 {
cristybb503372010-05-27 20:51:26 +00004346 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004347 op;
4348
4349 i++;
cristybb503372010-05-27 20:51:26 +00004350 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004351 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004352 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004353 if (op < 0)
4354 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4355 argv[i]);
4356 i++;
cristybb503372010-05-27 20:51:26 +00004357 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004358 ThrowMogrifyException(OptionError,"MissingArgument",option);
4359 break;
4360 }
4361 if (LocaleCompare("dither",option+1) == 0)
4362 {
cristybb503372010-05-27 20:51:26 +00004363 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004364 method;
4365
4366 if (*option == '+')
4367 break;
4368 i++;
cristybb503372010-05-27 20:51:26 +00004369 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004370 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004371 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004372 if (method < 0)
4373 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4374 argv[i]);
4375 break;
4376 }
4377 if (LocaleCompare("draw",option+1) == 0)
4378 {
4379 if (*option == '+')
4380 break;
4381 i++;
cristybb503372010-05-27 20:51:26 +00004382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004383 ThrowMogrifyException(OptionError,"MissingArgument",option);
4384 break;
4385 }
cristyecb10ff2011-03-22 13:14:03 +00004386 if (LocaleCompare("duplicate",option+1) == 0)
4387 {
4388 if (*option == '+')
4389 break;
4390 i++;
4391 if (i == (ssize_t) (argc-1))
4392 ThrowMogrifyException(OptionError,"MissingArgument",option);
4393 if (IsGeometry(argv[i]) == MagickFalse)
4394 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4395 break;
4396 }
cristy22879752009-10-25 23:55:40 +00004397 if (LocaleCompare("duration",option+1) == 0)
4398 {
4399 if (*option == '+')
4400 break;
4401 i++;
cristybb503372010-05-27 20:51:26 +00004402 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004403 ThrowMogrifyException(OptionError,"MissingArgument",option);
4404 if (IsGeometry(argv[i]) == MagickFalse)
4405 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4406 break;
4407 }
cristy3ed852e2009-09-05 21:47:34 +00004408 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4409 }
4410 case 'e':
4411 {
4412 if (LocaleCompare("edge",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("emboss",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 if (IsGeometry(argv[i]) == MagickFalse)
4431 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4432 break;
4433 }
4434 if (LocaleCompare("encipher",option+1) == 0)
4435 {
4436 if (*option == '+')
4437 break;
4438 i++;
cristybb503372010-05-27 20:51:26 +00004439 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004440 ThrowMogrifyException(OptionError,"MissingArgument",option);
4441 break;
4442 }
4443 if (LocaleCompare("encoding",option+1) == 0)
4444 {
4445 if (*option == '+')
4446 break;
4447 i++;
cristybb503372010-05-27 20:51:26 +00004448 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004449 ThrowMogrifyException(OptionError,"MissingArgument",option);
4450 break;
4451 }
4452 if (LocaleCompare("endian",option+1) == 0)
4453 {
cristybb503372010-05-27 20:51:26 +00004454 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004455 endian;
4456
4457 if (*option == '+')
4458 break;
4459 i++;
cristybb503372010-05-27 20:51:26 +00004460 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004461 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004462 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004463 if (endian < 0)
4464 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4465 argv[i]);
4466 break;
4467 }
4468 if (LocaleCompare("enhance",option+1) == 0)
4469 break;
4470 if (LocaleCompare("equalize",option+1) == 0)
4471 break;
4472 if (LocaleCompare("evaluate",option+1) == 0)
4473 {
cristybb503372010-05-27 20:51:26 +00004474 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004475 op;
4476
4477 if (*option == '+')
4478 break;
4479 i++;
cristybb503372010-05-27 20:51:26 +00004480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004481 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004482 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004483 if (op < 0)
4484 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4485 argv[i]);
4486 i++;
cristybb503372010-05-27 20:51:26 +00004487 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004488 ThrowMogrifyException(OptionError,"MissingArgument",option);
4489 if (IsGeometry(argv[i]) == MagickFalse)
4490 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4491 break;
4492 }
cristyd18ae7c2010-03-07 17:39:52 +00004493 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4494 {
cristybb503372010-05-27 20:51:26 +00004495 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004496 op;
4497
4498 if (*option == '+')
4499 break;
4500 i++;
cristybb503372010-05-27 20:51:26 +00004501 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004502 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004503 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004504 if (op < 0)
4505 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4506 argv[i]);
4507 break;
4508 }
cristy3ed852e2009-09-05 21:47:34 +00004509 if (LocaleCompare("extent",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 if (LocaleCompare("extract",option+1) == 0)
4521 {
4522 if (*option == '+')
4523 break;
4524 i++;
cristybb503372010-05-27 20:51:26 +00004525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004526 ThrowMogrifyException(OptionError,"MissingArgument",option);
4527 if (IsGeometry(argv[i]) == MagickFalse)
4528 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4529 break;
4530 }
4531 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4532 }
4533 case 'f':
4534 {
4535 if (LocaleCompare("family",option+1) == 0)
4536 {
4537 if (*option == '+')
4538 break;
4539 i++;
cristybb503372010-05-27 20:51:26 +00004540 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004541 ThrowMogrifyException(OptionError,"MissingArgument",option);
4542 break;
4543 }
4544 if (LocaleCompare("fill",option+1) == 0)
4545 {
4546 if (*option == '+')
4547 break;
4548 i++;
cristybb503372010-05-27 20:51:26 +00004549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004550 ThrowMogrifyException(OptionError,"MissingArgument",option);
4551 break;
4552 }
4553 if (LocaleCompare("filter",option+1) == 0)
4554 {
cristybb503372010-05-27 20:51:26 +00004555 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004556 filter;
4557
4558 if (*option == '+')
4559 break;
4560 i++;
cristybb503372010-05-27 20:51:26 +00004561 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004562 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004563 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004564 if (filter < 0)
4565 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4566 argv[i]);
4567 break;
4568 }
4569 if (LocaleCompare("flatten",option+1) == 0)
4570 break;
4571 if (LocaleCompare("flip",option+1) == 0)
4572 break;
4573 if (LocaleCompare("flop",option+1) == 0)
4574 break;
4575 if (LocaleCompare("floodfill",option+1) == 0)
4576 {
4577 if (*option == '+')
4578 break;
4579 i++;
cristybb503372010-05-27 20:51:26 +00004580 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004581 ThrowMogrifyException(OptionError,"MissingArgument",option);
4582 if (IsGeometry(argv[i]) == MagickFalse)
4583 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4584 i++;
cristybb503372010-05-27 20:51:26 +00004585 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004586 ThrowMogrifyException(OptionError,"MissingArgument",option);
4587 break;
4588 }
4589 if (LocaleCompare("font",option+1) == 0)
4590 {
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 break;
4597 }
4598 if (LocaleCompare("format",option+1) == 0)
4599 {
4600 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4601 (void) CloneString(&format,(char *) NULL);
4602 if (*option == '+')
4603 break;
4604 i++;
cristybb503372010-05-27 20:51:26 +00004605 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004606 ThrowMogrifyException(OptionError,"MissingArgument",option);
4607 (void) CloneString(&format,argv[i]);
4608 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4609 (void) ConcatenateMagickString(image_info->filename,":",
4610 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004611 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004612 if (*image_info->magick == '\0')
4613 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4614 format);
4615 break;
4616 }
4617 if (LocaleCompare("frame",option+1) == 0)
4618 {
4619 if (*option == '+')
4620 break;
4621 i++;
cristybb503372010-05-27 20:51:26 +00004622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004623 ThrowMogrifyException(OptionError,"MissingArgument",option);
4624 if (IsGeometry(argv[i]) == MagickFalse)
4625 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4626 break;
4627 }
4628 if (LocaleCompare("function",option+1) == 0)
4629 {
cristybb503372010-05-27 20:51:26 +00004630 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004631 op;
4632
4633 if (*option == '+')
4634 break;
4635 i++;
cristybb503372010-05-27 20:51:26 +00004636 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004637 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004638 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004639 if (op < 0)
4640 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4641 i++;
cristybb503372010-05-27 20:51:26 +00004642 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004643 ThrowMogrifyException(OptionError,"MissingArgument",option);
4644 break;
4645 }
4646 if (LocaleCompare("fuzz",option+1) == 0)
4647 {
4648 if (*option == '+')
4649 break;
4650 i++;
cristybb503372010-05-27 20:51:26 +00004651 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004652 ThrowMogrifyException(OptionError,"MissingArgument",option);
4653 if (IsGeometry(argv[i]) == MagickFalse)
4654 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4655 break;
4656 }
4657 if (LocaleCompare("fx",option+1) == 0)
4658 {
4659 if (*option == '+')
4660 break;
4661 i++;
cristybb503372010-05-27 20:51:26 +00004662 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004663 ThrowMogrifyException(OptionError,"MissingArgument",option);
4664 break;
4665 }
4666 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4667 }
4668 case 'g':
4669 {
4670 if (LocaleCompare("gamma",option+1) == 0)
4671 {
4672 i++;
cristybb503372010-05-27 20:51:26 +00004673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004674 ThrowMogrifyException(OptionError,"MissingArgument",option);
4675 if (IsGeometry(argv[i]) == MagickFalse)
4676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4677 break;
4678 }
4679 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4680 (LocaleCompare("gaussian",option+1) == 0))
4681 {
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("geometry",option+1) == 0)
4690 {
4691 if (*option == '+')
4692 break;
4693 i++;
cristybb503372010-05-27 20:51:26 +00004694 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004695 ThrowMogrifyException(OptionError,"MissingArgument",option);
4696 if (IsGeometry(argv[i]) == MagickFalse)
4697 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4698 break;
4699 }
4700 if (LocaleCompare("gravity",option+1) == 0)
4701 {
cristybb503372010-05-27 20:51:26 +00004702 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004703 gravity;
4704
4705 if (*option == '+')
4706 break;
4707 i++;
cristybb503372010-05-27 20:51:26 +00004708 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004709 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004710 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004711 if (gravity < 0)
4712 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4713 argv[i]);
4714 break;
4715 }
4716 if (LocaleCompare("green-primary",option+1) == 0)
4717 {
4718 if (*option == '+')
4719 break;
4720 i++;
cristybb503372010-05-27 20:51:26 +00004721 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004722 ThrowMogrifyException(OptionError,"MissingArgument",option);
4723 if (IsGeometry(argv[i]) == MagickFalse)
4724 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4725 break;
4726 }
4727 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4728 }
4729 case 'h':
4730 {
4731 if (LocaleCompare("hald-clut",option+1) == 0)
4732 break;
4733 if ((LocaleCompare("help",option+1) == 0) ||
4734 (LocaleCompare("-help",option+1) == 0))
4735 return(MogrifyUsage());
4736 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4737 }
4738 case 'i':
4739 {
4740 if (LocaleCompare("identify",option+1) == 0)
4741 break;
4742 if (LocaleCompare("idft",option+1) == 0)
4743 break;
4744 if (LocaleCompare("implode",option+1) == 0)
4745 {
4746 if (*option == '+')
4747 break;
4748 i++;
cristybb503372010-05-27 20:51:26 +00004749 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004750 ThrowMogrifyException(OptionError,"MissingArgument",option);
4751 if (IsGeometry(argv[i]) == MagickFalse)
4752 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4753 break;
4754 }
4755 if (LocaleCompare("intent",option+1) == 0)
4756 {
cristybb503372010-05-27 20:51:26 +00004757 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004758 intent;
4759
4760 if (*option == '+')
4761 break;
4762 i++;
cristybb503372010-05-27 20:51:26 +00004763 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004764 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004765 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004766 if (intent < 0)
4767 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4768 argv[i]);
4769 break;
4770 }
4771 if (LocaleCompare("interlace",option+1) == 0)
4772 {
cristybb503372010-05-27 20:51:26 +00004773 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004774 interlace;
4775
4776 if (*option == '+')
4777 break;
4778 i++;
cristybb503372010-05-27 20:51:26 +00004779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004780 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004781 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004782 argv[i]);
4783 if (interlace < 0)
4784 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4785 argv[i]);
4786 break;
4787 }
cristyb32b90a2009-09-07 21:45:48 +00004788 if (LocaleCompare("interline-spacing",option+1) == 0)
4789 {
4790 if (*option == '+')
4791 break;
4792 i++;
cristybb503372010-05-27 20:51:26 +00004793 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004794 ThrowMogrifyException(OptionError,"MissingArgument",option);
4795 if (IsGeometry(argv[i]) == MagickFalse)
4796 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4797 break;
4798 }
cristy3ed852e2009-09-05 21:47:34 +00004799 if (LocaleCompare("interpolate",option+1) == 0)
4800 {
cristybb503372010-05-27 20:51:26 +00004801 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004802 interpolate;
4803
4804 if (*option == '+')
4805 break;
4806 i++;
cristybb503372010-05-27 20:51:26 +00004807 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004808 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004809 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004810 argv[i]);
4811 if (interpolate < 0)
4812 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4813 argv[i]);
4814 break;
4815 }
4816 if (LocaleCompare("interword-spacing",option+1) == 0)
4817 {
4818 if (*option == '+')
4819 break;
4820 i++;
cristybb503372010-05-27 20:51:26 +00004821 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004822 ThrowMogrifyException(OptionError,"MissingArgument",option);
4823 if (IsGeometry(argv[i]) == MagickFalse)
4824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4825 break;
4826 }
4827 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4828 }
4829 case 'k':
4830 {
4831 if (LocaleCompare("kerning",option+1) == 0)
4832 {
4833 if (*option == '+')
4834 break;
4835 i++;
cristybb503372010-05-27 20:51:26 +00004836 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004837 ThrowMogrifyException(OptionError,"MissingArgument",option);
4838 if (IsGeometry(argv[i]) == MagickFalse)
4839 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4840 break;
4841 }
4842 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4843 }
4844 case 'l':
4845 {
4846 if (LocaleCompare("label",option+1) == 0)
4847 {
4848 if (*option == '+')
4849 break;
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 break;
4854 }
4855 if (LocaleCompare("lat",option+1) == 0)
4856 {
4857 if (*option == '+')
4858 break;
4859 i++;
cristybb503372010-05-27 20:51:26 +00004860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004861 ThrowMogrifyException(OptionError,"MissingArgument",option);
4862 if (IsGeometry(argv[i]) == MagickFalse)
4863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4864 }
4865 if (LocaleCompare("layers",option+1) == 0)
4866 {
cristybb503372010-05-27 20:51:26 +00004867 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004868 type;
4869
4870 if (*option == '+')
4871 break;
4872 i++;
cristybb503372010-05-27 20:51:26 +00004873 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004874 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004875 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004876 if (type < 0)
4877 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4878 argv[i]);
4879 break;
4880 }
4881 if (LocaleCompare("level",option+1) == 0)
4882 {
4883 i++;
cristybb503372010-05-27 20:51:26 +00004884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004885 ThrowMogrifyException(OptionError,"MissingArgument",option);
4886 if (IsGeometry(argv[i]) == MagickFalse)
4887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4888 break;
4889 }
4890 if (LocaleCompare("level-colors",option+1) == 0)
4891 {
4892 i++;
cristybb503372010-05-27 20:51:26 +00004893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004894 ThrowMogrifyException(OptionError,"MissingArgument",option);
4895 break;
4896 }
4897 if (LocaleCompare("linewidth",option+1) == 0)
4898 {
4899 if (*option == '+')
4900 break;
4901 i++;
cristybb503372010-05-27 20:51:26 +00004902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004903 ThrowMogrifyException(OptionError,"MissingArgument",option);
4904 if (IsGeometry(argv[i]) == MagickFalse)
4905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4906 break;
4907 }
4908 if (LocaleCompare("limit",option+1) == 0)
4909 {
4910 char
4911 *p;
4912
4913 double
4914 value;
4915
cristybb503372010-05-27 20:51:26 +00004916 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004917 resource;
4918
4919 if (*option == '+')
4920 break;
4921 i++;
cristybb503372010-05-27 20:51:26 +00004922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004923 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004924 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004925 argv[i]);
4926 if (resource < 0)
4927 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4928 argv[i]);
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);
cristyc1acd842011-05-19 23:05:47 +00004932 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004933 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004934 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4936 break;
4937 }
4938 if (LocaleCompare("liquid-rescale",option+1) == 0)
4939 {
4940 i++;
cristybb503372010-05-27 20:51:26 +00004941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004942 ThrowMogrifyException(OptionError,"MissingArgument",option);
4943 if (IsGeometry(argv[i]) == MagickFalse)
4944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4945 break;
4946 }
4947 if (LocaleCompare("list",option+1) == 0)
4948 {
cristybb503372010-05-27 20:51:26 +00004949 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004950 list;
4951
4952 if (*option == '+')
4953 break;
4954 i++;
cristybb503372010-05-27 20:51:26 +00004955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004956 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004957 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004958 if (list < 0)
4959 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004960 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004961 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004962 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004963 }
4964 if (LocaleCompare("log",option+1) == 0)
4965 {
4966 if (*option == '+')
4967 break;
4968 i++;
cristybb503372010-05-27 20:51:26 +00004969 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004970 (strchr(argv[i],'%') == (char *) NULL))
4971 ThrowMogrifyException(OptionError,"MissingArgument",option);
4972 break;
4973 }
4974 if (LocaleCompare("loop",option+1) == 0)
4975 {
4976 if (*option == '+')
4977 break;
4978 i++;
cristybb503372010-05-27 20:51:26 +00004979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004980 ThrowMogrifyException(OptionError,"MissingArgument",option);
4981 if (IsGeometry(argv[i]) == MagickFalse)
4982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4983 break;
4984 }
4985 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4986 }
4987 case 'm':
4988 {
4989 if (LocaleCompare("map",option+1) == 0)
4990 {
4991 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4992 if (*option == '+')
4993 break;
4994 i++;
cristybb503372010-05-27 20:51:26 +00004995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004996 ThrowMogrifyException(OptionError,"MissingArgument",option);
4997 break;
4998 }
4999 if (LocaleCompare("mask",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 }
5008 if (LocaleCompare("matte",option+1) == 0)
5009 break;
5010 if (LocaleCompare("mattecolor",option+1) == 0)
5011 {
5012 if (*option == '+')
5013 break;
5014 i++;
cristybb503372010-05-27 20:51:26 +00005015 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005016 ThrowMogrifyException(OptionError,"MissingArgument",option);
5017 break;
5018 }
cristyf40785b2010-03-06 02:27:27 +00005019 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005020 break;
cristyf40785b2010-03-06 02:27:27 +00005021 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005022 break;
cristy3ed852e2009-09-05 21:47:34 +00005023 if (LocaleCompare("modulate",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 }
5034 if (LocaleCompare("median",option+1) == 0)
5035 {
5036 if (*option == '+')
5037 break;
5038 i++;
cristybb503372010-05-27 20:51:26 +00005039 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005040 ThrowMogrifyException(OptionError,"MissingArgument",option);
5041 if (IsGeometry(argv[i]) == MagickFalse)
5042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5043 break;
5044 }
cristy69ec32d2011-02-27 23:57:09 +00005045 if (LocaleCompare("mode",option+1) == 0)
5046 {
5047 if (*option == '+')
5048 break;
5049 i++;
5050 if (i == (ssize_t) argc)
5051 ThrowMogrifyException(OptionError,"MissingArgument",option);
5052 if (IsGeometry(argv[i]) == MagickFalse)
5053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5054 break;
5055 }
cristy3ed852e2009-09-05 21:47:34 +00005056 if (LocaleCompare("monitor",option+1) == 0)
5057 break;
5058 if (LocaleCompare("monochrome",option+1) == 0)
5059 break;
5060 if (LocaleCompare("morph",option+1) == 0)
5061 {
5062 if (*option == '+')
5063 break;
5064 i++;
cristybb503372010-05-27 20:51:26 +00005065 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005066 ThrowMogrifyException(OptionError,"MissingArgument",option);
5067 if (IsGeometry(argv[i]) == MagickFalse)
5068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5069 break;
5070 }
anthony29188a82010-01-22 10:12:34 +00005071 if (LocaleCompare("morphology",option+1) == 0)
5072 {
anthony29188a82010-01-22 10:12:34 +00005073 char
5074 token[MaxTextExtent];
5075
cristyb6bd4ad2010-08-08 01:12:27 +00005076 KernelInfo
5077 *kernel_info;
5078
5079 ssize_t
5080 op;
5081
anthony29188a82010-01-22 10:12:34 +00005082 i++;
cristybb503372010-05-27 20:51:26 +00005083 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005084 ThrowMogrifyException(OptionError,"MissingArgument",option);
5085 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005086 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005087 if (op < 0)
5088 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005089 token);
anthony29188a82010-01-22 10:12:34 +00005090 i++;
cristybb503372010-05-27 20:51:26 +00005091 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005092 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005093 kernel_info=AcquireKernelInfo(argv[i]);
5094 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005095 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005096 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005097 break;
5098 }
cristy3ed852e2009-09-05 21:47:34 +00005099 if (LocaleCompare("mosaic",option+1) == 0)
5100 break;
5101 if (LocaleCompare("motion-blur",option+1) == 0)
5102 {
5103 if (*option == '+')
5104 break;
5105 i++;
cristybb503372010-05-27 20:51:26 +00005106 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005107 ThrowMogrifyException(OptionError,"MissingArgument",option);
5108 if (IsGeometry(argv[i]) == MagickFalse)
5109 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5110 break;
5111 }
5112 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5113 }
5114 case 'n':
5115 {
5116 if (LocaleCompare("negate",option+1) == 0)
5117 break;
5118 if (LocaleCompare("noise",option+1) == 0)
5119 {
5120 i++;
cristybb503372010-05-27 20:51:26 +00005121 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005122 ThrowMogrifyException(OptionError,"MissingArgument",option);
5123 if (*option == '+')
5124 {
cristybb503372010-05-27 20:51:26 +00005125 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005126 noise;
5127
cristy042ee782011-04-22 18:48:30 +00005128 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005129 if (noise < 0)
5130 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5131 argv[i]);
5132 break;
5133 }
5134 if (IsGeometry(argv[i]) == MagickFalse)
5135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5136 break;
5137 }
5138 if (LocaleCompare("noop",option+1) == 0)
5139 break;
5140 if (LocaleCompare("normalize",option+1) == 0)
5141 break;
5142 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5143 }
5144 case 'o':
5145 {
5146 if (LocaleCompare("opaque",option+1) == 0)
5147 {
cristy3ed852e2009-09-05 21:47:34 +00005148 i++;
cristybb503372010-05-27 20:51:26 +00005149 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005150 ThrowMogrifyException(OptionError,"MissingArgument",option);
5151 break;
5152 }
5153 if (LocaleCompare("ordered-dither",option+1) == 0)
5154 {
5155 if (*option == '+')
5156 break;
5157 i++;
cristybb503372010-05-27 20:51:26 +00005158 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005159 ThrowMogrifyException(OptionError,"MissingArgument",option);
5160 break;
5161 }
5162 if (LocaleCompare("orient",option+1) == 0)
5163 {
cristybb503372010-05-27 20:51:26 +00005164 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005165 orientation;
5166
5167 orientation=UndefinedOrientation;
5168 if (*option == '+')
5169 break;
5170 i++;
cristybb503372010-05-27 20:51:26 +00005171 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005172 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005173 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005174 argv[i]);
5175 if (orientation < 0)
5176 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5177 argv[i]);
5178 break;
5179 }
5180 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5181 }
5182 case 'p':
5183 {
5184 if (LocaleCompare("page",option+1) == 0)
5185 {
5186 if (*option == '+')
5187 break;
5188 i++;
cristybb503372010-05-27 20:51:26 +00005189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005190 ThrowMogrifyException(OptionError,"MissingArgument",option);
5191 break;
5192 }
5193 if (LocaleCompare("paint",option+1) == 0)
5194 {
5195 if (*option == '+')
5196 break;
5197 i++;
cristybb503372010-05-27 20:51:26 +00005198 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005199 ThrowMogrifyException(OptionError,"MissingArgument",option);
5200 if (IsGeometry(argv[i]) == MagickFalse)
5201 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5202 break;
5203 }
5204 if (LocaleCompare("path",option+1) == 0)
5205 {
5206 (void) CloneString(&path,(char *) NULL);
5207 if (*option == '+')
5208 break;
5209 i++;
cristybb503372010-05-27 20:51:26 +00005210 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005211 ThrowMogrifyException(OptionError,"MissingArgument",option);
5212 (void) CloneString(&path,argv[i]);
5213 break;
5214 }
5215 if (LocaleCompare("pointsize",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("polaroid",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 }
5237 if (LocaleCompare("posterize",option+1) == 0)
5238 {
5239 if (*option == '+')
5240 break;
5241 i++;
cristybb503372010-05-27 20:51:26 +00005242 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005243 ThrowMogrifyException(OptionError,"MissingArgument",option);
5244 if (IsGeometry(argv[i]) == MagickFalse)
5245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5246 break;
5247 }
cristye7f51092010-01-17 00:39:37 +00005248 if (LocaleCompare("precision",option+1) == 0)
5249 {
5250 if (*option == '+')
5251 break;
5252 i++;
cristybb503372010-05-27 20:51:26 +00005253 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005254 ThrowMogrifyException(OptionError,"MissingArgument",option);
5255 if (IsGeometry(argv[i]) == MagickFalse)
5256 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5257 break;
5258 }
cristy3ed852e2009-09-05 21:47:34 +00005259 if (LocaleCompare("print",option+1) == 0)
5260 {
5261 if (*option == '+')
5262 break;
5263 i++;
cristybb503372010-05-27 20:51:26 +00005264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005265 ThrowMogrifyException(OptionError,"MissingArgument",option);
5266 break;
5267 }
5268 if (LocaleCompare("process",option+1) == 0)
5269 {
5270 if (*option == '+')
5271 break;
5272 i++;
cristybb503372010-05-27 20:51:26 +00005273 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005274 ThrowMogrifyException(OptionError,"MissingArgument",option);
5275 break;
5276 }
5277 if (LocaleCompare("profile",option+1) == 0)
5278 {
5279 i++;
cristybb503372010-05-27 20:51:26 +00005280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005281 ThrowMogrifyException(OptionError,"MissingArgument",option);
5282 break;
5283 }
5284 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5285 }
5286 case 'q':
5287 {
5288 if (LocaleCompare("quality",option+1) == 0)
5289 {
5290 if (*option == '+')
5291 break;
5292 i++;
cristybb503372010-05-27 20:51:26 +00005293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005294 ThrowMogrifyException(OptionError,"MissingArgument",option);
5295 if (IsGeometry(argv[i]) == MagickFalse)
5296 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5297 break;
5298 }
5299 if (LocaleCompare("quantize",option+1) == 0)
5300 {
cristybb503372010-05-27 20:51:26 +00005301 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005302 colorspace;
5303
5304 if (*option == '+')
5305 break;
5306 i++;
cristybb503372010-05-27 20:51:26 +00005307 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005308 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005309 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005310 argv[i]);
5311 if (colorspace < 0)
5312 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5313 argv[i]);
5314 break;
5315 }
5316 if (LocaleCompare("quiet",option+1) == 0)
5317 break;
5318 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5319 }
5320 case 'r':
5321 {
5322 if (LocaleCompare("radial-blur",option+1) == 0)
5323 {
5324 i++;
cristybb503372010-05-27 20:51:26 +00005325 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005326 ThrowMogrifyException(OptionError,"MissingArgument",option);
5327 if (IsGeometry(argv[i]) == MagickFalse)
5328 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5329 break;
5330 }
5331 if (LocaleCompare("raise",option+1) == 0)
5332 {
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 }
5340 if (LocaleCompare("random-threshold",option+1) == 0)
5341 {
5342 if (*option == '+')
5343 break;
5344 i++;
cristybb503372010-05-27 20:51:26 +00005345 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005346 ThrowMogrifyException(OptionError,"MissingArgument",option);
5347 if (IsGeometry(argv[i]) == MagickFalse)
5348 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5349 break;
5350 }
cristye6365592010-04-02 17:31:23 +00005351 if (LocaleCompare("recolor",option+1) == 0)
5352 {
5353 if (*option == '+')
5354 break;
5355 i++;
cristybb503372010-05-27 20:51:26 +00005356 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005357 ThrowMogrifyException(OptionError,"MissingArgument",option);
5358 if (IsGeometry(argv[i]) == MagickFalse)
5359 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5360 break;
5361 }
cristy3ed852e2009-09-05 21:47:34 +00005362 if (LocaleCompare("red-primary",option+1) == 0)
5363 {
5364 if (*option == '+')
5365 break;
5366 i++;
cristybb503372010-05-27 20:51:26 +00005367 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005368 ThrowMogrifyException(OptionError,"MissingArgument",option);
5369 if (IsGeometry(argv[i]) == MagickFalse)
5370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5371 }
cristy9f2083a2010-04-22 19:48:05 +00005372 if (LocaleCompare("regard-warnings",option+1) == 0)
5373 break;
cristy3ed852e2009-09-05 21:47:34 +00005374 if (LocaleCompare("region",option+1) == 0)
5375 {
5376 if (*option == '+')
5377 break;
5378 i++;
cristybb503372010-05-27 20:51:26 +00005379 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005380 ThrowMogrifyException(OptionError,"MissingArgument",option);
5381 if (IsGeometry(argv[i]) == MagickFalse)
5382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5383 break;
5384 }
cristyf0c78232010-03-15 12:53:40 +00005385 if (LocaleCompare("remap",option+1) == 0)
5386 {
5387 if (*option == '+')
5388 break;
5389 i++;
cristybb503372010-05-27 20:51:26 +00005390 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005391 ThrowMogrifyException(OptionError,"MissingArgument",option);
5392 break;
5393 }
cristy3ed852e2009-09-05 21:47:34 +00005394 if (LocaleCompare("render",option+1) == 0)
5395 break;
5396 if (LocaleCompare("repage",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("resample",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 }
5418 if (LocaleCompare("resize",option+1) == 0)
5419 {
5420 if (*option == '+')
5421 break;
5422 i++;
cristybb503372010-05-27 20:51:26 +00005423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005424 ThrowMogrifyException(OptionError,"MissingArgument",option);
5425 if (IsGeometry(argv[i]) == MagickFalse)
5426 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5427 break;
5428 }
cristyebbcfea2011-02-25 02:43:54 +00005429 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5430 {
5431 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5432 break;
5433 }
cristy3ed852e2009-09-05 21:47:34 +00005434 if (LocaleCompare("reverse",option+1) == 0)
5435 break;
5436 if (LocaleCompare("roll",option+1) == 0)
5437 {
5438 if (*option == '+')
5439 break;
5440 i++;
cristybb503372010-05-27 20:51:26 +00005441 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005442 ThrowMogrifyException(OptionError,"MissingArgument",option);
5443 if (IsGeometry(argv[i]) == MagickFalse)
5444 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5445 break;
5446 }
5447 if (LocaleCompare("rotate",option+1) == 0)
5448 {
5449 i++;
cristybb503372010-05-27 20:51:26 +00005450 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005451 ThrowMogrifyException(OptionError,"MissingArgument",option);
5452 if (IsGeometry(argv[i]) == MagickFalse)
5453 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5454 break;
5455 }
5456 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5457 }
5458 case 's':
5459 {
5460 if (LocaleCompare("sample",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("sampling-factor",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("scale",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("scene",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("seed",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("segment",option+1) == 0)
5516 {
5517 if (*option == '+')
5518 break;
5519 i++;
cristybb503372010-05-27 20:51:26 +00005520 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005521 ThrowMogrifyException(OptionError,"MissingArgument",option);
5522 if (IsGeometry(argv[i]) == MagickFalse)
5523 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5524 break;
5525 }
5526 if (LocaleCompare("selective-blur",option+1) == 0)
5527 {
5528 i++;
cristybb503372010-05-27 20:51:26 +00005529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005530 ThrowMogrifyException(OptionError,"MissingArgument",option);
5531 if (IsGeometry(argv[i]) == MagickFalse)
5532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5533 break;
5534 }
5535 if (LocaleCompare("separate",option+1) == 0)
5536 break;
5537 if (LocaleCompare("sepia-tone",option+1) == 0)
5538 {
5539 if (*option == '+')
5540 break;
5541 i++;
cristybb503372010-05-27 20:51:26 +00005542 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005543 ThrowMogrifyException(OptionError,"MissingArgument",option);
5544 if (IsGeometry(argv[i]) == MagickFalse)
5545 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5546 break;
5547 }
5548 if (LocaleCompare("set",option+1) == 0)
5549 {
5550 i++;
cristybb503372010-05-27 20:51:26 +00005551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005552 ThrowMogrifyException(OptionError,"MissingArgument",option);
5553 if (*option == '+')
5554 break;
5555 i++;
cristybb503372010-05-27 20:51:26 +00005556 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005557 ThrowMogrifyException(OptionError,"MissingArgument",option);
5558 break;
5559 }
5560 if (LocaleCompare("shade",option+1) == 0)
5561 {
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("shadow",option+1) == 0)
5570 {
5571 if (*option == '+')
5572 break;
5573 i++;
cristybb503372010-05-27 20:51:26 +00005574 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005575 ThrowMogrifyException(OptionError,"MissingArgument",option);
5576 if (IsGeometry(argv[i]) == MagickFalse)
5577 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5578 break;
5579 }
5580 if (LocaleCompare("sharpen",option+1) == 0)
5581 {
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("shave",option+1) == 0)
5590 {
5591 if (*option == '+')
5592 break;
5593 i++;
cristybb503372010-05-27 20:51:26 +00005594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5598 break;
5599 }
5600 if (LocaleCompare("shear",option+1) == 0)
5601 {
5602 i++;
cristybb503372010-05-27 20:51:26 +00005603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005604 ThrowMogrifyException(OptionError,"MissingArgument",option);
5605 if (IsGeometry(argv[i]) == MagickFalse)
5606 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5607 break;
5608 }
5609 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5610 {
5611 i++;
cristybb503372010-05-27 20:51:26 +00005612 if (i == (ssize_t) (argc-1))
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("size",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 }
5629 if (LocaleCompare("sketch",option+1) == 0)
5630 {
5631 if (*option == '+')
5632 break;
5633 i++;
cristybb503372010-05-27 20:51:26 +00005634 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005635 ThrowMogrifyException(OptionError,"MissingArgument",option);
5636 if (IsGeometry(argv[i]) == MagickFalse)
5637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5638 break;
5639 }
cristy4285d782011-02-09 20:12:28 +00005640 if (LocaleCompare("smush",option+1) == 0)
5641 {
cristy4285d782011-02-09 20:12:28 +00005642 i++;
5643 if (i == (ssize_t) argc)
5644 ThrowMogrifyException(OptionError,"MissingArgument",option);
5645 if (IsGeometry(argv[i]) == MagickFalse)
5646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005647 i++;
5648 break;
5649 }
cristy3ed852e2009-09-05 21:47:34 +00005650 if (LocaleCompare("solarize",option+1) == 0)
5651 {
5652 if (*option == '+')
5653 break;
5654 i++;
cristybb503372010-05-27 20:51:26 +00005655 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005656 ThrowMogrifyException(OptionError,"MissingArgument",option);
5657 if (IsGeometry(argv[i]) == MagickFalse)
5658 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5659 break;
5660 }
5661 if (LocaleCompare("sparse-color",option+1) == 0)
5662 {
cristybb503372010-05-27 20:51:26 +00005663 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005664 op;
5665
5666 i++;
cristybb503372010-05-27 20:51:26 +00005667 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005668 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005669 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005670 if (op < 0)
5671 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5672 argv[i]);
5673 i++;
cristybb503372010-05-27 20:51:26 +00005674 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005675 ThrowMogrifyException(OptionError,"MissingArgument",option);
5676 break;
5677 }
5678 if (LocaleCompare("spread",option+1) == 0)
5679 {
5680 if (*option == '+')
5681 break;
5682 i++;
cristybb503372010-05-27 20:51:26 +00005683 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005684 ThrowMogrifyException(OptionError,"MissingArgument",option);
5685 if (IsGeometry(argv[i]) == MagickFalse)
5686 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5687 break;
5688 }
cristy0834d642011-03-18 18:26:08 +00005689 if (LocaleCompare("statistic",option+1) == 0)
5690 {
5691 ssize_t
5692 op;
5693
5694 if (*option == '+')
5695 break;
5696 i++;
5697 if (i == (ssize_t) argc)
5698 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005699 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005700 if (op < 0)
5701 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5702 argv[i]);
5703 i++;
5704 if (i == (ssize_t) (argc-1))
5705 ThrowMogrifyException(OptionError,"MissingArgument",option);
5706 if (IsGeometry(argv[i]) == MagickFalse)
5707 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5708 break;
5709 }
cristy3ed852e2009-09-05 21:47:34 +00005710 if (LocaleCompare("stretch",option+1) == 0)
5711 {
cristybb503372010-05-27 20:51:26 +00005712 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005713 stretch;
5714
5715 if (*option == '+')
5716 break;
5717 i++;
cristybb503372010-05-27 20:51:26 +00005718 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005719 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005720 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005721 if (stretch < 0)
5722 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5723 argv[i]);
5724 break;
5725 }
5726 if (LocaleCompare("strip",option+1) == 0)
5727 break;
5728 if (LocaleCompare("stroke",option+1) == 0)
5729 {
5730 if (*option == '+')
5731 break;
5732 i++;
cristybb503372010-05-27 20:51:26 +00005733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005734 ThrowMogrifyException(OptionError,"MissingArgument",option);
5735 break;
5736 }
5737 if (LocaleCompare("strokewidth",option+1) == 0)
5738 {
5739 if (*option == '+')
5740 break;
5741 i++;
cristybb503372010-05-27 20:51:26 +00005742 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005743 ThrowMogrifyException(OptionError,"MissingArgument",option);
5744 if (IsGeometry(argv[i]) == MagickFalse)
5745 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5746 break;
5747 }
5748 if (LocaleCompare("style",option+1) == 0)
5749 {
cristybb503372010-05-27 20:51:26 +00005750 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005751 style;
5752
5753 if (*option == '+')
5754 break;
5755 i++;
cristybb503372010-05-27 20:51:26 +00005756 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005757 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005758 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005759 if (style < 0)
5760 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5761 argv[i]);
5762 break;
5763 }
cristyecb10ff2011-03-22 13:14:03 +00005764 if (LocaleCompare("swap",option+1) == 0)
5765 {
5766 if (*option == '+')
5767 break;
5768 i++;
5769 if (i == (ssize_t) (argc-1))
5770 ThrowMogrifyException(OptionError,"MissingArgument",option);
5771 if (IsGeometry(argv[i]) == MagickFalse)
5772 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5773 break;
5774 }
cristy3ed852e2009-09-05 21:47:34 +00005775 if (LocaleCompare("swirl",option+1) == 0)
5776 {
5777 if (*option == '+')
5778 break;
5779 i++;
cristybb503372010-05-27 20:51:26 +00005780 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005781 ThrowMogrifyException(OptionError,"MissingArgument",option);
5782 if (IsGeometry(argv[i]) == MagickFalse)
5783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5784 break;
5785 }
cristyd9a29192010-10-16 16:49:53 +00005786 if (LocaleCompare("synchronize",option+1) == 0)
5787 break;
cristy3ed852e2009-09-05 21:47:34 +00005788 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5789 }
5790 case 't':
5791 {
5792 if (LocaleCompare("taint",option+1) == 0)
5793 break;
5794 if (LocaleCompare("texture",option+1) == 0)
5795 {
5796 if (*option == '+')
5797 break;
5798 i++;
cristybb503372010-05-27 20:51:26 +00005799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005800 ThrowMogrifyException(OptionError,"MissingArgument",option);
5801 break;
5802 }
5803 if (LocaleCompare("tile",option+1) == 0)
5804 {
5805 if (*option == '+')
5806 break;
5807 i++;
cristybb503372010-05-27 20:51:26 +00005808 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005809 ThrowMogrifyException(OptionError,"MissingArgument",option);
5810 break;
5811 }
5812 if (LocaleCompare("tile-offset",option+1) == 0)
5813 {
5814 if (*option == '+')
5815 break;
5816 i++;
cristybb503372010-05-27 20:51:26 +00005817 if (i == (ssize_t) argc)
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("tint",option+1) == 0)
5824 {
5825 if (*option == '+')
5826 break;
5827 i++;
cristybb503372010-05-27 20:51:26 +00005828 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005829 ThrowMogrifyException(OptionError,"MissingArgument",option);
5830 if (IsGeometry(argv[i]) == MagickFalse)
5831 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5832 break;
5833 }
5834 if (LocaleCompare("transform",option+1) == 0)
5835 break;
5836 if (LocaleCompare("transpose",option+1) == 0)
5837 break;
5838 if (LocaleCompare("transverse",option+1) == 0)
5839 break;
5840 if (LocaleCompare("threshold",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("thumbnail",option+1) == 0)
5852 {
5853 if (*option == '+')
5854 break;
5855 i++;
cristybb503372010-05-27 20:51:26 +00005856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005857 ThrowMogrifyException(OptionError,"MissingArgument",option);
5858 if (IsGeometry(argv[i]) == MagickFalse)
5859 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5860 break;
5861 }
5862 if (LocaleCompare("transparent",option+1) == 0)
5863 {
5864 i++;
cristybb503372010-05-27 20:51:26 +00005865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 break;
5868 }
5869 if (LocaleCompare("transparent-color",option+1) == 0)
5870 {
5871 if (*option == '+')
5872 break;
5873 i++;
cristybb503372010-05-27 20:51:26 +00005874 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005875 ThrowMogrifyException(OptionError,"MissingArgument",option);
5876 break;
5877 }
5878 if (LocaleCompare("treedepth",option+1) == 0)
5879 {
5880 if (*option == '+')
5881 break;
5882 i++;
cristybb503372010-05-27 20:51:26 +00005883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005884 ThrowMogrifyException(OptionError,"MissingArgument",option);
5885 if (IsGeometry(argv[i]) == MagickFalse)
5886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5887 break;
5888 }
5889 if (LocaleCompare("trim",option+1) == 0)
5890 break;
5891 if (LocaleCompare("type",option+1) == 0)
5892 {
cristybb503372010-05-27 20:51:26 +00005893 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005894 type;
5895
5896 if (*option == '+')
5897 break;
5898 i++;
cristybb503372010-05-27 20:51:26 +00005899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005900 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005901 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005902 if (type < 0)
5903 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5904 argv[i]);
5905 break;
5906 }
5907 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5908 }
5909 case 'u':
5910 {
5911 if (LocaleCompare("undercolor",option+1) == 0)
5912 {
5913 if (*option == '+')
5914 break;
5915 i++;
cristybb503372010-05-27 20:51:26 +00005916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005917 ThrowMogrifyException(OptionError,"MissingArgument",option);
5918 break;
5919 }
5920 if (LocaleCompare("unique-colors",option+1) == 0)
5921 break;
5922 if (LocaleCompare("units",option+1) == 0)
5923 {
cristybb503372010-05-27 20:51:26 +00005924 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005925 units;
5926
5927 if (*option == '+')
5928 break;
5929 i++;
cristybb503372010-05-27 20:51:26 +00005930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005931 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005932 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005933 argv[i]);
5934 if (units < 0)
5935 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5936 argv[i]);
5937 break;
5938 }
5939 if (LocaleCompare("unsharp",option+1) == 0)
5940 {
5941 i++;
cristybb503372010-05-27 20:51:26 +00005942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005943 ThrowMogrifyException(OptionError,"MissingArgument",option);
5944 if (IsGeometry(argv[i]) == MagickFalse)
5945 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5946 break;
5947 }
5948 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5949 }
5950 case 'v':
5951 {
5952 if (LocaleCompare("verbose",option+1) == 0)
5953 {
5954 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5955 break;
5956 }
5957 if ((LocaleCompare("version",option+1) == 0) ||
5958 (LocaleCompare("-version",option+1) == 0))
5959 {
cristyb51dff52011-05-19 16:55:47 +00005960 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005961 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005962 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5963 GetMagickCopyright());
5964 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5965 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005966 break;
5967 }
5968 if (LocaleCompare("view",option+1) == 0)
5969 {
5970 if (*option == '+')
5971 break;
5972 i++;
cristybb503372010-05-27 20:51:26 +00005973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005974 ThrowMogrifyException(OptionError,"MissingArgument",option);
5975 break;
5976 }
5977 if (LocaleCompare("vignette",option+1) == 0)
5978 {
5979 if (*option == '+')
5980 break;
5981 i++;
cristybb503372010-05-27 20:51:26 +00005982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005983 ThrowMogrifyException(OptionError,"MissingArgument",option);
5984 if (IsGeometry(argv[i]) == MagickFalse)
5985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5986 break;
5987 }
5988 if (LocaleCompare("virtual-pixel",option+1) == 0)
5989 {
cristybb503372010-05-27 20:51:26 +00005990 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005991 method;
5992
5993 if (*option == '+')
5994 break;
5995 i++;
cristybb503372010-05-27 20:51:26 +00005996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005997 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005998 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005999 argv[i]);
6000 if (method < 0)
6001 ThrowMogrifyException(OptionError,
6002 "UnrecognizedVirtualPixelMethod",argv[i]);
6003 break;
6004 }
6005 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6006 }
6007 case 'w':
6008 {
6009 if (LocaleCompare("wave",option+1) == 0)
6010 {
6011 i++;
cristybb503372010-05-27 20:51:26 +00006012 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006013 ThrowMogrifyException(OptionError,"MissingArgument",option);
6014 if (IsGeometry(argv[i]) == MagickFalse)
6015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6016 break;
6017 }
6018 if (LocaleCompare("weight",option+1) == 0)
6019 {
6020 if (*option == '+')
6021 break;
6022 i++;
cristybb503372010-05-27 20:51:26 +00006023 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006024 ThrowMogrifyException(OptionError,"MissingArgument",option);
6025 break;
6026 }
6027 if (LocaleCompare("white-point",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("white-threshold",option+1) == 0)
6039 {
6040 if (*option == '+')
6041 break;
6042 i++;
cristybb503372010-05-27 20:51:26 +00006043 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006044 ThrowMogrifyException(OptionError,"MissingArgument",option);
6045 if (IsGeometry(argv[i]) == MagickFalse)
6046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6047 break;
6048 }
6049 if (LocaleCompare("write",option+1) == 0)
6050 {
6051 i++;
cristybb503372010-05-27 20:51:26 +00006052 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006053 ThrowMogrifyException(OptionError,"MissingArgument",option);
6054 break;
6055 }
6056 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6057 }
6058 case '?':
6059 break;
6060 default:
6061 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6062 }
cristy042ee782011-04-22 18:48:30 +00006063 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6064 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006065 if (fire != MagickFalse)
6066 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6067 }
6068 if (k != 0)
6069 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006070 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006071 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6072 DestroyMogrify();
6073 return(status != 0 ? MagickTrue : MagickFalse);
6074}
6075
6076/*
6077%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6078% %
6079% %
6080% %
6081+ M o g r i f y I m a g e I n f o %
6082% %
6083% %
6084% %
6085%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6086%
6087% MogrifyImageInfo() applies image processing settings to the image as
6088% prescribed by command line options.
6089%
6090% The format of the MogrifyImageInfo method is:
6091%
6092% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6093% const char **argv,ExceptionInfo *exception)
6094%
6095% A description of each parameter follows:
6096%
6097% o image_info: the image info..
6098%
6099% o argc: Specifies a pointer to an integer describing the number of
6100% elements in the argument vector.
6101%
6102% o argv: Specifies a pointer to a text array containing the command line
6103% arguments.
6104%
6105% o exception: return any errors or warnings in this structure.
6106%
6107*/
6108WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6109 const int argc,const char **argv,ExceptionInfo *exception)
6110{
6111 const char
6112 *option;
6113
6114 GeometryInfo
6115 geometry_info;
6116
cristybb503372010-05-27 20:51:26 +00006117 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006118 count;
6119
cristybb503372010-05-27 20:51:26 +00006120 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006121 i;
6122
6123 /*
6124 Initialize method variables.
6125 */
6126 assert(image_info != (ImageInfo *) NULL);
6127 assert(image_info->signature == MagickSignature);
6128 if (image_info->debug != MagickFalse)
6129 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6130 image_info->filename);
6131 if (argc < 0)
6132 return(MagickTrue);
6133 /*
6134 Set the image settings.
6135 */
cristybb503372010-05-27 20:51:26 +00006136 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006137 {
6138 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006139 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006140 continue;
cristy042ee782011-04-22 18:48:30 +00006141 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006142 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006143 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006144 break;
6145 switch (*(option+1))
6146 {
6147 case 'a':
6148 {
6149 if (LocaleCompare("adjoin",option+1) == 0)
6150 {
6151 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6152 break;
6153 }
6154 if (LocaleCompare("antialias",option+1) == 0)
6155 {
6156 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6157 break;
6158 }
cristy3ed852e2009-09-05 21:47:34 +00006159 if (LocaleCompare("authenticate",option+1) == 0)
6160 {
6161 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006162 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006163 else
anthony1afdc7a2011-10-05 11:54:28 +00006164 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006165 break;
6166 }
6167 break;
6168 }
6169 case 'b':
6170 {
6171 if (LocaleCompare("background",option+1) == 0)
6172 {
6173 if (*option == '+')
6174 {
6175 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006176 (void) QueryColorCompliance(MogrifyBackgroundColor,
6177 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006178 break;
6179 }
6180 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006181 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6182 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006183 break;
6184 }
6185 if (LocaleCompare("bias",option+1) == 0)
6186 {
6187 if (*option == '+')
6188 {
6189 (void) SetImageOption(image_info,option+1,"0.0");
6190 break;
6191 }
6192 (void) SetImageOption(image_info,option+1,argv[i+1]);
6193 break;
6194 }
6195 if (LocaleCompare("black-point-compensation",option+1) == 0)
6196 {
6197 if (*option == '+')
6198 {
6199 (void) SetImageOption(image_info,option+1,"false");
6200 break;
6201 }
6202 (void) SetImageOption(image_info,option+1,"true");
6203 break;
6204 }
6205 if (LocaleCompare("blue-primary",option+1) == 0)
6206 {
6207 if (*option == '+')
6208 {
6209 (void) SetImageOption(image_info,option+1,"0.0");
6210 break;
6211 }
6212 (void) SetImageOption(image_info,option+1,argv[i+1]);
6213 break;
6214 }
6215 if (LocaleCompare("bordercolor",option+1) == 0)
6216 {
6217 if (*option == '+')
6218 {
6219 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006220 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006221 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006222 break;
6223 }
cristy9950d572011-10-01 18:22:35 +00006224 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6225 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006226 (void) SetImageOption(image_info,option+1,argv[i+1]);
6227 break;
6228 }
6229 if (LocaleCompare("box",option+1) == 0)
6230 {
6231 if (*option == '+')
6232 {
6233 (void) SetImageOption(image_info,"undercolor","none");
6234 break;
6235 }
6236 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6237 break;
6238 }
6239 break;
6240 }
6241 case 'c':
6242 {
6243 if (LocaleCompare("cache",option+1) == 0)
6244 {
6245 MagickSizeType
6246 limit;
6247
6248 limit=MagickResourceInfinity;
6249 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006250 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006251 (void) SetMagickResourceLimit(MemoryResource,limit);
6252 (void) SetMagickResourceLimit(MapResource,2*limit);
6253 break;
6254 }
6255 if (LocaleCompare("caption",option+1) == 0)
6256 {
6257 if (*option == '+')
6258 {
6259 (void) DeleteImageOption(image_info,option+1);
6260 break;
6261 }
6262 (void) SetImageOption(image_info,option+1,argv[i+1]);
6263 break;
6264 }
6265 if (LocaleCompare("channel",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 {
6269 image_info->channel=DefaultChannels;
6270 break;
6271 }
6272 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6273 break;
6274 }
cristy3ed852e2009-09-05 21:47:34 +00006275 if (LocaleCompare("colorspace",option+1) == 0)
6276 {
6277 if (*option == '+')
6278 {
6279 image_info->colorspace=UndefinedColorspace;
6280 (void) SetImageOption(image_info,option+1,"undefined");
6281 break;
6282 }
cristy042ee782011-04-22 18:48:30 +00006283 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006284 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6285 (void) SetImageOption(image_info,option+1,argv[i+1]);
6286 break;
6287 }
cristy3ed852e2009-09-05 21:47:34 +00006288 if (LocaleCompare("comment",option+1) == 0)
6289 {
6290 if (*option == '+')
6291 {
6292 (void) DeleteImageOption(image_info,option+1);
6293 break;
6294 }
6295 (void) SetImageOption(image_info,option+1,argv[i+1]);
6296 break;
6297 }
6298 if (LocaleCompare("compose",option+1) == 0)
6299 {
6300 if (*option == '+')
6301 {
6302 (void) SetImageOption(image_info,option+1,"undefined");
6303 break;
6304 }
6305 (void) SetImageOption(image_info,option+1,argv[i+1]);
6306 break;
6307 }
6308 if (LocaleCompare("compress",option+1) == 0)
6309 {
6310 if (*option == '+')
6311 {
6312 image_info->compression=UndefinedCompression;
6313 (void) SetImageOption(image_info,option+1,"undefined");
6314 break;
6315 }
cristy042ee782011-04-22 18:48:30 +00006316 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006317 MagickCompressOptions,MagickFalse,argv[i+1]);
6318 (void) SetImageOption(image_info,option+1,argv[i+1]);
6319 break;
6320 }
6321 break;
6322 }
6323 case 'd':
6324 {
6325 if (LocaleCompare("debug",option+1) == 0)
6326 {
6327 if (*option == '+')
6328 (void) SetLogEventMask("none");
6329 else
6330 (void) SetLogEventMask(argv[i+1]);
6331 image_info->debug=IsEventLogging();
6332 break;
6333 }
6334 if (LocaleCompare("define",option+1) == 0)
6335 {
6336 if (*option == '+')
6337 {
6338 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6339 (void) DeleteImageRegistry(argv[i+1]+9);
6340 else
6341 (void) DeleteImageOption(image_info,argv[i+1]);
6342 break;
6343 }
6344 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6345 {
6346 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6347 exception);
6348 break;
6349 }
6350 (void) DefineImageOption(image_info,argv[i+1]);
6351 break;
6352 }
6353 if (LocaleCompare("delay",option+1) == 0)
6354 {
6355 if (*option == '+')
6356 {
6357 (void) SetImageOption(image_info,option+1,"0");
6358 break;
6359 }
6360 (void) SetImageOption(image_info,option+1,argv[i+1]);
6361 break;
6362 }
6363 if (LocaleCompare("density",option+1) == 0)
6364 {
6365 /*
6366 Set image density.
6367 */
6368 if (*option == '+')
6369 {
6370 if (image_info->density != (char *) NULL)
6371 image_info->density=DestroyString(image_info->density);
6372 (void) SetImageOption(image_info,option+1,"72");
6373 break;
6374 }
6375 (void) CloneString(&image_info->density,argv[i+1]);
6376 (void) SetImageOption(image_info,option+1,argv[i+1]);
6377 break;
6378 }
6379 if (LocaleCompare("depth",option+1) == 0)
6380 {
6381 if (*option == '+')
6382 {
6383 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6384 break;
6385 }
cristye27293e2009-12-18 02:53:20 +00006386 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006387 break;
6388 }
cristyc9b12952010-03-28 01:12:28 +00006389 if (LocaleCompare("direction",option+1) == 0)
6390 {
6391 if (*option == '+')
6392 {
6393 (void) SetImageOption(image_info,option+1,"undefined");
6394 break;
6395 }
6396 (void) SetImageOption(image_info,option+1,argv[i+1]);
6397 break;
6398 }
cristy3ed852e2009-09-05 21:47:34 +00006399 if (LocaleCompare("display",option+1) == 0)
6400 {
6401 if (*option == '+')
6402 {
6403 if (image_info->server_name != (char *) NULL)
6404 image_info->server_name=DestroyString(
6405 image_info->server_name);
6406 break;
6407 }
6408 (void) CloneString(&image_info->server_name,argv[i+1]);
6409 break;
6410 }
6411 if (LocaleCompare("dispose",option+1) == 0)
6412 {
6413 if (*option == '+')
6414 {
6415 (void) SetImageOption(image_info,option+1,"undefined");
6416 break;
6417 }
6418 (void) SetImageOption(image_info,option+1,argv[i+1]);
6419 break;
6420 }
6421 if (LocaleCompare("dither",option+1) == 0)
6422 {
6423 if (*option == '+')
6424 {
6425 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006426 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006427 break;
6428 }
6429 (void) SetImageOption(image_info,option+1,argv[i+1]);
6430 image_info->dither=MagickTrue;
6431 break;
6432 }
6433 break;
6434 }
6435 case 'e':
6436 {
6437 if (LocaleCompare("encoding",option+1) == 0)
6438 {
6439 if (*option == '+')
6440 {
6441 (void) SetImageOption(image_info,option+1,"undefined");
6442 break;
6443 }
6444 (void) SetImageOption(image_info,option+1,argv[i+1]);
6445 break;
6446 }
6447 if (LocaleCompare("endian",option+1) == 0)
6448 {
6449 if (*option == '+')
6450 {
6451 image_info->endian=UndefinedEndian;
6452 (void) SetImageOption(image_info,option+1,"undefined");
6453 break;
6454 }
cristy042ee782011-04-22 18:48:30 +00006455 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006456 MagickEndianOptions,MagickFalse,argv[i+1]);
6457 (void) SetImageOption(image_info,option+1,argv[i+1]);
6458 break;
6459 }
6460 if (LocaleCompare("extract",option+1) == 0)
6461 {
6462 /*
6463 Set image extract geometry.
6464 */
6465 if (*option == '+')
6466 {
6467 if (image_info->extract != (char *) NULL)
6468 image_info->extract=DestroyString(image_info->extract);
6469 break;
6470 }
6471 (void) CloneString(&image_info->extract,argv[i+1]);
6472 break;
6473 }
6474 break;
6475 }
6476 case 'f':
6477 {
6478 if (LocaleCompare("fill",option+1) == 0)
6479 {
6480 if (*option == '+')
6481 {
6482 (void) SetImageOption(image_info,option+1,"none");
6483 break;
6484 }
6485 (void) SetImageOption(image_info,option+1,argv[i+1]);
6486 break;
6487 }
6488 if (LocaleCompare("filter",option+1) == 0)
6489 {
6490 if (*option == '+')
6491 {
6492 (void) SetImageOption(image_info,option+1,"undefined");
6493 break;
6494 }
6495 (void) SetImageOption(image_info,option+1,argv[i+1]);
6496 break;
6497 }
6498 if (LocaleCompare("font",option+1) == 0)
6499 {
6500 if (*option == '+')
6501 {
6502 if (image_info->font != (char *) NULL)
6503 image_info->font=DestroyString(image_info->font);
6504 break;
6505 }
6506 (void) CloneString(&image_info->font,argv[i+1]);
6507 break;
6508 }
6509 if (LocaleCompare("format",option+1) == 0)
6510 {
6511 register const char
6512 *q;
6513
6514 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006515 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006516 image_info->ping=MagickFalse;
6517 (void) SetImageOption(image_info,option+1,argv[i+1]);
6518 break;
6519 }
6520 if (LocaleCompare("fuzz",option+1) == 0)
6521 {
6522 if (*option == '+')
6523 {
6524 image_info->fuzz=0.0;
6525 (void) SetImageOption(image_info,option+1,"0");
6526 break;
6527 }
cristyf2f27272009-12-17 14:48:46 +00006528 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006529 1.0);
6530 (void) SetImageOption(image_info,option+1,argv[i+1]);
6531 break;
6532 }
6533 break;
6534 }
6535 case 'g':
6536 {
6537 if (LocaleCompare("gravity",option+1) == 0)
6538 {
6539 if (*option == '+')
6540 {
6541 (void) SetImageOption(image_info,option+1,"undefined");
6542 break;
6543 }
6544 (void) SetImageOption(image_info,option+1,argv[i+1]);
6545 break;
6546 }
6547 if (LocaleCompare("green-primary",option+1) == 0)
6548 {
6549 if (*option == '+')
6550 {
6551 (void) SetImageOption(image_info,option+1,"0.0");
6552 break;
6553 }
6554 (void) SetImageOption(image_info,option+1,argv[i+1]);
6555 break;
6556 }
6557 break;
6558 }
6559 case 'i':
6560 {
6561 if (LocaleCompare("intent",option+1) == 0)
6562 {
6563 if (*option == '+')
6564 {
6565 (void) SetImageOption(image_info,option+1,"undefined");
6566 break;
6567 }
6568 (void) SetImageOption(image_info,option+1,argv[i+1]);
6569 break;
6570 }
6571 if (LocaleCompare("interlace",option+1) == 0)
6572 {
6573 if (*option == '+')
6574 {
6575 image_info->interlace=UndefinedInterlace;
6576 (void) SetImageOption(image_info,option+1,"undefined");
6577 break;
6578 }
cristy042ee782011-04-22 18:48:30 +00006579 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006580 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
cristyb32b90a2009-09-07 21:45:48 +00006584 if (LocaleCompare("interline-spacing",option+1) == 0)
6585 {
6586 if (*option == '+')
6587 {
6588 (void) SetImageOption(image_info,option+1,"undefined");
6589 break;
6590 }
6591 (void) SetImageOption(image_info,option+1,argv[i+1]);
6592 break;
6593 }
cristy3ed852e2009-09-05 21:47:34 +00006594 if (LocaleCompare("interpolate",option+1) == 0)
6595 {
6596 if (*option == '+')
6597 {
6598 (void) SetImageOption(image_info,option+1,"undefined");
6599 break;
6600 }
6601 (void) SetImageOption(image_info,option+1,argv[i+1]);
6602 break;
6603 }
6604 if (LocaleCompare("interword-spacing",option+1) == 0)
6605 {
6606 if (*option == '+')
6607 {
6608 (void) SetImageOption(image_info,option+1,"undefined");
6609 break;
6610 }
6611 (void) SetImageOption(image_info,option+1,argv[i+1]);
6612 break;
6613 }
6614 break;
6615 }
6616 case 'k':
6617 {
6618 if (LocaleCompare("kerning",option+1) == 0)
6619 {
6620 if (*option == '+')
6621 {
6622 (void) SetImageOption(image_info,option+1,"undefined");
6623 break;
6624 }
6625 (void) SetImageOption(image_info,option+1,argv[i+1]);
6626 break;
6627 }
6628 break;
6629 }
6630 case 'l':
6631 {
6632 if (LocaleCompare("label",option+1) == 0)
6633 {
6634 if (*option == '+')
6635 {
6636 (void) DeleteImageOption(image_info,option+1);
6637 break;
6638 }
6639 (void) SetImageOption(image_info,option+1,argv[i+1]);
6640 break;
6641 }
6642 if (LocaleCompare("limit",option+1) == 0)
6643 {
6644 MagickSizeType
6645 limit;
6646
6647 ResourceType
6648 type;
6649
6650 if (*option == '+')
6651 break;
cristy042ee782011-04-22 18:48:30 +00006652 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006653 MagickFalse,argv[i+1]);
6654 limit=MagickResourceInfinity;
6655 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006656 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006657 (void) SetMagickResourceLimit(type,limit);
6658 break;
6659 }
6660 if (LocaleCompare("list",option+1) == 0)
6661 {
cristybb503372010-05-27 20:51:26 +00006662 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006663 list;
6664
6665 /*
6666 Display configuration list.
6667 */
cristy042ee782011-04-22 18:48:30 +00006668 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006669 switch (list)
6670 {
6671 case MagickCoderOptions:
6672 {
6673 (void) ListCoderInfo((FILE *) NULL,exception);
6674 break;
6675 }
6676 case MagickColorOptions:
6677 {
6678 (void) ListColorInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickConfigureOptions:
6682 {
6683 (void) ListConfigureInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickDelegateOptions:
6687 {
6688 (void) ListDelegateInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickFontOptions:
6692 {
6693 (void) ListTypeInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickFormatOptions:
6697 {
6698 (void) ListMagickInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickLocaleOptions:
6702 {
6703 (void) ListLocaleInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickLogOptions:
6707 {
6708 (void) ListLogInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickMagicOptions:
6712 {
6713 (void) ListMagicInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickMimeOptions:
6717 {
6718 (void) ListMimeInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickModuleOptions:
6722 {
6723 (void) ListModuleInfo((FILE *) NULL,exception);
6724 break;
6725 }
6726 case MagickPolicyOptions:
6727 {
6728 (void) ListPolicyInfo((FILE *) NULL,exception);
6729 break;
6730 }
6731 case MagickResourceOptions:
6732 {
6733 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6734 break;
6735 }
6736 case MagickThresholdOptions:
6737 {
6738 (void) ListThresholdMaps((FILE *) NULL,exception);
6739 break;
6740 }
6741 default:
6742 {
cristy042ee782011-04-22 18:48:30 +00006743 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006744 exception);
6745 break;
6746 }
6747 }
cristyaeb2cbc2010-05-07 13:28:58 +00006748 break;
cristy3ed852e2009-09-05 21:47:34 +00006749 }
6750 if (LocaleCompare("log",option+1) == 0)
6751 {
6752 if (*option == '+')
6753 break;
6754 (void) SetLogFormat(argv[i+1]);
6755 break;
6756 }
6757 if (LocaleCompare("loop",option+1) == 0)
6758 {
6759 if (*option == '+')
6760 {
6761 (void) SetImageOption(image_info,option+1,"0");
6762 break;
6763 }
6764 (void) SetImageOption(image_info,option+1,argv[i+1]);
6765 break;
6766 }
6767 break;
6768 }
6769 case 'm':
6770 {
6771 if (LocaleCompare("matte",option+1) == 0)
6772 {
6773 if (*option == '+')
6774 {
6775 (void) SetImageOption(image_info,option+1,"false");
6776 break;
6777 }
6778 (void) SetImageOption(image_info,option+1,"true");
6779 break;
6780 }
6781 if (LocaleCompare("mattecolor",option+1) == 0)
6782 {
6783 if (*option == '+')
6784 {
6785 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006786 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006787 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006788 break;
6789 }
6790 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006791 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6792 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006793 break;
6794 }
6795 if (LocaleCompare("monitor",option+1) == 0)
6796 {
6797 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6798 (void *) NULL);
6799 break;
6800 }
6801 if (LocaleCompare("monochrome",option+1) == 0)
6802 {
6803 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6804 break;
6805 }
6806 break;
6807 }
6808 case 'o':
6809 {
6810 if (LocaleCompare("orient",option+1) == 0)
6811 {
6812 if (*option == '+')
6813 {
6814 image_info->orientation=UndefinedOrientation;
6815 (void) SetImageOption(image_info,option+1,"undefined");
6816 break;
6817 }
cristy042ee782011-04-22 18:48:30 +00006818 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006819 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006820 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006821 break;
6822 }
6823 }
6824 case 'p':
6825 {
6826 if (LocaleCompare("page",option+1) == 0)
6827 {
6828 char
6829 *canonical_page,
6830 page[MaxTextExtent];
6831
6832 const char
6833 *image_option;
6834
6835 MagickStatusType
6836 flags;
6837
6838 RectangleInfo
6839 geometry;
6840
6841 if (*option == '+')
6842 {
6843 (void) DeleteImageOption(image_info,option+1);
6844 (void) CloneString(&image_info->page,(char *) NULL);
6845 break;
6846 }
6847 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6848 image_option=GetImageOption(image_info,"page");
6849 if (image_option != (const char *) NULL)
6850 flags=ParseAbsoluteGeometry(image_option,&geometry);
6851 canonical_page=GetPageGeometry(argv[i+1]);
6852 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6853 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006854 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006855 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006856 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006857 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006858 (unsigned long) geometry.width,(unsigned long) geometry.height,
6859 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006860 (void) SetImageOption(image_info,option+1,page);
6861 (void) CloneString(&image_info->page,page);
6862 break;
6863 }
6864 if (LocaleCompare("pen",option+1) == 0)
6865 {
6866 if (*option == '+')
6867 {
6868 (void) SetImageOption(image_info,option+1,"none");
6869 break;
6870 }
6871 (void) SetImageOption(image_info,option+1,argv[i+1]);
6872 break;
6873 }
6874 if (LocaleCompare("ping",option+1) == 0)
6875 {
6876 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6877 break;
6878 }
6879 if (LocaleCompare("pointsize",option+1) == 0)
6880 {
6881 if (*option == '+')
6882 geometry_info.rho=0.0;
6883 else
6884 (void) ParseGeometry(argv[i+1],&geometry_info);
6885 image_info->pointsize=geometry_info.rho;
6886 break;
6887 }
cristye7f51092010-01-17 00:39:37 +00006888 if (LocaleCompare("precision",option+1) == 0)
6889 {
cristybf2766a2010-01-17 03:33:23 +00006890 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006891 break;
6892 }
cristy3ed852e2009-09-05 21:47:34 +00006893 if (LocaleCompare("preview",option+1) == 0)
6894 {
6895 /*
6896 Preview image.
6897 */
6898 if (*option == '+')
6899 {
6900 image_info->preview_type=UndefinedPreview;
6901 break;
6902 }
cristy042ee782011-04-22 18:48:30 +00006903 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006904 MagickPreviewOptions,MagickFalse,argv[i+1]);
6905 break;
6906 }
6907 break;
6908 }
6909 case 'q':
6910 {
6911 if (LocaleCompare("quality",option+1) == 0)
6912 {
6913 /*
6914 Set image compression quality.
6915 */
6916 if (*option == '+')
6917 {
6918 image_info->quality=UndefinedCompressionQuality;
6919 (void) SetImageOption(image_info,option+1,"0");
6920 break;
6921 }
cristye27293e2009-12-18 02:53:20 +00006922 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006923 (void) SetImageOption(image_info,option+1,argv[i+1]);
6924 break;
6925 }
6926 if (LocaleCompare("quiet",option+1) == 0)
6927 {
6928 static WarningHandler
6929 warning_handler = (WarningHandler) NULL;
6930
6931 if (*option == '+')
6932 {
6933 /*
6934 Restore error or warning messages.
6935 */
6936 warning_handler=SetWarningHandler(warning_handler);
6937 break;
6938 }
6939 /*
6940 Suppress error or warning messages.
6941 */
6942 warning_handler=SetWarningHandler((WarningHandler) NULL);
6943 break;
6944 }
6945 break;
6946 }
6947 case 'r':
6948 {
6949 if (LocaleCompare("red-primary",option+1) == 0)
6950 {
6951 if (*option == '+')
6952 {
6953 (void) SetImageOption(image_info,option+1,"0.0");
6954 break;
6955 }
6956 (void) SetImageOption(image_info,option+1,argv[i+1]);
6957 break;
6958 }
6959 break;
6960 }
6961 case 's':
6962 {
6963 if (LocaleCompare("sampling-factor",option+1) == 0)
6964 {
6965 /*
6966 Set image sampling factor.
6967 */
6968 if (*option == '+')
6969 {
6970 if (image_info->sampling_factor != (char *) NULL)
6971 image_info->sampling_factor=DestroyString(
6972 image_info->sampling_factor);
6973 break;
6974 }
6975 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6976 break;
6977 }
6978 if (LocaleCompare("scene",option+1) == 0)
6979 {
6980 /*
6981 Set image scene.
6982 */
6983 if (*option == '+')
6984 {
6985 image_info->scene=0;
6986 (void) SetImageOption(image_info,option+1,"0");
6987 break;
6988 }
cristye27293e2009-12-18 02:53:20 +00006989 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006990 (void) SetImageOption(image_info,option+1,argv[i+1]);
6991 break;
6992 }
6993 if (LocaleCompare("seed",option+1) == 0)
6994 {
cristybb503372010-05-27 20:51:26 +00006995 size_t
cristy3ed852e2009-09-05 21:47:34 +00006996 seed;
6997
6998 if (*option == '+')
6999 {
cristybb503372010-05-27 20:51:26 +00007000 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007001 SeedPseudoRandomGenerator(seed);
7002 break;
7003 }
cristye27293e2009-12-18 02:53:20 +00007004 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007005 SeedPseudoRandomGenerator(seed);
7006 break;
7007 }
7008 if (LocaleCompare("size",option+1) == 0)
7009 {
7010 if (*option == '+')
7011 {
7012 if (image_info->size != (char *) NULL)
7013 image_info->size=DestroyString(image_info->size);
7014 break;
7015 }
7016 (void) CloneString(&image_info->size,argv[i+1]);
7017 break;
7018 }
7019 if (LocaleCompare("stroke",option+1) == 0)
7020 {
7021 if (*option == '+')
7022 {
7023 (void) SetImageOption(image_info,option+1,"none");
7024 break;
7025 }
7026 (void) SetImageOption(image_info,option+1,argv[i+1]);
7027 break;
7028 }
7029 if (LocaleCompare("strokewidth",option+1) == 0)
7030 {
7031 if (*option == '+')
7032 {
7033 (void) SetImageOption(image_info,option+1,"0");
7034 break;
7035 }
7036 (void) SetImageOption(image_info,option+1,argv[i+1]);
7037 break;
7038 }
cristyd9a29192010-10-16 16:49:53 +00007039 if (LocaleCompare("synchronize",option+1) == 0)
7040 {
7041 if (*option == '+')
7042 {
7043 image_info->synchronize=MagickFalse;
7044 break;
7045 }
7046 image_info->synchronize=MagickTrue;
7047 break;
7048 }
cristy3ed852e2009-09-05 21:47:34 +00007049 break;
7050 }
7051 case 't':
7052 {
7053 if (LocaleCompare("taint",option+1) == 0)
7054 {
7055 if (*option == '+')
7056 {
7057 (void) SetImageOption(image_info,option+1,"false");
7058 break;
7059 }
7060 (void) SetImageOption(image_info,option+1,"true");
7061 break;
7062 }
7063 if (LocaleCompare("texture",option+1) == 0)
7064 {
7065 if (*option == '+')
7066 {
7067 if (image_info->texture != (char *) NULL)
7068 image_info->texture=DestroyString(image_info->texture);
7069 break;
7070 }
7071 (void) CloneString(&image_info->texture,argv[i+1]);
7072 break;
7073 }
7074 if (LocaleCompare("tile-offset",option+1) == 0)
7075 {
7076 if (*option == '+')
7077 {
7078 (void) SetImageOption(image_info,option+1,"0");
7079 break;
7080 }
7081 (void) SetImageOption(image_info,option+1,argv[i+1]);
7082 break;
7083 }
7084 if (LocaleCompare("transparent-color",option+1) == 0)
7085 {
7086 if (*option == '+')
7087 {
cristy9950d572011-10-01 18:22:35 +00007088 (void) QueryColorCompliance("none",AllCompliance,
7089 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007090 (void) SetImageOption(image_info,option+1,"none");
7091 break;
7092 }
cristy9950d572011-10-01 18:22:35 +00007093 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7094 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007095 (void) SetImageOption(image_info,option+1,argv[i+1]);
7096 break;
7097 }
7098 if (LocaleCompare("type",option+1) == 0)
7099 {
7100 if (*option == '+')
7101 {
cristy5f1c1ff2010-12-23 21:38:06 +00007102 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007103 (void) SetImageOption(image_info,option+1,"undefined");
7104 break;
7105 }
cristy042ee782011-04-22 18:48:30 +00007106 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007107 MagickFalse,argv[i+1]);
7108 (void) SetImageOption(image_info,option+1,argv[i+1]);
7109 break;
7110 }
7111 break;
7112 }
7113 case 'u':
7114 {
7115 if (LocaleCompare("undercolor",option+1) == 0)
7116 {
7117 if (*option == '+')
7118 {
7119 (void) DeleteImageOption(image_info,option+1);
7120 break;
7121 }
7122 (void) SetImageOption(image_info,option+1,argv[i+1]);
7123 break;
7124 }
7125 if (LocaleCompare("units",option+1) == 0)
7126 {
7127 if (*option == '+')
7128 {
7129 image_info->units=UndefinedResolution;
7130 (void) SetImageOption(image_info,option+1,"undefined");
7131 break;
7132 }
cristy042ee782011-04-22 18:48:30 +00007133 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007134 MagickResolutionOptions,MagickFalse,argv[i+1]);
7135 (void) SetImageOption(image_info,option+1,argv[i+1]);
7136 break;
7137 }
7138 break;
7139 }
7140 case 'v':
7141 {
7142 if (LocaleCompare("verbose",option+1) == 0)
7143 {
7144 if (*option == '+')
7145 {
7146 image_info->verbose=MagickFalse;
7147 break;
7148 }
7149 image_info->verbose=MagickTrue;
7150 image_info->ping=MagickFalse;
7151 break;
7152 }
7153 if (LocaleCompare("view",option+1) == 0)
7154 {
7155 if (*option == '+')
7156 {
7157 if (image_info->view != (char *) NULL)
7158 image_info->view=DestroyString(image_info->view);
7159 break;
7160 }
7161 (void) CloneString(&image_info->view,argv[i+1]);
7162 break;
7163 }
7164 if (LocaleCompare("virtual-pixel",option+1) == 0)
7165 {
7166 if (*option == '+')
7167 {
7168 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7169 (void) SetImageOption(image_info,option+1,"undefined");
7170 break;
7171 }
7172 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007173 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007174 argv[i+1]);
7175 (void) SetImageOption(image_info,option+1,argv[i+1]);
7176 break;
7177 }
7178 break;
7179 }
7180 case 'w':
7181 {
7182 if (LocaleCompare("white-point",option+1) == 0)
7183 {
7184 if (*option == '+')
7185 {
7186 (void) SetImageOption(image_info,option+1,"0.0");
7187 break;
7188 }
7189 (void) SetImageOption(image_info,option+1,argv[i+1]);
7190 break;
7191 }
7192 break;
7193 }
7194 default:
7195 break;
7196 }
7197 i+=count;
7198 }
7199 return(MagickTrue);
7200}
7201
7202/*
7203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7204% %
7205% %
7206% %
7207+ M o g r i f y I m a g e L i s t %
7208% %
7209% %
7210% %
7211%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7212%
7213% MogrifyImageList() applies any command line options that might affect the
7214% entire image list (e.g. -append, -coalesce, etc.).
7215%
7216% The format of the MogrifyImage method is:
7217%
7218% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7219% const char **argv,Image **images,ExceptionInfo *exception)
7220%
7221% A description of each parameter follows:
7222%
7223% o image_info: the image info..
7224%
7225% o argc: Specifies a pointer to an integer describing the number of
7226% elements in the argument vector.
7227%
7228% o argv: Specifies a pointer to a text array containing the command line
7229% arguments.
7230%
anthonye9c27192011-03-27 08:07:06 +00007231% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007232%
7233% o exception: return any errors or warnings in this structure.
7234%
7235*/
7236WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7237 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7238{
cristy3ed852e2009-09-05 21:47:34 +00007239 const char
7240 *option;
7241
cristy6b3da3a2010-06-20 02:21:46 +00007242 ImageInfo
7243 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007244
7245 MagickStatusType
7246 status;
7247
cristy28474bf2011-09-11 23:32:52 +00007248 PixelInterpolateMethod
7249 interpolate_method;
7250
cristy3ed852e2009-09-05 21:47:34 +00007251 QuantizeInfo
7252 *quantize_info;
7253
cristybb503372010-05-27 20:51:26 +00007254 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007255 i;
7256
cristy6b3da3a2010-06-20 02:21:46 +00007257 ssize_t
7258 count,
7259 index;
7260
cristy3ed852e2009-09-05 21:47:34 +00007261 /*
7262 Apply options to the image list.
7263 */
7264 assert(image_info != (ImageInfo *) NULL);
7265 assert(image_info->signature == MagickSignature);
7266 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007267 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007268 assert((*images)->signature == MagickSignature);
7269 if ((*images)->debug != MagickFalse)
7270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7271 (*images)->filename);
7272 if ((argc <= 0) || (*argv == (char *) NULL))
7273 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007274 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007275 mogrify_info=CloneImageInfo(image_info);
7276 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007277 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007278 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007279 {
cristy74fe8f12009-10-03 19:09:01 +00007280 if (*images == (Image *) NULL)
7281 break;
cristy3ed852e2009-09-05 21:47:34 +00007282 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007283 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007284 continue;
cristy042ee782011-04-22 18:48:30 +00007285 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007286 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007287 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007288 break;
cristy6b3da3a2010-06-20 02:21:46 +00007289 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007290 switch (*(option+1))
7291 {
7292 case 'a':
7293 {
7294 if (LocaleCompare("affinity",option+1) == 0)
7295 {
cristy6b3da3a2010-06-20 02:21:46 +00007296 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007297 if (*option == '+')
7298 {
cristy018f07f2011-09-04 21:15:19 +00007299 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7300 exception);
cristy3ed852e2009-09-05 21:47:34 +00007301 break;
7302 }
7303 i++;
7304 break;
7305 }
7306 if (LocaleCompare("append",option+1) == 0)
7307 {
7308 Image
7309 *append_image;
7310
cristy6b3da3a2010-06-20 02:21:46 +00007311 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007312 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7313 MagickFalse,exception);
7314 if (append_image == (Image *) NULL)
7315 {
7316 status=MagickFalse;
7317 break;
7318 }
7319 *images=DestroyImageList(*images);
7320 *images=append_image;
7321 break;
7322 }
7323 if (LocaleCompare("average",option+1) == 0)
7324 {
7325 Image
7326 *average_image;
7327
cristyd18ae7c2010-03-07 17:39:52 +00007328 /*
7329 Average an image sequence (deprecated).
7330 */
cristy6b3da3a2010-06-20 02:21:46 +00007331 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007332 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7333 exception);
cristy3ed852e2009-09-05 21:47:34 +00007334 if (average_image == (Image *) NULL)
7335 {
7336 status=MagickFalse;
7337 break;
7338 }
7339 *images=DestroyImageList(*images);
7340 *images=average_image;
7341 break;
7342 }
7343 break;
7344 }
7345 case 'c':
7346 {
7347 if (LocaleCompare("channel",option+1) == 0)
7348 {
cristyf4ad9df2011-07-08 16:49:03 +00007349 ChannelType
7350 channel;
7351
cristy3ed852e2009-09-05 21:47:34 +00007352 if (*option == '+')
7353 {
7354 channel=DefaultChannels;
7355 break;
7356 }
7357 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007358 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007359 break;
7360 }
7361 if (LocaleCompare("clut",option+1) == 0)
7362 {
7363 Image
7364 *clut_image,
7365 *image;
7366
cristy6b3da3a2010-06-20 02:21:46 +00007367 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007368 image=RemoveFirstImageFromList(images);
7369 clut_image=RemoveFirstImageFromList(images);
7370 if (clut_image == (Image *) NULL)
7371 {
7372 status=MagickFalse;
7373 break;
7374 }
cristy28474bf2011-09-11 23:32:52 +00007375 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007376 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007377 *images=DestroyImageList(*images);
7378 *images=image;
7379 break;
7380 }
7381 if (LocaleCompare("coalesce",option+1) == 0)
7382 {
7383 Image
7384 *coalesce_image;
7385
cristy6b3da3a2010-06-20 02:21:46 +00007386 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007387 coalesce_image=CoalesceImages(*images,exception);
7388 if (coalesce_image == (Image *) NULL)
7389 {
7390 status=MagickFalse;
7391 break;
7392 }
7393 *images=DestroyImageList(*images);
7394 *images=coalesce_image;
7395 break;
7396 }
7397 if (LocaleCompare("combine",option+1) == 0)
7398 {
7399 Image
7400 *combine_image;
7401
cristy6b3da3a2010-06-20 02:21:46 +00007402 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007403 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007404 if (combine_image == (Image *) NULL)
7405 {
7406 status=MagickFalse;
7407 break;
7408 }
7409 *images=DestroyImageList(*images);
7410 *images=combine_image;
7411 break;
7412 }
7413 if (LocaleCompare("composite",option+1) == 0)
7414 {
7415 Image
7416 *mask_image,
7417 *composite_image,
7418 *image;
7419
7420 RectangleInfo
7421 geometry;
7422
cristy6b3da3a2010-06-20 02:21:46 +00007423 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007424 image=RemoveFirstImageFromList(images);
7425 composite_image=RemoveFirstImageFromList(images);
7426 if (composite_image == (Image *) NULL)
7427 {
7428 status=MagickFalse;
7429 break;
7430 }
7431 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007432 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007433 SetGeometry(composite_image,&geometry);
7434 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7435 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7436 &geometry);
7437 mask_image=RemoveFirstImageFromList(images);
7438 if (mask_image != (Image *) NULL)
7439 {
7440 if ((image->compose == DisplaceCompositeOp) ||
7441 (image->compose == DistortCompositeOp))
7442 {
7443 /*
7444 Merge Y displacement into X displacement image.
7445 */
7446 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007447 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007448 mask_image=DestroyImage(mask_image);
7449 }
7450 else
7451 {
7452 /*
7453 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007454 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007455 */
7456 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007457 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007458 }
7459 }
cristyf4ad9df2011-07-08 16:49:03 +00007460 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007461 geometry.x,geometry.y,exception);
anthonya129f702011-04-14 01:08:48 +00007462 if (mask_image != (Image *) NULL)
7463 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007464 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007465 *images=DestroyImageList(*images);
7466 *images=image;
7467 break;
7468 }
cristy3ed852e2009-09-05 21:47:34 +00007469 break;
7470 }
7471 case 'd':
7472 {
7473 if (LocaleCompare("deconstruct",option+1) == 0)
7474 {
7475 Image
7476 *deconstruct_image;
7477
cristy6b3da3a2010-06-20 02:21:46 +00007478 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007479 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007480 exception);
cristy3ed852e2009-09-05 21:47:34 +00007481 if (deconstruct_image == (Image *) NULL)
7482 {
7483 status=MagickFalse;
7484 break;
7485 }
7486 *images=DestroyImageList(*images);
7487 *images=deconstruct_image;
7488 break;
7489 }
7490 if (LocaleCompare("delete",option+1) == 0)
7491 {
7492 if (*option == '+')
7493 DeleteImages(images,"-1",exception);
7494 else
7495 DeleteImages(images,argv[i+1],exception);
7496 break;
7497 }
7498 if (LocaleCompare("dither",option+1) == 0)
7499 {
7500 if (*option == '+')
7501 {
7502 quantize_info->dither=MagickFalse;
7503 break;
7504 }
7505 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007506 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007507 MagickDitherOptions,MagickFalse,argv[i+1]);
7508 break;
7509 }
cristyecb10ff2011-03-22 13:14:03 +00007510 if (LocaleCompare("duplicate",option+1) == 0)
7511 {
cristy72988482011-03-29 16:34:38 +00007512 Image
7513 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007514
anthony2b6bcae2011-03-23 13:05:34 +00007515 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007516 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7517 else
7518 {
7519 const char
7520 *p;
7521
anthony2b6bcae2011-03-23 13:05:34 +00007522 size_t
7523 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007524
anthony2b6bcae2011-03-23 13:05:34 +00007525 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007526 p=strchr(argv[i+1],',');
7527 if (p == (const char *) NULL)
7528 duplicate_images=DuplicateImages(*images,number_duplicates,
7529 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007530 else
cristy72988482011-03-29 16:34:38 +00007531 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7532 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007533 }
7534 AppendImageToList(images, duplicate_images);
7535 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007536 break;
7537 }
cristy3ed852e2009-09-05 21:47:34 +00007538 break;
7539 }
cristyd18ae7c2010-03-07 17:39:52 +00007540 case 'e':
7541 {
7542 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7543 {
7544 Image
7545 *evaluate_image;
7546
7547 MagickEvaluateOperator
7548 op;
7549
cristy6b3da3a2010-06-20 02:21:46 +00007550 (void) SyncImageSettings(mogrify_info,*images);
cristy28474bf2011-09-11 23:32:52 +00007551 op=(MagickEvaluateOperator) ParseCommandOption(
7552 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007553 evaluate_image=EvaluateImages(*images,op,exception);
7554 if (evaluate_image == (Image *) NULL)
7555 {
7556 status=MagickFalse;
7557 break;
7558 }
7559 *images=DestroyImageList(*images);
7560 *images=evaluate_image;
7561 break;
7562 }
7563 break;
7564 }
cristy3ed852e2009-09-05 21:47:34 +00007565 case 'f':
7566 {
cristyf0a247f2009-10-04 00:20:03 +00007567 if (LocaleCompare("fft",option+1) == 0)
7568 {
7569 Image
7570 *fourier_image;
7571
7572 /*
7573 Implements the discrete Fourier transform (DFT).
7574 */
cristy6b3da3a2010-06-20 02:21:46 +00007575 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007576 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7577 MagickTrue : MagickFalse,exception);
7578 if (fourier_image == (Image *) NULL)
7579 break;
7580 *images=DestroyImage(*images);
7581 *images=fourier_image;
7582 break;
7583 }
cristy3ed852e2009-09-05 21:47:34 +00007584 if (LocaleCompare("flatten",option+1) == 0)
7585 {
7586 Image
7587 *flatten_image;
7588
cristy6b3da3a2010-06-20 02:21:46 +00007589 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007590 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7591 if (flatten_image == (Image *) NULL)
7592 break;
7593 *images=DestroyImageList(*images);
7594 *images=flatten_image;
7595 break;
7596 }
7597 if (LocaleCompare("fx",option+1) == 0)
7598 {
7599 Image
7600 *fx_image;
7601
cristy6b3da3a2010-06-20 02:21:46 +00007602 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007603 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007604 if (fx_image == (Image *) NULL)
7605 {
7606 status=MagickFalse;
7607 break;
7608 }
7609 *images=DestroyImageList(*images);
7610 *images=fx_image;
7611 break;
7612 }
7613 break;
7614 }
7615 case 'h':
7616 {
7617 if (LocaleCompare("hald-clut",option+1) == 0)
7618 {
7619 Image
7620 *hald_image,
7621 *image;
7622
cristy6b3da3a2010-06-20 02:21:46 +00007623 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007624 image=RemoveFirstImageFromList(images);
7625 hald_image=RemoveFirstImageFromList(images);
7626 if (hald_image == (Image *) NULL)
7627 {
7628 status=MagickFalse;
7629 break;
7630 }
cristy7c0a0a42011-08-23 17:57:25 +00007631 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007632 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007633 if (*images != (Image *) NULL)
7634 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007635 *images=image;
7636 break;
7637 }
7638 break;
7639 }
7640 case 'i':
7641 {
7642 if (LocaleCompare("ift",option+1) == 0)
7643 {
7644 Image
cristy8587f882009-11-13 20:28:49 +00007645 *fourier_image,
7646 *magnitude_image,
7647 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007648
7649 /*
7650 Implements the inverse fourier discrete Fourier transform (DFT).
7651 */
cristy6b3da3a2010-06-20 02:21:46 +00007652 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007653 magnitude_image=RemoveFirstImageFromList(images);
7654 phase_image=RemoveFirstImageFromList(images);
7655 if (phase_image == (Image *) NULL)
7656 {
7657 status=MagickFalse;
7658 break;
7659 }
7660 fourier_image=InverseFourierTransformImage(magnitude_image,
7661 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007662 if (fourier_image == (Image *) NULL)
7663 break;
cristy0aff6ea2009-11-14 01:40:53 +00007664 if (*images != (Image *) NULL)
7665 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007666 *images=fourier_image;
7667 break;
7668 }
7669 if (LocaleCompare("insert",option+1) == 0)
7670 {
7671 Image
7672 *p,
7673 *q;
7674
7675 index=0;
7676 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007677 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007678 p=RemoveLastImageFromList(images);
7679 if (p == (Image *) NULL)
7680 {
7681 (void) ThrowMagickException(exception,GetMagickModule(),
7682 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7683 status=MagickFalse;
7684 break;
7685 }
7686 q=p;
7687 if (index == 0)
7688 PrependImageToList(images,q);
7689 else
cristybb503372010-05-27 20:51:26 +00007690 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007691 AppendImageToList(images,q);
7692 else
7693 {
7694 q=GetImageFromList(*images,index-1);
7695 if (q == (Image *) NULL)
7696 {
7697 (void) ThrowMagickException(exception,GetMagickModule(),
7698 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7699 status=MagickFalse;
7700 break;
7701 }
7702 InsertImageInList(&q,p);
7703 }
7704 *images=GetFirstImageInList(q);
7705 break;
7706 }
cristy28474bf2011-09-11 23:32:52 +00007707 if (LocaleCompare("interpolate",option+1) == 0)
7708 {
7709 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7710 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7711 break;
7712 }
cristy3ed852e2009-09-05 21:47:34 +00007713 break;
7714 }
7715 case 'l':
7716 {
7717 if (LocaleCompare("layers",option+1) == 0)
7718 {
7719 Image
7720 *layers;
7721
7722 ImageLayerMethod
7723 method;
7724
cristy6b3da3a2010-06-20 02:21:46 +00007725 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007726 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007727 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007728 MagickFalse,argv[i+1]);
7729 switch (method)
7730 {
7731 case CoalesceLayer:
7732 {
7733 layers=CoalesceImages(*images,exception);
7734 break;
7735 }
7736 case CompareAnyLayer:
7737 case CompareClearLayer:
7738 case CompareOverlayLayer:
7739 default:
7740 {
cristy8a9106f2011-07-05 14:39:26 +00007741 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007742 break;
7743 }
7744 case MergeLayer:
7745 case FlattenLayer:
7746 case MosaicLayer:
7747 case TrimBoundsLayer:
7748 {
7749 layers=MergeImageLayers(*images,method,exception);
7750 break;
7751 }
7752 case DisposeLayer:
7753 {
7754 layers=DisposeImages(*images,exception);
7755 break;
7756 }
7757 case OptimizeImageLayer:
7758 {
7759 layers=OptimizeImageLayers(*images,exception);
7760 break;
7761 }
7762 case OptimizePlusLayer:
7763 {
7764 layers=OptimizePlusImageLayers(*images,exception);
7765 break;
7766 }
7767 case OptimizeTransLayer:
7768 {
7769 OptimizeImageTransparency(*images,exception);
7770 break;
7771 }
7772 case RemoveDupsLayer:
7773 {
7774 RemoveDuplicateLayers(images,exception);
7775 break;
7776 }
7777 case RemoveZeroLayer:
7778 {
7779 RemoveZeroDelayLayers(images,exception);
7780 break;
7781 }
7782 case OptimizeLayer:
7783 {
7784 /*
7785 General Purpose, GIF Animation Optimizer.
7786 */
7787 layers=CoalesceImages(*images,exception);
7788 if (layers == (Image *) NULL)
7789 {
7790 status=MagickFalse;
7791 break;
7792 }
cristy3ed852e2009-09-05 21:47:34 +00007793 *images=DestroyImageList(*images);
7794 *images=layers;
7795 layers=OptimizeImageLayers(*images,exception);
7796 if (layers == (Image *) NULL)
7797 {
7798 status=MagickFalse;
7799 break;
7800 }
cristy3ed852e2009-09-05 21:47:34 +00007801 *images=DestroyImageList(*images);
7802 *images=layers;
7803 layers=(Image *) NULL;
7804 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007805 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7806 exception);
cristy3ed852e2009-09-05 21:47:34 +00007807 break;
7808 }
7809 case CompositeLayer:
7810 {
7811 CompositeOperator
7812 compose;
7813
7814 Image
7815 *source;
7816
7817 RectangleInfo
7818 geometry;
7819
7820 /*
7821 Split image sequence at the first 'NULL:' image.
7822 */
7823 source=(*images);
7824 while (source != (Image *) NULL)
7825 {
7826 source=GetNextImageInList(source);
7827 if ((source != (Image *) NULL) &&
7828 (LocaleCompare(source->magick,"NULL") == 0))
7829 break;
7830 }
7831 if (source != (Image *) NULL)
7832 {
7833 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7834 (GetNextImageInList(source) == (Image *) NULL))
7835 source=(Image *) NULL;
7836 else
7837 {
7838 /*
7839 Separate the two lists, junk the null: image.
7840 */
7841 source=SplitImageList(source->previous);
7842 DeleteImageFromList(&source);
7843 }
7844 }
7845 if (source == (Image *) NULL)
7846 {
7847 (void) ThrowMagickException(exception,GetMagickModule(),
7848 OptionError,"MissingNullSeparator","layers Composite");
7849 status=MagickFalse;
7850 break;
7851 }
7852 /*
7853 Adjust offset with gravity and virtual canvas.
7854 */
7855 SetGeometry(*images,&geometry);
7856 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7857 geometry.width=source->page.width != 0 ?
7858 source->page.width : source->columns;
7859 geometry.height=source->page.height != 0 ?
7860 source->page.height : source->rows;
7861 GravityAdjustGeometry((*images)->page.width != 0 ?
7862 (*images)->page.width : (*images)->columns,
7863 (*images)->page.height != 0 ? (*images)->page.height :
7864 (*images)->rows,(*images)->gravity,&geometry);
7865 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007866 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007867 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007868 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007869 MagickComposeOptions,MagickFalse,option);
7870 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7871 exception);
7872 source=DestroyImageList(source);
7873 break;
7874 }
7875 }
7876 if (layers == (Image *) NULL)
7877 break;
cristy3ed852e2009-09-05 21:47:34 +00007878 *images=DestroyImageList(*images);
7879 *images=layers;
7880 break;
7881 }
7882 break;
7883 }
7884 case 'm':
7885 {
7886 if (LocaleCompare("map",option+1) == 0)
7887 {
cristy6b3da3a2010-06-20 02:21:46 +00007888 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007889 if (*option == '+')
7890 {
cristy018f07f2011-09-04 21:15:19 +00007891 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7892 exception);
cristy3ed852e2009-09-05 21:47:34 +00007893 break;
7894 }
7895 i++;
7896 break;
7897 }
cristyf40785b2010-03-06 02:27:27 +00007898 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007899 {
7900 Image
cristyf40785b2010-03-06 02:27:27 +00007901 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007902
cristyd18ae7c2010-03-07 17:39:52 +00007903 /*
7904 Maximum image sequence (deprecated).
7905 */
cristy6b3da3a2010-06-20 02:21:46 +00007906 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007907 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007908 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007909 {
7910 status=MagickFalse;
7911 break;
7912 }
7913 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007914 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007915 break;
7916 }
cristyf40785b2010-03-06 02:27:27 +00007917 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007918 {
7919 Image
cristyf40785b2010-03-06 02:27:27 +00007920 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007921
cristyd18ae7c2010-03-07 17:39:52 +00007922 /*
7923 Minimum image sequence (deprecated).
7924 */
cristy6b3da3a2010-06-20 02:21:46 +00007925 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007926 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007927 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007928 {
7929 status=MagickFalse;
7930 break;
7931 }
7932 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007933 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007934 break;
7935 }
cristy3ed852e2009-09-05 21:47:34 +00007936 if (LocaleCompare("morph",option+1) == 0)
7937 {
7938 Image
7939 *morph_image;
7940
cristy6b3da3a2010-06-20 02:21:46 +00007941 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007942 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007943 exception);
7944 if (morph_image == (Image *) NULL)
7945 {
7946 status=MagickFalse;
7947 break;
7948 }
7949 *images=DestroyImageList(*images);
7950 *images=morph_image;
7951 break;
7952 }
7953 if (LocaleCompare("mosaic",option+1) == 0)
7954 {
7955 Image
7956 *mosaic_image;
7957
cristy6b3da3a2010-06-20 02:21:46 +00007958 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007959 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7960 if (mosaic_image == (Image *) NULL)
7961 {
7962 status=MagickFalse;
7963 break;
7964 }
7965 *images=DestroyImageList(*images);
7966 *images=mosaic_image;
7967 break;
7968 }
7969 break;
7970 }
7971 case 'p':
7972 {
7973 if (LocaleCompare("print",option+1) == 0)
7974 {
7975 char
7976 *string;
7977
cristy6b3da3a2010-06-20 02:21:46 +00007978 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007979 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7980 exception);
cristy3ed852e2009-09-05 21:47:34 +00007981 if (string == (char *) NULL)
7982 break;
cristyb51dff52011-05-19 16:55:47 +00007983 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007984 string=DestroyString(string);
7985 }
7986 if (LocaleCompare("process",option+1) == 0)
7987 {
7988 char
7989 **arguments;
7990
7991 int
7992 j,
7993 number_arguments;
7994
cristy6b3da3a2010-06-20 02:21:46 +00007995 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007996 arguments=StringToArgv(argv[i+1],&number_arguments);
7997 if (arguments == (char **) NULL)
7998 break;
7999 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8000 {
8001 char
8002 breaker,
8003 quote,
8004 *token;
8005
8006 const char
8007 *arguments;
8008
8009 int
8010 next,
8011 status;
8012
8013 size_t
8014 length;
8015
8016 TokenInfo
8017 *token_info;
8018
8019 /*
8020 Support old style syntax, filter="-option arg".
8021 */
8022 length=strlen(argv[i+1]);
8023 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008024 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008025 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8026 sizeof(*token));
8027 if (token == (char *) NULL)
8028 break;
8029 next=0;
8030 arguments=argv[i+1];
8031 token_info=AcquireTokenInfo();
8032 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8033 "\"",'\0',&breaker,&next,&quote);
8034 token_info=DestroyTokenInfo(token_info);
8035 if (status == 0)
8036 {
8037 const char
8038 *argv;
8039
8040 argv=(&(arguments[next]));
8041 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8042 exception);
8043 }
8044 token=DestroyString(token);
8045 break;
8046 }
cristy91c0da22010-05-02 01:44:07 +00008047 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008048 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8049 number_arguments-2,(const char **) arguments+2,exception);
8050 for (j=0; j < number_arguments; j++)
8051 arguments[j]=DestroyString(arguments[j]);
8052 arguments=(char **) RelinquishMagickMemory(arguments);
8053 break;
8054 }
8055 break;
8056 }
8057 case 'r':
8058 {
8059 if (LocaleCompare("reverse",option+1) == 0)
8060 {
8061 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008062 break;
8063 }
8064 break;
8065 }
8066 case 's':
8067 {
cristy4285d782011-02-09 20:12:28 +00008068 if (LocaleCompare("smush",option+1) == 0)
8069 {
8070 Image
8071 *smush_image;
8072
8073 ssize_t
8074 offset;
8075
8076 (void) SyncImagesSettings(mogrify_info,*images);
8077 offset=(ssize_t) StringToLong(argv[i+1]);
8078 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8079 MagickFalse,offset,exception);
8080 if (smush_image == (Image *) NULL)
8081 {
8082 status=MagickFalse;
8083 break;
8084 }
8085 *images=DestroyImageList(*images);
8086 *images=smush_image;
8087 break;
8088 }
cristy3ed852e2009-09-05 21:47:34 +00008089 if (LocaleCompare("swap",option+1) == 0)
8090 {
8091 Image
8092 *p,
8093 *q,
8094 *swap;
8095
cristybb503372010-05-27 20:51:26 +00008096 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008097 swap_index;
8098
8099 index=(-1);
8100 swap_index=(-2);
8101 if (*option != '+')
8102 {
8103 GeometryInfo
8104 geometry_info;
8105
8106 MagickStatusType
8107 flags;
8108
8109 swap_index=(-1);
8110 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008111 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008112 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008113 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008114 }
8115 p=GetImageFromList(*images,index);
8116 q=GetImageFromList(*images,swap_index);
8117 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8118 {
8119 (void) ThrowMagickException(exception,GetMagickModule(),
8120 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8121 status=MagickFalse;
8122 break;
8123 }
8124 if (p == q)
8125 break;
8126 swap=CloneImage(p,0,0,MagickTrue,exception);
8127 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8128 ReplaceImageInList(&q,swap);
8129 *images=GetFirstImageInList(q);
8130 break;
8131 }
8132 break;
8133 }
8134 case 'w':
8135 {
8136 if (LocaleCompare("write",option+1) == 0)
8137 {
cristy071dd7b2010-04-09 13:04:54 +00008138 char
cristy06609ee2010-03-17 20:21:27 +00008139 key[MaxTextExtent];
8140
cristy3ed852e2009-09-05 21:47:34 +00008141 Image
8142 *write_images;
8143
8144 ImageInfo
8145 *write_info;
8146
cristy6b3da3a2010-06-20 02:21:46 +00008147 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008148 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008149 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008150 write_images=(*images);
8151 if (*option == '+')
8152 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008153 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008154 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8155 write_info=DestroyImageInfo(write_info);
8156 if (*option == '+')
8157 write_images=DestroyImageList(write_images);
8158 break;
8159 }
8160 break;
8161 }
8162 default:
8163 break;
8164 }
8165 i+=count;
8166 }
8167 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008168 mogrify_info=DestroyImageInfo(mogrify_info);
8169 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008170 return(status != 0 ? MagickTrue : MagickFalse);
8171}
8172
8173/*
8174%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8175% %
8176% %
8177% %
8178+ M o g r i f y I m a g e s %
8179% %
8180% %
8181% %
8182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8183%
8184% MogrifyImages() applies image processing options to a sequence of images as
8185% prescribed by command line options.
8186%
8187% The format of the MogrifyImage method is:
8188%
8189% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8190% const MagickBooleanType post,const int argc,const char **argv,
8191% Image **images,Exceptioninfo *exception)
8192%
8193% A description of each parameter follows:
8194%
8195% o image_info: the image info..
8196%
8197% o post: If true, post process image list operators otherwise pre-process.
8198%
8199% o argc: Specifies a pointer to an integer describing the number of
8200% elements in the argument vector.
8201%
8202% o argv: Specifies a pointer to a text array containing the command line
8203% arguments.
8204%
anthonye9c27192011-03-27 08:07:06 +00008205% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008206%
8207% o exception: return any errors or warnings in this structure.
8208%
8209*/
8210WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8211 const MagickBooleanType post,const int argc,const char **argv,
8212 Image **images,ExceptionInfo *exception)
8213{
8214#define MogrifyImageTag "Mogrify/Image"
8215
anthonye9c27192011-03-27 08:07:06 +00008216 MagickStatusType
8217 status;
cristy3ed852e2009-09-05 21:47:34 +00008218
cristy0e9f9c12010-02-11 03:00:47 +00008219 MagickBooleanType
8220 proceed;
8221
anthonye9c27192011-03-27 08:07:06 +00008222 size_t
8223 n;
cristy3ed852e2009-09-05 21:47:34 +00008224
cristybb503372010-05-27 20:51:26 +00008225 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008226 i;
8227
cristy3ed852e2009-09-05 21:47:34 +00008228 assert(image_info != (ImageInfo *) NULL);
8229 assert(image_info->signature == MagickSignature);
8230 if (images == (Image **) NULL)
8231 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008232 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008233 assert((*images)->signature == MagickSignature);
8234 if ((*images)->debug != MagickFalse)
8235 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8236 (*images)->filename);
8237 if ((argc <= 0) || (*argv == (char *) NULL))
8238 return(MagickTrue);
8239 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8240 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008241 status=0;
anthonye9c27192011-03-27 08:07:06 +00008242
anthonyce2716b2011-04-22 09:51:34 +00008243#if 0
cristy1e604812011-05-19 18:07:50 +00008244 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8245 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008246#endif
8247
anthonye9c27192011-03-27 08:07:06 +00008248 /*
8249 Pre-process multi-image sequence operators
8250 */
cristy3ed852e2009-09-05 21:47:34 +00008251 if (post == MagickFalse)
8252 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008253 /*
8254 For each image, process simple single image operators
8255 */
8256 i=0;
8257 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008258 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008259 {
anthonyce2716b2011-04-22 09:51:34 +00008260#if 0
cristy1e604812011-05-19 18:07:50 +00008261 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8262 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008263#endif
anthonye9c27192011-03-27 08:07:06 +00008264 status&=MogrifyImage(image_info,argc,argv,images,exception);
8265 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008266 if (proceed == MagickFalse)
8267 break;
anthonye9c27192011-03-27 08:07:06 +00008268 if ( (*images)->next == (Image *) NULL )
8269 break;
8270 *images=(*images)->next;
8271 i++;
cristy3ed852e2009-09-05 21:47:34 +00008272 }
anthonye9c27192011-03-27 08:07:06 +00008273 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008274#if 0
cristy1e604812011-05-19 18:07:50 +00008275 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8276 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008277#endif
anthonye9c27192011-03-27 08:07:06 +00008278
8279 /*
8280 Post-process, multi-image sequence operators
8281 */
8282 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008283 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008284 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008285 return(status != 0 ? MagickTrue : MagickFalse);
8286}