blob: 0ba24f562e2555eac0ea664a395f2980dd8cc105 [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 InheritException(exception,&(*image)->exception);
907 break;
908 }
909 if (LocaleCompare("blue-shift",option+1) == 0)
910 {
911 /*
912 Blue shift image.
913 */
914 (void) SyncImageSettings(mogrify_info,*image);
915 geometry_info.rho=1.5;
916 if (*option == '-')
917 flags=ParseGeometry(argv[i+1],&geometry_info);
918 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
919 break;
920 }
921 if (LocaleCompare("blur",option+1) == 0)
922 {
923 /*
924 Gaussian blur image.
925 */
926 (void) SyncImageSettings(mogrify_info,*image);
927 flags=ParseGeometry(argv[i+1],&geometry_info);
928 if ((flags & SigmaValue) == 0)
929 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000930 if ((flags & XiValue) == 0)
931 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000932 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000933 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000934 break;
935 }
936 if (LocaleCompare("border",option+1) == 0)
937 {
938 /*
939 Surround image with a border of solid color.
940 */
941 (void) SyncImageSettings(mogrify_info,*image);
942 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
943 if ((flags & SigmaValue) == 0)
944 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000945 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000946 break;
947 }
948 if (LocaleCompare("bordercolor",option+1) == 0)
949 {
950 if (*option == '+')
951 {
cristy9950d572011-10-01 18:22:35 +0000952 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000953 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000954 break;
955 }
cristy9950d572011-10-01 18:22:35 +0000956 (void) QueryColorCompliance(argv[i+1],AllCompliance,
957 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000958 break;
959 }
960 if (LocaleCompare("box",option+1) == 0)
961 {
cristy9950d572011-10-01 18:22:35 +0000962 (void) QueryColorCompliance(argv[i+1],AllCompliance,
963 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000964 break;
965 }
966 if (LocaleCompare("brightness-contrast",option+1) == 0)
967 {
968 double
969 brightness,
970 contrast;
971
972 GeometryInfo
973 geometry_info;
974
975 MagickStatusType
976 flags;
977
978 /*
979 Brightness / contrast image.
980 */
981 (void) SyncImageSettings(mogrify_info,*image);
982 flags=ParseGeometry(argv[i+1],&geometry_info);
983 brightness=geometry_info.rho;
984 contrast=0.0;
985 if ((flags & SigmaValue) != 0)
986 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000987 (void) BrightnessContrastImage(*image,brightness,contrast,
988 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000989 InheritException(exception,&(*image)->exception);
990 break;
991 }
992 break;
993 }
994 case 'c':
995 {
996 if (LocaleCompare("cdl",option+1) == 0)
997 {
998 char
999 *color_correction_collection;
1000
1001 /*
1002 Color correct with a color decision list.
1003 */
1004 (void) SyncImageSettings(mogrify_info,*image);
1005 color_correction_collection=FileToString(argv[i+1],~0,exception);
1006 if (color_correction_collection == (char *) NULL)
1007 break;
cristy1bfa9f02011-08-11 02:35:43 +00001008 (void) ColorDecisionListImage(*image,color_correction_collection,
1009 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001010 InheritException(exception,&(*image)->exception);
1011 break;
1012 }
1013 if (LocaleCompare("channel",option+1) == 0)
1014 {
1015 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001016 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001017 else
cristyfa806a72011-07-04 02:06:13 +00001018 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00001019 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001020 break;
1021 }
1022 if (LocaleCompare("charcoal",option+1) == 0)
1023 {
1024 /*
1025 Charcoal image.
1026 */
1027 (void) SyncImageSettings(mogrify_info,*image);
1028 flags=ParseGeometry(argv[i+1],&geometry_info);
1029 if ((flags & SigmaValue) == 0)
1030 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001031 if ((flags & XiValue) == 0)
1032 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001033 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001034 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001035 break;
1036 }
1037 if (LocaleCompare("chop",option+1) == 0)
1038 {
1039 /*
1040 Chop the image.
1041 */
1042 (void) SyncImageSettings(mogrify_info,*image);
1043 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1044 mogrify_image=ChopImage(*image,&geometry,exception);
1045 break;
1046 }
1047 if (LocaleCompare("clamp",option+1) == 0)
1048 {
1049 /*
1050 Clamp image.
1051 */
1052 (void) SyncImageSettings(mogrify_info,*image);
cristy092d71c2011-10-14 18:01:29 +00001053 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001054 break;
1055 }
1056 if (LocaleCompare("clip",option+1) == 0)
1057 {
1058 (void) SyncImageSettings(mogrify_info,*image);
1059 if (*option == '+')
1060 {
cristy018f07f2011-09-04 21:15:19 +00001061 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001062 break;
1063 }
cristy018f07f2011-09-04 21:15:19 +00001064 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001065 break;
1066 }
1067 if (LocaleCompare("clip-mask",option+1) == 0)
1068 {
1069 CacheView
1070 *mask_view;
1071
1072 Image
1073 *mask_image;
1074
cristy4c08aed2011-07-01 19:47:50 +00001075 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001076 *restrict q;
1077
1078 register ssize_t
1079 x;
1080
1081 ssize_t
1082 y;
1083
1084 (void) SyncImageSettings(mogrify_info,*image);
1085 if (*option == '+')
1086 {
1087 /*
1088 Remove a mask.
1089 */
cristy018f07f2011-09-04 21:15:19 +00001090 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001091 break;
1092 }
1093 /*
1094 Set the image mask.
1095 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1096 */
1097 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1098 if (mask_image == (Image *) NULL)
1099 break;
cristy574cc262011-08-05 01:23:58 +00001100 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001101 return(MagickFalse);
1102 mask_view=AcquireCacheView(mask_image);
1103 for (y=0; y < (ssize_t) mask_image->rows; y++)
1104 {
1105 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1106 exception);
cristyacd2ed22011-08-30 01:44:23 +00001107 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001108 break;
1109 for (x=0; x < (ssize_t) mask_image->columns; x++)
1110 {
1111 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001112 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1113 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1114 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1115 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001116 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001117 }
1118 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1119 break;
1120 }
1121 mask_view=DestroyCacheView(mask_view);
1122 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001123 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001124 InheritException(exception,&(*image)->exception);
1125 break;
1126 }
1127 if (LocaleCompare("clip-path",option+1) == 0)
1128 {
1129 (void) SyncImageSettings(mogrify_info,*image);
1130 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001131 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001132 break;
1133 }
1134 if (LocaleCompare("colorize",option+1) == 0)
1135 {
1136 /*
1137 Colorize the image.
1138 */
1139 (void) SyncImageSettings(mogrify_info,*image);
cristyc7e6ff62011-10-03 13:46:11 +00001140 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001141 break;
1142 }
1143 if (LocaleCompare("color-matrix",option+1) == 0)
1144 {
1145 KernelInfo
1146 *kernel;
1147
1148 (void) SyncImageSettings(mogrify_info,*image);
1149 kernel=AcquireKernelInfo(argv[i+1]);
1150 if (kernel == (KernelInfo *) NULL)
1151 break;
1152 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1153 kernel=DestroyKernelInfo(kernel);
1154 break;
1155 }
1156 if (LocaleCompare("colors",option+1) == 0)
1157 {
1158 /*
1159 Reduce the number of colors in the image.
1160 */
1161 (void) SyncImageSettings(mogrify_info,*image);
1162 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1163 if (quantize_info->number_colors == 0)
1164 break;
1165 if (((*image)->storage_class == DirectClass) ||
1166 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001167 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001168 else
cristy018f07f2011-09-04 21:15:19 +00001169 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001170 break;
1171 }
1172 if (LocaleCompare("colorspace",option+1) == 0)
1173 {
1174 ColorspaceType
1175 colorspace;
1176
1177 (void) SyncImageSettings(mogrify_info,*image);
1178 if (*option == '+')
1179 {
1180 (void) TransformImageColorspace(*image,RGBColorspace);
1181 InheritException(exception,&(*image)->exception);
1182 break;
1183 }
1184 colorspace=(ColorspaceType) ParseCommandOption(
1185 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1186 (void) TransformImageColorspace(*image,colorspace);
1187 InheritException(exception,&(*image)->exception);
1188 break;
1189 }
cristy633f0c62011-09-15 13:27:36 +00001190 if (LocaleCompare("compose",option+1) == 0)
1191 {
1192 (void) SyncImageSettings(mogrify_info,*image);
1193 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1194 MagickFalse,argv[i+1]);
1195 break;
1196 }
anthonydf8ebac2011-04-27 09:03:19 +00001197 if (LocaleCompare("contrast",option+1) == 0)
1198 {
1199 (void) SyncImageSettings(mogrify_info,*image);
1200 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001201 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001202 break;
1203 }
1204 if (LocaleCompare("contrast-stretch",option+1) == 0)
1205 {
1206 double
1207 black_point,
1208 white_point;
1209
1210 MagickStatusType
1211 flags;
1212
1213 /*
1214 Contrast stretch image.
1215 */
1216 (void) SyncImageSettings(mogrify_info,*image);
1217 flags=ParseGeometry(argv[i+1],&geometry_info);
1218 black_point=geometry_info.rho;
1219 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1220 black_point;
1221 if ((flags & PercentValue) != 0)
1222 {
1223 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1224 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1225 }
1226 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1227 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001228 (void) ContrastStretchImage(*image,black_point,white_point,
1229 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001230 InheritException(exception,&(*image)->exception);
1231 break;
1232 }
1233 if (LocaleCompare("convolve",option+1) == 0)
1234 {
anthonydf8ebac2011-04-27 09:03:19 +00001235 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001236 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001237
anthonydf8ebac2011-04-27 09:03:19 +00001238 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001239 kernel_info=AcquireKernelInfo(argv[i+1]);
1240 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001241 break;
cristy0a922382011-07-16 15:30:34 +00001242 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001243 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001244 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001245 break;
1246 }
1247 if (LocaleCompare("crop",option+1) == 0)
1248 {
1249 /*
1250 Crop a image to a smaller size
1251 */
1252 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001253 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001254 break;
1255 }
1256 if (LocaleCompare("cycle",option+1) == 0)
1257 {
1258 /*
1259 Cycle an image colormap.
1260 */
1261 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001262 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1263 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001264 break;
1265 }
1266 break;
1267 }
1268 case 'd':
1269 {
1270 if (LocaleCompare("decipher",option+1) == 0)
1271 {
1272 StringInfo
1273 *passkey;
1274
1275 /*
1276 Decipher pixels.
1277 */
1278 (void) SyncImageSettings(mogrify_info,*image);
1279 passkey=FileToStringInfo(argv[i+1],~0,exception);
1280 if (passkey != (StringInfo *) NULL)
1281 {
1282 (void) PasskeyDecipherImage(*image,passkey,exception);
1283 passkey=DestroyStringInfo(passkey);
1284 }
1285 break;
1286 }
1287 if (LocaleCompare("density",option+1) == 0)
1288 {
1289 /*
1290 Set image density.
1291 */
1292 (void) CloneString(&draw_info->density,argv[i+1]);
1293 break;
1294 }
1295 if (LocaleCompare("depth",option+1) == 0)
1296 {
1297 (void) SyncImageSettings(mogrify_info,*image);
1298 if (*option == '+')
1299 {
1300 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1301 break;
1302 }
1303 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1304 break;
1305 }
1306 if (LocaleCompare("deskew",option+1) == 0)
1307 {
1308 double
1309 threshold;
1310
1311 /*
1312 Straighten the image.
1313 */
1314 (void) SyncImageSettings(mogrify_info,*image);
1315 if (*option == '+')
1316 threshold=40.0*QuantumRange/100.0;
1317 else
1318 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1319 mogrify_image=DeskewImage(*image,threshold,exception);
1320 break;
1321 }
1322 if (LocaleCompare("despeckle",option+1) == 0)
1323 {
1324 /*
1325 Reduce the speckles within an image.
1326 */
1327 (void) SyncImageSettings(mogrify_info,*image);
1328 mogrify_image=DespeckleImage(*image,exception);
1329 break;
1330 }
1331 if (LocaleCompare("display",option+1) == 0)
1332 {
1333 (void) CloneString(&draw_info->server_name,argv[i+1]);
1334 break;
1335 }
1336 if (LocaleCompare("distort",option+1) == 0)
1337 {
1338 char
1339 *args,
1340 token[MaxTextExtent];
1341
1342 const char
1343 *p;
1344
1345 DistortImageMethod
1346 method;
1347
1348 double
1349 *arguments;
1350
1351 register ssize_t
1352 x;
1353
1354 size_t
1355 number_arguments;
1356
1357 /*
1358 Distort image.
1359 */
1360 (void) SyncImageSettings(mogrify_info,*image);
1361 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1362 MagickFalse,argv[i+1]);
1363 if ( method == ResizeDistortion )
1364 {
1365 /* Special Case - Argument is actually a resize geometry!
1366 ** Convert that to an appropriate distortion argument array.
1367 */
1368 double
1369 resize_args[2];
1370 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1371 exception);
1372 resize_args[0]=(double)geometry.width;
1373 resize_args[1]=(double)geometry.height;
1374 mogrify_image=DistortImage(*image,method,(size_t)2,
1375 resize_args,MagickTrue,exception);
1376 break;
1377 }
cristy018f07f2011-09-04 21:15:19 +00001378 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1379 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001380 if (args == (char *) NULL)
1381 break;
1382 p=(char *) args;
1383 for (x=0; *p != '\0'; x++)
1384 {
1385 GetMagickToken(p,&p,token);
1386 if (*token == ',')
1387 GetMagickToken(p,&p,token);
1388 }
1389 number_arguments=(size_t) x;
1390 arguments=(double *) AcquireQuantumMemory(number_arguments,
1391 sizeof(*arguments));
1392 if (arguments == (double *) NULL)
1393 ThrowWandFatalException(ResourceLimitFatalError,
1394 "MemoryAllocationFailed",(*image)->filename);
1395 (void) ResetMagickMemory(arguments,0,number_arguments*
1396 sizeof(*arguments));
1397 p=(char *) args;
1398 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1399 {
1400 GetMagickToken(p,&p,token);
1401 if (*token == ',')
1402 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001403 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001404 }
1405 args=DestroyString(args);
1406 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1407 (*option == '+') ? MagickTrue : MagickFalse,exception);
1408 arguments=(double *) RelinquishMagickMemory(arguments);
1409 break;
1410 }
1411 if (LocaleCompare("dither",option+1) == 0)
1412 {
1413 if (*option == '+')
1414 {
1415 quantize_info->dither=MagickFalse;
1416 break;
1417 }
1418 quantize_info->dither=MagickTrue;
1419 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1420 MagickDitherOptions,MagickFalse,argv[i+1]);
1421 if (quantize_info->dither_method == NoDitherMethod)
1422 quantize_info->dither=MagickFalse;
1423 break;
1424 }
1425 if (LocaleCompare("draw",option+1) == 0)
1426 {
1427 /*
1428 Draw image.
1429 */
1430 (void) SyncImageSettings(mogrify_info,*image);
1431 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001432 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001433 break;
1434 }
1435 break;
1436 }
1437 case 'e':
1438 {
1439 if (LocaleCompare("edge",option+1) == 0)
1440 {
1441 /*
1442 Enhance edges in the image.
1443 */
1444 (void) SyncImageSettings(mogrify_info,*image);
1445 flags=ParseGeometry(argv[i+1],&geometry_info);
1446 if ((flags & SigmaValue) == 0)
1447 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001448 mogrify_image=EdgeImage(*image,geometry_info.rho,
1449 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001450 break;
1451 }
1452 if (LocaleCompare("emboss",option+1) == 0)
1453 {
1454 /*
1455 Gaussian embossen image.
1456 */
1457 (void) SyncImageSettings(mogrify_info,*image);
1458 flags=ParseGeometry(argv[i+1],&geometry_info);
1459 if ((flags & SigmaValue) == 0)
1460 geometry_info.sigma=1.0;
1461 mogrify_image=EmbossImage(*image,geometry_info.rho,
1462 geometry_info.sigma,exception);
1463 break;
1464 }
1465 if (LocaleCompare("encipher",option+1) == 0)
1466 {
1467 StringInfo
1468 *passkey;
1469
1470 /*
1471 Encipher pixels.
1472 */
1473 (void) SyncImageSettings(mogrify_info,*image);
1474 passkey=FileToStringInfo(argv[i+1],~0,exception);
1475 if (passkey != (StringInfo *) NULL)
1476 {
1477 (void) PasskeyEncipherImage(*image,passkey,exception);
1478 passkey=DestroyStringInfo(passkey);
1479 }
1480 break;
1481 }
1482 if (LocaleCompare("encoding",option+1) == 0)
1483 {
1484 (void) CloneString(&draw_info->encoding,argv[i+1]);
1485 break;
1486 }
1487 if (LocaleCompare("enhance",option+1) == 0)
1488 {
1489 /*
1490 Enhance image.
1491 */
1492 (void) SyncImageSettings(mogrify_info,*image);
1493 mogrify_image=EnhanceImage(*image,exception);
1494 break;
1495 }
1496 if (LocaleCompare("equalize",option+1) == 0)
1497 {
1498 /*
1499 Equalize image.
1500 */
1501 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001502 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001503 break;
1504 }
1505 if (LocaleCompare("evaluate",option+1) == 0)
1506 {
1507 double
1508 constant;
1509
1510 MagickEvaluateOperator
1511 op;
1512
1513 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001514 op=(MagickEvaluateOperator) ParseCommandOption(
1515 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001516 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001517 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001518 break;
1519 }
1520 if (LocaleCompare("extent",option+1) == 0)
1521 {
1522 /*
1523 Set the image extent.
1524 */
1525 (void) SyncImageSettings(mogrify_info,*image);
1526 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1527 if (geometry.width == 0)
1528 geometry.width=(*image)->columns;
1529 if (geometry.height == 0)
1530 geometry.height=(*image)->rows;
1531 mogrify_image=ExtentImage(*image,&geometry,exception);
1532 break;
1533 }
1534 break;
1535 }
1536 case 'f':
1537 {
1538 if (LocaleCompare("family",option+1) == 0)
1539 {
1540 if (*option == '+')
1541 {
1542 if (draw_info->family != (char *) NULL)
1543 draw_info->family=DestroyString(draw_info->family);
1544 break;
1545 }
1546 (void) CloneString(&draw_info->family,argv[i+1]);
1547 break;
1548 }
1549 if (LocaleCompare("features",option+1) == 0)
1550 {
1551 if (*option == '+')
1552 {
1553 (void) DeleteImageArtifact(*image,"identify:features");
1554 break;
1555 }
1556 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1557 break;
1558 }
1559 if (LocaleCompare("fill",option+1) == 0)
1560 {
1561 ExceptionInfo
1562 *sans;
1563
cristy4c08aed2011-07-01 19:47:50 +00001564 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001565 if (*option == '+')
1566 {
cristy269c9412011-10-13 23:41:15 +00001567 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001568 exception);
1569 (void) QueryColorCompliance("none",AllCompliance,
1570 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001571 if (draw_info->fill_pattern != (Image *) NULL)
1572 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1573 break;
1574 }
1575 sans=AcquireExceptionInfo();
cristy269c9412011-10-13 23:41:15 +00001576 (void) QueryColorCompliance(argv[i+1],AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001577 sans);
1578 status=QueryColorCompliance(argv[i+1],AllCompliance,
1579 &draw_info->fill,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001580 sans=DestroyExceptionInfo(sans);
1581 if (status == MagickFalse)
1582 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1583 exception);
1584 break;
1585 }
1586 if (LocaleCompare("flip",option+1) == 0)
1587 {
1588 /*
1589 Flip image scanlines.
1590 */
1591 (void) SyncImageSettings(mogrify_info,*image);
1592 mogrify_image=FlipImage(*image,exception);
1593 break;
1594 }
anthonydf8ebac2011-04-27 09:03:19 +00001595 if (LocaleCompare("floodfill",option+1) == 0)
1596 {
cristy4c08aed2011-07-01 19:47:50 +00001597 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001598 target;
1599
1600 /*
1601 Floodfill image.
1602 */
1603 (void) SyncImageSettings(mogrify_info,*image);
1604 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001605 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001606 exception);
cristyd42d9952011-07-08 14:21:50 +00001607 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001608 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001609 break;
1610 }
anthony3d2f4862011-05-01 13:48:16 +00001611 if (LocaleCompare("flop",option+1) == 0)
1612 {
1613 /*
1614 Flop image scanlines.
1615 */
1616 (void) SyncImageSettings(mogrify_info,*image);
1617 mogrify_image=FlopImage(*image,exception);
1618 break;
1619 }
anthonydf8ebac2011-04-27 09:03:19 +00001620 if (LocaleCompare("font",option+1) == 0)
1621 {
1622 if (*option == '+')
1623 {
1624 if (draw_info->font != (char *) NULL)
1625 draw_info->font=DestroyString(draw_info->font);
1626 break;
1627 }
1628 (void) CloneString(&draw_info->font,argv[i+1]);
1629 break;
1630 }
1631 if (LocaleCompare("format",option+1) == 0)
1632 {
1633 format=argv[i+1];
1634 break;
1635 }
1636 if (LocaleCompare("frame",option+1) == 0)
1637 {
1638 FrameInfo
1639 frame_info;
1640
1641 /*
1642 Surround image with an ornamental border.
1643 */
1644 (void) SyncImageSettings(mogrify_info,*image);
1645 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1646 frame_info.width=geometry.width;
1647 frame_info.height=geometry.height;
1648 if ((flags & HeightValue) == 0)
1649 frame_info.height=geometry.width;
1650 frame_info.outer_bevel=geometry.x;
1651 frame_info.inner_bevel=geometry.y;
1652 frame_info.x=(ssize_t) frame_info.width;
1653 frame_info.y=(ssize_t) frame_info.height;
1654 frame_info.width=(*image)->columns+2*frame_info.width;
1655 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001656 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001657 break;
1658 }
1659 if (LocaleCompare("function",option+1) == 0)
1660 {
1661 char
1662 *arguments,
1663 token[MaxTextExtent];
1664
1665 const char
1666 *p;
1667
1668 double
1669 *parameters;
1670
1671 MagickFunction
1672 function;
1673
1674 register ssize_t
1675 x;
1676
1677 size_t
1678 number_parameters;
1679
1680 /*
1681 Function Modify Image Values
1682 */
1683 (void) SyncImageSettings(mogrify_info,*image);
1684 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1685 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001686 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1687 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001688 if (arguments == (char *) NULL)
1689 break;
1690 p=(char *) arguments;
1691 for (x=0; *p != '\0'; x++)
1692 {
1693 GetMagickToken(p,&p,token);
1694 if (*token == ',')
1695 GetMagickToken(p,&p,token);
1696 }
1697 number_parameters=(size_t) x;
1698 parameters=(double *) AcquireQuantumMemory(number_parameters,
1699 sizeof(*parameters));
1700 if (parameters == (double *) NULL)
1701 ThrowWandFatalException(ResourceLimitFatalError,
1702 "MemoryAllocationFailed",(*image)->filename);
1703 (void) ResetMagickMemory(parameters,0,number_parameters*
1704 sizeof(*parameters));
1705 p=(char *) arguments;
1706 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1707 {
1708 GetMagickToken(p,&p,token);
1709 if (*token == ',')
1710 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001711 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001712 }
1713 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001714 (void) FunctionImage(*image,function,number_parameters,parameters,
1715 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001716 parameters=(double *) RelinquishMagickMemory(parameters);
1717 break;
1718 }
1719 break;
1720 }
1721 case 'g':
1722 {
1723 if (LocaleCompare("gamma",option+1) == 0)
1724 {
1725 /*
1726 Gamma image.
1727 */
1728 (void) SyncImageSettings(mogrify_info,*image);
1729 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001730 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001731 else
cristyb3e7c6c2011-07-24 01:43:55 +00001732 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1733 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001734 break;
1735 }
1736 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1737 (LocaleCompare("gaussian",option+1) == 0))
1738 {
1739 /*
1740 Gaussian blur image.
1741 */
1742 (void) SyncImageSettings(mogrify_info,*image);
1743 flags=ParseGeometry(argv[i+1],&geometry_info);
1744 if ((flags & SigmaValue) == 0)
1745 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001746 if ((flags & XiValue) == 0)
1747 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001748 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001749 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001750 break;
1751 }
1752 if (LocaleCompare("geometry",option+1) == 0)
1753 {
1754 /*
1755 Record Image offset, Resize last image.
1756 */
1757 (void) SyncImageSettings(mogrify_info,*image);
1758 if (*option == '+')
1759 {
1760 if ((*image)->geometry != (char *) NULL)
1761 (*image)->geometry=DestroyString((*image)->geometry);
1762 break;
1763 }
1764 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1765 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1766 (void) CloneString(&(*image)->geometry,argv[i+1]);
1767 else
1768 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1769 (*image)->filter,(*image)->blur,exception);
1770 break;
1771 }
1772 if (LocaleCompare("gravity",option+1) == 0)
1773 {
1774 if (*option == '+')
1775 {
1776 draw_info->gravity=UndefinedGravity;
1777 break;
1778 }
1779 draw_info->gravity=(GravityType) ParseCommandOption(
1780 MagickGravityOptions,MagickFalse,argv[i+1]);
1781 break;
1782 }
1783 break;
1784 }
1785 case 'h':
1786 {
1787 if (LocaleCompare("highlight-color",option+1) == 0)
1788 {
1789 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1790 break;
1791 }
1792 break;
1793 }
1794 case 'i':
1795 {
1796 if (LocaleCompare("identify",option+1) == 0)
1797 {
1798 char
1799 *text;
1800
1801 (void) SyncImageSettings(mogrify_info,*image);
1802 if (format == (char *) NULL)
1803 {
cristya4037272011-08-28 15:11:39 +00001804 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1805 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001806 break;
1807 }
cristy018f07f2011-09-04 21:15:19 +00001808 text=InterpretImageProperties(mogrify_info,*image,format,
1809 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001810 if (text == (char *) NULL)
1811 break;
1812 (void) fputs(text,stdout);
1813 (void) fputc('\n',stdout);
1814 text=DestroyString(text);
1815 break;
1816 }
1817 if (LocaleCompare("implode",option+1) == 0)
1818 {
1819 /*
1820 Implode image.
1821 */
1822 (void) SyncImageSettings(mogrify_info,*image);
1823 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001824 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1825 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001826 break;
1827 }
1828 if (LocaleCompare("interline-spacing",option+1) == 0)
1829 {
1830 if (*option == '+')
1831 (void) ParseGeometry("0",&geometry_info);
1832 else
1833 (void) ParseGeometry(argv[i+1],&geometry_info);
1834 draw_info->interline_spacing=geometry_info.rho;
1835 break;
1836 }
cristy28474bf2011-09-11 23:32:52 +00001837 if (LocaleCompare("interpolate",option+1) == 0)
1838 {
1839 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1840 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1841 break;
1842 }
anthonydf8ebac2011-04-27 09:03:19 +00001843 if (LocaleCompare("interword-spacing",option+1) == 0)
1844 {
1845 if (*option == '+')
1846 (void) ParseGeometry("0",&geometry_info);
1847 else
1848 (void) ParseGeometry(argv[i+1],&geometry_info);
1849 draw_info->interword_spacing=geometry_info.rho;
1850 break;
1851 }
1852 break;
1853 }
1854 case 'k':
1855 {
1856 if (LocaleCompare("kerning",option+1) == 0)
1857 {
1858 if (*option == '+')
1859 (void) ParseGeometry("0",&geometry_info);
1860 else
1861 (void) ParseGeometry(argv[i+1],&geometry_info);
1862 draw_info->kerning=geometry_info.rho;
1863 break;
1864 }
1865 break;
1866 }
1867 case 'l':
1868 {
1869 if (LocaleCompare("lat",option+1) == 0)
1870 {
1871 /*
1872 Local adaptive threshold image.
1873 */
1874 (void) SyncImageSettings(mogrify_info,*image);
1875 flags=ParseGeometry(argv[i+1],&geometry_info);
1876 if ((flags & PercentValue) != 0)
1877 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1878 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001879 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001880 geometry_info.xi,exception);
1881 break;
1882 }
1883 if (LocaleCompare("level",option+1) == 0)
1884 {
1885 MagickRealType
1886 black_point,
1887 gamma,
1888 white_point;
1889
1890 MagickStatusType
1891 flags;
1892
1893 /*
1894 Parse levels.
1895 */
1896 (void) SyncImageSettings(mogrify_info,*image);
1897 flags=ParseGeometry(argv[i+1],&geometry_info);
1898 black_point=geometry_info.rho;
1899 white_point=(MagickRealType) QuantumRange;
1900 if ((flags & SigmaValue) != 0)
1901 white_point=geometry_info.sigma;
1902 gamma=1.0;
1903 if ((flags & XiValue) != 0)
1904 gamma=geometry_info.xi;
1905 if ((flags & PercentValue) != 0)
1906 {
1907 black_point*=(MagickRealType) (QuantumRange/100.0);
1908 white_point*=(MagickRealType) (QuantumRange/100.0);
1909 }
1910 if ((flags & SigmaValue) == 0)
1911 white_point=(MagickRealType) QuantumRange-black_point;
1912 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001913 (void) LevelizeImage(*image,black_point,white_point,gamma,
1914 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001915 else
cristy01e9afd2011-08-10 17:38:41 +00001916 (void) LevelImage(*image,black_point,white_point,gamma,
1917 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001918 InheritException(exception,&(*image)->exception);
1919 break;
1920 }
1921 if (LocaleCompare("level-colors",option+1) == 0)
1922 {
1923 char
1924 token[MaxTextExtent];
1925
1926 const char
1927 *p;
1928
cristy4c08aed2011-07-01 19:47:50 +00001929 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001930 black_point,
1931 white_point;
1932
1933 p=(const char *) argv[i+1];
1934 GetMagickToken(p,&p,token); /* get black point color */
1935 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001936 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001937 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001938 else
cristy269c9412011-10-13 23:41:15 +00001939 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001940 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001941 if (isalpha((int) token[0]) || (token[0] == '#'))
1942 GetMagickToken(p,&p,token);
1943 if (*token == '\0')
1944 white_point=black_point; /* set everything to that color */
1945 else
1946 {
1947 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1948 GetMagickToken(p,&p,token); /* Get white point color. */
1949 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001950 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001951 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001952 else
cristy269c9412011-10-13 23:41:15 +00001953 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001954 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001955 }
cristy490408a2011-07-07 14:42:05 +00001956 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001957 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001958 break;
1959 }
1960 if (LocaleCompare("linear-stretch",option+1) == 0)
1961 {
1962 double
1963 black_point,
1964 white_point;
1965
1966 MagickStatusType
1967 flags;
1968
1969 (void) SyncImageSettings(mogrify_info,*image);
1970 flags=ParseGeometry(argv[i+1],&geometry_info);
1971 black_point=geometry_info.rho;
1972 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1973 if ((flags & SigmaValue) != 0)
1974 white_point=geometry_info.sigma;
1975 if ((flags & PercentValue) != 0)
1976 {
1977 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1978 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1979 }
1980 if ((flags & SigmaValue) == 0)
1981 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1982 black_point;
cristy33bd5152011-08-24 01:42:24 +00001983 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001984 InheritException(exception,&(*image)->exception);
1985 break;
1986 }
1987 if (LocaleCompare("linewidth",option+1) == 0)
1988 {
cristyc1acd842011-05-19 23:05:47 +00001989 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1990 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001991 break;
1992 }
1993 if (LocaleCompare("liquid-rescale",option+1) == 0)
1994 {
1995 /*
1996 Liquid rescale image.
1997 */
1998 (void) SyncImageSettings(mogrify_info,*image);
1999 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2000 if ((flags & XValue) == 0)
2001 geometry.x=1;
2002 if ((flags & YValue) == 0)
2003 geometry.y=0;
2004 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2005 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2006 break;
2007 }
2008 if (LocaleCompare("lowlight-color",option+1) == 0)
2009 {
2010 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2011 break;
2012 }
2013 break;
2014 }
2015 case 'm':
2016 {
2017 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002018 {
cristy3ed852e2009-09-05 21:47:34 +00002019 Image
anthonydf8ebac2011-04-27 09:03:19 +00002020 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002021
anthonydf8ebac2011-04-27 09:03:19 +00002022 /*
2023 Transform image colors to match this set of colors.
2024 */
2025 (void) SyncImageSettings(mogrify_info,*image);
2026 if (*option == '+')
2027 break;
2028 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2029 if (remap_image == (Image *) NULL)
2030 break;
cristy018f07f2011-09-04 21:15:19 +00002031 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002032 remap_image=DestroyImage(remap_image);
2033 break;
2034 }
2035 if (LocaleCompare("mask",option+1) == 0)
2036 {
2037 Image
2038 *mask;
2039
2040 (void) SyncImageSettings(mogrify_info,*image);
2041 if (*option == '+')
2042 {
2043 /*
2044 Remove a mask.
2045 */
cristy018f07f2011-09-04 21:15:19 +00002046 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002047 break;
2048 }
2049 /*
2050 Set the image mask.
2051 */
2052 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2053 if (mask == (Image *) NULL)
2054 break;
cristy018f07f2011-09-04 21:15:19 +00002055 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002056 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002057 break;
2058 }
2059 if (LocaleCompare("matte",option+1) == 0)
2060 {
2061 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002062 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002063 break;
2064 }
2065 if (LocaleCompare("median",option+1) == 0)
2066 {
2067 /*
2068 Median filter image.
2069 */
2070 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002071 flags=ParseGeometry(argv[i+1],&geometry_info);
2072 if ((flags & SigmaValue) == 0)
2073 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002074 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002075 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002076 break;
2077 }
2078 if (LocaleCompare("mode",option+1) == 0)
2079 {
2080 /*
2081 Mode image.
2082 */
2083 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002084 flags=ParseGeometry(argv[i+1],&geometry_info);
2085 if ((flags & SigmaValue) == 0)
2086 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002087 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002088 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002089 break;
2090 }
2091 if (LocaleCompare("modulate",option+1) == 0)
2092 {
2093 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002094 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002095 break;
2096 }
2097 if (LocaleCompare("monitor",option+1) == 0)
2098 {
2099 if (*option == '+')
2100 {
2101 (void) SetImageProgressMonitor(*image,
2102 (MagickProgressMonitor) NULL,(void *) NULL);
2103 break;
2104 }
2105 (void) SetImageProgressMonitor(*image,MonitorProgress,
2106 (void *) NULL);
2107 break;
2108 }
2109 if (LocaleCompare("monochrome",option+1) == 0)
2110 {
2111 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002112 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002113 break;
2114 }
2115 if (LocaleCompare("morphology",option+1) == 0)
2116 {
2117 char
2118 token[MaxTextExtent];
2119
2120 const char
2121 *p;
2122
2123 KernelInfo
2124 *kernel;
2125
2126 MorphologyMethod
2127 method;
2128
2129 ssize_t
2130 iterations;
2131
2132 /*
2133 Morphological Image Operation
2134 */
2135 (void) SyncImageSettings(mogrify_info,*image);
2136 p=argv[i+1];
2137 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002138 method=(MorphologyMethod) ParseCommandOption(
2139 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002140 iterations=1L;
2141 GetMagickToken(p,&p,token);
2142 if ((*p == ':') || (*p == ','))
2143 GetMagickToken(p,&p,token);
2144 if ((*p != '\0'))
2145 iterations=(ssize_t) StringToLong(p);
2146 kernel=AcquireKernelInfo(argv[i+2]);
2147 if (kernel == (KernelInfo *) NULL)
2148 {
2149 (void) ThrowMagickException(exception,GetMagickModule(),
2150 OptionError,"UnabletoParseKernel","morphology");
2151 status=MagickFalse;
2152 break;
2153 }
cristyf4ad9df2011-07-08 16:49:03 +00002154 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2155 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002156 kernel=DestroyKernelInfo(kernel);
2157 break;
2158 }
2159 if (LocaleCompare("motion-blur",option+1) == 0)
2160 {
2161 /*
2162 Motion blur image.
2163 */
2164 (void) SyncImageSettings(mogrify_info,*image);
2165 flags=ParseGeometry(argv[i+1],&geometry_info);
2166 if ((flags & SigmaValue) == 0)
2167 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002168 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002169 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2170 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002171 break;
2172 }
2173 break;
2174 }
2175 case 'n':
2176 {
2177 if (LocaleCompare("negate",option+1) == 0)
2178 {
2179 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002180 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002181 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002182 break;
2183 }
2184 if (LocaleCompare("noise",option+1) == 0)
2185 {
2186 (void) SyncImageSettings(mogrify_info,*image);
2187 if (*option == '-')
2188 {
cristyf36cbcb2011-09-07 13:28:22 +00002189 flags=ParseGeometry(argv[i+1],&geometry_info);
2190 if ((flags & SigmaValue) == 0)
2191 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002192 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002193 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002194 }
2195 else
2196 {
2197 NoiseType
2198 noise;
2199
2200 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2201 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002202 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002203 }
2204 break;
2205 }
2206 if (LocaleCompare("normalize",option+1) == 0)
2207 {
2208 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002209 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002210 break;
2211 }
2212 break;
2213 }
2214 case 'o':
2215 {
2216 if (LocaleCompare("opaque",option+1) == 0)
2217 {
cristy4c08aed2011-07-01 19:47:50 +00002218 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002219 target;
2220
2221 (void) SyncImageSettings(mogrify_info,*image);
cristy269c9412011-10-13 23:41:15 +00002222 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002223 exception);
cristyd42d9952011-07-08 14:21:50 +00002224 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002225 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002226 break;
2227 }
2228 if (LocaleCompare("ordered-dither",option+1) == 0)
2229 {
2230 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002231 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002232 break;
2233 }
2234 break;
2235 }
2236 case 'p':
2237 {
2238 if (LocaleCompare("paint",option+1) == 0)
2239 {
anthonydf8ebac2011-04-27 09:03:19 +00002240 (void) SyncImageSettings(mogrify_info,*image);
2241 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002242 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2243 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002244 break;
2245 }
2246 if (LocaleCompare("pen",option+1) == 0)
2247 {
2248 if (*option == '+')
2249 {
cristy9950d572011-10-01 18:22:35 +00002250 (void) QueryColorCompliance("none",AllCompliance,
2251 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002252 break;
2253 }
cristy9950d572011-10-01 18:22:35 +00002254 (void) QueryColorCompliance(argv[i+1],AllCompliance,
2255 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002256 break;
2257 }
2258 if (LocaleCompare("pointsize",option+1) == 0)
2259 {
2260 if (*option == '+')
2261 (void) ParseGeometry("12",&geometry_info);
2262 else
2263 (void) ParseGeometry(argv[i+1],&geometry_info);
2264 draw_info->pointsize=geometry_info.rho;
2265 break;
2266 }
2267 if (LocaleCompare("polaroid",option+1) == 0)
2268 {
2269 double
2270 angle;
2271
2272 RandomInfo
2273 *random_info;
2274
2275 /*
2276 Simulate a Polaroid picture.
2277 */
2278 (void) SyncImageSettings(mogrify_info,*image);
2279 random_info=AcquireRandomInfo();
2280 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2281 random_info=DestroyRandomInfo(random_info);
2282 if (*option == '-')
2283 {
2284 SetGeometryInfo(&geometry_info);
2285 flags=ParseGeometry(argv[i+1],&geometry_info);
2286 angle=geometry_info.rho;
2287 }
cristy5c4e2582011-09-11 19:21:03 +00002288 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002289 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002290 break;
2291 }
2292 if (LocaleCompare("posterize",option+1) == 0)
2293 {
2294 /*
2295 Posterize image.
2296 */
2297 (void) SyncImageSettings(mogrify_info,*image);
2298 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002299 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002300 break;
2301 }
2302 if (LocaleCompare("preview",option+1) == 0)
2303 {
2304 PreviewType
2305 preview_type;
2306
2307 /*
2308 Preview image.
2309 */
2310 (void) SyncImageSettings(mogrify_info,*image);
2311 if (*option == '+')
2312 preview_type=UndefinedPreview;
2313 else
cristy28474bf2011-09-11 23:32:52 +00002314 preview_type=(PreviewType) ParseCommandOption(
2315 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002316 mogrify_image=PreviewImage(*image,preview_type,exception);
2317 break;
2318 }
2319 if (LocaleCompare("profile",option+1) == 0)
2320 {
2321 const char
2322 *name;
2323
2324 const StringInfo
2325 *profile;
2326
2327 Image
2328 *profile_image;
2329
2330 ImageInfo
2331 *profile_info;
2332
2333 (void) SyncImageSettings(mogrify_info,*image);
2334 if (*option == '+')
2335 {
2336 /*
2337 Remove a profile from the image.
2338 */
2339 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002340 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002341 break;
2342 }
2343 /*
2344 Associate a profile with the image.
2345 */
2346 profile_info=CloneImageInfo(mogrify_info);
2347 profile=GetImageProfile(*image,"iptc");
2348 if (profile != (StringInfo *) NULL)
2349 profile_info->profile=(void *) CloneStringInfo(profile);
2350 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2351 profile_info=DestroyImageInfo(profile_info);
2352 if (profile_image == (Image *) NULL)
2353 {
2354 StringInfo
2355 *profile;
2356
2357 profile_info=CloneImageInfo(mogrify_info);
2358 (void) CopyMagickString(profile_info->filename,argv[i+1],
2359 MaxTextExtent);
2360 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2361 if (profile != (StringInfo *) NULL)
2362 {
2363 (void) ProfileImage(*image,profile_info->magick,
2364 GetStringInfoDatum(profile),(size_t)
2365 GetStringInfoLength(profile),MagickFalse);
2366 profile=DestroyStringInfo(profile);
2367 }
2368 profile_info=DestroyImageInfo(profile_info);
2369 break;
2370 }
2371 ResetImageProfileIterator(profile_image);
2372 name=GetNextImageProfile(profile_image);
2373 while (name != (const char *) NULL)
2374 {
2375 profile=GetImageProfile(profile_image,name);
2376 if (profile != (StringInfo *) NULL)
2377 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2378 (size_t) GetStringInfoLength(profile),MagickFalse);
2379 name=GetNextImageProfile(profile_image);
2380 }
2381 profile_image=DestroyImage(profile_image);
2382 break;
2383 }
2384 break;
2385 }
2386 case 'q':
2387 {
2388 if (LocaleCompare("quantize",option+1) == 0)
2389 {
2390 if (*option == '+')
2391 {
2392 quantize_info->colorspace=UndefinedColorspace;
2393 break;
2394 }
2395 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2396 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2397 break;
2398 }
2399 break;
2400 }
2401 case 'r':
2402 {
2403 if (LocaleCompare("radial-blur",option+1) == 0)
2404 {
2405 /*
2406 Radial blur image.
2407 */
2408 (void) SyncImageSettings(mogrify_info,*image);
cristy6435bd92011-09-10 02:10:07 +00002409 flags=ParseGeometry(argv[i+1],&geometry_info);
2410 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2411 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002412 break;
2413 }
2414 if (LocaleCompare("raise",option+1) == 0)
2415 {
2416 /*
2417 Surround image with a raise of solid color.
2418 */
2419 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2420 if ((flags & SigmaValue) == 0)
2421 geometry.height=geometry.width;
2422 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002423 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002424 break;
2425 }
2426 if (LocaleCompare("random-threshold",option+1) == 0)
2427 {
2428 /*
2429 Threshold image.
2430 */
2431 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002432 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002433 break;
2434 }
2435 if (LocaleCompare("recolor",option+1) == 0)
2436 {
2437 KernelInfo
2438 *kernel;
2439
2440 (void) SyncImageSettings(mogrify_info,*image);
2441 kernel=AcquireKernelInfo(argv[i+1]);
2442 if (kernel == (KernelInfo *) NULL)
2443 break;
2444 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2445 kernel=DestroyKernelInfo(kernel);
2446 break;
2447 }
2448 if (LocaleCompare("region",option+1) == 0)
2449 {
2450 (void) SyncImageSettings(mogrify_info,*image);
2451 if (region_image != (Image *) NULL)
2452 {
2453 /*
2454 Composite region.
2455 */
2456 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002457 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2458 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002459 InheritException(exception,&region_image->exception);
2460 *image=DestroyImage(*image);
2461 *image=region_image;
2462 region_image = (Image *) NULL;
2463 }
2464 if (*option == '+')
2465 break;
2466 /*
2467 Apply transformations to a selected region of the image.
2468 */
cristy3ed852e2009-09-05 21:47:34 +00002469 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2470 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002471 mogrify_image=CropImage(*image,&region_geometry,exception);
2472 if (mogrify_image == (Image *) NULL)
2473 break;
2474 region_image=(*image);
2475 *image=mogrify_image;
2476 mogrify_image=(Image *) NULL;
2477 break;
cristy3ed852e2009-09-05 21:47:34 +00002478 }
anthonydf8ebac2011-04-27 09:03:19 +00002479 if (LocaleCompare("render",option+1) == 0)
2480 {
2481 (void) SyncImageSettings(mogrify_info,*image);
2482 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2483 break;
2484 }
2485 if (LocaleCompare("remap",option+1) == 0)
2486 {
2487 Image
2488 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002489
anthonydf8ebac2011-04-27 09:03:19 +00002490 /*
2491 Transform image colors to match this set of colors.
2492 */
2493 (void) SyncImageSettings(mogrify_info,*image);
2494 if (*option == '+')
2495 break;
2496 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2497 if (remap_image == (Image *) NULL)
2498 break;
cristy018f07f2011-09-04 21:15:19 +00002499 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002500 remap_image=DestroyImage(remap_image);
2501 break;
2502 }
2503 if (LocaleCompare("repage",option+1) == 0)
2504 {
2505 if (*option == '+')
2506 {
2507 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2508 break;
2509 }
2510 (void) ResetImagePage(*image,argv[i+1]);
2511 InheritException(exception,&(*image)->exception);
2512 break;
2513 }
2514 if (LocaleCompare("resample",option+1) == 0)
2515 {
2516 /*
2517 Resample image.
2518 */
2519 (void) SyncImageSettings(mogrify_info,*image);
2520 flags=ParseGeometry(argv[i+1],&geometry_info);
2521 if ((flags & SigmaValue) == 0)
2522 geometry_info.sigma=geometry_info.rho;
2523 mogrify_image=ResampleImage(*image,geometry_info.rho,
2524 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2525 break;
2526 }
2527 if (LocaleCompare("resize",option+1) == 0)
2528 {
2529 /*
2530 Resize image.
2531 */
2532 (void) SyncImageSettings(mogrify_info,*image);
2533 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2534 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2535 (*image)->filter,(*image)->blur,exception);
2536 break;
2537 }
2538 if (LocaleCompare("roll",option+1) == 0)
2539 {
2540 /*
2541 Roll image.
2542 */
2543 (void) SyncImageSettings(mogrify_info,*image);
2544 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2545 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2546 break;
2547 }
2548 if (LocaleCompare("rotate",option+1) == 0)
2549 {
2550 char
2551 *geometry;
2552
2553 /*
2554 Check for conditional image rotation.
2555 */
2556 (void) SyncImageSettings(mogrify_info,*image);
2557 if (strchr(argv[i+1],'>') != (char *) NULL)
2558 if ((*image)->columns <= (*image)->rows)
2559 break;
2560 if (strchr(argv[i+1],'<') != (char *) NULL)
2561 if ((*image)->columns >= (*image)->rows)
2562 break;
2563 /*
2564 Rotate image.
2565 */
2566 geometry=ConstantString(argv[i+1]);
2567 (void) SubstituteString(&geometry,">","");
2568 (void) SubstituteString(&geometry,"<","");
2569 (void) ParseGeometry(geometry,&geometry_info);
2570 geometry=DestroyString(geometry);
2571 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2572 break;
2573 }
2574 break;
2575 }
2576 case 's':
2577 {
2578 if (LocaleCompare("sample",option+1) == 0)
2579 {
2580 /*
2581 Sample image with pixel replication.
2582 */
2583 (void) SyncImageSettings(mogrify_info,*image);
2584 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2585 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2586 exception);
2587 break;
2588 }
2589 if (LocaleCompare("scale",option+1) == 0)
2590 {
2591 /*
2592 Resize image.
2593 */
2594 (void) SyncImageSettings(mogrify_info,*image);
2595 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2596 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2597 exception);
2598 break;
2599 }
2600 if (LocaleCompare("selective-blur",option+1) == 0)
2601 {
2602 /*
2603 Selectively blur pixels within a contrast threshold.
2604 */
2605 (void) SyncImageSettings(mogrify_info,*image);
2606 flags=ParseGeometry(argv[i+1],&geometry_info);
2607 if ((flags & PercentValue) != 0)
2608 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002609 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002610 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002611 break;
2612 }
2613 if (LocaleCompare("separate",option+1) == 0)
2614 {
2615 /*
2616 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002617 */
2618 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002619 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002620 break;
2621 }
2622 if (LocaleCompare("sepia-tone",option+1) == 0)
2623 {
2624 double
2625 threshold;
2626
2627 /*
2628 Sepia-tone image.
2629 */
2630 (void) SyncImageSettings(mogrify_info,*image);
2631 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2632 mogrify_image=SepiaToneImage(*image,threshold,exception);
2633 break;
2634 }
2635 if (LocaleCompare("segment",option+1) == 0)
2636 {
2637 /*
2638 Segment image.
2639 */
2640 (void) SyncImageSettings(mogrify_info,*image);
2641 flags=ParseGeometry(argv[i+1],&geometry_info);
2642 if ((flags & SigmaValue) == 0)
2643 geometry_info.sigma=1.0;
2644 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002645 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2646 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002647 break;
2648 }
2649 if (LocaleCompare("set",option+1) == 0)
2650 {
2651 char
2652 *value;
2653
2654 /*
2655 Set image option.
2656 */
2657 if (*option == '+')
2658 {
2659 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2660 (void) DeleteImageRegistry(argv[i+1]+9);
2661 else
2662 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2663 {
2664 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2665 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2666 }
2667 else
2668 (void) DeleteImageProperty(*image,argv[i+1]);
2669 break;
2670 }
cristy018f07f2011-09-04 21:15:19 +00002671 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2672 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002673 if (value == (char *) NULL)
2674 break;
2675 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2676 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2677 exception);
2678 else
2679 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2680 {
2681 (void) SetImageOption(image_info,argv[i+1]+7,value);
2682 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2683 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2684 }
2685 else
cristyd15e6592011-10-15 00:13:06 +00002686 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002687 value=DestroyString(value);
2688 break;
2689 }
2690 if (LocaleCompare("shade",option+1) == 0)
2691 {
2692 /*
2693 Shade image.
2694 */
2695 (void) SyncImageSettings(mogrify_info,*image);
2696 flags=ParseGeometry(argv[i+1],&geometry_info);
2697 if ((flags & SigmaValue) == 0)
2698 geometry_info.sigma=1.0;
2699 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2700 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2701 break;
2702 }
2703 if (LocaleCompare("shadow",option+1) == 0)
2704 {
2705 /*
2706 Shadow image.
2707 */
2708 (void) SyncImageSettings(mogrify_info,*image);
2709 flags=ParseGeometry(argv[i+1],&geometry_info);
2710 if ((flags & SigmaValue) == 0)
2711 geometry_info.sigma=1.0;
2712 if ((flags & XiValue) == 0)
2713 geometry_info.xi=4.0;
2714 if ((flags & PsiValue) == 0)
2715 geometry_info.psi=4.0;
2716 mogrify_image=ShadowImage(*image,geometry_info.rho,
2717 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2718 ceil(geometry_info.psi-0.5),exception);
2719 break;
2720 }
2721 if (LocaleCompare("sharpen",option+1) == 0)
2722 {
2723 /*
2724 Sharpen image.
2725 */
2726 (void) SyncImageSettings(mogrify_info,*image);
2727 flags=ParseGeometry(argv[i+1],&geometry_info);
2728 if ((flags & SigmaValue) == 0)
2729 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002730 if ((flags & XiValue) == 0)
2731 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002732 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002733 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002734 break;
2735 }
2736 if (LocaleCompare("shave",option+1) == 0)
2737 {
2738 /*
2739 Shave the image edges.
2740 */
2741 (void) SyncImageSettings(mogrify_info,*image);
2742 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2743 mogrify_image=ShaveImage(*image,&geometry,exception);
2744 break;
2745 }
2746 if (LocaleCompare("shear",option+1) == 0)
2747 {
2748 /*
2749 Shear image.
2750 */
2751 (void) SyncImageSettings(mogrify_info,*image);
2752 flags=ParseGeometry(argv[i+1],&geometry_info);
2753 if ((flags & SigmaValue) == 0)
2754 geometry_info.sigma=geometry_info.rho;
2755 mogrify_image=ShearImage(*image,geometry_info.rho,
2756 geometry_info.sigma,exception);
2757 break;
2758 }
2759 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2760 {
2761 /*
2762 Sigmoidal non-linearity contrast control.
2763 */
2764 (void) SyncImageSettings(mogrify_info,*image);
2765 flags=ParseGeometry(argv[i+1],&geometry_info);
2766 if ((flags & SigmaValue) == 0)
2767 geometry_info.sigma=(double) QuantumRange/2.0;
2768 if ((flags & PercentValue) != 0)
2769 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2770 100.0;
cristy9ee60942011-07-06 14:54:38 +00002771 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002772 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2773 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002774 break;
2775 }
2776 if (LocaleCompare("sketch",option+1) == 0)
2777 {
2778 /*
2779 Sketch image.
2780 */
2781 (void) SyncImageSettings(mogrify_info,*image);
2782 flags=ParseGeometry(argv[i+1],&geometry_info);
2783 if ((flags & SigmaValue) == 0)
2784 geometry_info.sigma=1.0;
2785 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002786 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002787 break;
2788 }
2789 if (LocaleCompare("solarize",option+1) == 0)
2790 {
2791 double
2792 threshold;
2793
2794 (void) SyncImageSettings(mogrify_info,*image);
2795 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002796 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002797 break;
2798 }
2799 if (LocaleCompare("sparse-color",option+1) == 0)
2800 {
2801 SparseColorMethod
2802 method;
2803
2804 char
2805 *arguments;
2806
2807 /*
2808 Sparse Color Interpolated Gradient
2809 */
2810 (void) SyncImageSettings(mogrify_info,*image);
2811 method=(SparseColorMethod) ParseCommandOption(
2812 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002813 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2814 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002815 if (arguments == (char *) NULL)
2816 break;
cristy3884f692011-07-08 18:00:18 +00002817 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002818 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2819 arguments=DestroyString(arguments);
2820 break;
2821 }
2822 if (LocaleCompare("splice",option+1) == 0)
2823 {
2824 /*
2825 Splice a solid color into the image.
2826 */
2827 (void) SyncImageSettings(mogrify_info,*image);
2828 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2829 mogrify_image=SpliceImage(*image,&geometry,exception);
2830 break;
2831 }
2832 if (LocaleCompare("spread",option+1) == 0)
2833 {
2834 /*
2835 Spread an image.
2836 */
2837 (void) SyncImageSettings(mogrify_info,*image);
2838 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002839 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002840 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002841 break;
2842 }
2843 if (LocaleCompare("statistic",option+1) == 0)
2844 {
2845 StatisticType
2846 type;
2847
2848 (void) SyncImageSettings(mogrify_info,*image);
2849 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2850 MagickFalse,argv[i+1]);
2851 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002852 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2853 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002854 break;
2855 }
2856 if (LocaleCompare("stretch",option+1) == 0)
2857 {
2858 if (*option == '+')
2859 {
2860 draw_info->stretch=UndefinedStretch;
2861 break;
2862 }
2863 draw_info->stretch=(StretchType) ParseCommandOption(
2864 MagickStretchOptions,MagickFalse,argv[i+1]);
2865 break;
2866 }
2867 if (LocaleCompare("strip",option+1) == 0)
2868 {
2869 /*
2870 Strip image of profiles and comments.
2871 */
2872 (void) SyncImageSettings(mogrify_info,*image);
2873 (void) StripImage(*image);
2874 InheritException(exception,&(*image)->exception);
2875 break;
2876 }
2877 if (LocaleCompare("stroke",option+1) == 0)
2878 {
2879 ExceptionInfo
2880 *sans;
2881
2882 if (*option == '+')
2883 {
cristy9950d572011-10-01 18:22:35 +00002884 (void) QueryColorCompliance("none",AllCompliance,
2885 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002886 if (draw_info->stroke_pattern != (Image *) NULL)
2887 draw_info->stroke_pattern=DestroyImage(
2888 draw_info->stroke_pattern);
2889 break;
2890 }
2891 sans=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00002892 status=QueryColorCompliance(argv[i+1],AllCompliance,
2893 &draw_info->stroke,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002894 sans=DestroyExceptionInfo(sans);
2895 if (status == MagickFalse)
2896 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2897 exception);
2898 break;
2899 }
2900 if (LocaleCompare("strokewidth",option+1) == 0)
2901 {
cristyc1acd842011-05-19 23:05:47 +00002902 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2903 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002904 break;
2905 }
2906 if (LocaleCompare("style",option+1) == 0)
2907 {
2908 if (*option == '+')
2909 {
2910 draw_info->style=UndefinedStyle;
2911 break;
2912 }
2913 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2914 MagickFalse,argv[i+1]);
2915 break;
2916 }
2917 if (LocaleCompare("swirl",option+1) == 0)
2918 {
2919 /*
2920 Swirl image.
2921 */
2922 (void) SyncImageSettings(mogrify_info,*image);
2923 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002924 mogrify_image=SwirlImage(*image,geometry_info.rho,
2925 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002926 break;
2927 }
2928 break;
2929 }
2930 case 't':
2931 {
2932 if (LocaleCompare("threshold",option+1) == 0)
2933 {
2934 double
2935 threshold;
2936
2937 /*
2938 Threshold image.
2939 */
2940 (void) SyncImageSettings(mogrify_info,*image);
2941 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002942 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002943 else
2944 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002945 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002946 InheritException(exception,&(*image)->exception);
2947 break;
2948 }
2949 if (LocaleCompare("thumbnail",option+1) == 0)
2950 {
2951 /*
2952 Thumbnail image.
2953 */
2954 (void) SyncImageSettings(mogrify_info,*image);
2955 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2956 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2957 exception);
2958 break;
2959 }
2960 if (LocaleCompare("tile",option+1) == 0)
2961 {
2962 if (*option == '+')
2963 {
2964 if (draw_info->fill_pattern != (Image *) NULL)
2965 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2966 break;
2967 }
2968 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2969 exception);
2970 break;
2971 }
2972 if (LocaleCompare("tint",option+1) == 0)
2973 {
2974 /*
2975 Tint the image.
2976 */
2977 (void) SyncImageSettings(mogrify_info,*image);
cristy28474bf2011-09-11 23:32:52 +00002978 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002979 break;
2980 }
2981 if (LocaleCompare("transform",option+1) == 0)
2982 {
2983 /*
2984 Affine transform image.
2985 */
2986 (void) SyncImageSettings(mogrify_info,*image);
2987 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2988 exception);
2989 break;
2990 }
2991 if (LocaleCompare("transparent",option+1) == 0)
2992 {
cristy4c08aed2011-07-01 19:47:50 +00002993 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002994 target;
2995
2996 (void) SyncImageSettings(mogrify_info,*image);
cristy269c9412011-10-13 23:41:15 +00002997 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002998 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002999 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003000 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
3001 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00003002 break;
3003 }
3004 if (LocaleCompare("transpose",option+1) == 0)
3005 {
3006 /*
3007 Transpose image scanlines.
3008 */
3009 (void) SyncImageSettings(mogrify_info,*image);
3010 mogrify_image=TransposeImage(*image,exception);
3011 break;
3012 }
3013 if (LocaleCompare("transverse",option+1) == 0)
3014 {
3015 /*
3016 Transverse image scanlines.
3017 */
3018 (void) SyncImageSettings(mogrify_info,*image);
3019 mogrify_image=TransverseImage(*image,exception);
3020 break;
3021 }
3022 if (LocaleCompare("treedepth",option+1) == 0)
3023 {
3024 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3025 break;
3026 }
3027 if (LocaleCompare("trim",option+1) == 0)
3028 {
3029 /*
3030 Trim image.
3031 */
3032 (void) SyncImageSettings(mogrify_info,*image);
3033 mogrify_image=TrimImage(*image,exception);
3034 break;
3035 }
3036 if (LocaleCompare("type",option+1) == 0)
3037 {
3038 ImageType
3039 type;
3040
3041 (void) SyncImageSettings(mogrify_info,*image);
3042 if (*option == '+')
3043 type=UndefinedType;
3044 else
3045 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3046 argv[i+1]);
3047 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003048 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003049 break;
3050 }
3051 break;
3052 }
3053 case 'u':
3054 {
3055 if (LocaleCompare("undercolor",option+1) == 0)
3056 {
cristy9950d572011-10-01 18:22:35 +00003057 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3058 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003059 break;
3060 }
3061 if (LocaleCompare("unique",option+1) == 0)
3062 {
3063 if (*option == '+')
3064 {
3065 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3066 break;
3067 }
3068 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3069 (void) SetImageArtifact(*image,"verbose","true");
3070 break;
3071 }
3072 if (LocaleCompare("unique-colors",option+1) == 0)
3073 {
3074 /*
3075 Unique image colors.
3076 */
3077 (void) SyncImageSettings(mogrify_info,*image);
3078 mogrify_image=UniqueImageColors(*image,exception);
3079 break;
3080 }
3081 if (LocaleCompare("unsharp",option+1) == 0)
3082 {
3083 /*
3084 Unsharp mask image.
3085 */
3086 (void) SyncImageSettings(mogrify_info,*image);
3087 flags=ParseGeometry(argv[i+1],&geometry_info);
3088 if ((flags & SigmaValue) == 0)
3089 geometry_info.sigma=1.0;
3090 if ((flags & XiValue) == 0)
3091 geometry_info.xi=1.0;
3092 if ((flags & PsiValue) == 0)
3093 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003094 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3095 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003096 break;
3097 }
3098 break;
3099 }
3100 case 'v':
3101 {
3102 if (LocaleCompare("verbose",option+1) == 0)
3103 {
3104 (void) SetImageArtifact(*image,option+1,
3105 *option == '+' ? "false" : "true");
3106 break;
3107 }
3108 if (LocaleCompare("vignette",option+1) == 0)
3109 {
3110 /*
3111 Vignette image.
3112 */
3113 (void) SyncImageSettings(mogrify_info,*image);
3114 flags=ParseGeometry(argv[i+1],&geometry_info);
3115 if ((flags & SigmaValue) == 0)
3116 geometry_info.sigma=1.0;
3117 if ((flags & XiValue) == 0)
3118 geometry_info.xi=0.1*(*image)->columns;
3119 if ((flags & PsiValue) == 0)
3120 geometry_info.psi=0.1*(*image)->rows;
3121 mogrify_image=VignetteImage(*image,geometry_info.rho,
3122 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3123 ceil(geometry_info.psi-0.5),exception);
3124 break;
3125 }
3126 if (LocaleCompare("virtual-pixel",option+1) == 0)
3127 {
3128 if (*option == '+')
3129 {
3130 (void) SetImageVirtualPixelMethod(*image,
3131 UndefinedVirtualPixelMethod);
3132 break;
3133 }
3134 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3135 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3136 argv[i+1]));
3137 break;
3138 }
3139 break;
3140 }
3141 case 'w':
3142 {
3143 if (LocaleCompare("wave",option+1) == 0)
3144 {
3145 /*
3146 Wave image.
3147 */
3148 (void) SyncImageSettings(mogrify_info,*image);
3149 flags=ParseGeometry(argv[i+1],&geometry_info);
3150 if ((flags & SigmaValue) == 0)
3151 geometry_info.sigma=1.0;
3152 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003153 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003154 break;
3155 }
3156 if (LocaleCompare("weight",option+1) == 0)
3157 {
3158 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3159 if (LocaleCompare(argv[i+1],"all") == 0)
3160 draw_info->weight=0;
3161 if (LocaleCompare(argv[i+1],"bold") == 0)
3162 draw_info->weight=700;
3163 if (LocaleCompare(argv[i+1],"bolder") == 0)
3164 if (draw_info->weight <= 800)
3165 draw_info->weight+=100;
3166 if (LocaleCompare(argv[i+1],"lighter") == 0)
3167 if (draw_info->weight >= 100)
3168 draw_info->weight-=100;
3169 if (LocaleCompare(argv[i+1],"normal") == 0)
3170 draw_info->weight=400;
3171 break;
3172 }
3173 if (LocaleCompare("white-threshold",option+1) == 0)
3174 {
3175 /*
3176 White threshold image.
3177 */
3178 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003179 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003180 InheritException(exception,&(*image)->exception);
3181 break;
3182 }
3183 break;
3184 }
3185 default:
3186 break;
3187 }
3188 /*
3189 Replace current image with any image that was generated
3190 */
3191 if (mogrify_image != (Image *) NULL)
3192 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003193 i+=count;
3194 }
3195 if (region_image != (Image *) NULL)
3196 {
anthonydf8ebac2011-04-27 09:03:19 +00003197 /*
3198 Composite transformed region onto image.
3199 */
cristy6b3da3a2010-06-20 02:21:46 +00003200 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003201 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003202 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3203 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003204 InheritException(exception,&region_image->exception);
3205 *image=DestroyImage(*image);
3206 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003207 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003208 }
3209 /*
3210 Free resources.
3211 */
anthonydf8ebac2011-04-27 09:03:19 +00003212 quantize_info=DestroyQuantizeInfo(quantize_info);
3213 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003214 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003215 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003216 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003217 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003218}
3219
3220/*
3221%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3222% %
3223% %
3224% %
cristy5063d812010-10-19 16:28:10 +00003225+ 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 +00003226% %
3227% %
3228% %
3229%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3230%
3231% MogrifyImageCommand() transforms an image or a sequence of images. These
3232% transforms include image scaling, image rotation, color reduction, and
3233% others. The transmogrified image overwrites the original image.
3234%
3235% The format of the MogrifyImageCommand method is:
3236%
3237% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3238% const char **argv,char **metadata,ExceptionInfo *exception)
3239%
3240% A description of each parameter follows:
3241%
3242% o image_info: the image info.
3243%
3244% o argc: the number of elements in the argument vector.
3245%
3246% o argv: A text array containing the command line arguments.
3247%
3248% o metadata: any metadata is returned here.
3249%
3250% o exception: return any errors or warnings in this structure.
3251%
3252*/
3253
3254static MagickBooleanType MogrifyUsage(void)
3255{
3256 static const char
3257 *miscellaneous[]=
3258 {
3259 "-debug events display copious debugging information",
3260 "-help print program options",
3261 "-list type print a list of supported option arguments",
3262 "-log format format of debugging information",
3263 "-version print version information",
3264 (char *) NULL
3265 },
3266 *operators[]=
3267 {
3268 "-adaptive-blur geometry",
3269 " adaptively blur pixels; decrease effect near edges",
3270 "-adaptive-resize geometry",
3271 " adaptively resize image using 'mesh' interpolation",
3272 "-adaptive-sharpen geometry",
3273 " adaptively sharpen pixels; increase effect near edges",
3274 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3275 " transparent, extract, background, or shape",
3276 "-annotate geometry text",
3277 " annotate the image with text",
3278 "-auto-gamma automagically adjust gamma level of image",
3279 "-auto-level automagically adjust color levels of image",
3280 "-auto-orient automagically orient (rotate) image",
3281 "-bench iterations measure performance",
3282 "-black-threshold value",
3283 " force all pixels below the threshold into black",
3284 "-blue-shift simulate a scene at nighttime in the moonlight",
3285 "-blur geometry reduce image noise and reduce detail levels",
3286 "-border geometry surround image with a border of color",
3287 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003288 "-brightness-contrast geometry",
3289 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003290 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003291 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003292 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003293 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003294 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003295 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003296 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003297 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003298 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003299 "-contrast enhance or reduce the image contrast",
3300 "-contrast-stretch geometry",
3301 " improve contrast by `stretching' the intensity range",
3302 "-convolve coefficients",
3303 " apply a convolution kernel to the image",
3304 "-cycle amount cycle the image colormap",
3305 "-decipher filename convert cipher pixels to plain pixels",
3306 "-deskew threshold straighten an image",
3307 "-despeckle reduce the speckles within an image",
3308 "-distort method args",
3309 " distort images according to given method ad args",
3310 "-draw string annotate the image with a graphic primitive",
3311 "-edge radius apply a filter to detect edges in the image",
3312 "-encipher filename convert plain pixels to cipher pixels",
3313 "-emboss radius emboss an image",
3314 "-enhance apply a digital filter to enhance a noisy image",
3315 "-equalize perform histogram equalization to an image",
3316 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003317 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003318 "-extent geometry set the image size",
3319 "-extract geometry extract area from image",
3320 "-fft implements the discrete Fourier transform (DFT)",
3321 "-flip flip image vertically",
3322 "-floodfill geometry color",
3323 " floodfill the image with color",
3324 "-flop flop image horizontally",
3325 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003326 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003327 " apply function over image values",
3328 "-gamma value level of gamma correction",
3329 "-gaussian-blur geometry",
3330 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003331 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003332 "-identify identify the format and characteristics of the image",
3333 "-ift implements the inverse discrete Fourier transform (DFT)",
3334 "-implode amount implode image pixels about the center",
3335 "-lat geometry local adaptive thresholding",
3336 "-layers method optimize, merge, or compare image layers",
3337 "-level value adjust the level of image contrast",
3338 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003339 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003340 "-linear-stretch geometry",
3341 " improve contrast by `stretching with saturation'",
3342 "-liquid-rescale geometry",
3343 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003344 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003345 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003346 "-modulate value vary the brightness, saturation, and hue",
3347 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003348 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003349 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003350 "-motion-blur geometry",
3351 " simulate motion blur",
3352 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003353 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003354 "-normalize transform image to span the full range of colors",
3355 "-opaque color change this color to the fill color",
3356 "-ordered-dither NxN",
3357 " add a noise pattern to the image with specific",
3358 " amplitudes",
3359 "-paint radius simulate an oil painting",
3360 "-polaroid angle simulate a Polaroid picture",
3361 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003362 "-profile filename add, delete, or apply an image profile",
3363 "-quantize colorspace reduce colors in this colorspace",
3364 "-radial-blur angle radial blur the image",
3365 "-raise value lighten/darken image edges to create a 3-D effect",
3366 "-random-threshold low,high",
3367 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003368 "-region geometry apply options to a portion of the image",
3369 "-render render vector graphics",
3370 "-repage geometry size and location of an image canvas",
3371 "-resample geometry change the resolution of an image",
3372 "-resize geometry resize the image",
3373 "-roll geometry roll an image vertically or horizontally",
3374 "-rotate degrees apply Paeth rotation to the image",
3375 "-sample geometry scale image with pixel sampling",
3376 "-scale geometry scale the image",
3377 "-segment values segment an image",
3378 "-selective-blur geometry",
3379 " selectively blur pixels within a contrast threshold",
3380 "-sepia-tone threshold",
3381 " simulate a sepia-toned photo",
3382 "-set property value set an image property",
3383 "-shade degrees shade the image using a distant light source",
3384 "-shadow geometry simulate an image shadow",
3385 "-sharpen geometry sharpen the image",
3386 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003387 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003388 "-sigmoidal-contrast geometry",
3389 " increase the contrast without saturating highlights or shadows",
3390 "-sketch geometry simulate a pencil sketch",
3391 "-solarize threshold negate all pixels above the threshold level",
3392 "-sparse-color method args",
3393 " fill in a image based on a few color points",
3394 "-splice geometry splice the background color into the image",
3395 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003396 "-statistic type radius",
3397 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003398 "-strip strip image of all profiles and comments",
3399 "-swirl degrees swirl image pixels about the center",
3400 "-threshold value threshold the image",
3401 "-thumbnail geometry create a thumbnail of the image",
3402 "-tile filename tile image when filling a graphic primitive",
3403 "-tint value tint the image with the fill color",
3404 "-transform affine transform image",
3405 "-transparent color make this color transparent within the image",
3406 "-transpose flip image vertically and rotate 90 degrees",
3407 "-transverse flop image horizontally and rotate 270 degrees",
3408 "-trim trim image edges",
3409 "-type type image type",
3410 "-unique-colors discard all but one of any pixel color",
3411 "-unsharp geometry sharpen the image",
3412 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003413 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003414 "-white-threshold value",
3415 " force all pixels above the threshold into white",
3416 (char *) NULL
3417 },
3418 *sequence_operators[]=
3419 {
cristy4285d782011-02-09 20:12:28 +00003420 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003421 "-clut apply a color lookup table to the image",
3422 "-coalesce merge a sequence of images",
3423 "-combine combine a sequence of images",
3424 "-composite composite image",
3425 "-crop geometry cut out a rectangular region of the image",
3426 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003427 "-evaluate-sequence operator",
3428 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003429 "-flatten flatten a sequence of images",
3430 "-fx expression apply mathematical expression to an image channel(s)",
3431 "-hald-clut apply a Hald color lookup table to the image",
3432 "-morph value morph an image sequence",
3433 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003434 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003435 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003436 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003437 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003438 "-write filename write images to this file",
3439 (char *) NULL
3440 },
3441 *settings[]=
3442 {
3443 "-adjoin join images into a single multi-image file",
3444 "-affine matrix affine transform matrix",
3445 "-alpha option activate, deactivate, reset, or set the alpha channel",
3446 "-antialias remove pixel-aliasing",
3447 "-authenticate password",
3448 " decipher image with this password",
3449 "-attenuate value lessen (or intensify) when adding noise to an image",
3450 "-background color background color",
3451 "-bias value add bias when convolving an image",
3452 "-black-point-compensation",
3453 " use black point compensation",
3454 "-blue-primary point chromaticity blue primary point",
3455 "-bordercolor color border color",
3456 "-caption string assign a caption to an image",
3457 "-channel type apply option to select image channels",
3458 "-colors value preferred number of colors in the image",
3459 "-colorspace type alternate image colorspace",
3460 "-comment string annotate image with comment",
3461 "-compose operator set image composite operator",
3462 "-compress type type of pixel compression when writing the image",
3463 "-define format:option",
3464 " define one or more image format options",
3465 "-delay value display the next image after pausing",
3466 "-density geometry horizontal and vertical density of the image",
3467 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003468 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003469 "-display server get image or font from this X server",
3470 "-dispose method layer disposal method",
3471 "-dither method apply error diffusion to image",
3472 "-encoding type text encoding type",
3473 "-endian type endianness (MSB or LSB) of the image",
3474 "-family name render text with this font family",
3475 "-fill color color to use when filling a graphic primitive",
3476 "-filter type use this filter when resizing an image",
3477 "-font name render text with this font",
3478 "-format \"string\" output formatted image characteristics",
3479 "-fuzz distance colors within this distance are considered equal",
3480 "-gravity type horizontal and vertical text placement",
3481 "-green-primary point chromaticity green primary point",
3482 "-intent type type of rendering intent when managing the image color",
3483 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003484 "-interline-spacing value",
3485 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003486 "-interpolate method pixel color interpolation method",
3487 "-interword-spacing value",
3488 " set the space between two words",
3489 "-kerning value set the space between two letters",
3490 "-label string assign a label to an image",
3491 "-limit type value pixel cache resource limit",
3492 "-loop iterations add Netscape loop extension to your GIF animation",
3493 "-mask filename associate a mask with the image",
3494 "-mattecolor color frame color",
3495 "-monitor monitor progress",
3496 "-orient type image orientation",
3497 "-page geometry size and location of an image canvas (setting)",
3498 "-ping efficiently determine image attributes",
3499 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003500 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003501 "-preview type image preview type",
3502 "-quality value JPEG/MIFF/PNG compression level",
3503 "-quiet suppress all warning messages",
3504 "-red-primary point chromaticity red primary point",
3505 "-regard-warnings pay attention to warning messages",
3506 "-remap filename transform image colors to match this set of colors",
3507 "-respect-parentheses settings remain in effect until parenthesis boundary",
3508 "-sampling-factor geometry",
3509 " horizontal and vertical sampling factor",
3510 "-scene value image scene number",
3511 "-seed value seed a new sequence of pseudo-random numbers",
3512 "-size geometry width and height of image",
3513 "-stretch type render text with this font stretch",
3514 "-stroke color graphic primitive stroke color",
3515 "-strokewidth value graphic primitive stroke width",
3516 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003517 "-synchronize synchronize image to storage device",
3518 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003519 "-texture filename name of texture to tile onto the image background",
3520 "-tile-offset geometry",
3521 " tile offset",
3522 "-treedepth value color tree depth",
3523 "-transparent-color color",
3524 " transparent color",
3525 "-undercolor color annotation bounding box color",
3526 "-units type the units of image resolution",
3527 "-verbose print detailed information about the image",
3528 "-view FlashPix viewing transforms",
3529 "-virtual-pixel method",
3530 " virtual pixel access method",
3531 "-weight type render text with this font weight",
3532 "-white-point point chromaticity white point",
3533 (char *) NULL
3534 },
3535 *stack_operators[]=
3536 {
anthonyb69c4b32011-03-23 04:37:44 +00003537 "-delete indexes delete the image from the image sequence",
3538 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003539 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003540 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003541 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003542 "-swap indexes swap two images in the image sequence",
3543 (char *) NULL
3544 };
3545
3546 const char
3547 **p;
3548
cristybb503372010-05-27 20:51:26 +00003549 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003550 (void) printf("Copyright: %s\n",GetMagickCopyright());
3551 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003552 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3553 GetClientName());
3554 (void) printf("\nImage Settings:\n");
3555 for (p=settings; *p != (char *) NULL; p++)
3556 (void) printf(" %s\n",*p);
3557 (void) printf("\nImage Operators:\n");
3558 for (p=operators; *p != (char *) NULL; p++)
3559 (void) printf(" %s\n",*p);
3560 (void) printf("\nImage Sequence Operators:\n");
3561 for (p=sequence_operators; *p != (char *) NULL; p++)
3562 (void) printf(" %s\n",*p);
3563 (void) printf("\nImage Stack Operators:\n");
3564 for (p=stack_operators; *p != (char *) NULL; p++)
3565 (void) printf(" %s\n",*p);
3566 (void) printf("\nMiscellaneous Options:\n");
3567 for (p=miscellaneous; *p != (char *) NULL; p++)
3568 (void) printf(" %s\n",*p);
3569 (void) printf(
3570 "\nBy default, the image format of `file' is determined by its magic\n");
3571 (void) printf(
3572 "number. To specify a particular image format, precede the filename\n");
3573 (void) printf(
3574 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3575 (void) printf(
3576 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3577 (void) printf("'-' for standard input or output.\n");
3578 return(MagickFalse);
3579}
3580
3581WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3582 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3583{
3584#define DestroyMogrify() \
3585{ \
3586 if (format != (char *) NULL) \
3587 format=DestroyString(format); \
3588 if (path != (char *) NULL) \
3589 path=DestroyString(path); \
3590 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003591 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003592 argv[i]=DestroyString(argv[i]); \
3593 argv=(char **) RelinquishMagickMemory(argv); \
3594}
3595#define ThrowMogrifyException(asperity,tag,option) \
3596{ \
3597 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3598 option); \
3599 DestroyMogrify(); \
3600 return(MagickFalse); \
3601}
3602#define ThrowMogrifyInvalidArgumentException(option,argument) \
3603{ \
3604 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3605 "InvalidArgument","`%s': %s",argument,option); \
3606 DestroyMogrify(); \
3607 return(MagickFalse); \
3608}
3609
3610 char
3611 *format,
3612 *option,
3613 *path;
3614
3615 Image
3616 *image;
3617
3618 ImageStack
3619 image_stack[MaxImageStackDepth+1];
3620
cristy3ed852e2009-09-05 21:47:34 +00003621 MagickBooleanType
3622 global_colormap;
3623
3624 MagickBooleanType
3625 fire,
cristyebbcfea2011-02-25 02:43:54 +00003626 pend,
3627 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003628
3629 MagickStatusType
3630 status;
3631
cristyebbcfea2011-02-25 02:43:54 +00003632 register ssize_t
3633 i;
3634
3635 ssize_t
3636 j,
3637 k;
3638
cristy3ed852e2009-09-05 21:47:34 +00003639 /*
3640 Set defaults.
3641 */
3642 assert(image_info != (ImageInfo *) NULL);
3643 assert(image_info->signature == MagickSignature);
3644 if (image_info->debug != MagickFalse)
3645 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3646 assert(exception != (ExceptionInfo *) NULL);
3647 if (argc == 2)
3648 {
3649 option=argv[1];
3650 if ((LocaleCompare("version",option+1) == 0) ||
3651 (LocaleCompare("-version",option+1) == 0))
3652 {
cristyb51dff52011-05-19 16:55:47 +00003653 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003654 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003655 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3656 GetMagickCopyright());
3657 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3658 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003659 return(MagickFalse);
3660 }
3661 }
3662 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003663 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003664 format=(char *) NULL;
3665 path=(char *) NULL;
3666 global_colormap=MagickFalse;
3667 k=0;
3668 j=1;
3669 NewImageStack();
3670 option=(char *) NULL;
3671 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003672 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003673 status=MagickTrue;
3674 /*
3675 Parse command line.
3676 */
3677 ReadCommandlLine(argc,&argv);
3678 status=ExpandFilenames(&argc,&argv);
3679 if (status == MagickFalse)
3680 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3681 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003682 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003683 {
3684 option=argv[i];
3685 if (LocaleCompare(option,"(") == 0)
3686 {
3687 FireImageStack(MagickFalse,MagickTrue,pend);
3688 if (k == MaxImageStackDepth)
3689 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3690 option);
3691 PushImageStack();
3692 continue;
3693 }
3694 if (LocaleCompare(option,")") == 0)
3695 {
3696 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3697 if (k == 0)
3698 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3699 PopImageStack();
3700 continue;
3701 }
cristy042ee782011-04-22 18:48:30 +00003702 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003703 {
3704 char
3705 backup_filename[MaxTextExtent],
3706 *filename;
3707
3708 Image
3709 *images;
3710
3711 /*
3712 Option is a file name: begin by reading image from specified file.
3713 */
3714 FireImageStack(MagickFalse,MagickFalse,pend);
3715 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003716 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003717 filename=argv[++i];
3718 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3719 images=ReadImages(image_info,exception);
3720 status&=(images != (Image *) NULL) &&
3721 (exception->severity < ErrorException);
3722 if (images == (Image *) NULL)
3723 continue;
cristydaa76602010-06-30 13:05:11 +00003724 if (format != (char *) NULL)
3725 (void) CopyMagickString(images->filename,images->magick_filename,
3726 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003727 if (path != (char *) NULL)
3728 {
3729 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003730 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003731 path,*DirectorySeparator,filename);
3732 }
3733 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003734 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003735 AppendImageStack(images);
3736 FinalizeImageSettings(image_info,image,MagickFalse);
3737 if (global_colormap != MagickFalse)
3738 {
3739 QuantizeInfo
3740 *quantize_info;
3741
3742 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003743 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003744 quantize_info=DestroyQuantizeInfo(quantize_info);
3745 }
3746 *backup_filename='\0';
3747 if ((LocaleCompare(image->filename,"-") != 0) &&
3748 (IsPathWritable(image->filename) != MagickFalse))
3749 {
cristybb503372010-05-27 20:51:26 +00003750 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003751 i;
3752
3753 /*
3754 Rename image file as backup.
3755 */
3756 (void) CopyMagickString(backup_filename,image->filename,
3757 MaxTextExtent);
3758 for (i=0; i < 6; i++)
3759 {
3760 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3761 if (IsPathAccessible(backup_filename) == MagickFalse)
3762 break;
3763 }
3764 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003765 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003766 *backup_filename='\0';
3767 }
3768 /*
3769 Write transmogrified image to disk.
3770 */
3771 image_info->synchronize=MagickTrue;
3772 status&=WriteImages(image_info,image,image->filename,exception);
3773 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003774 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003775 RemoveAllImageStack();
3776 continue;
3777 }
3778 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3779 switch (*(option+1))
3780 {
3781 case 'a':
3782 {
3783 if (LocaleCompare("adaptive-blur",option+1) == 0)
3784 {
3785 i++;
cristybb503372010-05-27 20:51:26 +00003786 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003787 ThrowMogrifyException(OptionError,"MissingArgument",option);
3788 if (IsGeometry(argv[i]) == MagickFalse)
3789 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3790 break;
3791 }
3792 if (LocaleCompare("adaptive-resize",option+1) == 0)
3793 {
3794 i++;
cristybb503372010-05-27 20:51:26 +00003795 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003796 ThrowMogrifyException(OptionError,"MissingArgument",option);
3797 if (IsGeometry(argv[i]) == MagickFalse)
3798 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3799 break;
3800 }
3801 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3802 {
3803 i++;
cristybb503372010-05-27 20:51:26 +00003804 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003805 ThrowMogrifyException(OptionError,"MissingArgument",option);
3806 if (IsGeometry(argv[i]) == MagickFalse)
3807 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3808 break;
3809 }
3810 if (LocaleCompare("affine",option+1) == 0)
3811 {
3812 if (*option == '+')
3813 break;
3814 i++;
cristybb503372010-05-27 20:51:26 +00003815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003816 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003817 break;
3818 }
3819 if (LocaleCompare("alpha",option+1) == 0)
3820 {
cristybb503372010-05-27 20:51:26 +00003821 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003822 type;
3823
3824 if (*option == '+')
3825 break;
3826 i++;
cristybb503372010-05-27 20:51:26 +00003827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003828 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003829 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003830 if (type < 0)
3831 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3832 argv[i]);
3833 break;
3834 }
3835 if (LocaleCompare("annotate",option+1) == 0)
3836 {
3837 if (*option == '+')
3838 break;
3839 i++;
cristybb503372010-05-27 20:51:26 +00003840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003841 ThrowMogrifyException(OptionError,"MissingArgument",option);
3842 if (IsGeometry(argv[i]) == MagickFalse)
3843 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003845 ThrowMogrifyException(OptionError,"MissingArgument",option);
3846 i++;
3847 break;
3848 }
3849 if (LocaleCompare("antialias",option+1) == 0)
3850 break;
3851 if (LocaleCompare("append",option+1) == 0)
3852 break;
3853 if (LocaleCompare("attenuate",option+1) == 0)
3854 {
3855 if (*option == '+')
3856 break;
3857 i++;
cristybb503372010-05-27 20:51:26 +00003858 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003859 ThrowMogrifyException(OptionError,"MissingArgument",option);
3860 if (IsGeometry(argv[i]) == MagickFalse)
3861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3862 break;
3863 }
3864 if (LocaleCompare("authenticate",option+1) == 0)
3865 {
3866 if (*option == '+')
3867 break;
3868 i++;
cristybb503372010-05-27 20:51:26 +00003869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003870 ThrowMogrifyException(OptionError,"MissingArgument",option);
3871 break;
3872 }
3873 if (LocaleCompare("auto-gamma",option+1) == 0)
3874 break;
3875 if (LocaleCompare("auto-level",option+1) == 0)
3876 break;
3877 if (LocaleCompare("auto-orient",option+1) == 0)
3878 break;
3879 if (LocaleCompare("average",option+1) == 0)
3880 break;
3881 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3882 }
3883 case 'b':
3884 {
3885 if (LocaleCompare("background",option+1) == 0)
3886 {
3887 if (*option == '+')
3888 break;
3889 i++;
cristybb503372010-05-27 20:51:26 +00003890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003891 ThrowMogrifyException(OptionError,"MissingArgument",option);
3892 break;
3893 }
3894 if (LocaleCompare("bias",option+1) == 0)
3895 {
3896 if (*option == '+')
3897 break;
3898 i++;
cristybb503372010-05-27 20:51:26 +00003899 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003900 ThrowMogrifyException(OptionError,"MissingArgument",option);
3901 if (IsGeometry(argv[i]) == MagickFalse)
3902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3903 break;
3904 }
3905 if (LocaleCompare("black-point-compensation",option+1) == 0)
3906 break;
3907 if (LocaleCompare("black-threshold",option+1) == 0)
3908 {
3909 if (*option == '+')
3910 break;
3911 i++;
cristybb503372010-05-27 20:51:26 +00003912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003913 ThrowMogrifyException(OptionError,"MissingArgument",option);
3914 if (IsGeometry(argv[i]) == MagickFalse)
3915 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3916 break;
3917 }
3918 if (LocaleCompare("blue-primary",option+1) == 0)
3919 {
3920 if (*option == '+')
3921 break;
3922 i++;
cristybb503372010-05-27 20:51:26 +00003923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003924 ThrowMogrifyException(OptionError,"MissingArgument",option);
3925 if (IsGeometry(argv[i]) == MagickFalse)
3926 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3927 break;
3928 }
3929 if (LocaleCompare("blue-shift",option+1) == 0)
3930 {
3931 i++;
cristybb503372010-05-27 20:51:26 +00003932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003933 ThrowMogrifyException(OptionError,"MissingArgument",option);
3934 if (IsGeometry(argv[i]) == MagickFalse)
3935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3936 break;
3937 }
3938 if (LocaleCompare("blur",option+1) == 0)
3939 {
3940 i++;
cristybb503372010-05-27 20:51:26 +00003941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003942 ThrowMogrifyException(OptionError,"MissingArgument",option);
3943 if (IsGeometry(argv[i]) == MagickFalse)
3944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3945 break;
3946 }
3947 if (LocaleCompare("border",option+1) == 0)
3948 {
3949 if (*option == '+')
3950 break;
3951 i++;
cristybb503372010-05-27 20:51:26 +00003952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003953 ThrowMogrifyException(OptionError,"MissingArgument",option);
3954 if (IsGeometry(argv[i]) == MagickFalse)
3955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3956 break;
3957 }
3958 if (LocaleCompare("bordercolor",option+1) == 0)
3959 {
3960 if (*option == '+')
3961 break;
3962 i++;
cristybb503372010-05-27 20:51:26 +00003963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003964 ThrowMogrifyException(OptionError,"MissingArgument",option);
3965 break;
3966 }
3967 if (LocaleCompare("box",option+1) == 0)
3968 {
3969 if (*option == '+')
3970 break;
3971 i++;
cristybb503372010-05-27 20:51:26 +00003972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003973 ThrowMogrifyException(OptionError,"MissingArgument",option);
3974 break;
3975 }
cristya28d6b82010-01-11 20:03:47 +00003976 if (LocaleCompare("brightness-contrast",option+1) == 0)
3977 {
3978 i++;
cristybb503372010-05-27 20:51:26 +00003979 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003980 ThrowMogrifyException(OptionError,"MissingArgument",option);
3981 if (IsGeometry(argv[i]) == MagickFalse)
3982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3983 break;
3984 }
cristy3ed852e2009-09-05 21:47:34 +00003985 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3986 }
3987 case 'c':
3988 {
3989 if (LocaleCompare("cache",option+1) == 0)
3990 {
3991 if (*option == '+')
3992 break;
3993 i++;
cristybb503372010-05-27 20:51:26 +00003994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003995 ThrowMogrifyException(OptionError,"MissingArgument",option);
3996 if (IsGeometry(argv[i]) == MagickFalse)
3997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3998 break;
3999 }
4000 if (LocaleCompare("caption",option+1) == 0)
4001 {
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 break;
4008 }
4009 if (LocaleCompare("channel",option+1) == 0)
4010 {
cristybb503372010-05-27 20:51:26 +00004011 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004012 channel;
4013
4014 if (*option == '+')
4015 break;
4016 i++;
cristybb503372010-05-27 20:51:26 +00004017 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004018 ThrowMogrifyException(OptionError,"MissingArgument",option);
4019 channel=ParseChannelOption(argv[i]);
4020 if (channel < 0)
4021 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4022 argv[i]);
4023 break;
4024 }
4025 if (LocaleCompare("cdl",option+1) == 0)
4026 {
4027 if (*option == '+')
4028 break;
4029 i++;
cristybb503372010-05-27 20:51:26 +00004030 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004031 ThrowMogrifyException(OptionError,"MissingArgument",option);
4032 break;
4033 }
4034 if (LocaleCompare("charcoal",option+1) == 0)
4035 {
4036 if (*option == '+')
4037 break;
4038 i++;
cristybb503372010-05-27 20:51:26 +00004039 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004040 ThrowMogrifyException(OptionError,"MissingArgument",option);
4041 if (IsGeometry(argv[i]) == MagickFalse)
4042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4043 break;
4044 }
4045 if (LocaleCompare("chop",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 if (IsGeometry(argv[i]) == MagickFalse)
4053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4054 break;
4055 }
cristy1eb45dd2009-09-25 16:38:06 +00004056 if (LocaleCompare("clamp",option+1) == 0)
4057 break;
4058 if (LocaleCompare("clip",option+1) == 0)
4059 break;
cristy3ed852e2009-09-05 21:47:34 +00004060 if (LocaleCompare("clip-mask",option+1) == 0)
4061 {
4062 if (*option == '+')
4063 break;
4064 i++;
cristybb503372010-05-27 20:51:26 +00004065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004066 ThrowMogrifyException(OptionError,"MissingArgument",option);
4067 break;
4068 }
4069 if (LocaleCompare("clut",option+1) == 0)
4070 break;
4071 if (LocaleCompare("coalesce",option+1) == 0)
4072 break;
4073 if (LocaleCompare("colorize",option+1) == 0)
4074 {
4075 if (*option == '+')
4076 break;
4077 i++;
cristybb503372010-05-27 20:51:26 +00004078 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004079 ThrowMogrifyException(OptionError,"MissingArgument",option);
4080 if (IsGeometry(argv[i]) == MagickFalse)
4081 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4082 break;
4083 }
cristye6365592010-04-02 17:31:23 +00004084 if (LocaleCompare("color-matrix",option+1) == 0)
4085 {
cristyb6bd4ad2010-08-08 01:12:27 +00004086 KernelInfo
4087 *kernel_info;
4088
cristye6365592010-04-02 17:31:23 +00004089 if (*option == '+')
4090 break;
4091 i++;
cristybb503372010-05-27 20:51:26 +00004092 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004093 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004094 kernel_info=AcquireKernelInfo(argv[i]);
4095 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004097 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004098 break;
4099 }
cristy3ed852e2009-09-05 21:47:34 +00004100 if (LocaleCompare("colors",option+1) == 0)
4101 {
4102 if (*option == '+')
4103 break;
4104 i++;
cristybb503372010-05-27 20:51:26 +00004105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004106 ThrowMogrifyException(OptionError,"MissingArgument",option);
4107 if (IsGeometry(argv[i]) == MagickFalse)
4108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4109 break;
4110 }
4111 if (LocaleCompare("colorspace",option+1) == 0)
4112 {
cristybb503372010-05-27 20:51:26 +00004113 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004114 colorspace;
4115
4116 if (*option == '+')
4117 break;
4118 i++;
cristybb503372010-05-27 20:51:26 +00004119 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004120 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004121 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004122 argv[i]);
4123 if (colorspace < 0)
4124 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4125 argv[i]);
4126 break;
4127 }
4128 if (LocaleCompare("combine",option+1) == 0)
4129 break;
4130 if (LocaleCompare("comment",option+1) == 0)
4131 {
4132 if (*option == '+')
4133 break;
4134 i++;
cristybb503372010-05-27 20:51:26 +00004135 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004136 ThrowMogrifyException(OptionError,"MissingArgument",option);
4137 break;
4138 }
4139 if (LocaleCompare("composite",option+1) == 0)
4140 break;
4141 if (LocaleCompare("compress",option+1) == 0)
4142 {
cristybb503372010-05-27 20:51:26 +00004143 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004144 compress;
4145
4146 if (*option == '+')
4147 break;
4148 i++;
cristybb503372010-05-27 20:51:26 +00004149 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004150 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004151 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004152 argv[i]);
4153 if (compress < 0)
4154 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4155 argv[i]);
4156 break;
4157 }
cristy22879752009-10-25 23:55:40 +00004158 if (LocaleCompare("concurrent",option+1) == 0)
4159 break;
cristy3ed852e2009-09-05 21:47:34 +00004160 if (LocaleCompare("contrast",option+1) == 0)
4161 break;
4162 if (LocaleCompare("contrast-stretch",option+1) == 0)
4163 {
4164 i++;
cristybb503372010-05-27 20:51:26 +00004165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004166 ThrowMogrifyException(OptionError,"MissingArgument",option);
4167 if (IsGeometry(argv[i]) == MagickFalse)
4168 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4169 break;
4170 }
4171 if (LocaleCompare("convolve",option+1) == 0)
4172 {
cristyb6bd4ad2010-08-08 01:12:27 +00004173 KernelInfo
4174 *kernel_info;
4175
cristy3ed852e2009-09-05 21:47:34 +00004176 if (*option == '+')
4177 break;
4178 i++;
cristybb503372010-05-27 20:51:26 +00004179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004180 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004181 kernel_info=AcquireKernelInfo(argv[i]);
4182 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004184 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004185 break;
4186 }
4187 if (LocaleCompare("crop",option+1) == 0)
4188 {
4189 if (*option == '+')
4190 break;
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
4194 if (IsGeometry(argv[i]) == MagickFalse)
4195 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4196 break;
4197 }
4198 if (LocaleCompare("cycle",option+1) == 0)
4199 {
4200 if (*option == '+')
4201 break;
4202 i++;
cristybb503372010-05-27 20:51:26 +00004203 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004204 ThrowMogrifyException(OptionError,"MissingArgument",option);
4205 if (IsGeometry(argv[i]) == MagickFalse)
4206 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4207 break;
4208 }
4209 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4210 }
4211 case 'd':
4212 {
4213 if (LocaleCompare("decipher",option+1) == 0)
4214 {
4215 if (*option == '+')
4216 break;
4217 i++;
cristybb503372010-05-27 20:51:26 +00004218 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004219 ThrowMogrifyException(OptionError,"MissingArgument",option);
4220 break;
4221 }
4222 if (LocaleCompare("deconstruct",option+1) == 0)
4223 break;
4224 if (LocaleCompare("debug",option+1) == 0)
4225 {
cristybb503372010-05-27 20:51:26 +00004226 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004227 event;
4228
4229 if (*option == '+')
4230 break;
4231 i++;
cristybb503372010-05-27 20:51:26 +00004232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004233 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004234 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004235 if (event < 0)
4236 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4237 argv[i]);
4238 (void) SetLogEventMask(argv[i]);
4239 break;
4240 }
4241 if (LocaleCompare("define",option+1) == 0)
4242 {
4243 i++;
cristybb503372010-05-27 20:51:26 +00004244 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004245 ThrowMogrifyException(OptionError,"MissingArgument",option);
4246 if (*option == '+')
4247 {
4248 const char
4249 *define;
4250
4251 define=GetImageOption(image_info,argv[i]);
4252 if (define == (const char *) NULL)
4253 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4254 break;
4255 }
4256 break;
4257 }
4258 if (LocaleCompare("delay",option+1) == 0)
4259 {
4260 if (*option == '+')
4261 break;
4262 i++;
cristybb503372010-05-27 20:51:26 +00004263 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004264 ThrowMogrifyException(OptionError,"MissingArgument",option);
4265 if (IsGeometry(argv[i]) == MagickFalse)
4266 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4267 break;
4268 }
cristyecb10ff2011-03-22 13:14:03 +00004269 if (LocaleCompare("delete",option+1) == 0)
4270 {
4271 if (*option == '+')
4272 break;
4273 i++;
4274 if (i == (ssize_t) (argc-1))
4275 ThrowMogrifyException(OptionError,"MissingArgument",option);
4276 if (IsGeometry(argv[i]) == MagickFalse)
4277 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4278 break;
4279 }
cristy3ed852e2009-09-05 21:47:34 +00004280 if (LocaleCompare("density",option+1) == 0)
4281 {
4282 if (*option == '+')
4283 break;
4284 i++;
cristybb503372010-05-27 20:51:26 +00004285 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004286 ThrowMogrifyException(OptionError,"MissingArgument",option);
4287 if (IsGeometry(argv[i]) == MagickFalse)
4288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4289 break;
4290 }
4291 if (LocaleCompare("depth",option+1) == 0)
4292 {
4293 if (*option == '+')
4294 break;
4295 i++;
cristybb503372010-05-27 20:51:26 +00004296 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004297 ThrowMogrifyException(OptionError,"MissingArgument",option);
4298 if (IsGeometry(argv[i]) == MagickFalse)
4299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4300 break;
4301 }
4302 if (LocaleCompare("deskew",option+1) == 0)
4303 {
4304 if (*option == '+')
4305 break;
4306 i++;
cristybb503372010-05-27 20:51:26 +00004307 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004308 ThrowMogrifyException(OptionError,"MissingArgument",option);
4309 if (IsGeometry(argv[i]) == MagickFalse)
4310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4311 break;
4312 }
4313 if (LocaleCompare("despeckle",option+1) == 0)
4314 break;
4315 if (LocaleCompare("dft",option+1) == 0)
4316 break;
cristyc9b12952010-03-28 01:12:28 +00004317 if (LocaleCompare("direction",option+1) == 0)
4318 {
cristybb503372010-05-27 20:51:26 +00004319 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004320 direction;
4321
4322 if (*option == '+')
4323 break;
4324 i++;
cristybb503372010-05-27 20:51:26 +00004325 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004326 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004327 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004328 argv[i]);
4329 if (direction < 0)
4330 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4331 argv[i]);
4332 break;
4333 }
cristy3ed852e2009-09-05 21:47:34 +00004334 if (LocaleCompare("display",option+1) == 0)
4335 {
4336 if (*option == '+')
4337 break;
4338 i++;
cristybb503372010-05-27 20:51:26 +00004339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004340 ThrowMogrifyException(OptionError,"MissingArgument",option);
4341 break;
4342 }
4343 if (LocaleCompare("dispose",option+1) == 0)
4344 {
cristybb503372010-05-27 20:51:26 +00004345 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004346 dispose;
4347
4348 if (*option == '+')
4349 break;
4350 i++;
cristybb503372010-05-27 20:51:26 +00004351 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004352 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004353 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004354 if (dispose < 0)
4355 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4356 argv[i]);
4357 break;
4358 }
4359 if (LocaleCompare("distort",option+1) == 0)
4360 {
cristybb503372010-05-27 20:51:26 +00004361 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004362 op;
4363
4364 i++;
cristybb503372010-05-27 20:51:26 +00004365 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004366 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004367 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004368 if (op < 0)
4369 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4370 argv[i]);
4371 i++;
cristybb503372010-05-27 20:51:26 +00004372 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004373 ThrowMogrifyException(OptionError,"MissingArgument",option);
4374 break;
4375 }
4376 if (LocaleCompare("dither",option+1) == 0)
4377 {
cristybb503372010-05-27 20:51:26 +00004378 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004379 method;
4380
4381 if (*option == '+')
4382 break;
4383 i++;
cristybb503372010-05-27 20:51:26 +00004384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004385 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004386 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004387 if (method < 0)
4388 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4389 argv[i]);
4390 break;
4391 }
4392 if (LocaleCompare("draw",option+1) == 0)
4393 {
4394 if (*option == '+')
4395 break;
4396 i++;
cristybb503372010-05-27 20:51:26 +00004397 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004398 ThrowMogrifyException(OptionError,"MissingArgument",option);
4399 break;
4400 }
cristyecb10ff2011-03-22 13:14:03 +00004401 if (LocaleCompare("duplicate",option+1) == 0)
4402 {
4403 if (*option == '+')
4404 break;
4405 i++;
4406 if (i == (ssize_t) (argc-1))
4407 ThrowMogrifyException(OptionError,"MissingArgument",option);
4408 if (IsGeometry(argv[i]) == MagickFalse)
4409 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4410 break;
4411 }
cristy22879752009-10-25 23:55:40 +00004412 if (LocaleCompare("duration",option+1) == 0)
4413 {
4414 if (*option == '+')
4415 break;
4416 i++;
cristybb503372010-05-27 20:51:26 +00004417 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004418 ThrowMogrifyException(OptionError,"MissingArgument",option);
4419 if (IsGeometry(argv[i]) == MagickFalse)
4420 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4421 break;
4422 }
cristy3ed852e2009-09-05 21:47:34 +00004423 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4424 }
4425 case 'e':
4426 {
4427 if (LocaleCompare("edge",option+1) == 0)
4428 {
4429 if (*option == '+')
4430 break;
4431 i++;
cristybb503372010-05-27 20:51:26 +00004432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004433 ThrowMogrifyException(OptionError,"MissingArgument",option);
4434 if (IsGeometry(argv[i]) == MagickFalse)
4435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4436 break;
4437 }
4438 if (LocaleCompare("emboss",option+1) == 0)
4439 {
4440 if (*option == '+')
4441 break;
4442 i++;
cristybb503372010-05-27 20:51:26 +00004443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004444 ThrowMogrifyException(OptionError,"MissingArgument",option);
4445 if (IsGeometry(argv[i]) == MagickFalse)
4446 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4447 break;
4448 }
4449 if (LocaleCompare("encipher",option+1) == 0)
4450 {
4451 if (*option == '+')
4452 break;
4453 i++;
cristybb503372010-05-27 20:51:26 +00004454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004455 ThrowMogrifyException(OptionError,"MissingArgument",option);
4456 break;
4457 }
4458 if (LocaleCompare("encoding",option+1) == 0)
4459 {
4460 if (*option == '+')
4461 break;
4462 i++;
cristybb503372010-05-27 20:51:26 +00004463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004464 ThrowMogrifyException(OptionError,"MissingArgument",option);
4465 break;
4466 }
4467 if (LocaleCompare("endian",option+1) == 0)
4468 {
cristybb503372010-05-27 20:51:26 +00004469 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004470 endian;
4471
4472 if (*option == '+')
4473 break;
4474 i++;
cristybb503372010-05-27 20:51:26 +00004475 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004476 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004477 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004478 if (endian < 0)
4479 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4480 argv[i]);
4481 break;
4482 }
4483 if (LocaleCompare("enhance",option+1) == 0)
4484 break;
4485 if (LocaleCompare("equalize",option+1) == 0)
4486 break;
4487 if (LocaleCompare("evaluate",option+1) == 0)
4488 {
cristybb503372010-05-27 20:51:26 +00004489 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004490 op;
4491
4492 if (*option == '+')
4493 break;
4494 i++;
cristybb503372010-05-27 20:51:26 +00004495 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004496 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004497 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004498 if (op < 0)
4499 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4500 argv[i]);
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
4504 if (IsGeometry(argv[i]) == MagickFalse)
4505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4506 break;
4507 }
cristyd18ae7c2010-03-07 17:39:52 +00004508 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4509 {
cristybb503372010-05-27 20:51:26 +00004510 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004511 op;
4512
4513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004518 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004519 if (op < 0)
4520 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4521 argv[i]);
4522 break;
4523 }
cristy3ed852e2009-09-05 21:47:34 +00004524 if (LocaleCompare("extent",option+1) == 0)
4525 {
4526 if (*option == '+')
4527 break;
4528 i++;
cristybb503372010-05-27 20:51:26 +00004529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004530 ThrowMogrifyException(OptionError,"MissingArgument",option);
4531 if (IsGeometry(argv[i]) == MagickFalse)
4532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4533 break;
4534 }
4535 if (LocaleCompare("extract",option+1) == 0)
4536 {
4537 if (*option == '+')
4538 break;
4539 i++;
cristybb503372010-05-27 20:51:26 +00004540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004541 ThrowMogrifyException(OptionError,"MissingArgument",option);
4542 if (IsGeometry(argv[i]) == MagickFalse)
4543 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4544 break;
4545 }
4546 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4547 }
4548 case 'f':
4549 {
4550 if (LocaleCompare("family",option+1) == 0)
4551 {
4552 if (*option == '+')
4553 break;
4554 i++;
cristybb503372010-05-27 20:51:26 +00004555 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004556 ThrowMogrifyException(OptionError,"MissingArgument",option);
4557 break;
4558 }
4559 if (LocaleCompare("fill",option+1) == 0)
4560 {
4561 if (*option == '+')
4562 break;
4563 i++;
cristybb503372010-05-27 20:51:26 +00004564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004565 ThrowMogrifyException(OptionError,"MissingArgument",option);
4566 break;
4567 }
4568 if (LocaleCompare("filter",option+1) == 0)
4569 {
cristybb503372010-05-27 20:51:26 +00004570 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004571 filter;
4572
4573 if (*option == '+')
4574 break;
4575 i++;
cristybb503372010-05-27 20:51:26 +00004576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004577 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004578 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004579 if (filter < 0)
4580 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4581 argv[i]);
4582 break;
4583 }
4584 if (LocaleCompare("flatten",option+1) == 0)
4585 break;
4586 if (LocaleCompare("flip",option+1) == 0)
4587 break;
4588 if (LocaleCompare("flop",option+1) == 0)
4589 break;
4590 if (LocaleCompare("floodfill",option+1) == 0)
4591 {
4592 if (*option == '+')
4593 break;
4594 i++;
cristybb503372010-05-27 20:51:26 +00004595 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004596 ThrowMogrifyException(OptionError,"MissingArgument",option);
4597 if (IsGeometry(argv[i]) == MagickFalse)
4598 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4599 i++;
cristybb503372010-05-27 20:51:26 +00004600 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004601 ThrowMogrifyException(OptionError,"MissingArgument",option);
4602 break;
4603 }
4604 if (LocaleCompare("font",option+1) == 0)
4605 {
4606 if (*option == '+')
4607 break;
4608 i++;
cristybb503372010-05-27 20:51:26 +00004609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004610 ThrowMogrifyException(OptionError,"MissingArgument",option);
4611 break;
4612 }
4613 if (LocaleCompare("format",option+1) == 0)
4614 {
4615 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4616 (void) CloneString(&format,(char *) NULL);
4617 if (*option == '+')
4618 break;
4619 i++;
cristybb503372010-05-27 20:51:26 +00004620 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 (void) CloneString(&format,argv[i]);
4623 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4624 (void) ConcatenateMagickString(image_info->filename,":",
4625 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004626 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004627 if (*image_info->magick == '\0')
4628 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4629 format);
4630 break;
4631 }
4632 if (LocaleCompare("frame",option+1) == 0)
4633 {
4634 if (*option == '+')
4635 break;
4636 i++;
cristybb503372010-05-27 20:51:26 +00004637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004638 ThrowMogrifyException(OptionError,"MissingArgument",option);
4639 if (IsGeometry(argv[i]) == MagickFalse)
4640 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4641 break;
4642 }
4643 if (LocaleCompare("function",option+1) == 0)
4644 {
cristybb503372010-05-27 20:51:26 +00004645 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004646 op;
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);
cristy042ee782011-04-22 18:48:30 +00004653 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004654 if (op < 0)
4655 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4656 i++;
cristybb503372010-05-27 20:51:26 +00004657 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004658 ThrowMogrifyException(OptionError,"MissingArgument",option);
4659 break;
4660 }
4661 if (LocaleCompare("fuzz",option+1) == 0)
4662 {
4663 if (*option == '+')
4664 break;
4665 i++;
cristybb503372010-05-27 20:51:26 +00004666 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004667 ThrowMogrifyException(OptionError,"MissingArgument",option);
4668 if (IsGeometry(argv[i]) == MagickFalse)
4669 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4670 break;
4671 }
4672 if (LocaleCompare("fx",option+1) == 0)
4673 {
4674 if (*option == '+')
4675 break;
4676 i++;
cristybb503372010-05-27 20:51:26 +00004677 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004678 ThrowMogrifyException(OptionError,"MissingArgument",option);
4679 break;
4680 }
4681 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4682 }
4683 case 'g':
4684 {
4685 if (LocaleCompare("gamma",option+1) == 0)
4686 {
4687 i++;
cristybb503372010-05-27 20:51:26 +00004688 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004689 ThrowMogrifyException(OptionError,"MissingArgument",option);
4690 if (IsGeometry(argv[i]) == MagickFalse)
4691 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4692 break;
4693 }
4694 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4695 (LocaleCompare("gaussian",option+1) == 0))
4696 {
4697 i++;
cristybb503372010-05-27 20:51:26 +00004698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004699 ThrowMogrifyException(OptionError,"MissingArgument",option);
4700 if (IsGeometry(argv[i]) == MagickFalse)
4701 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4702 break;
4703 }
4704 if (LocaleCompare("geometry",option+1) == 0)
4705 {
4706 if (*option == '+')
4707 break;
4708 i++;
cristybb503372010-05-27 20:51:26 +00004709 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004710 ThrowMogrifyException(OptionError,"MissingArgument",option);
4711 if (IsGeometry(argv[i]) == MagickFalse)
4712 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4713 break;
4714 }
4715 if (LocaleCompare("gravity",option+1) == 0)
4716 {
cristybb503372010-05-27 20:51:26 +00004717 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004718 gravity;
4719
4720 if (*option == '+')
4721 break;
4722 i++;
cristybb503372010-05-27 20:51:26 +00004723 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004724 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004725 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004726 if (gravity < 0)
4727 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4728 argv[i]);
4729 break;
4730 }
4731 if (LocaleCompare("green-primary",option+1) == 0)
4732 {
4733 if (*option == '+')
4734 break;
4735 i++;
cristybb503372010-05-27 20:51:26 +00004736 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004737 ThrowMogrifyException(OptionError,"MissingArgument",option);
4738 if (IsGeometry(argv[i]) == MagickFalse)
4739 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4740 break;
4741 }
4742 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4743 }
4744 case 'h':
4745 {
4746 if (LocaleCompare("hald-clut",option+1) == 0)
4747 break;
4748 if ((LocaleCompare("help",option+1) == 0) ||
4749 (LocaleCompare("-help",option+1) == 0))
4750 return(MogrifyUsage());
4751 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4752 }
4753 case 'i':
4754 {
4755 if (LocaleCompare("identify",option+1) == 0)
4756 break;
4757 if (LocaleCompare("idft",option+1) == 0)
4758 break;
4759 if (LocaleCompare("implode",option+1) == 0)
4760 {
4761 if (*option == '+')
4762 break;
4763 i++;
cristybb503372010-05-27 20:51:26 +00004764 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004765 ThrowMogrifyException(OptionError,"MissingArgument",option);
4766 if (IsGeometry(argv[i]) == MagickFalse)
4767 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4768 break;
4769 }
4770 if (LocaleCompare("intent",option+1) == 0)
4771 {
cristybb503372010-05-27 20:51:26 +00004772 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004773 intent;
4774
4775 if (*option == '+')
4776 break;
4777 i++;
cristybb503372010-05-27 20:51:26 +00004778 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004779 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004780 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004781 if (intent < 0)
4782 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4783 argv[i]);
4784 break;
4785 }
4786 if (LocaleCompare("interlace",option+1) == 0)
4787 {
cristybb503372010-05-27 20:51:26 +00004788 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004789 interlace;
4790
4791 if (*option == '+')
4792 break;
4793 i++;
cristybb503372010-05-27 20:51:26 +00004794 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004795 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004796 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004797 argv[i]);
4798 if (interlace < 0)
4799 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4800 argv[i]);
4801 break;
4802 }
cristyb32b90a2009-09-07 21:45:48 +00004803 if (LocaleCompare("interline-spacing",option+1) == 0)
4804 {
4805 if (*option == '+')
4806 break;
4807 i++;
cristybb503372010-05-27 20:51:26 +00004808 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004809 ThrowMogrifyException(OptionError,"MissingArgument",option);
4810 if (IsGeometry(argv[i]) == MagickFalse)
4811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4812 break;
4813 }
cristy3ed852e2009-09-05 21:47:34 +00004814 if (LocaleCompare("interpolate",option+1) == 0)
4815 {
cristybb503372010-05-27 20:51:26 +00004816 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004817 interpolate;
4818
4819 if (*option == '+')
4820 break;
4821 i++;
cristybb503372010-05-27 20:51:26 +00004822 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004823 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004824 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004825 argv[i]);
4826 if (interpolate < 0)
4827 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4828 argv[i]);
4829 break;
4830 }
4831 if (LocaleCompare("interword-spacing",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 'k':
4845 {
4846 if (LocaleCompare("kerning",option+1) == 0)
4847 {
4848 if (*option == '+')
4849 break;
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 if (IsGeometry(argv[i]) == MagickFalse)
4854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4855 break;
4856 }
4857 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4858 }
4859 case 'l':
4860 {
4861 if (LocaleCompare("label",option+1) == 0)
4862 {
4863 if (*option == '+')
4864 break;
4865 i++;
cristybb503372010-05-27 20:51:26 +00004866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004867 ThrowMogrifyException(OptionError,"MissingArgument",option);
4868 break;
4869 }
4870 if (LocaleCompare("lat",option+1) == 0)
4871 {
4872 if (*option == '+')
4873 break;
4874 i++;
cristybb503372010-05-27 20:51:26 +00004875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004876 ThrowMogrifyException(OptionError,"MissingArgument",option);
4877 if (IsGeometry(argv[i]) == MagickFalse)
4878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4879 }
4880 if (LocaleCompare("layers",option+1) == 0)
4881 {
cristybb503372010-05-27 20:51:26 +00004882 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004883 type;
4884
4885 if (*option == '+')
4886 break;
4887 i++;
cristybb503372010-05-27 20:51:26 +00004888 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004889 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004890 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004891 if (type < 0)
4892 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4893 argv[i]);
4894 break;
4895 }
4896 if (LocaleCompare("level",option+1) == 0)
4897 {
4898 i++;
cristybb503372010-05-27 20:51:26 +00004899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004900 ThrowMogrifyException(OptionError,"MissingArgument",option);
4901 if (IsGeometry(argv[i]) == MagickFalse)
4902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4903 break;
4904 }
4905 if (LocaleCompare("level-colors",option+1) == 0)
4906 {
4907 i++;
cristybb503372010-05-27 20:51:26 +00004908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004909 ThrowMogrifyException(OptionError,"MissingArgument",option);
4910 break;
4911 }
4912 if (LocaleCompare("linewidth",option+1) == 0)
4913 {
4914 if (*option == '+')
4915 break;
4916 i++;
cristybb503372010-05-27 20:51:26 +00004917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004918 ThrowMogrifyException(OptionError,"MissingArgument",option);
4919 if (IsGeometry(argv[i]) == MagickFalse)
4920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4921 break;
4922 }
4923 if (LocaleCompare("limit",option+1) == 0)
4924 {
4925 char
4926 *p;
4927
4928 double
4929 value;
4930
cristybb503372010-05-27 20:51:26 +00004931 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004932 resource;
4933
4934 if (*option == '+')
4935 break;
4936 i++;
cristybb503372010-05-27 20:51:26 +00004937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004938 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004939 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004940 argv[i]);
4941 if (resource < 0)
4942 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4943 argv[i]);
4944 i++;
cristybb503372010-05-27 20:51:26 +00004945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004946 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004947 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004948 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004949 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4950 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4951 break;
4952 }
4953 if (LocaleCompare("liquid-rescale",option+1) == 0)
4954 {
4955 i++;
cristybb503372010-05-27 20:51:26 +00004956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004957 ThrowMogrifyException(OptionError,"MissingArgument",option);
4958 if (IsGeometry(argv[i]) == MagickFalse)
4959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4960 break;
4961 }
4962 if (LocaleCompare("list",option+1) == 0)
4963 {
cristybb503372010-05-27 20:51:26 +00004964 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004965 list;
4966
4967 if (*option == '+')
4968 break;
4969 i++;
cristybb503372010-05-27 20:51:26 +00004970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004971 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004972 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004973 if (list < 0)
4974 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004975 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004976 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004977 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004978 }
4979 if (LocaleCompare("log",option+1) == 0)
4980 {
4981 if (*option == '+')
4982 break;
4983 i++;
cristybb503372010-05-27 20:51:26 +00004984 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004985 (strchr(argv[i],'%') == (char *) NULL))
4986 ThrowMogrifyException(OptionError,"MissingArgument",option);
4987 break;
4988 }
4989 if (LocaleCompare("loop",option+1) == 0)
4990 {
4991 if (*option == '+')
4992 break;
4993 i++;
cristybb503372010-05-27 20:51:26 +00004994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004995 ThrowMogrifyException(OptionError,"MissingArgument",option);
4996 if (IsGeometry(argv[i]) == MagickFalse)
4997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4998 break;
4999 }
5000 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5001 }
5002 case 'm':
5003 {
5004 if (LocaleCompare("map",option+1) == 0)
5005 {
5006 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5007 if (*option == '+')
5008 break;
5009 i++;
cristybb503372010-05-27 20:51:26 +00005010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005011 ThrowMogrifyException(OptionError,"MissingArgument",option);
5012 break;
5013 }
5014 if (LocaleCompare("mask",option+1) == 0)
5015 {
5016 if (*option == '+')
5017 break;
5018 i++;
cristybb503372010-05-27 20:51:26 +00005019 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005020 ThrowMogrifyException(OptionError,"MissingArgument",option);
5021 break;
5022 }
5023 if (LocaleCompare("matte",option+1) == 0)
5024 break;
5025 if (LocaleCompare("mattecolor",option+1) == 0)
5026 {
5027 if (*option == '+')
5028 break;
5029 i++;
cristybb503372010-05-27 20:51:26 +00005030 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005031 ThrowMogrifyException(OptionError,"MissingArgument",option);
5032 break;
5033 }
cristyf40785b2010-03-06 02:27:27 +00005034 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005035 break;
cristyf40785b2010-03-06 02:27:27 +00005036 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005037 break;
cristy3ed852e2009-09-05 21:47:34 +00005038 if (LocaleCompare("modulate",option+1) == 0)
5039 {
5040 if (*option == '+')
5041 break;
5042 i++;
cristybb503372010-05-27 20:51:26 +00005043 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005044 ThrowMogrifyException(OptionError,"MissingArgument",option);
5045 if (IsGeometry(argv[i]) == MagickFalse)
5046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5047 break;
5048 }
5049 if (LocaleCompare("median",option+1) == 0)
5050 {
5051 if (*option == '+')
5052 break;
5053 i++;
cristybb503372010-05-27 20:51:26 +00005054 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005055 ThrowMogrifyException(OptionError,"MissingArgument",option);
5056 if (IsGeometry(argv[i]) == MagickFalse)
5057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5058 break;
5059 }
cristy69ec32d2011-02-27 23:57:09 +00005060 if (LocaleCompare("mode",option+1) == 0)
5061 {
5062 if (*option == '+')
5063 break;
5064 i++;
5065 if (i == (ssize_t) argc)
5066 ThrowMogrifyException(OptionError,"MissingArgument",option);
5067 if (IsGeometry(argv[i]) == MagickFalse)
5068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5069 break;
5070 }
cristy3ed852e2009-09-05 21:47:34 +00005071 if (LocaleCompare("monitor",option+1) == 0)
5072 break;
5073 if (LocaleCompare("monochrome",option+1) == 0)
5074 break;
5075 if (LocaleCompare("morph",option+1) == 0)
5076 {
5077 if (*option == '+')
5078 break;
5079 i++;
cristybb503372010-05-27 20:51:26 +00005080 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005081 ThrowMogrifyException(OptionError,"MissingArgument",option);
5082 if (IsGeometry(argv[i]) == MagickFalse)
5083 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5084 break;
5085 }
anthony29188a82010-01-22 10:12:34 +00005086 if (LocaleCompare("morphology",option+1) == 0)
5087 {
anthony29188a82010-01-22 10:12:34 +00005088 char
5089 token[MaxTextExtent];
5090
cristyb6bd4ad2010-08-08 01:12:27 +00005091 KernelInfo
5092 *kernel_info;
5093
5094 ssize_t
5095 op;
5096
anthony29188a82010-01-22 10:12:34 +00005097 i++;
cristybb503372010-05-27 20:51:26 +00005098 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005099 ThrowMogrifyException(OptionError,"MissingArgument",option);
5100 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005101 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005102 if (op < 0)
5103 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005104 token);
anthony29188a82010-01-22 10:12:34 +00005105 i++;
cristybb503372010-05-27 20:51:26 +00005106 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005107 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005108 kernel_info=AcquireKernelInfo(argv[i]);
5109 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005110 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005111 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005112 break;
5113 }
cristy3ed852e2009-09-05 21:47:34 +00005114 if (LocaleCompare("mosaic",option+1) == 0)
5115 break;
5116 if (LocaleCompare("motion-blur",option+1) == 0)
5117 {
5118 if (*option == '+')
5119 break;
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 (IsGeometry(argv[i]) == MagickFalse)
5124 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5125 break;
5126 }
5127 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5128 }
5129 case 'n':
5130 {
5131 if (LocaleCompare("negate",option+1) == 0)
5132 break;
5133 if (LocaleCompare("noise",option+1) == 0)
5134 {
5135 i++;
cristybb503372010-05-27 20:51:26 +00005136 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005137 ThrowMogrifyException(OptionError,"MissingArgument",option);
5138 if (*option == '+')
5139 {
cristybb503372010-05-27 20:51:26 +00005140 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005141 noise;
5142
cristy042ee782011-04-22 18:48:30 +00005143 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005144 if (noise < 0)
5145 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5146 argv[i]);
5147 break;
5148 }
5149 if (IsGeometry(argv[i]) == MagickFalse)
5150 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5151 break;
5152 }
5153 if (LocaleCompare("noop",option+1) == 0)
5154 break;
5155 if (LocaleCompare("normalize",option+1) == 0)
5156 break;
5157 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5158 }
5159 case 'o':
5160 {
5161 if (LocaleCompare("opaque",option+1) == 0)
5162 {
cristy3ed852e2009-09-05 21:47:34 +00005163 i++;
cristybb503372010-05-27 20:51:26 +00005164 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005165 ThrowMogrifyException(OptionError,"MissingArgument",option);
5166 break;
5167 }
5168 if (LocaleCompare("ordered-dither",option+1) == 0)
5169 {
5170 if (*option == '+')
5171 break;
5172 i++;
cristybb503372010-05-27 20:51:26 +00005173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 break;
5176 }
5177 if (LocaleCompare("orient",option+1) == 0)
5178 {
cristybb503372010-05-27 20:51:26 +00005179 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005180 orientation;
5181
5182 orientation=UndefinedOrientation;
5183 if (*option == '+')
5184 break;
5185 i++;
cristybb503372010-05-27 20:51:26 +00005186 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005187 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005188 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005189 argv[i]);
5190 if (orientation < 0)
5191 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5192 argv[i]);
5193 break;
5194 }
5195 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5196 }
5197 case 'p':
5198 {
5199 if (LocaleCompare("page",option+1) == 0)
5200 {
5201 if (*option == '+')
5202 break;
5203 i++;
cristybb503372010-05-27 20:51:26 +00005204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005205 ThrowMogrifyException(OptionError,"MissingArgument",option);
5206 break;
5207 }
5208 if (LocaleCompare("paint",option+1) == 0)
5209 {
5210 if (*option == '+')
5211 break;
5212 i++;
cristybb503372010-05-27 20:51:26 +00005213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005214 ThrowMogrifyException(OptionError,"MissingArgument",option);
5215 if (IsGeometry(argv[i]) == MagickFalse)
5216 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5217 break;
5218 }
5219 if (LocaleCompare("path",option+1) == 0)
5220 {
5221 (void) CloneString(&path,(char *) NULL);
5222 if (*option == '+')
5223 break;
5224 i++;
cristybb503372010-05-27 20:51:26 +00005225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005226 ThrowMogrifyException(OptionError,"MissingArgument",option);
5227 (void) CloneString(&path,argv[i]);
5228 break;
5229 }
5230 if (LocaleCompare("pointsize",option+1) == 0)
5231 {
5232 if (*option == '+')
5233 break;
5234 i++;
cristybb503372010-05-27 20:51:26 +00005235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 if (IsGeometry(argv[i]) == MagickFalse)
5238 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5239 break;
5240 }
5241 if (LocaleCompare("polaroid",option+1) == 0)
5242 {
5243 if (*option == '+')
5244 break;
5245 i++;
cristybb503372010-05-27 20:51:26 +00005246 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005247 ThrowMogrifyException(OptionError,"MissingArgument",option);
5248 if (IsGeometry(argv[i]) == MagickFalse)
5249 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5250 break;
5251 }
5252 if (LocaleCompare("posterize",option+1) == 0)
5253 {
5254 if (*option == '+')
5255 break;
5256 i++;
cristybb503372010-05-27 20:51:26 +00005257 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005258 ThrowMogrifyException(OptionError,"MissingArgument",option);
5259 if (IsGeometry(argv[i]) == MagickFalse)
5260 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5261 break;
5262 }
cristye7f51092010-01-17 00:39:37 +00005263 if (LocaleCompare("precision",option+1) == 0)
5264 {
5265 if (*option == '+')
5266 break;
5267 i++;
cristybb503372010-05-27 20:51:26 +00005268 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005269 ThrowMogrifyException(OptionError,"MissingArgument",option);
5270 if (IsGeometry(argv[i]) == MagickFalse)
5271 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5272 break;
5273 }
cristy3ed852e2009-09-05 21:47:34 +00005274 if (LocaleCompare("print",option+1) == 0)
5275 {
5276 if (*option == '+')
5277 break;
5278 i++;
cristybb503372010-05-27 20:51:26 +00005279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005280 ThrowMogrifyException(OptionError,"MissingArgument",option);
5281 break;
5282 }
5283 if (LocaleCompare("process",option+1) == 0)
5284 {
5285 if (*option == '+')
5286 break;
5287 i++;
cristybb503372010-05-27 20:51:26 +00005288 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005289 ThrowMogrifyException(OptionError,"MissingArgument",option);
5290 break;
5291 }
5292 if (LocaleCompare("profile",option+1) == 0)
5293 {
5294 i++;
cristybb503372010-05-27 20:51:26 +00005295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005296 ThrowMogrifyException(OptionError,"MissingArgument",option);
5297 break;
5298 }
5299 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5300 }
5301 case 'q':
5302 {
5303 if (LocaleCompare("quality",option+1) == 0)
5304 {
5305 if (*option == '+')
5306 break;
5307 i++;
cristybb503372010-05-27 20:51:26 +00005308 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005309 ThrowMogrifyException(OptionError,"MissingArgument",option);
5310 if (IsGeometry(argv[i]) == MagickFalse)
5311 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5312 break;
5313 }
5314 if (LocaleCompare("quantize",option+1) == 0)
5315 {
cristybb503372010-05-27 20:51:26 +00005316 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005317 colorspace;
5318
5319 if (*option == '+')
5320 break;
5321 i++;
cristybb503372010-05-27 20:51:26 +00005322 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005323 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005324 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005325 argv[i]);
5326 if (colorspace < 0)
5327 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5328 argv[i]);
5329 break;
5330 }
5331 if (LocaleCompare("quiet",option+1) == 0)
5332 break;
5333 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5334 }
5335 case 'r':
5336 {
5337 if (LocaleCompare("radial-blur",option+1) == 0)
5338 {
5339 i++;
cristybb503372010-05-27 20:51:26 +00005340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005341 ThrowMogrifyException(OptionError,"MissingArgument",option);
5342 if (IsGeometry(argv[i]) == MagickFalse)
5343 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5344 break;
5345 }
5346 if (LocaleCompare("raise",option+1) == 0)
5347 {
5348 i++;
cristybb503372010-05-27 20:51:26 +00005349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005350 ThrowMogrifyException(OptionError,"MissingArgument",option);
5351 if (IsGeometry(argv[i]) == MagickFalse)
5352 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5353 break;
5354 }
5355 if (LocaleCompare("random-threshold",option+1) == 0)
5356 {
5357 if (*option == '+')
5358 break;
5359 i++;
cristybb503372010-05-27 20:51:26 +00005360 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005361 ThrowMogrifyException(OptionError,"MissingArgument",option);
5362 if (IsGeometry(argv[i]) == MagickFalse)
5363 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5364 break;
5365 }
cristye6365592010-04-02 17:31:23 +00005366 if (LocaleCompare("recolor",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
cristybb503372010-05-27 20:51:26 +00005371 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 break;
5376 }
cristy3ed852e2009-09-05 21:47:34 +00005377 if (LocaleCompare("red-primary",option+1) == 0)
5378 {
5379 if (*option == '+')
5380 break;
5381 i++;
cristybb503372010-05-27 20:51:26 +00005382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005383 ThrowMogrifyException(OptionError,"MissingArgument",option);
5384 if (IsGeometry(argv[i]) == MagickFalse)
5385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5386 }
cristy9f2083a2010-04-22 19:48:05 +00005387 if (LocaleCompare("regard-warnings",option+1) == 0)
5388 break;
cristy3ed852e2009-09-05 21:47:34 +00005389 if (LocaleCompare("region",option+1) == 0)
5390 {
5391 if (*option == '+')
5392 break;
5393 i++;
cristybb503372010-05-27 20:51:26 +00005394 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005395 ThrowMogrifyException(OptionError,"MissingArgument",option);
5396 if (IsGeometry(argv[i]) == MagickFalse)
5397 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5398 break;
5399 }
cristyf0c78232010-03-15 12:53:40 +00005400 if (LocaleCompare("remap",option+1) == 0)
5401 {
5402 if (*option == '+')
5403 break;
5404 i++;
cristybb503372010-05-27 20:51:26 +00005405 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 break;
5408 }
cristy3ed852e2009-09-05 21:47:34 +00005409 if (LocaleCompare("render",option+1) == 0)
5410 break;
5411 if (LocaleCompare("repage",option+1) == 0)
5412 {
5413 if (*option == '+')
5414 break;
5415 i++;
cristybb503372010-05-27 20:51:26 +00005416 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005417 ThrowMogrifyException(OptionError,"MissingArgument",option);
5418 if (IsGeometry(argv[i]) == MagickFalse)
5419 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5420 break;
5421 }
5422 if (LocaleCompare("resample",option+1) == 0)
5423 {
5424 if (*option == '+')
5425 break;
5426 i++;
cristybb503372010-05-27 20:51:26 +00005427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005428 ThrowMogrifyException(OptionError,"MissingArgument",option);
5429 if (IsGeometry(argv[i]) == MagickFalse)
5430 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5431 break;
5432 }
5433 if (LocaleCompare("resize",option+1) == 0)
5434 {
5435 if (*option == '+')
5436 break;
5437 i++;
cristybb503372010-05-27 20:51:26 +00005438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005439 ThrowMogrifyException(OptionError,"MissingArgument",option);
5440 if (IsGeometry(argv[i]) == MagickFalse)
5441 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5442 break;
5443 }
cristyebbcfea2011-02-25 02:43:54 +00005444 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5445 {
5446 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5447 break;
5448 }
cristy3ed852e2009-09-05 21:47:34 +00005449 if (LocaleCompare("reverse",option+1) == 0)
5450 break;
5451 if (LocaleCompare("roll",option+1) == 0)
5452 {
5453 if (*option == '+')
5454 break;
5455 i++;
cristybb503372010-05-27 20:51:26 +00005456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005457 ThrowMogrifyException(OptionError,"MissingArgument",option);
5458 if (IsGeometry(argv[i]) == MagickFalse)
5459 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5460 break;
5461 }
5462 if (LocaleCompare("rotate",option+1) == 0)
5463 {
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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5472 }
5473 case 's':
5474 {
5475 if (LocaleCompare("sample",option+1) == 0)
5476 {
5477 if (*option == '+')
5478 break;
5479 i++;
cristybb503372010-05-27 20:51:26 +00005480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005481 ThrowMogrifyException(OptionError,"MissingArgument",option);
5482 if (IsGeometry(argv[i]) == MagickFalse)
5483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484 break;
5485 }
5486 if (LocaleCompare("sampling-factor",option+1) == 0)
5487 {
5488 if (*option == '+')
5489 break;
5490 i++;
cristybb503372010-05-27 20:51:26 +00005491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005492 ThrowMogrifyException(OptionError,"MissingArgument",option);
5493 if (IsGeometry(argv[i]) == MagickFalse)
5494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5495 break;
5496 }
5497 if (LocaleCompare("scale",option+1) == 0)
5498 {
5499 if (*option == '+')
5500 break;
5501 i++;
cristybb503372010-05-27 20:51:26 +00005502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005503 ThrowMogrifyException(OptionError,"MissingArgument",option);
5504 if (IsGeometry(argv[i]) == MagickFalse)
5505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5506 break;
5507 }
5508 if (LocaleCompare("scene",option+1) == 0)
5509 {
5510 if (*option == '+')
5511 break;
5512 i++;
cristybb503372010-05-27 20:51:26 +00005513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005514 ThrowMogrifyException(OptionError,"MissingArgument",option);
5515 if (IsGeometry(argv[i]) == MagickFalse)
5516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5517 break;
5518 }
5519 if (LocaleCompare("seed",option+1) == 0)
5520 {
5521 if (*option == '+')
5522 break;
5523 i++;
cristybb503372010-05-27 20:51:26 +00005524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005525 ThrowMogrifyException(OptionError,"MissingArgument",option);
5526 if (IsGeometry(argv[i]) == MagickFalse)
5527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5528 break;
5529 }
5530 if (LocaleCompare("segment",option+1) == 0)
5531 {
5532 if (*option == '+')
5533 break;
5534 i++;
cristybb503372010-05-27 20:51:26 +00005535 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005536 ThrowMogrifyException(OptionError,"MissingArgument",option);
5537 if (IsGeometry(argv[i]) == MagickFalse)
5538 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5539 break;
5540 }
5541 if (LocaleCompare("selective-blur",option+1) == 0)
5542 {
5543 i++;
cristybb503372010-05-27 20:51:26 +00005544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005545 ThrowMogrifyException(OptionError,"MissingArgument",option);
5546 if (IsGeometry(argv[i]) == MagickFalse)
5547 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5548 break;
5549 }
5550 if (LocaleCompare("separate",option+1) == 0)
5551 break;
5552 if (LocaleCompare("sepia-tone",option+1) == 0)
5553 {
5554 if (*option == '+')
5555 break;
5556 i++;
cristybb503372010-05-27 20:51:26 +00005557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005558 ThrowMogrifyException(OptionError,"MissingArgument",option);
5559 if (IsGeometry(argv[i]) == MagickFalse)
5560 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5561 break;
5562 }
5563 if (LocaleCompare("set",option+1) == 0)
5564 {
5565 i++;
cristybb503372010-05-27 20:51:26 +00005566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005567 ThrowMogrifyException(OptionError,"MissingArgument",option);
5568 if (*option == '+')
5569 break;
5570 i++;
cristybb503372010-05-27 20:51:26 +00005571 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005572 ThrowMogrifyException(OptionError,"MissingArgument",option);
5573 break;
5574 }
5575 if (LocaleCompare("shade",option+1) == 0)
5576 {
5577 i++;
cristybb503372010-05-27 20:51:26 +00005578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005579 ThrowMogrifyException(OptionError,"MissingArgument",option);
5580 if (IsGeometry(argv[i]) == MagickFalse)
5581 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582 break;
5583 }
5584 if (LocaleCompare("shadow",option+1) == 0)
5585 {
5586 if (*option == '+')
5587 break;
5588 i++;
cristybb503372010-05-27 20:51:26 +00005589 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005590 ThrowMogrifyException(OptionError,"MissingArgument",option);
5591 if (IsGeometry(argv[i]) == MagickFalse)
5592 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5593 break;
5594 }
5595 if (LocaleCompare("sharpen",option+1) == 0)
5596 {
5597 i++;
cristybb503372010-05-27 20:51:26 +00005598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005599 ThrowMogrifyException(OptionError,"MissingArgument",option);
5600 if (IsGeometry(argv[i]) == MagickFalse)
5601 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5602 break;
5603 }
5604 if (LocaleCompare("shave",option+1) == 0)
5605 {
5606 if (*option == '+')
5607 break;
5608 i++;
cristybb503372010-05-27 20:51:26 +00005609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005610 ThrowMogrifyException(OptionError,"MissingArgument",option);
5611 if (IsGeometry(argv[i]) == MagickFalse)
5612 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5613 break;
5614 }
5615 if (LocaleCompare("shear",option+1) == 0)
5616 {
5617 i++;
cristybb503372010-05-27 20:51:26 +00005618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005619 ThrowMogrifyException(OptionError,"MissingArgument",option);
5620 if (IsGeometry(argv[i]) == MagickFalse)
5621 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5622 break;
5623 }
5624 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5625 {
5626 i++;
cristybb503372010-05-27 20:51:26 +00005627 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005628 ThrowMogrifyException(OptionError,"MissingArgument",option);
5629 if (IsGeometry(argv[i]) == MagickFalse)
5630 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5631 break;
5632 }
5633 if (LocaleCompare("size",option+1) == 0)
5634 {
5635 if (*option == '+')
5636 break;
5637 i++;
cristybb503372010-05-27 20:51:26 +00005638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 if (IsGeometry(argv[i]) == MagickFalse)
5641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5642 break;
5643 }
5644 if (LocaleCompare("sketch",option+1) == 0)
5645 {
5646 if (*option == '+')
5647 break;
5648 i++;
cristybb503372010-05-27 20:51:26 +00005649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005650 ThrowMogrifyException(OptionError,"MissingArgument",option);
5651 if (IsGeometry(argv[i]) == MagickFalse)
5652 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5653 break;
5654 }
cristy4285d782011-02-09 20:12:28 +00005655 if (LocaleCompare("smush",option+1) == 0)
5656 {
cristy4285d782011-02-09 20:12:28 +00005657 i++;
5658 if (i == (ssize_t) argc)
5659 ThrowMogrifyException(OptionError,"MissingArgument",option);
5660 if (IsGeometry(argv[i]) == MagickFalse)
5661 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005662 i++;
5663 break;
5664 }
cristy3ed852e2009-09-05 21:47:34 +00005665 if (LocaleCompare("solarize",option+1) == 0)
5666 {
5667 if (*option == '+')
5668 break;
5669 i++;
cristybb503372010-05-27 20:51:26 +00005670 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005671 ThrowMogrifyException(OptionError,"MissingArgument",option);
5672 if (IsGeometry(argv[i]) == MagickFalse)
5673 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5674 break;
5675 }
5676 if (LocaleCompare("sparse-color",option+1) == 0)
5677 {
cristybb503372010-05-27 20:51:26 +00005678 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005679 op;
5680
5681 i++;
cristybb503372010-05-27 20:51:26 +00005682 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005683 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005684 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005685 if (op < 0)
5686 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5687 argv[i]);
5688 i++;
cristybb503372010-05-27 20:51:26 +00005689 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005690 ThrowMogrifyException(OptionError,"MissingArgument",option);
5691 break;
5692 }
5693 if (LocaleCompare("spread",option+1) == 0)
5694 {
5695 if (*option == '+')
5696 break;
5697 i++;
cristybb503372010-05-27 20:51:26 +00005698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005699 ThrowMogrifyException(OptionError,"MissingArgument",option);
5700 if (IsGeometry(argv[i]) == MagickFalse)
5701 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5702 break;
5703 }
cristy0834d642011-03-18 18:26:08 +00005704 if (LocaleCompare("statistic",option+1) == 0)
5705 {
5706 ssize_t
5707 op;
5708
5709 if (*option == '+')
5710 break;
5711 i++;
5712 if (i == (ssize_t) argc)
5713 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005714 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005715 if (op < 0)
5716 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5717 argv[i]);
5718 i++;
5719 if (i == (ssize_t) (argc-1))
5720 ThrowMogrifyException(OptionError,"MissingArgument",option);
5721 if (IsGeometry(argv[i]) == MagickFalse)
5722 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5723 break;
5724 }
cristy3ed852e2009-09-05 21:47:34 +00005725 if (LocaleCompare("stretch",option+1) == 0)
5726 {
cristybb503372010-05-27 20:51:26 +00005727 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005728 stretch;
5729
5730 if (*option == '+')
5731 break;
5732 i++;
cristybb503372010-05-27 20:51:26 +00005733 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005734 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005735 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005736 if (stretch < 0)
5737 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5738 argv[i]);
5739 break;
5740 }
5741 if (LocaleCompare("strip",option+1) == 0)
5742 break;
5743 if (LocaleCompare("stroke",option+1) == 0)
5744 {
5745 if (*option == '+')
5746 break;
5747 i++;
cristybb503372010-05-27 20:51:26 +00005748 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005749 ThrowMogrifyException(OptionError,"MissingArgument",option);
5750 break;
5751 }
5752 if (LocaleCompare("strokewidth",option+1) == 0)
5753 {
5754 if (*option == '+')
5755 break;
5756 i++;
cristybb503372010-05-27 20:51:26 +00005757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005758 ThrowMogrifyException(OptionError,"MissingArgument",option);
5759 if (IsGeometry(argv[i]) == MagickFalse)
5760 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5761 break;
5762 }
5763 if (LocaleCompare("style",option+1) == 0)
5764 {
cristybb503372010-05-27 20:51:26 +00005765 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005766 style;
5767
5768 if (*option == '+')
5769 break;
5770 i++;
cristybb503372010-05-27 20:51:26 +00005771 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005772 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005773 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005774 if (style < 0)
5775 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5776 argv[i]);
5777 break;
5778 }
cristyecb10ff2011-03-22 13:14:03 +00005779 if (LocaleCompare("swap",option+1) == 0)
5780 {
5781 if (*option == '+')
5782 break;
5783 i++;
5784 if (i == (ssize_t) (argc-1))
5785 ThrowMogrifyException(OptionError,"MissingArgument",option);
5786 if (IsGeometry(argv[i]) == MagickFalse)
5787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5788 break;
5789 }
cristy3ed852e2009-09-05 21:47:34 +00005790 if (LocaleCompare("swirl",option+1) == 0)
5791 {
5792 if (*option == '+')
5793 break;
5794 i++;
cristybb503372010-05-27 20:51:26 +00005795 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005796 ThrowMogrifyException(OptionError,"MissingArgument",option);
5797 if (IsGeometry(argv[i]) == MagickFalse)
5798 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5799 break;
5800 }
cristyd9a29192010-10-16 16:49:53 +00005801 if (LocaleCompare("synchronize",option+1) == 0)
5802 break;
cristy3ed852e2009-09-05 21:47:34 +00005803 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5804 }
5805 case 't':
5806 {
5807 if (LocaleCompare("taint",option+1) == 0)
5808 break;
5809 if (LocaleCompare("texture",option+1) == 0)
5810 {
5811 if (*option == '+')
5812 break;
5813 i++;
cristybb503372010-05-27 20:51:26 +00005814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005815 ThrowMogrifyException(OptionError,"MissingArgument",option);
5816 break;
5817 }
5818 if (LocaleCompare("tile",option+1) == 0)
5819 {
5820 if (*option == '+')
5821 break;
5822 i++;
cristybb503372010-05-27 20:51:26 +00005823 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005824 ThrowMogrifyException(OptionError,"MissingArgument",option);
5825 break;
5826 }
5827 if (LocaleCompare("tile-offset",option+1) == 0)
5828 {
5829 if (*option == '+')
5830 break;
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 if (IsGeometry(argv[i]) == MagickFalse)
5835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5836 break;
5837 }
5838 if (LocaleCompare("tint",option+1) == 0)
5839 {
5840 if (*option == '+')
5841 break;
5842 i++;
cristybb503372010-05-27 20:51:26 +00005843 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005844 ThrowMogrifyException(OptionError,"MissingArgument",option);
5845 if (IsGeometry(argv[i]) == MagickFalse)
5846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5847 break;
5848 }
5849 if (LocaleCompare("transform",option+1) == 0)
5850 break;
5851 if (LocaleCompare("transpose",option+1) == 0)
5852 break;
5853 if (LocaleCompare("transverse",option+1) == 0)
5854 break;
5855 if (LocaleCompare("threshold",option+1) == 0)
5856 {
5857 if (*option == '+')
5858 break;
5859 i++;
cristybb503372010-05-27 20:51:26 +00005860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005861 ThrowMogrifyException(OptionError,"MissingArgument",option);
5862 if (IsGeometry(argv[i]) == MagickFalse)
5863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5864 break;
5865 }
5866 if (LocaleCompare("thumbnail",option+1) == 0)
5867 {
5868 if (*option == '+')
5869 break;
5870 i++;
cristybb503372010-05-27 20:51:26 +00005871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005872 ThrowMogrifyException(OptionError,"MissingArgument",option);
5873 if (IsGeometry(argv[i]) == MagickFalse)
5874 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5875 break;
5876 }
5877 if (LocaleCompare("transparent",option+1) == 0)
5878 {
5879 i++;
cristybb503372010-05-27 20:51:26 +00005880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005881 ThrowMogrifyException(OptionError,"MissingArgument",option);
5882 break;
5883 }
5884 if (LocaleCompare("transparent-color",option+1) == 0)
5885 {
5886 if (*option == '+')
5887 break;
5888 i++;
cristybb503372010-05-27 20:51:26 +00005889 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005890 ThrowMogrifyException(OptionError,"MissingArgument",option);
5891 break;
5892 }
5893 if (LocaleCompare("treedepth",option+1) == 0)
5894 {
5895 if (*option == '+')
5896 break;
5897 i++;
cristybb503372010-05-27 20:51:26 +00005898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005899 ThrowMogrifyException(OptionError,"MissingArgument",option);
5900 if (IsGeometry(argv[i]) == MagickFalse)
5901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5902 break;
5903 }
5904 if (LocaleCompare("trim",option+1) == 0)
5905 break;
5906 if (LocaleCompare("type",option+1) == 0)
5907 {
cristybb503372010-05-27 20:51:26 +00005908 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005909 type;
5910
5911 if (*option == '+')
5912 break;
5913 i++;
cristybb503372010-05-27 20:51:26 +00005914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005915 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005916 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005917 if (type < 0)
5918 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5919 argv[i]);
5920 break;
5921 }
5922 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5923 }
5924 case 'u':
5925 {
5926 if (LocaleCompare("undercolor",option+1) == 0)
5927 {
5928 if (*option == '+')
5929 break;
5930 i++;
cristybb503372010-05-27 20:51:26 +00005931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 break;
5934 }
5935 if (LocaleCompare("unique-colors",option+1) == 0)
5936 break;
5937 if (LocaleCompare("units",option+1) == 0)
5938 {
cristybb503372010-05-27 20:51:26 +00005939 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005940 units;
5941
5942 if (*option == '+')
5943 break;
5944 i++;
cristybb503372010-05-27 20:51:26 +00005945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005946 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005947 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005948 argv[i]);
5949 if (units < 0)
5950 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5951 argv[i]);
5952 break;
5953 }
5954 if (LocaleCompare("unsharp",option+1) == 0)
5955 {
5956 i++;
cristybb503372010-05-27 20:51:26 +00005957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005958 ThrowMogrifyException(OptionError,"MissingArgument",option);
5959 if (IsGeometry(argv[i]) == MagickFalse)
5960 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5961 break;
5962 }
5963 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5964 }
5965 case 'v':
5966 {
5967 if (LocaleCompare("verbose",option+1) == 0)
5968 {
5969 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5970 break;
5971 }
5972 if ((LocaleCompare("version",option+1) == 0) ||
5973 (LocaleCompare("-version",option+1) == 0))
5974 {
cristyb51dff52011-05-19 16:55:47 +00005975 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005976 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005977 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5978 GetMagickCopyright());
5979 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5980 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005981 break;
5982 }
5983 if (LocaleCompare("view",option+1) == 0)
5984 {
5985 if (*option == '+')
5986 break;
5987 i++;
cristybb503372010-05-27 20:51:26 +00005988 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005989 ThrowMogrifyException(OptionError,"MissingArgument",option);
5990 break;
5991 }
5992 if (LocaleCompare("vignette",option+1) == 0)
5993 {
5994 if (*option == '+')
5995 break;
5996 i++;
cristybb503372010-05-27 20:51:26 +00005997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005998 ThrowMogrifyException(OptionError,"MissingArgument",option);
5999 if (IsGeometry(argv[i]) == MagickFalse)
6000 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6001 break;
6002 }
6003 if (LocaleCompare("virtual-pixel",option+1) == 0)
6004 {
cristybb503372010-05-27 20:51:26 +00006005 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006006 method;
6007
6008 if (*option == '+')
6009 break;
6010 i++;
cristybb503372010-05-27 20:51:26 +00006011 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006012 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006013 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006014 argv[i]);
6015 if (method < 0)
6016 ThrowMogrifyException(OptionError,
6017 "UnrecognizedVirtualPixelMethod",argv[i]);
6018 break;
6019 }
6020 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6021 }
6022 case 'w':
6023 {
6024 if (LocaleCompare("wave",option+1) == 0)
6025 {
6026 i++;
cristybb503372010-05-27 20:51:26 +00006027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006028 ThrowMogrifyException(OptionError,"MissingArgument",option);
6029 if (IsGeometry(argv[i]) == MagickFalse)
6030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6031 break;
6032 }
6033 if (LocaleCompare("weight",option+1) == 0)
6034 {
6035 if (*option == '+')
6036 break;
6037 i++;
cristybb503372010-05-27 20:51:26 +00006038 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006039 ThrowMogrifyException(OptionError,"MissingArgument",option);
6040 break;
6041 }
6042 if (LocaleCompare("white-point",option+1) == 0)
6043 {
6044 if (*option == '+')
6045 break;
6046 i++;
cristybb503372010-05-27 20:51:26 +00006047 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006048 ThrowMogrifyException(OptionError,"MissingArgument",option);
6049 if (IsGeometry(argv[i]) == MagickFalse)
6050 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6051 break;
6052 }
6053 if (LocaleCompare("white-threshold",option+1) == 0)
6054 {
6055 if (*option == '+')
6056 break;
6057 i++;
cristybb503372010-05-27 20:51:26 +00006058 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006059 ThrowMogrifyException(OptionError,"MissingArgument",option);
6060 if (IsGeometry(argv[i]) == MagickFalse)
6061 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6062 break;
6063 }
6064 if (LocaleCompare("write",option+1) == 0)
6065 {
6066 i++;
cristybb503372010-05-27 20:51:26 +00006067 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006068 ThrowMogrifyException(OptionError,"MissingArgument",option);
6069 break;
6070 }
6071 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6072 }
6073 case '?':
6074 break;
6075 default:
6076 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6077 }
cristy042ee782011-04-22 18:48:30 +00006078 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6079 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006080 if (fire != MagickFalse)
6081 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6082 }
6083 if (k != 0)
6084 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006085 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006086 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6087 DestroyMogrify();
6088 return(status != 0 ? MagickTrue : MagickFalse);
6089}
6090
6091/*
6092%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6093% %
6094% %
6095% %
6096+ M o g r i f y I m a g e I n f o %
6097% %
6098% %
6099% %
6100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6101%
6102% MogrifyImageInfo() applies image processing settings to the image as
6103% prescribed by command line options.
6104%
6105% The format of the MogrifyImageInfo method is:
6106%
6107% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6108% const char **argv,ExceptionInfo *exception)
6109%
6110% A description of each parameter follows:
6111%
6112% o image_info: the image info..
6113%
6114% o argc: Specifies a pointer to an integer describing the number of
6115% elements in the argument vector.
6116%
6117% o argv: Specifies a pointer to a text array containing the command line
6118% arguments.
6119%
6120% o exception: return any errors or warnings in this structure.
6121%
6122*/
6123WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6124 const int argc,const char **argv,ExceptionInfo *exception)
6125{
6126 const char
6127 *option;
6128
6129 GeometryInfo
6130 geometry_info;
6131
cristybb503372010-05-27 20:51:26 +00006132 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006133 count;
6134
cristybb503372010-05-27 20:51:26 +00006135 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006136 i;
6137
6138 /*
6139 Initialize method variables.
6140 */
6141 assert(image_info != (ImageInfo *) NULL);
6142 assert(image_info->signature == MagickSignature);
6143 if (image_info->debug != MagickFalse)
6144 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6145 image_info->filename);
6146 if (argc < 0)
6147 return(MagickTrue);
6148 /*
6149 Set the image settings.
6150 */
cristybb503372010-05-27 20:51:26 +00006151 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006152 {
6153 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006154 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006155 continue;
cristy042ee782011-04-22 18:48:30 +00006156 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006157 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006158 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006159 break;
6160 switch (*(option+1))
6161 {
6162 case 'a':
6163 {
6164 if (LocaleCompare("adjoin",option+1) == 0)
6165 {
6166 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6167 break;
6168 }
6169 if (LocaleCompare("antialias",option+1) == 0)
6170 {
6171 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6172 break;
6173 }
cristy3ed852e2009-09-05 21:47:34 +00006174 if (LocaleCompare("authenticate",option+1) == 0)
6175 {
6176 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006177 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006178 else
anthony1afdc7a2011-10-05 11:54:28 +00006179 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006180 break;
6181 }
6182 break;
6183 }
6184 case 'b':
6185 {
6186 if (LocaleCompare("background",option+1) == 0)
6187 {
6188 if (*option == '+')
6189 {
6190 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006191 (void) QueryColorCompliance(MogrifyBackgroundColor,
6192 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006193 break;
6194 }
6195 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006196 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6197 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006198 break;
6199 }
6200 if (LocaleCompare("bias",option+1) == 0)
6201 {
6202 if (*option == '+')
6203 {
6204 (void) SetImageOption(image_info,option+1,"0.0");
6205 break;
6206 }
6207 (void) SetImageOption(image_info,option+1,argv[i+1]);
6208 break;
6209 }
6210 if (LocaleCompare("black-point-compensation",option+1) == 0)
6211 {
6212 if (*option == '+')
6213 {
6214 (void) SetImageOption(image_info,option+1,"false");
6215 break;
6216 }
6217 (void) SetImageOption(image_info,option+1,"true");
6218 break;
6219 }
6220 if (LocaleCompare("blue-primary",option+1) == 0)
6221 {
6222 if (*option == '+')
6223 {
6224 (void) SetImageOption(image_info,option+1,"0.0");
6225 break;
6226 }
6227 (void) SetImageOption(image_info,option+1,argv[i+1]);
6228 break;
6229 }
6230 if (LocaleCompare("bordercolor",option+1) == 0)
6231 {
6232 if (*option == '+')
6233 {
6234 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006235 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006236 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006237 break;
6238 }
cristy9950d572011-10-01 18:22:35 +00006239 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6240 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006241 (void) SetImageOption(image_info,option+1,argv[i+1]);
6242 break;
6243 }
6244 if (LocaleCompare("box",option+1) == 0)
6245 {
6246 if (*option == '+')
6247 {
6248 (void) SetImageOption(image_info,"undercolor","none");
6249 break;
6250 }
6251 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6252 break;
6253 }
6254 break;
6255 }
6256 case 'c':
6257 {
6258 if (LocaleCompare("cache",option+1) == 0)
6259 {
6260 MagickSizeType
6261 limit;
6262
6263 limit=MagickResourceInfinity;
6264 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006265 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006266 (void) SetMagickResourceLimit(MemoryResource,limit);
6267 (void) SetMagickResourceLimit(MapResource,2*limit);
6268 break;
6269 }
6270 if (LocaleCompare("caption",option+1) == 0)
6271 {
6272 if (*option == '+')
6273 {
6274 (void) DeleteImageOption(image_info,option+1);
6275 break;
6276 }
6277 (void) SetImageOption(image_info,option+1,argv[i+1]);
6278 break;
6279 }
6280 if (LocaleCompare("channel",option+1) == 0)
6281 {
6282 if (*option == '+')
6283 {
6284 image_info->channel=DefaultChannels;
6285 break;
6286 }
6287 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6288 break;
6289 }
cristy3ed852e2009-09-05 21:47:34 +00006290 if (LocaleCompare("colorspace",option+1) == 0)
6291 {
6292 if (*option == '+')
6293 {
6294 image_info->colorspace=UndefinedColorspace;
6295 (void) SetImageOption(image_info,option+1,"undefined");
6296 break;
6297 }
cristy042ee782011-04-22 18:48:30 +00006298 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006299 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6300 (void) SetImageOption(image_info,option+1,argv[i+1]);
6301 break;
6302 }
cristy3ed852e2009-09-05 21:47:34 +00006303 if (LocaleCompare("comment",option+1) == 0)
6304 {
6305 if (*option == '+')
6306 {
6307 (void) DeleteImageOption(image_info,option+1);
6308 break;
6309 }
6310 (void) SetImageOption(image_info,option+1,argv[i+1]);
6311 break;
6312 }
6313 if (LocaleCompare("compose",option+1) == 0)
6314 {
6315 if (*option == '+')
6316 {
6317 (void) SetImageOption(image_info,option+1,"undefined");
6318 break;
6319 }
6320 (void) SetImageOption(image_info,option+1,argv[i+1]);
6321 break;
6322 }
6323 if (LocaleCompare("compress",option+1) == 0)
6324 {
6325 if (*option == '+')
6326 {
6327 image_info->compression=UndefinedCompression;
6328 (void) SetImageOption(image_info,option+1,"undefined");
6329 break;
6330 }
cristy042ee782011-04-22 18:48:30 +00006331 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006332 MagickCompressOptions,MagickFalse,argv[i+1]);
6333 (void) SetImageOption(image_info,option+1,argv[i+1]);
6334 break;
6335 }
6336 break;
6337 }
6338 case 'd':
6339 {
6340 if (LocaleCompare("debug",option+1) == 0)
6341 {
6342 if (*option == '+')
6343 (void) SetLogEventMask("none");
6344 else
6345 (void) SetLogEventMask(argv[i+1]);
6346 image_info->debug=IsEventLogging();
6347 break;
6348 }
6349 if (LocaleCompare("define",option+1) == 0)
6350 {
6351 if (*option == '+')
6352 {
6353 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6354 (void) DeleteImageRegistry(argv[i+1]+9);
6355 else
6356 (void) DeleteImageOption(image_info,argv[i+1]);
6357 break;
6358 }
6359 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6360 {
6361 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6362 exception);
6363 break;
6364 }
6365 (void) DefineImageOption(image_info,argv[i+1]);
6366 break;
6367 }
6368 if (LocaleCompare("delay",option+1) == 0)
6369 {
6370 if (*option == '+')
6371 {
6372 (void) SetImageOption(image_info,option+1,"0");
6373 break;
6374 }
6375 (void) SetImageOption(image_info,option+1,argv[i+1]);
6376 break;
6377 }
6378 if (LocaleCompare("density",option+1) == 0)
6379 {
6380 /*
6381 Set image density.
6382 */
6383 if (*option == '+')
6384 {
6385 if (image_info->density != (char *) NULL)
6386 image_info->density=DestroyString(image_info->density);
6387 (void) SetImageOption(image_info,option+1,"72");
6388 break;
6389 }
6390 (void) CloneString(&image_info->density,argv[i+1]);
6391 (void) SetImageOption(image_info,option+1,argv[i+1]);
6392 break;
6393 }
6394 if (LocaleCompare("depth",option+1) == 0)
6395 {
6396 if (*option == '+')
6397 {
6398 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6399 break;
6400 }
cristye27293e2009-12-18 02:53:20 +00006401 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006402 break;
6403 }
cristyc9b12952010-03-28 01:12:28 +00006404 if (LocaleCompare("direction",option+1) == 0)
6405 {
6406 if (*option == '+')
6407 {
6408 (void) SetImageOption(image_info,option+1,"undefined");
6409 break;
6410 }
6411 (void) SetImageOption(image_info,option+1,argv[i+1]);
6412 break;
6413 }
cristy3ed852e2009-09-05 21:47:34 +00006414 if (LocaleCompare("display",option+1) == 0)
6415 {
6416 if (*option == '+')
6417 {
6418 if (image_info->server_name != (char *) NULL)
6419 image_info->server_name=DestroyString(
6420 image_info->server_name);
6421 break;
6422 }
6423 (void) CloneString(&image_info->server_name,argv[i+1]);
6424 break;
6425 }
6426 if (LocaleCompare("dispose",option+1) == 0)
6427 {
6428 if (*option == '+')
6429 {
6430 (void) SetImageOption(image_info,option+1,"undefined");
6431 break;
6432 }
6433 (void) SetImageOption(image_info,option+1,argv[i+1]);
6434 break;
6435 }
6436 if (LocaleCompare("dither",option+1) == 0)
6437 {
6438 if (*option == '+')
6439 {
6440 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006441 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006442 break;
6443 }
6444 (void) SetImageOption(image_info,option+1,argv[i+1]);
6445 image_info->dither=MagickTrue;
6446 break;
6447 }
6448 break;
6449 }
6450 case 'e':
6451 {
6452 if (LocaleCompare("encoding",option+1) == 0)
6453 {
6454 if (*option == '+')
6455 {
6456 (void) SetImageOption(image_info,option+1,"undefined");
6457 break;
6458 }
6459 (void) SetImageOption(image_info,option+1,argv[i+1]);
6460 break;
6461 }
6462 if (LocaleCompare("endian",option+1) == 0)
6463 {
6464 if (*option == '+')
6465 {
6466 image_info->endian=UndefinedEndian;
6467 (void) SetImageOption(image_info,option+1,"undefined");
6468 break;
6469 }
cristy042ee782011-04-22 18:48:30 +00006470 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006471 MagickEndianOptions,MagickFalse,argv[i+1]);
6472 (void) SetImageOption(image_info,option+1,argv[i+1]);
6473 break;
6474 }
6475 if (LocaleCompare("extract",option+1) == 0)
6476 {
6477 /*
6478 Set image extract geometry.
6479 */
6480 if (*option == '+')
6481 {
6482 if (image_info->extract != (char *) NULL)
6483 image_info->extract=DestroyString(image_info->extract);
6484 break;
6485 }
6486 (void) CloneString(&image_info->extract,argv[i+1]);
6487 break;
6488 }
6489 break;
6490 }
6491 case 'f':
6492 {
6493 if (LocaleCompare("fill",option+1) == 0)
6494 {
6495 if (*option == '+')
6496 {
6497 (void) SetImageOption(image_info,option+1,"none");
6498 break;
6499 }
6500 (void) SetImageOption(image_info,option+1,argv[i+1]);
6501 break;
6502 }
6503 if (LocaleCompare("filter",option+1) == 0)
6504 {
6505 if (*option == '+')
6506 {
6507 (void) SetImageOption(image_info,option+1,"undefined");
6508 break;
6509 }
6510 (void) SetImageOption(image_info,option+1,argv[i+1]);
6511 break;
6512 }
6513 if (LocaleCompare("font",option+1) == 0)
6514 {
6515 if (*option == '+')
6516 {
6517 if (image_info->font != (char *) NULL)
6518 image_info->font=DestroyString(image_info->font);
6519 break;
6520 }
6521 (void) CloneString(&image_info->font,argv[i+1]);
6522 break;
6523 }
6524 if (LocaleCompare("format",option+1) == 0)
6525 {
6526 register const char
6527 *q;
6528
6529 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006530 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006531 image_info->ping=MagickFalse;
6532 (void) SetImageOption(image_info,option+1,argv[i+1]);
6533 break;
6534 }
6535 if (LocaleCompare("fuzz",option+1) == 0)
6536 {
6537 if (*option == '+')
6538 {
6539 image_info->fuzz=0.0;
6540 (void) SetImageOption(image_info,option+1,"0");
6541 break;
6542 }
cristyf2f27272009-12-17 14:48:46 +00006543 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006544 1.0);
6545 (void) SetImageOption(image_info,option+1,argv[i+1]);
6546 break;
6547 }
6548 break;
6549 }
6550 case 'g':
6551 {
6552 if (LocaleCompare("gravity",option+1) == 0)
6553 {
6554 if (*option == '+')
6555 {
6556 (void) SetImageOption(image_info,option+1,"undefined");
6557 break;
6558 }
6559 (void) SetImageOption(image_info,option+1,argv[i+1]);
6560 break;
6561 }
6562 if (LocaleCompare("green-primary",option+1) == 0)
6563 {
6564 if (*option == '+')
6565 {
6566 (void) SetImageOption(image_info,option+1,"0.0");
6567 break;
6568 }
6569 (void) SetImageOption(image_info,option+1,argv[i+1]);
6570 break;
6571 }
6572 break;
6573 }
6574 case 'i':
6575 {
6576 if (LocaleCompare("intent",option+1) == 0)
6577 {
6578 if (*option == '+')
6579 {
6580 (void) SetImageOption(image_info,option+1,"undefined");
6581 break;
6582 }
6583 (void) SetImageOption(image_info,option+1,argv[i+1]);
6584 break;
6585 }
6586 if (LocaleCompare("interlace",option+1) == 0)
6587 {
6588 if (*option == '+')
6589 {
6590 image_info->interlace=UndefinedInterlace;
6591 (void) SetImageOption(image_info,option+1,"undefined");
6592 break;
6593 }
cristy042ee782011-04-22 18:48:30 +00006594 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006595 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6596 (void) SetImageOption(image_info,option+1,argv[i+1]);
6597 break;
6598 }
cristyb32b90a2009-09-07 21:45:48 +00006599 if (LocaleCompare("interline-spacing",option+1) == 0)
6600 {
6601 if (*option == '+')
6602 {
6603 (void) SetImageOption(image_info,option+1,"undefined");
6604 break;
6605 }
6606 (void) SetImageOption(image_info,option+1,argv[i+1]);
6607 break;
6608 }
cristy3ed852e2009-09-05 21:47:34 +00006609 if (LocaleCompare("interpolate",option+1) == 0)
6610 {
6611 if (*option == '+')
6612 {
6613 (void) SetImageOption(image_info,option+1,"undefined");
6614 break;
6615 }
6616 (void) SetImageOption(image_info,option+1,argv[i+1]);
6617 break;
6618 }
6619 if (LocaleCompare("interword-spacing",option+1) == 0)
6620 {
6621 if (*option == '+')
6622 {
6623 (void) SetImageOption(image_info,option+1,"undefined");
6624 break;
6625 }
6626 (void) SetImageOption(image_info,option+1,argv[i+1]);
6627 break;
6628 }
6629 break;
6630 }
6631 case 'k':
6632 {
6633 if (LocaleCompare("kerning",option+1) == 0)
6634 {
6635 if (*option == '+')
6636 {
6637 (void) SetImageOption(image_info,option+1,"undefined");
6638 break;
6639 }
6640 (void) SetImageOption(image_info,option+1,argv[i+1]);
6641 break;
6642 }
6643 break;
6644 }
6645 case 'l':
6646 {
6647 if (LocaleCompare("label",option+1) == 0)
6648 {
6649 if (*option == '+')
6650 {
6651 (void) DeleteImageOption(image_info,option+1);
6652 break;
6653 }
6654 (void) SetImageOption(image_info,option+1,argv[i+1]);
6655 break;
6656 }
6657 if (LocaleCompare("limit",option+1) == 0)
6658 {
6659 MagickSizeType
6660 limit;
6661
6662 ResourceType
6663 type;
6664
6665 if (*option == '+')
6666 break;
cristy042ee782011-04-22 18:48:30 +00006667 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006668 MagickFalse,argv[i+1]);
6669 limit=MagickResourceInfinity;
6670 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006671 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006672 (void) SetMagickResourceLimit(type,limit);
6673 break;
6674 }
6675 if (LocaleCompare("list",option+1) == 0)
6676 {
cristybb503372010-05-27 20:51:26 +00006677 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006678 list;
6679
6680 /*
6681 Display configuration list.
6682 */
cristy042ee782011-04-22 18:48:30 +00006683 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006684 switch (list)
6685 {
6686 case MagickCoderOptions:
6687 {
6688 (void) ListCoderInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickColorOptions:
6692 {
6693 (void) ListColorInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickConfigureOptions:
6697 {
6698 (void) ListConfigureInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickDelegateOptions:
6702 {
6703 (void) ListDelegateInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickFontOptions:
6707 {
6708 (void) ListTypeInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickFormatOptions:
6712 {
6713 (void) ListMagickInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickLocaleOptions:
6717 {
6718 (void) ListLocaleInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickLogOptions:
6722 {
6723 (void) ListLogInfo((FILE *) NULL,exception);
6724 break;
6725 }
6726 case MagickMagicOptions:
6727 {
6728 (void) ListMagicInfo((FILE *) NULL,exception);
6729 break;
6730 }
6731 case MagickMimeOptions:
6732 {
6733 (void) ListMimeInfo((FILE *) NULL,exception);
6734 break;
6735 }
6736 case MagickModuleOptions:
6737 {
6738 (void) ListModuleInfo((FILE *) NULL,exception);
6739 break;
6740 }
6741 case MagickPolicyOptions:
6742 {
6743 (void) ListPolicyInfo((FILE *) NULL,exception);
6744 break;
6745 }
6746 case MagickResourceOptions:
6747 {
6748 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6749 break;
6750 }
6751 case MagickThresholdOptions:
6752 {
6753 (void) ListThresholdMaps((FILE *) NULL,exception);
6754 break;
6755 }
6756 default:
6757 {
cristy042ee782011-04-22 18:48:30 +00006758 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006759 exception);
6760 break;
6761 }
6762 }
cristyaeb2cbc2010-05-07 13:28:58 +00006763 break;
cristy3ed852e2009-09-05 21:47:34 +00006764 }
6765 if (LocaleCompare("log",option+1) == 0)
6766 {
6767 if (*option == '+')
6768 break;
6769 (void) SetLogFormat(argv[i+1]);
6770 break;
6771 }
6772 if (LocaleCompare("loop",option+1) == 0)
6773 {
6774 if (*option == '+')
6775 {
6776 (void) SetImageOption(image_info,option+1,"0");
6777 break;
6778 }
6779 (void) SetImageOption(image_info,option+1,argv[i+1]);
6780 break;
6781 }
6782 break;
6783 }
6784 case 'm':
6785 {
6786 if (LocaleCompare("matte",option+1) == 0)
6787 {
6788 if (*option == '+')
6789 {
6790 (void) SetImageOption(image_info,option+1,"false");
6791 break;
6792 }
6793 (void) SetImageOption(image_info,option+1,"true");
6794 break;
6795 }
6796 if (LocaleCompare("mattecolor",option+1) == 0)
6797 {
6798 if (*option == '+')
6799 {
6800 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006801 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006802 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006803 break;
6804 }
6805 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006806 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6807 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006808 break;
6809 }
6810 if (LocaleCompare("monitor",option+1) == 0)
6811 {
6812 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6813 (void *) NULL);
6814 break;
6815 }
6816 if (LocaleCompare("monochrome",option+1) == 0)
6817 {
6818 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6819 break;
6820 }
6821 break;
6822 }
6823 case 'o':
6824 {
6825 if (LocaleCompare("orient",option+1) == 0)
6826 {
6827 if (*option == '+')
6828 {
6829 image_info->orientation=UndefinedOrientation;
6830 (void) SetImageOption(image_info,option+1,"undefined");
6831 break;
6832 }
cristy042ee782011-04-22 18:48:30 +00006833 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006834 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006835 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006836 break;
6837 }
6838 }
6839 case 'p':
6840 {
6841 if (LocaleCompare("page",option+1) == 0)
6842 {
6843 char
6844 *canonical_page,
6845 page[MaxTextExtent];
6846
6847 const char
6848 *image_option;
6849
6850 MagickStatusType
6851 flags;
6852
6853 RectangleInfo
6854 geometry;
6855
6856 if (*option == '+')
6857 {
6858 (void) DeleteImageOption(image_info,option+1);
6859 (void) CloneString(&image_info->page,(char *) NULL);
6860 break;
6861 }
6862 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6863 image_option=GetImageOption(image_info,"page");
6864 if (image_option != (const char *) NULL)
6865 flags=ParseAbsoluteGeometry(image_option,&geometry);
6866 canonical_page=GetPageGeometry(argv[i+1]);
6867 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6868 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006869 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006870 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006871 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006872 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006873 (unsigned long) geometry.width,(unsigned long) geometry.height,
6874 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006875 (void) SetImageOption(image_info,option+1,page);
6876 (void) CloneString(&image_info->page,page);
6877 break;
6878 }
6879 if (LocaleCompare("pen",option+1) == 0)
6880 {
6881 if (*option == '+')
6882 {
6883 (void) SetImageOption(image_info,option+1,"none");
6884 break;
6885 }
6886 (void) SetImageOption(image_info,option+1,argv[i+1]);
6887 break;
6888 }
6889 if (LocaleCompare("ping",option+1) == 0)
6890 {
6891 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6892 break;
6893 }
6894 if (LocaleCompare("pointsize",option+1) == 0)
6895 {
6896 if (*option == '+')
6897 geometry_info.rho=0.0;
6898 else
6899 (void) ParseGeometry(argv[i+1],&geometry_info);
6900 image_info->pointsize=geometry_info.rho;
6901 break;
6902 }
cristye7f51092010-01-17 00:39:37 +00006903 if (LocaleCompare("precision",option+1) == 0)
6904 {
cristybf2766a2010-01-17 03:33:23 +00006905 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006906 break;
6907 }
cristy3ed852e2009-09-05 21:47:34 +00006908 if (LocaleCompare("preview",option+1) == 0)
6909 {
6910 /*
6911 Preview image.
6912 */
6913 if (*option == '+')
6914 {
6915 image_info->preview_type=UndefinedPreview;
6916 break;
6917 }
cristy042ee782011-04-22 18:48:30 +00006918 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006919 MagickPreviewOptions,MagickFalse,argv[i+1]);
6920 break;
6921 }
6922 break;
6923 }
6924 case 'q':
6925 {
6926 if (LocaleCompare("quality",option+1) == 0)
6927 {
6928 /*
6929 Set image compression quality.
6930 */
6931 if (*option == '+')
6932 {
6933 image_info->quality=UndefinedCompressionQuality;
6934 (void) SetImageOption(image_info,option+1,"0");
6935 break;
6936 }
cristye27293e2009-12-18 02:53:20 +00006937 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006938 (void) SetImageOption(image_info,option+1,argv[i+1]);
6939 break;
6940 }
6941 if (LocaleCompare("quiet",option+1) == 0)
6942 {
6943 static WarningHandler
6944 warning_handler = (WarningHandler) NULL;
6945
6946 if (*option == '+')
6947 {
6948 /*
6949 Restore error or warning messages.
6950 */
6951 warning_handler=SetWarningHandler(warning_handler);
6952 break;
6953 }
6954 /*
6955 Suppress error or warning messages.
6956 */
6957 warning_handler=SetWarningHandler((WarningHandler) NULL);
6958 break;
6959 }
6960 break;
6961 }
6962 case 'r':
6963 {
6964 if (LocaleCompare("red-primary",option+1) == 0)
6965 {
6966 if (*option == '+')
6967 {
6968 (void) SetImageOption(image_info,option+1,"0.0");
6969 break;
6970 }
6971 (void) SetImageOption(image_info,option+1,argv[i+1]);
6972 break;
6973 }
6974 break;
6975 }
6976 case 's':
6977 {
6978 if (LocaleCompare("sampling-factor",option+1) == 0)
6979 {
6980 /*
6981 Set image sampling factor.
6982 */
6983 if (*option == '+')
6984 {
6985 if (image_info->sampling_factor != (char *) NULL)
6986 image_info->sampling_factor=DestroyString(
6987 image_info->sampling_factor);
6988 break;
6989 }
6990 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6991 break;
6992 }
6993 if (LocaleCompare("scene",option+1) == 0)
6994 {
6995 /*
6996 Set image scene.
6997 */
6998 if (*option == '+')
6999 {
7000 image_info->scene=0;
7001 (void) SetImageOption(image_info,option+1,"0");
7002 break;
7003 }
cristye27293e2009-12-18 02:53:20 +00007004 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007005 (void) SetImageOption(image_info,option+1,argv[i+1]);
7006 break;
7007 }
7008 if (LocaleCompare("seed",option+1) == 0)
7009 {
cristybb503372010-05-27 20:51:26 +00007010 size_t
cristy3ed852e2009-09-05 21:47:34 +00007011 seed;
7012
7013 if (*option == '+')
7014 {
cristybb503372010-05-27 20:51:26 +00007015 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007016 SeedPseudoRandomGenerator(seed);
7017 break;
7018 }
cristye27293e2009-12-18 02:53:20 +00007019 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007020 SeedPseudoRandomGenerator(seed);
7021 break;
7022 }
7023 if (LocaleCompare("size",option+1) == 0)
7024 {
7025 if (*option == '+')
7026 {
7027 if (image_info->size != (char *) NULL)
7028 image_info->size=DestroyString(image_info->size);
7029 break;
7030 }
7031 (void) CloneString(&image_info->size,argv[i+1]);
7032 break;
7033 }
7034 if (LocaleCompare("stroke",option+1) == 0)
7035 {
7036 if (*option == '+')
7037 {
7038 (void) SetImageOption(image_info,option+1,"none");
7039 break;
7040 }
7041 (void) SetImageOption(image_info,option+1,argv[i+1]);
7042 break;
7043 }
7044 if (LocaleCompare("strokewidth",option+1) == 0)
7045 {
7046 if (*option == '+')
7047 {
7048 (void) SetImageOption(image_info,option+1,"0");
7049 break;
7050 }
7051 (void) SetImageOption(image_info,option+1,argv[i+1]);
7052 break;
7053 }
cristyd9a29192010-10-16 16:49:53 +00007054 if (LocaleCompare("synchronize",option+1) == 0)
7055 {
7056 if (*option == '+')
7057 {
7058 image_info->synchronize=MagickFalse;
7059 break;
7060 }
7061 image_info->synchronize=MagickTrue;
7062 break;
7063 }
cristy3ed852e2009-09-05 21:47:34 +00007064 break;
7065 }
7066 case 't':
7067 {
7068 if (LocaleCompare("taint",option+1) == 0)
7069 {
7070 if (*option == '+')
7071 {
7072 (void) SetImageOption(image_info,option+1,"false");
7073 break;
7074 }
7075 (void) SetImageOption(image_info,option+1,"true");
7076 break;
7077 }
7078 if (LocaleCompare("texture",option+1) == 0)
7079 {
7080 if (*option == '+')
7081 {
7082 if (image_info->texture != (char *) NULL)
7083 image_info->texture=DestroyString(image_info->texture);
7084 break;
7085 }
7086 (void) CloneString(&image_info->texture,argv[i+1]);
7087 break;
7088 }
7089 if (LocaleCompare("tile-offset",option+1) == 0)
7090 {
7091 if (*option == '+')
7092 {
7093 (void) SetImageOption(image_info,option+1,"0");
7094 break;
7095 }
7096 (void) SetImageOption(image_info,option+1,argv[i+1]);
7097 break;
7098 }
7099 if (LocaleCompare("transparent-color",option+1) == 0)
7100 {
7101 if (*option == '+')
7102 {
cristy9950d572011-10-01 18:22:35 +00007103 (void) QueryColorCompliance("none",AllCompliance,
7104 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007105 (void) SetImageOption(image_info,option+1,"none");
7106 break;
7107 }
cristy9950d572011-10-01 18:22:35 +00007108 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7109 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007110 (void) SetImageOption(image_info,option+1,argv[i+1]);
7111 break;
7112 }
7113 if (LocaleCompare("type",option+1) == 0)
7114 {
7115 if (*option == '+')
7116 {
cristy5f1c1ff2010-12-23 21:38:06 +00007117 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007118 (void) SetImageOption(image_info,option+1,"undefined");
7119 break;
7120 }
cristy042ee782011-04-22 18:48:30 +00007121 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007122 MagickFalse,argv[i+1]);
7123 (void) SetImageOption(image_info,option+1,argv[i+1]);
7124 break;
7125 }
7126 break;
7127 }
7128 case 'u':
7129 {
7130 if (LocaleCompare("undercolor",option+1) == 0)
7131 {
7132 if (*option == '+')
7133 {
7134 (void) DeleteImageOption(image_info,option+1);
7135 break;
7136 }
7137 (void) SetImageOption(image_info,option+1,argv[i+1]);
7138 break;
7139 }
7140 if (LocaleCompare("units",option+1) == 0)
7141 {
7142 if (*option == '+')
7143 {
7144 image_info->units=UndefinedResolution;
7145 (void) SetImageOption(image_info,option+1,"undefined");
7146 break;
7147 }
cristy042ee782011-04-22 18:48:30 +00007148 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007149 MagickResolutionOptions,MagickFalse,argv[i+1]);
7150 (void) SetImageOption(image_info,option+1,argv[i+1]);
7151 break;
7152 }
7153 break;
7154 }
7155 case 'v':
7156 {
7157 if (LocaleCompare("verbose",option+1) == 0)
7158 {
7159 if (*option == '+')
7160 {
7161 image_info->verbose=MagickFalse;
7162 break;
7163 }
7164 image_info->verbose=MagickTrue;
7165 image_info->ping=MagickFalse;
7166 break;
7167 }
7168 if (LocaleCompare("view",option+1) == 0)
7169 {
7170 if (*option == '+')
7171 {
7172 if (image_info->view != (char *) NULL)
7173 image_info->view=DestroyString(image_info->view);
7174 break;
7175 }
7176 (void) CloneString(&image_info->view,argv[i+1]);
7177 break;
7178 }
7179 if (LocaleCompare("virtual-pixel",option+1) == 0)
7180 {
7181 if (*option == '+')
7182 {
7183 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7184 (void) SetImageOption(image_info,option+1,"undefined");
7185 break;
7186 }
7187 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007188 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007189 argv[i+1]);
7190 (void) SetImageOption(image_info,option+1,argv[i+1]);
7191 break;
7192 }
7193 break;
7194 }
7195 case 'w':
7196 {
7197 if (LocaleCompare("white-point",option+1) == 0)
7198 {
7199 if (*option == '+')
7200 {
7201 (void) SetImageOption(image_info,option+1,"0.0");
7202 break;
7203 }
7204 (void) SetImageOption(image_info,option+1,argv[i+1]);
7205 break;
7206 }
7207 break;
7208 }
7209 default:
7210 break;
7211 }
7212 i+=count;
7213 }
7214 return(MagickTrue);
7215}
7216
7217/*
7218%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7219% %
7220% %
7221% %
7222+ M o g r i f y I m a g e L i s t %
7223% %
7224% %
7225% %
7226%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7227%
7228% MogrifyImageList() applies any command line options that might affect the
7229% entire image list (e.g. -append, -coalesce, etc.).
7230%
7231% The format of the MogrifyImage method is:
7232%
7233% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7234% const char **argv,Image **images,ExceptionInfo *exception)
7235%
7236% A description of each parameter follows:
7237%
7238% o image_info: the image info..
7239%
7240% o argc: Specifies a pointer to an integer describing the number of
7241% elements in the argument vector.
7242%
7243% o argv: Specifies a pointer to a text array containing the command line
7244% arguments.
7245%
anthonye9c27192011-03-27 08:07:06 +00007246% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007247%
7248% o exception: return any errors or warnings in this structure.
7249%
7250*/
7251WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7252 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7253{
cristy3ed852e2009-09-05 21:47:34 +00007254 const char
7255 *option;
7256
cristy6b3da3a2010-06-20 02:21:46 +00007257 ImageInfo
7258 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007259
7260 MagickStatusType
7261 status;
7262
cristy28474bf2011-09-11 23:32:52 +00007263 PixelInterpolateMethod
7264 interpolate_method;
7265
cristy3ed852e2009-09-05 21:47:34 +00007266 QuantizeInfo
7267 *quantize_info;
7268
cristybb503372010-05-27 20:51:26 +00007269 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007270 i;
7271
cristy6b3da3a2010-06-20 02:21:46 +00007272 ssize_t
7273 count,
7274 index;
7275
cristy3ed852e2009-09-05 21:47:34 +00007276 /*
7277 Apply options to the image list.
7278 */
7279 assert(image_info != (ImageInfo *) NULL);
7280 assert(image_info->signature == MagickSignature);
7281 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007282 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007283 assert((*images)->signature == MagickSignature);
7284 if ((*images)->debug != MagickFalse)
7285 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7286 (*images)->filename);
7287 if ((argc <= 0) || (*argv == (char *) NULL))
7288 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007289 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007290 mogrify_info=CloneImageInfo(image_info);
7291 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007292 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007293 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007294 {
cristy74fe8f12009-10-03 19:09:01 +00007295 if (*images == (Image *) NULL)
7296 break;
cristy3ed852e2009-09-05 21:47:34 +00007297 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007298 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007299 continue;
cristy042ee782011-04-22 18:48:30 +00007300 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007301 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007302 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007303 break;
cristy6b3da3a2010-06-20 02:21:46 +00007304 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007305 switch (*(option+1))
7306 {
7307 case 'a':
7308 {
7309 if (LocaleCompare("affinity",option+1) == 0)
7310 {
cristy6b3da3a2010-06-20 02:21:46 +00007311 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007312 if (*option == '+')
7313 {
cristy018f07f2011-09-04 21:15:19 +00007314 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7315 exception);
cristy3ed852e2009-09-05 21:47:34 +00007316 break;
7317 }
7318 i++;
7319 break;
7320 }
7321 if (LocaleCompare("append",option+1) == 0)
7322 {
7323 Image
7324 *append_image;
7325
cristy6b3da3a2010-06-20 02:21:46 +00007326 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007327 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7328 MagickFalse,exception);
7329 if (append_image == (Image *) NULL)
7330 {
7331 status=MagickFalse;
7332 break;
7333 }
7334 *images=DestroyImageList(*images);
7335 *images=append_image;
7336 break;
7337 }
7338 if (LocaleCompare("average",option+1) == 0)
7339 {
7340 Image
7341 *average_image;
7342
cristyd18ae7c2010-03-07 17:39:52 +00007343 /*
7344 Average an image sequence (deprecated).
7345 */
cristy6b3da3a2010-06-20 02:21:46 +00007346 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007347 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7348 exception);
cristy3ed852e2009-09-05 21:47:34 +00007349 if (average_image == (Image *) NULL)
7350 {
7351 status=MagickFalse;
7352 break;
7353 }
7354 *images=DestroyImageList(*images);
7355 *images=average_image;
7356 break;
7357 }
7358 break;
7359 }
7360 case 'c':
7361 {
7362 if (LocaleCompare("channel",option+1) == 0)
7363 {
cristyf4ad9df2011-07-08 16:49:03 +00007364 ChannelType
7365 channel;
7366
cristy3ed852e2009-09-05 21:47:34 +00007367 if (*option == '+')
7368 {
7369 channel=DefaultChannels;
7370 break;
7371 }
7372 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007373 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007374 break;
7375 }
7376 if (LocaleCompare("clut",option+1) == 0)
7377 {
7378 Image
7379 *clut_image,
7380 *image;
7381
cristy6b3da3a2010-06-20 02:21:46 +00007382 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007383 image=RemoveFirstImageFromList(images);
7384 clut_image=RemoveFirstImageFromList(images);
7385 if (clut_image == (Image *) NULL)
7386 {
7387 status=MagickFalse;
7388 break;
7389 }
cristy28474bf2011-09-11 23:32:52 +00007390 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007391 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007392 *images=DestroyImageList(*images);
7393 *images=image;
7394 break;
7395 }
7396 if (LocaleCompare("coalesce",option+1) == 0)
7397 {
7398 Image
7399 *coalesce_image;
7400
cristy6b3da3a2010-06-20 02:21:46 +00007401 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007402 coalesce_image=CoalesceImages(*images,exception);
7403 if (coalesce_image == (Image *) NULL)
7404 {
7405 status=MagickFalse;
7406 break;
7407 }
7408 *images=DestroyImageList(*images);
7409 *images=coalesce_image;
7410 break;
7411 }
7412 if (LocaleCompare("combine",option+1) == 0)
7413 {
7414 Image
7415 *combine_image;
7416
cristy6b3da3a2010-06-20 02:21:46 +00007417 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007418 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007419 if (combine_image == (Image *) NULL)
7420 {
7421 status=MagickFalse;
7422 break;
7423 }
7424 *images=DestroyImageList(*images);
7425 *images=combine_image;
7426 break;
7427 }
7428 if (LocaleCompare("composite",option+1) == 0)
7429 {
7430 Image
7431 *mask_image,
7432 *composite_image,
7433 *image;
7434
7435 RectangleInfo
7436 geometry;
7437
cristy6b3da3a2010-06-20 02:21:46 +00007438 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007439 image=RemoveFirstImageFromList(images);
7440 composite_image=RemoveFirstImageFromList(images);
7441 if (composite_image == (Image *) NULL)
7442 {
7443 status=MagickFalse;
7444 break;
7445 }
7446 (void) TransformImage(&composite_image,(char *) NULL,
7447 composite_image->geometry);
7448 SetGeometry(composite_image,&geometry);
7449 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7450 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7451 &geometry);
7452 mask_image=RemoveFirstImageFromList(images);
7453 if (mask_image != (Image *) NULL)
7454 {
7455 if ((image->compose == DisplaceCompositeOp) ||
7456 (image->compose == DistortCompositeOp))
7457 {
7458 /*
7459 Merge Y displacement into X displacement image.
7460 */
7461 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7462 mask_image,0,0);
7463 mask_image=DestroyImage(mask_image);
7464 }
7465 else
7466 {
7467 /*
7468 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007469 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007470 */
7471 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007472 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007473 }
7474 }
cristyf4ad9df2011-07-08 16:49:03 +00007475 (void) CompositeImage(image,image->compose,composite_image,
7476 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007477 if (mask_image != (Image *) NULL)
7478 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007479 composite_image=DestroyImage(composite_image);
7480 InheritException(exception,&image->exception);
7481 *images=DestroyImageList(*images);
7482 *images=image;
7483 break;
7484 }
cristy3ed852e2009-09-05 21:47:34 +00007485 break;
7486 }
7487 case 'd':
7488 {
7489 if (LocaleCompare("deconstruct",option+1) == 0)
7490 {
7491 Image
7492 *deconstruct_image;
7493
cristy6b3da3a2010-06-20 02:21:46 +00007494 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007495 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007496 exception);
cristy3ed852e2009-09-05 21:47:34 +00007497 if (deconstruct_image == (Image *) NULL)
7498 {
7499 status=MagickFalse;
7500 break;
7501 }
7502 *images=DestroyImageList(*images);
7503 *images=deconstruct_image;
7504 break;
7505 }
7506 if (LocaleCompare("delete",option+1) == 0)
7507 {
7508 if (*option == '+')
7509 DeleteImages(images,"-1",exception);
7510 else
7511 DeleteImages(images,argv[i+1],exception);
7512 break;
7513 }
7514 if (LocaleCompare("dither",option+1) == 0)
7515 {
7516 if (*option == '+')
7517 {
7518 quantize_info->dither=MagickFalse;
7519 break;
7520 }
7521 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007522 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007523 MagickDitherOptions,MagickFalse,argv[i+1]);
7524 break;
7525 }
cristyecb10ff2011-03-22 13:14:03 +00007526 if (LocaleCompare("duplicate",option+1) == 0)
7527 {
cristy72988482011-03-29 16:34:38 +00007528 Image
7529 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007530
anthony2b6bcae2011-03-23 13:05:34 +00007531 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007532 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7533 else
7534 {
7535 const char
7536 *p;
7537
anthony2b6bcae2011-03-23 13:05:34 +00007538 size_t
7539 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007540
anthony2b6bcae2011-03-23 13:05:34 +00007541 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007542 p=strchr(argv[i+1],',');
7543 if (p == (const char *) NULL)
7544 duplicate_images=DuplicateImages(*images,number_duplicates,
7545 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007546 else
cristy72988482011-03-29 16:34:38 +00007547 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7548 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007549 }
7550 AppendImageToList(images, duplicate_images);
7551 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007552 break;
7553 }
cristy3ed852e2009-09-05 21:47:34 +00007554 break;
7555 }
cristyd18ae7c2010-03-07 17:39:52 +00007556 case 'e':
7557 {
7558 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7559 {
7560 Image
7561 *evaluate_image;
7562
7563 MagickEvaluateOperator
7564 op;
7565
cristy6b3da3a2010-06-20 02:21:46 +00007566 (void) SyncImageSettings(mogrify_info,*images);
cristy28474bf2011-09-11 23:32:52 +00007567 op=(MagickEvaluateOperator) ParseCommandOption(
7568 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007569 evaluate_image=EvaluateImages(*images,op,exception);
7570 if (evaluate_image == (Image *) NULL)
7571 {
7572 status=MagickFalse;
7573 break;
7574 }
7575 *images=DestroyImageList(*images);
7576 *images=evaluate_image;
7577 break;
7578 }
7579 break;
7580 }
cristy3ed852e2009-09-05 21:47:34 +00007581 case 'f':
7582 {
cristyf0a247f2009-10-04 00:20:03 +00007583 if (LocaleCompare("fft",option+1) == 0)
7584 {
7585 Image
7586 *fourier_image;
7587
7588 /*
7589 Implements the discrete Fourier transform (DFT).
7590 */
cristy6b3da3a2010-06-20 02:21:46 +00007591 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007592 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7593 MagickTrue : MagickFalse,exception);
7594 if (fourier_image == (Image *) NULL)
7595 break;
7596 *images=DestroyImage(*images);
7597 *images=fourier_image;
7598 break;
7599 }
cristy3ed852e2009-09-05 21:47:34 +00007600 if (LocaleCompare("flatten",option+1) == 0)
7601 {
7602 Image
7603 *flatten_image;
7604
cristy6b3da3a2010-06-20 02:21:46 +00007605 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007606 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7607 if (flatten_image == (Image *) NULL)
7608 break;
7609 *images=DestroyImageList(*images);
7610 *images=flatten_image;
7611 break;
7612 }
7613 if (LocaleCompare("fx",option+1) == 0)
7614 {
7615 Image
7616 *fx_image;
7617
cristy6b3da3a2010-06-20 02:21:46 +00007618 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007619 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007620 if (fx_image == (Image *) NULL)
7621 {
7622 status=MagickFalse;
7623 break;
7624 }
7625 *images=DestroyImageList(*images);
7626 *images=fx_image;
7627 break;
7628 }
7629 break;
7630 }
7631 case 'h':
7632 {
7633 if (LocaleCompare("hald-clut",option+1) == 0)
7634 {
7635 Image
7636 *hald_image,
7637 *image;
7638
cristy6b3da3a2010-06-20 02:21:46 +00007639 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007640 image=RemoveFirstImageFromList(images);
7641 hald_image=RemoveFirstImageFromList(images);
7642 if (hald_image == (Image *) NULL)
7643 {
7644 status=MagickFalse;
7645 break;
7646 }
cristy7c0a0a42011-08-23 17:57:25 +00007647 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007648 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007649 if (*images != (Image *) NULL)
7650 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007651 *images=image;
7652 break;
7653 }
7654 break;
7655 }
7656 case 'i':
7657 {
7658 if (LocaleCompare("ift",option+1) == 0)
7659 {
7660 Image
cristy8587f882009-11-13 20:28:49 +00007661 *fourier_image,
7662 *magnitude_image,
7663 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007664
7665 /*
7666 Implements the inverse fourier discrete Fourier transform (DFT).
7667 */
cristy6b3da3a2010-06-20 02:21:46 +00007668 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007669 magnitude_image=RemoveFirstImageFromList(images);
7670 phase_image=RemoveFirstImageFromList(images);
7671 if (phase_image == (Image *) NULL)
7672 {
7673 status=MagickFalse;
7674 break;
7675 }
7676 fourier_image=InverseFourierTransformImage(magnitude_image,
7677 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007678 if (fourier_image == (Image *) NULL)
7679 break;
cristy0aff6ea2009-11-14 01:40:53 +00007680 if (*images != (Image *) NULL)
7681 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007682 *images=fourier_image;
7683 break;
7684 }
7685 if (LocaleCompare("insert",option+1) == 0)
7686 {
7687 Image
7688 *p,
7689 *q;
7690
7691 index=0;
7692 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007693 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007694 p=RemoveLastImageFromList(images);
7695 if (p == (Image *) NULL)
7696 {
7697 (void) ThrowMagickException(exception,GetMagickModule(),
7698 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7699 status=MagickFalse;
7700 break;
7701 }
7702 q=p;
7703 if (index == 0)
7704 PrependImageToList(images,q);
7705 else
cristybb503372010-05-27 20:51:26 +00007706 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007707 AppendImageToList(images,q);
7708 else
7709 {
7710 q=GetImageFromList(*images,index-1);
7711 if (q == (Image *) NULL)
7712 {
7713 (void) ThrowMagickException(exception,GetMagickModule(),
7714 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7715 status=MagickFalse;
7716 break;
7717 }
7718 InsertImageInList(&q,p);
7719 }
7720 *images=GetFirstImageInList(q);
7721 break;
7722 }
cristy28474bf2011-09-11 23:32:52 +00007723 if (LocaleCompare("interpolate",option+1) == 0)
7724 {
7725 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7726 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7727 break;
7728 }
cristy3ed852e2009-09-05 21:47:34 +00007729 break;
7730 }
7731 case 'l':
7732 {
7733 if (LocaleCompare("layers",option+1) == 0)
7734 {
7735 Image
7736 *layers;
7737
7738 ImageLayerMethod
7739 method;
7740
cristy6b3da3a2010-06-20 02:21:46 +00007741 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007742 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007743 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007744 MagickFalse,argv[i+1]);
7745 switch (method)
7746 {
7747 case CoalesceLayer:
7748 {
7749 layers=CoalesceImages(*images,exception);
7750 break;
7751 }
7752 case CompareAnyLayer:
7753 case CompareClearLayer:
7754 case CompareOverlayLayer:
7755 default:
7756 {
cristy8a9106f2011-07-05 14:39:26 +00007757 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007758 break;
7759 }
7760 case MergeLayer:
7761 case FlattenLayer:
7762 case MosaicLayer:
7763 case TrimBoundsLayer:
7764 {
7765 layers=MergeImageLayers(*images,method,exception);
7766 break;
7767 }
7768 case DisposeLayer:
7769 {
7770 layers=DisposeImages(*images,exception);
7771 break;
7772 }
7773 case OptimizeImageLayer:
7774 {
7775 layers=OptimizeImageLayers(*images,exception);
7776 break;
7777 }
7778 case OptimizePlusLayer:
7779 {
7780 layers=OptimizePlusImageLayers(*images,exception);
7781 break;
7782 }
7783 case OptimizeTransLayer:
7784 {
7785 OptimizeImageTransparency(*images,exception);
7786 break;
7787 }
7788 case RemoveDupsLayer:
7789 {
7790 RemoveDuplicateLayers(images,exception);
7791 break;
7792 }
7793 case RemoveZeroLayer:
7794 {
7795 RemoveZeroDelayLayers(images,exception);
7796 break;
7797 }
7798 case OptimizeLayer:
7799 {
7800 /*
7801 General Purpose, GIF Animation Optimizer.
7802 */
7803 layers=CoalesceImages(*images,exception);
7804 if (layers == (Image *) NULL)
7805 {
7806 status=MagickFalse;
7807 break;
7808 }
cristy3ed852e2009-09-05 21:47:34 +00007809 *images=DestroyImageList(*images);
7810 *images=layers;
7811 layers=OptimizeImageLayers(*images,exception);
7812 if (layers == (Image *) NULL)
7813 {
7814 status=MagickFalse;
7815 break;
7816 }
cristy3ed852e2009-09-05 21:47:34 +00007817 *images=DestroyImageList(*images);
7818 *images=layers;
7819 layers=(Image *) NULL;
7820 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007821 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7822 exception);
cristy3ed852e2009-09-05 21:47:34 +00007823 break;
7824 }
7825 case CompositeLayer:
7826 {
7827 CompositeOperator
7828 compose;
7829
7830 Image
7831 *source;
7832
7833 RectangleInfo
7834 geometry;
7835
7836 /*
7837 Split image sequence at the first 'NULL:' image.
7838 */
7839 source=(*images);
7840 while (source != (Image *) NULL)
7841 {
7842 source=GetNextImageInList(source);
7843 if ((source != (Image *) NULL) &&
7844 (LocaleCompare(source->magick,"NULL") == 0))
7845 break;
7846 }
7847 if (source != (Image *) NULL)
7848 {
7849 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7850 (GetNextImageInList(source) == (Image *) NULL))
7851 source=(Image *) NULL;
7852 else
7853 {
7854 /*
7855 Separate the two lists, junk the null: image.
7856 */
7857 source=SplitImageList(source->previous);
7858 DeleteImageFromList(&source);
7859 }
7860 }
7861 if (source == (Image *) NULL)
7862 {
7863 (void) ThrowMagickException(exception,GetMagickModule(),
7864 OptionError,"MissingNullSeparator","layers Composite");
7865 status=MagickFalse;
7866 break;
7867 }
7868 /*
7869 Adjust offset with gravity and virtual canvas.
7870 */
7871 SetGeometry(*images,&geometry);
7872 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7873 geometry.width=source->page.width != 0 ?
7874 source->page.width : source->columns;
7875 geometry.height=source->page.height != 0 ?
7876 source->page.height : source->rows;
7877 GravityAdjustGeometry((*images)->page.width != 0 ?
7878 (*images)->page.width : (*images)->columns,
7879 (*images)->page.height != 0 ? (*images)->page.height :
7880 (*images)->rows,(*images)->gravity,&geometry);
7881 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007882 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007883 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007884 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007885 MagickComposeOptions,MagickFalse,option);
7886 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7887 exception);
7888 source=DestroyImageList(source);
7889 break;
7890 }
7891 }
7892 if (layers == (Image *) NULL)
7893 break;
7894 InheritException(exception,&layers->exception);
7895 *images=DestroyImageList(*images);
7896 *images=layers;
7897 break;
7898 }
7899 break;
7900 }
7901 case 'm':
7902 {
7903 if (LocaleCompare("map",option+1) == 0)
7904 {
cristy6b3da3a2010-06-20 02:21:46 +00007905 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007906 if (*option == '+')
7907 {
cristy018f07f2011-09-04 21:15:19 +00007908 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7909 exception);
cristy3ed852e2009-09-05 21:47:34 +00007910 break;
7911 }
7912 i++;
7913 break;
7914 }
cristyf40785b2010-03-06 02:27:27 +00007915 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007916 {
7917 Image
cristyf40785b2010-03-06 02:27:27 +00007918 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007919
cristyd18ae7c2010-03-07 17:39:52 +00007920 /*
7921 Maximum image sequence (deprecated).
7922 */
cristy6b3da3a2010-06-20 02:21:46 +00007923 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007924 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007925 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007926 {
7927 status=MagickFalse;
7928 break;
7929 }
7930 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007931 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007932 break;
7933 }
cristyf40785b2010-03-06 02:27:27 +00007934 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007935 {
7936 Image
cristyf40785b2010-03-06 02:27:27 +00007937 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007938
cristyd18ae7c2010-03-07 17:39:52 +00007939 /*
7940 Minimum image sequence (deprecated).
7941 */
cristy6b3da3a2010-06-20 02:21:46 +00007942 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007943 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007944 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007945 {
7946 status=MagickFalse;
7947 break;
7948 }
7949 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007950 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007951 break;
7952 }
cristy3ed852e2009-09-05 21:47:34 +00007953 if (LocaleCompare("morph",option+1) == 0)
7954 {
7955 Image
7956 *morph_image;
7957
cristy6b3da3a2010-06-20 02:21:46 +00007958 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007959 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007960 exception);
7961 if (morph_image == (Image *) NULL)
7962 {
7963 status=MagickFalse;
7964 break;
7965 }
7966 *images=DestroyImageList(*images);
7967 *images=morph_image;
7968 break;
7969 }
7970 if (LocaleCompare("mosaic",option+1) == 0)
7971 {
7972 Image
7973 *mosaic_image;
7974
cristy6b3da3a2010-06-20 02:21:46 +00007975 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007976 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7977 if (mosaic_image == (Image *) NULL)
7978 {
7979 status=MagickFalse;
7980 break;
7981 }
7982 *images=DestroyImageList(*images);
7983 *images=mosaic_image;
7984 break;
7985 }
7986 break;
7987 }
7988 case 'p':
7989 {
7990 if (LocaleCompare("print",option+1) == 0)
7991 {
7992 char
7993 *string;
7994
cristy6b3da3a2010-06-20 02:21:46 +00007995 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007996 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7997 exception);
cristy3ed852e2009-09-05 21:47:34 +00007998 if (string == (char *) NULL)
7999 break;
cristyb51dff52011-05-19 16:55:47 +00008000 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008001 string=DestroyString(string);
8002 }
8003 if (LocaleCompare("process",option+1) == 0)
8004 {
8005 char
8006 **arguments;
8007
8008 int
8009 j,
8010 number_arguments;
8011
cristy6b3da3a2010-06-20 02:21:46 +00008012 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008013 arguments=StringToArgv(argv[i+1],&number_arguments);
8014 if (arguments == (char **) NULL)
8015 break;
8016 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8017 {
8018 char
8019 breaker,
8020 quote,
8021 *token;
8022
8023 const char
8024 *arguments;
8025
8026 int
8027 next,
8028 status;
8029
8030 size_t
8031 length;
8032
8033 TokenInfo
8034 *token_info;
8035
8036 /*
8037 Support old style syntax, filter="-option arg".
8038 */
8039 length=strlen(argv[i+1]);
8040 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008041 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008042 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8043 sizeof(*token));
8044 if (token == (char *) NULL)
8045 break;
8046 next=0;
8047 arguments=argv[i+1];
8048 token_info=AcquireTokenInfo();
8049 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8050 "\"",'\0',&breaker,&next,&quote);
8051 token_info=DestroyTokenInfo(token_info);
8052 if (status == 0)
8053 {
8054 const char
8055 *argv;
8056
8057 argv=(&(arguments[next]));
8058 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8059 exception);
8060 }
8061 token=DestroyString(token);
8062 break;
8063 }
cristy91c0da22010-05-02 01:44:07 +00008064 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008065 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8066 number_arguments-2,(const char **) arguments+2,exception);
8067 for (j=0; j < number_arguments; j++)
8068 arguments[j]=DestroyString(arguments[j]);
8069 arguments=(char **) RelinquishMagickMemory(arguments);
8070 break;
8071 }
8072 break;
8073 }
8074 case 'r':
8075 {
8076 if (LocaleCompare("reverse",option+1) == 0)
8077 {
8078 ReverseImageList(images);
8079 InheritException(exception,&(*images)->exception);
8080 break;
8081 }
8082 break;
8083 }
8084 case 's':
8085 {
cristy4285d782011-02-09 20:12:28 +00008086 if (LocaleCompare("smush",option+1) == 0)
8087 {
8088 Image
8089 *smush_image;
8090
8091 ssize_t
8092 offset;
8093
8094 (void) SyncImagesSettings(mogrify_info,*images);
8095 offset=(ssize_t) StringToLong(argv[i+1]);
8096 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8097 MagickFalse,offset,exception);
8098 if (smush_image == (Image *) NULL)
8099 {
8100 status=MagickFalse;
8101 break;
8102 }
8103 *images=DestroyImageList(*images);
8104 *images=smush_image;
8105 break;
8106 }
cristy3ed852e2009-09-05 21:47:34 +00008107 if (LocaleCompare("swap",option+1) == 0)
8108 {
8109 Image
8110 *p,
8111 *q,
8112 *swap;
8113
cristybb503372010-05-27 20:51:26 +00008114 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008115 swap_index;
8116
8117 index=(-1);
8118 swap_index=(-2);
8119 if (*option != '+')
8120 {
8121 GeometryInfo
8122 geometry_info;
8123
8124 MagickStatusType
8125 flags;
8126
8127 swap_index=(-1);
8128 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008129 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008130 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008131 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008132 }
8133 p=GetImageFromList(*images,index);
8134 q=GetImageFromList(*images,swap_index);
8135 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8136 {
8137 (void) ThrowMagickException(exception,GetMagickModule(),
8138 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8139 status=MagickFalse;
8140 break;
8141 }
8142 if (p == q)
8143 break;
8144 swap=CloneImage(p,0,0,MagickTrue,exception);
8145 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8146 ReplaceImageInList(&q,swap);
8147 *images=GetFirstImageInList(q);
8148 break;
8149 }
8150 break;
8151 }
8152 case 'w':
8153 {
8154 if (LocaleCompare("write",option+1) == 0)
8155 {
cristy071dd7b2010-04-09 13:04:54 +00008156 char
cristy06609ee2010-03-17 20:21:27 +00008157 key[MaxTextExtent];
8158
cristy3ed852e2009-09-05 21:47:34 +00008159 Image
8160 *write_images;
8161
8162 ImageInfo
8163 *write_info;
8164
cristy6b3da3a2010-06-20 02:21:46 +00008165 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008166 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008167 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008168 write_images=(*images);
8169 if (*option == '+')
8170 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008171 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008172 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8173 write_info=DestroyImageInfo(write_info);
8174 if (*option == '+')
8175 write_images=DestroyImageList(write_images);
8176 break;
8177 }
8178 break;
8179 }
8180 default:
8181 break;
8182 }
8183 i+=count;
8184 }
8185 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008186 mogrify_info=DestroyImageInfo(mogrify_info);
8187 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008188 return(status != 0 ? MagickTrue : MagickFalse);
8189}
8190
8191/*
8192%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8193% %
8194% %
8195% %
8196+ M o g r i f y I m a g e s %
8197% %
8198% %
8199% %
8200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8201%
8202% MogrifyImages() applies image processing options to a sequence of images as
8203% prescribed by command line options.
8204%
8205% The format of the MogrifyImage method is:
8206%
8207% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8208% const MagickBooleanType post,const int argc,const char **argv,
8209% Image **images,Exceptioninfo *exception)
8210%
8211% A description of each parameter follows:
8212%
8213% o image_info: the image info..
8214%
8215% o post: If true, post process image list operators otherwise pre-process.
8216%
8217% o argc: Specifies a pointer to an integer describing the number of
8218% elements in the argument vector.
8219%
8220% o argv: Specifies a pointer to a text array containing the command line
8221% arguments.
8222%
anthonye9c27192011-03-27 08:07:06 +00008223% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008224%
8225% o exception: return any errors or warnings in this structure.
8226%
8227*/
8228WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8229 const MagickBooleanType post,const int argc,const char **argv,
8230 Image **images,ExceptionInfo *exception)
8231{
8232#define MogrifyImageTag "Mogrify/Image"
8233
anthonye9c27192011-03-27 08:07:06 +00008234 MagickStatusType
8235 status;
cristy3ed852e2009-09-05 21:47:34 +00008236
cristy0e9f9c12010-02-11 03:00:47 +00008237 MagickBooleanType
8238 proceed;
8239
anthonye9c27192011-03-27 08:07:06 +00008240 size_t
8241 n;
cristy3ed852e2009-09-05 21:47:34 +00008242
cristybb503372010-05-27 20:51:26 +00008243 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008244 i;
8245
cristy3ed852e2009-09-05 21:47:34 +00008246 assert(image_info != (ImageInfo *) NULL);
8247 assert(image_info->signature == MagickSignature);
8248 if (images == (Image **) NULL)
8249 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008250 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008251 assert((*images)->signature == MagickSignature);
8252 if ((*images)->debug != MagickFalse)
8253 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8254 (*images)->filename);
8255 if ((argc <= 0) || (*argv == (char *) NULL))
8256 return(MagickTrue);
8257 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8258 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008259 status=0;
anthonye9c27192011-03-27 08:07:06 +00008260
anthonyce2716b2011-04-22 09:51:34 +00008261#if 0
cristy1e604812011-05-19 18:07:50 +00008262 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8263 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008264#endif
8265
anthonye9c27192011-03-27 08:07:06 +00008266 /*
8267 Pre-process multi-image sequence operators
8268 */
cristy3ed852e2009-09-05 21:47:34 +00008269 if (post == MagickFalse)
8270 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008271 /*
8272 For each image, process simple single image operators
8273 */
8274 i=0;
8275 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008276 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008277 {
anthonyce2716b2011-04-22 09:51:34 +00008278#if 0
cristy1e604812011-05-19 18:07:50 +00008279 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8280 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008281#endif
anthonye9c27192011-03-27 08:07:06 +00008282 status&=MogrifyImage(image_info,argc,argv,images,exception);
8283 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008284 if (proceed == MagickFalse)
8285 break;
anthonye9c27192011-03-27 08:07:06 +00008286 if ( (*images)->next == (Image *) NULL )
8287 break;
8288 *images=(*images)->next;
8289 i++;
cristy3ed852e2009-09-05 21:47:34 +00008290 }
anthonye9c27192011-03-27 08:07:06 +00008291 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008292#if 0
cristy1e604812011-05-19 18:07:50 +00008293 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8294 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008295#endif
anthonye9c27192011-03-27 08:07:06 +00008296
8297 /*
8298 Post-process, multi-image sequence operators
8299 */
8300 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008301 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008302 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008303 return(status != 0 ? MagickTrue : MagickFalse);
8304}