blob: cad2fedb0f4994f395bbf0b029627ec6a97a3caf [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
cristy154fa9d2011-08-05 14:25:15 +000058 Constant declaration.
59*/
cristy3a557c02011-08-06 19:48:02 +000060static const char
cristy638895a2011-08-06 23:19:14 +000061 MogrifyBackgroundColor[] = "#ffffff", /* white */
62 MogrifyBorderColor[] = "#dfdfdf", /* gray */
63 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000064
65/*
cristy3ed852e2009-09-05 21:47:34 +000066 Define declarations.
67*/
68#define UndefinedCompressionQuality 0UL
69
70/*
cristy3ed852e2009-09-05 21:47:34 +000071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
cristy5063d812010-10-19 16:28:10 +000075% 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 +000076% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
81% MagickCommandGenesis() applies image processing options to an image as
82% prescribed by command line options.
83%
84% The format of the MagickCommandGenesis method is:
85%
86% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000087% MagickCommand command,int argc,char **argv,char **metadata,
88% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000089%
90% A description of each parameter follows:
91%
92% o image_info: the image info.
93%
cristy5063d812010-10-19 16:28:10 +000094% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000095% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000096% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
97% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o argc: Specifies a pointer to an integer describing the number of
100% elements in the argument vector.
101%
102% o argv: Specifies a pointer to a text array containing the command line
103% arguments.
104%
cristy5063d812010-10-19 16:28:10 +0000105% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000106%
107% o exception: return any errors or warnings in this structure.
108%
109*/
110WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
111 MagickCommand command,int argc,char **argv,char **metadata,
112 ExceptionInfo *exception)
113{
114 char
115 *option;
116
117 double
118 duration,
119 elapsed_time,
120 user_time;
121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
130 TimerInfo
131 *timer;
132
cristybb503372010-05-27 20:51:26 +0000133 size_t
cristy3980b0d2009-10-25 14:37:13 +0000134 iterations;
135
cristyd0a94fa2010-03-12 14:18:11 +0000136 (void) setlocale(LC_ALL,"");
137 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000138 concurrent=MagickFalse;
139 duration=(-1.0);
140 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000141 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000142 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000143 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000144 {
145 option=argv[i];
146 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
147 continue;
148 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000149 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000150 if (LocaleCompare("concurrent",option+1) == 0)
151 concurrent=MagickTrue;
152 if (LocaleCompare("debug",option+1) == 0)
153 (void) SetLogEventMask(argv[++i]);
154 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000155 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000156 if (LocaleCompare("regard-warnings",option+1) == 0)
157 regard_warnings=MagickTrue;
158 }
159 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000160 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000161 {
cristybb503372010-05-27 20:51:26 +0000162 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000163 {
cristy33557d72009-11-06 00:54:33 +0000164 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000165 continue;
166 if (duration > 0)
167 {
168 if (GetElapsedTime(timer) > duration)
169 continue;
170 (void) ContinueTimer(timer);
171 }
172 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000173 if (exception->severity != UndefinedException)
174 {
175 if ((exception->severity > ErrorException) ||
176 (regard_warnings != MagickFalse))
177 status=MagickTrue;
178 CatchException(exception);
179 }
cristy3d1a5512009-10-25 21:23:27 +0000180 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000181 {
182 (void) fputs(*metadata,stdout);
183 (void) fputc('\n',stdout);
184 *metadata=DestroyString(*metadata);
185 }
186 }
187 }
cristyceae09d2009-10-28 17:18:47 +0000188 else
189 {
190 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000191#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000192 # pragma omp parallel for shared(status)
193#endif
cristybb503372010-05-27 20:51:26 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristy33557d72009-11-06 00:54:33 +0000196 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000197 continue;
198 if (duration > 0)
199 {
200 if (GetElapsedTime(timer) > duration)
201 continue;
202 (void) ContinueTimer(timer);
203 }
204 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000205#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000206 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000207#endif
208 {
209 if (exception->severity != UndefinedException)
210 {
211 if ((exception->severity > ErrorException) ||
212 (regard_warnings != MagickFalse))
213 status=MagickTrue;
214 CatchException(exception);
215 }
216 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
217 {
218 (void) fputs(*metadata,stdout);
219 (void) fputc('\n',stdout);
220 *metadata=DestroyString(*metadata);
221 }
222 }
223 }
224 }
cristy3980b0d2009-10-25 14:37:13 +0000225 if (iterations > 1)
226 {
227 elapsed_time=GetElapsedTime(timer);
228 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000229 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000230 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
231 iterations,1.0*iterations/elapsed_time,user_time,(double)
232 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
233 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000234 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000235 }
236 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000237 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
cristy3ed852e2009-09-05 21:47:34 +0000245+ M o g r i f y I m a g e %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
anthonye9c27192011-03-27 08:07:06 +0000251% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000252% image that may be part of a large list, but also handles any 'region'
253% image handling.
anthonye9c27192011-03-27 08:07:06 +0000254%
255% The image in the list may be modified in three different ways...
256%
257% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
258% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
259% * replace by a list of images (only the -separate option!)
260%
261% In each case the result is returned into the list, and a pointer to the
262% modified image (last image added if replaced by a list of images) is
263% returned.
264%
265% ASIDE: The -crop is present but restricted to non-tile single image crops
266%
267% This means if all the images are being processed (such as by
268% MogrifyImages(), next image to be processed will be as per the pointer
269% (*image)->next. Also the image list may grow as a result of some specific
270% operations but as images are never merged or deleted, it will never shrink
271% in length. Typically the list will remain the same length.
272%
273% WARNING: As the image pointed to may be replaced, the first image in the
274% list may also change. GetFirstImageInList() should be used by caller if
275% they wish return the Image pointer to the first image in list.
276%
cristy3ed852e2009-09-05 21:47:34 +0000277%
278% The format of the MogrifyImage method is:
279%
280% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
281% const char **argv,Image **image)
282%
283% A description of each parameter follows:
284%
285% o image_info: the image info..
286%
287% o argc: Specifies a pointer to an integer describing the number of
288% elements in the argument vector.
289%
290% o argv: Specifies a pointer to a text array containing the command line
291% arguments.
292%
293% o image: the image.
294%
295% o exception: return any errors or warnings in this structure.
296%
297*/
298
cristy4c08aed2011-07-01 19:47:50 +0000299/*
300** GetImageCache() will read an image into a image cache if not already
301** present then return the image that is in the cache under that filename.
302*/
anthonydf8ebac2011-04-27 09:03:19 +0000303static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
304 ExceptionInfo *exception)
305{
306 char
307 key[MaxTextExtent];
308
309 ExceptionInfo
310 *sans_exception;
311
312 Image
313 *image;
314
315 ImageInfo
316 *read_info;
317
cristyb51dff52011-05-19 16:55:47 +0000318 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000319 sans_exception=AcquireExceptionInfo();
320 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
321 sans_exception=DestroyExceptionInfo(sans_exception);
322 if (image != (Image *) NULL)
323 return(image);
324 read_info=CloneImageInfo(image_info);
325 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
326 image=ReadImage(read_info,exception);
327 read_info=DestroyImageInfo(read_info);
328 if (image != (Image *) NULL)
329 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
330 return(image);
331}
332
cristy3ed852e2009-09-05 21:47:34 +0000333static MagickBooleanType IsPathWritable(const char *path)
334{
335 if (IsPathAccessible(path) == MagickFalse)
336 return(MagickFalse);
337 if (access(path,W_OK) != 0)
338 return(MagickFalse);
339 return(MagickTrue);
340}
341
cristybb503372010-05-27 20:51:26 +0000342static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000343{
344 if (x > y)
345 return(x);
346 return(y);
347}
348
anthonydf8ebac2011-04-27 09:03:19 +0000349static MagickBooleanType MonitorProgress(const char *text,
350 const MagickOffsetType offset,const MagickSizeType extent,
351 void *wand_unused(client_data))
352{
353 char
354 message[MaxTextExtent],
355 tag[MaxTextExtent];
356
357 const char
358 *locale_message;
359
360 register char
361 *p;
362
363 if (extent < 2)
364 return(MagickTrue);
365 (void) CopyMagickMemory(tag,text,MaxTextExtent);
366 p=strrchr(tag,'/');
367 if (p != (char *) NULL)
368 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000369 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000370 locale_message=GetLocaleMessage(message);
371 if (locale_message == message)
372 locale_message=tag;
373 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000374 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
375 locale_message,(long) offset,(unsigned long) extent,(long)
376 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000377 else
cristyb51dff52011-05-19 16:55:47 +0000378 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000379 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
380 (100L*offset/(extent-1)));
381 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000382 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000383 (void) fflush(stderr);
384 return(MagickTrue);
385}
386
387/*
anthony3d2f4862011-05-01 13:48:16 +0000388** SparseColorOption() parses the complex -sparse-color argument into an
389** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000390** Argument is a complex mix of floating-point pixel coodinates, and color
391** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000392** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000393** setting.
394*/
cristy3884f692011-07-08 18:00:18 +0000395static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000396 const SparseColorMethod method,const char *arguments,
397 const MagickBooleanType color_from_image,ExceptionInfo *exception)
398{
anthonydf8ebac2011-04-27 09:03:19 +0000399 char
400 token[MaxTextExtent];
401
402 const char
403 *p;
404
405 double
406 *sparse_arguments;
407
anthonydf8ebac2011-04-27 09:03:19 +0000408 Image
409 *sparse_image;
410
cristy4c08aed2011-07-01 19:47:50 +0000411 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000412 color;
413
414 MagickBooleanType
415 error;
416
cristy5f09d852011-05-29 01:39:29 +0000417 register size_t
418 x;
419
420 size_t
421 number_arguments,
422 number_colors;
423
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristyc1acd842011-05-19 23:05:47 +0000510 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristyc1acd842011-05-19 23:05:47 +0000521 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
536 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristyc1acd842011-05-19 23:05:47 +0000583 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristyc1acd842011-05-19 23:05:47 +0000592 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
620 const char
621 *format,
622 *option;
623
624 DrawInfo
625 *draw_info;
626
627 GeometryInfo
628 geometry_info;
629
cristy3ed852e2009-09-05 21:47:34 +0000630 Image
631 *region_image;
632
anthonydf8ebac2011-04-27 09:03:19 +0000633 ImageInfo
634 *mogrify_info;
635
cristyebbcfea2011-02-25 02:43:54 +0000636 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000637 status;
638
cristy4c08aed2011-07-01 19:47:50 +0000639 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000640 fill;
cristy3ed852e2009-09-05 21:47:34 +0000641
anthonydf8ebac2011-04-27 09:03:19 +0000642 MagickStatusType
643 flags;
644
645 QuantizeInfo
646 *quantize_info;
647
648 RectangleInfo
649 geometry,
650 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000651
cristybb503372010-05-27 20:51:26 +0000652 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000653 i;
654
655 /*
656 Initialize method variables.
657 */
658 assert(image_info != (const ImageInfo *) NULL);
659 assert(image_info->signature == MagickSignature);
660 assert(image != (Image **) NULL);
661 assert((*image)->signature == MagickSignature);
662 if ((*image)->debug != MagickFalse)
663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
664 if (argc < 0)
665 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000666 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000667 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
668 quantize_info=AcquireQuantizeInfo(mogrify_info);
669 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000670 GetPixelInfo(*image,&fill);
671 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000672 channel=mogrify_info->channel;
673 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000674 SetGeometry(*image,&region_geometry);
675 region_image=NewImageList();
676 /*
677 Transmogrify the image.
678 */
cristybb503372010-05-27 20:51:26 +0000679 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000680 {
anthonydf8ebac2011-04-27 09:03:19 +0000681 Image
682 *mogrify_image;
683
anthonye9c27192011-03-27 08:07:06 +0000684 ssize_t
685 count;
686
anthonydf8ebac2011-04-27 09:03:19 +0000687 option=argv[i];
688 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000689 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000690 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
691 0L);
cristycee97112010-05-28 00:44:52 +0000692 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000693 break;
cristy6b3da3a2010-06-20 02:21:46 +0000694 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000695 mogrify_image=(Image *)NULL;
696 switch (*(option+1))
697 {
698 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000699 {
anthonydf8ebac2011-04-27 09:03:19 +0000700 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000701 {
anthonydf8ebac2011-04-27 09:03:19 +0000702 /*
703 Adaptive blur image.
704 */
705 (void) SyncImageSettings(mogrify_info,*image);
706 flags=ParseGeometry(argv[i+1],&geometry_info);
707 if ((flags & SigmaValue) == 0)
708 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000709 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
710 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000711 break;
cristy3ed852e2009-09-05 21:47:34 +0000712 }
anthonydf8ebac2011-04-27 09:03:19 +0000713 if (LocaleCompare("adaptive-resize",option+1) == 0)
714 {
715 /*
716 Adaptive resize image.
717 */
718 (void) SyncImageSettings(mogrify_info,*image);
719 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
720 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
721 geometry.height,exception);
722 break;
723 }
724 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
725 {
726 /*
727 Adaptive sharpen image.
728 */
729 (void) SyncImageSettings(mogrify_info,*image);
730 flags=ParseGeometry(argv[i+1],&geometry_info);
731 if ((flags & SigmaValue) == 0)
732 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000733 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
734 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000735 break;
736 }
737 if (LocaleCompare("affine",option+1) == 0)
738 {
739 /*
740 Affine matrix.
741 */
742 if (*option == '+')
743 {
744 GetAffineMatrix(&draw_info->affine);
745 break;
746 }
747 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
748 break;
749 }
750 if (LocaleCompare("alpha",option+1) == 0)
751 {
752 AlphaChannelType
753 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000754
anthonydf8ebac2011-04-27 09:03:19 +0000755 (void) SyncImageSettings(mogrify_info,*image);
756 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
757 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000758 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000759 break;
760 }
761 if (LocaleCompare("annotate",option+1) == 0)
762 {
763 char
764 *text,
765 geometry[MaxTextExtent];
766
767 /*
768 Annotate image.
769 */
770 (void) SyncImageSettings(mogrify_info,*image);
771 SetGeometryInfo(&geometry_info);
772 flags=ParseGeometry(argv[i+1],&geometry_info);
773 if ((flags & SigmaValue) == 0)
774 geometry_info.sigma=geometry_info.rho;
775 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
776 InheritException(exception,&(*image)->exception);
777 if (text == (char *) NULL)
778 break;
779 (void) CloneString(&draw_info->text,text);
780 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000781 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000782 geometry_info.xi,geometry_info.psi);
783 (void) CloneString(&draw_info->geometry,geometry);
784 draw_info->affine.sx=cos(DegreesToRadians(
785 fmod(geometry_info.rho,360.0)));
786 draw_info->affine.rx=sin(DegreesToRadians(
787 fmod(geometry_info.rho,360.0)));
788 draw_info->affine.ry=(-sin(DegreesToRadians(
789 fmod(geometry_info.sigma,360.0))));
790 draw_info->affine.sy=cos(DegreesToRadians(
791 fmod(geometry_info.sigma,360.0)));
792 (void) AnnotateImage(*image,draw_info);
793 InheritException(exception,&(*image)->exception);
794 break;
795 }
796 if (LocaleCompare("antialias",option+1) == 0)
797 {
798 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
799 MagickFalse;
800 draw_info->text_antialias=(*option == '-') ? MagickTrue :
801 MagickFalse;
802 break;
803 }
804 if (LocaleCompare("auto-gamma",option+1) == 0)
805 {
806 /*
807 Auto Adjust Gamma of image based on its mean
808 */
809 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000810 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000811 break;
812 }
813 if (LocaleCompare("auto-level",option+1) == 0)
814 {
815 /*
816 Perfectly Normalize (max/min stretch) the image
817 */
818 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000819 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000820 break;
821 }
822 if (LocaleCompare("auto-orient",option+1) == 0)
823 {
824 (void) SyncImageSettings(mogrify_info,*image);
825 switch ((*image)->orientation)
826 {
827 case TopRightOrientation:
828 {
829 mogrify_image=FlopImage(*image,exception);
830 break;
831 }
832 case BottomRightOrientation:
833 {
834 mogrify_image=RotateImage(*image,180.0,exception);
835 break;
836 }
837 case BottomLeftOrientation:
838 {
839 mogrify_image=FlipImage(*image,exception);
840 break;
841 }
842 case LeftTopOrientation:
843 {
844 mogrify_image=TransposeImage(*image,exception);
845 break;
846 }
847 case RightTopOrientation:
848 {
849 mogrify_image=RotateImage(*image,90.0,exception);
850 break;
851 }
852 case RightBottomOrientation:
853 {
854 mogrify_image=TransverseImage(*image,exception);
855 break;
856 }
857 case LeftBottomOrientation:
858 {
859 mogrify_image=RotateImage(*image,270.0,exception);
860 break;
861 }
862 default:
863 break;
864 }
865 if (mogrify_image != (Image *) NULL)
866 mogrify_image->orientation=TopLeftOrientation;
867 break;
868 }
869 break;
870 }
871 case 'b':
872 {
873 if (LocaleCompare("black-threshold",option+1) == 0)
874 {
875 /*
876 Black threshold image.
877 */
878 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000879 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000880 InheritException(exception,&(*image)->exception);
881 break;
882 }
883 if (LocaleCompare("blue-shift",option+1) == 0)
884 {
885 /*
886 Blue shift image.
887 */
888 (void) SyncImageSettings(mogrify_info,*image);
889 geometry_info.rho=1.5;
890 if (*option == '-')
891 flags=ParseGeometry(argv[i+1],&geometry_info);
892 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
893 break;
894 }
895 if (LocaleCompare("blur",option+1) == 0)
896 {
897 /*
898 Gaussian blur image.
899 */
900 (void) SyncImageSettings(mogrify_info,*image);
901 flags=ParseGeometry(argv[i+1],&geometry_info);
902 if ((flags & SigmaValue) == 0)
903 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000904 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000905 geometry_info.sigma,exception);
906 break;
907 }
908 if (LocaleCompare("border",option+1) == 0)
909 {
910 /*
911 Surround image with a border of solid color.
912 */
913 (void) SyncImageSettings(mogrify_info,*image);
914 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
915 if ((flags & SigmaValue) == 0)
916 geometry.height=geometry.width;
917 mogrify_image=BorderImage(*image,&geometry,exception);
918 break;
919 }
920 if (LocaleCompare("bordercolor",option+1) == 0)
921 {
922 if (*option == '+')
923 {
cristy638895a2011-08-06 23:19:14 +0000924 (void) QueryColorDatabase(MogrifyBorderColor,&draw_info->border_color,
anthonydf8ebac2011-04-27 09:03:19 +0000925 exception);
926 break;
927 }
928 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
929 exception);
930 break;
931 }
932 if (LocaleCompare("box",option+1) == 0)
933 {
934 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
935 exception);
936 break;
937 }
938 if (LocaleCompare("brightness-contrast",option+1) == 0)
939 {
940 double
941 brightness,
942 contrast;
943
944 GeometryInfo
945 geometry_info;
946
947 MagickStatusType
948 flags;
949
950 /*
951 Brightness / contrast image.
952 */
953 (void) SyncImageSettings(mogrify_info,*image);
954 flags=ParseGeometry(argv[i+1],&geometry_info);
955 brightness=geometry_info.rho;
956 contrast=0.0;
957 if ((flags & SigmaValue) != 0)
958 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000959 (void) BrightnessContrastImage(*image,brightness,contrast,
960 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000961 InheritException(exception,&(*image)->exception);
962 break;
963 }
964 break;
965 }
966 case 'c':
967 {
968 if (LocaleCompare("cdl",option+1) == 0)
969 {
970 char
971 *color_correction_collection;
972
973 /*
974 Color correct with a color decision list.
975 */
976 (void) SyncImageSettings(mogrify_info,*image);
977 color_correction_collection=FileToString(argv[i+1],~0,exception);
978 if (color_correction_collection == (char *) NULL)
979 break;
cristy1bfa9f02011-08-11 02:35:43 +0000980 (void) ColorDecisionListImage(*image,color_correction_collection,
981 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000982 InheritException(exception,&(*image)->exception);
983 break;
984 }
985 if (LocaleCompare("channel",option+1) == 0)
986 {
987 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000988 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000989 else
cristyfa806a72011-07-04 02:06:13 +0000990 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000991 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000992 break;
993 }
994 if (LocaleCompare("charcoal",option+1) == 0)
995 {
996 /*
997 Charcoal image.
998 */
999 (void) SyncImageSettings(mogrify_info,*image);
1000 flags=ParseGeometry(argv[i+1],&geometry_info);
1001 if ((flags & SigmaValue) == 0)
1002 geometry_info.sigma=1.0;
1003 mogrify_image=CharcoalImage(*image,geometry_info.rho,
1004 geometry_info.sigma,exception);
1005 break;
1006 }
1007 if (LocaleCompare("chop",option+1) == 0)
1008 {
1009 /*
1010 Chop the image.
1011 */
1012 (void) SyncImageSettings(mogrify_info,*image);
1013 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1014 mogrify_image=ChopImage(*image,&geometry,exception);
1015 break;
1016 }
1017 if (LocaleCompare("clamp",option+1) == 0)
1018 {
1019 /*
1020 Clamp image.
1021 */
1022 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001023 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001024 InheritException(exception,&(*image)->exception);
1025 break;
1026 }
1027 if (LocaleCompare("clip",option+1) == 0)
1028 {
1029 (void) SyncImageSettings(mogrify_info,*image);
1030 if (*option == '+')
1031 {
1032 (void) SetImageClipMask(*image,(Image *) NULL);
1033 InheritException(exception,&(*image)->exception);
1034 break;
1035 }
1036 (void) ClipImage(*image);
1037 InheritException(exception,&(*image)->exception);
1038 break;
1039 }
1040 if (LocaleCompare("clip-mask",option+1) == 0)
1041 {
1042 CacheView
1043 *mask_view;
1044
1045 Image
1046 *mask_image;
1047
cristy4c08aed2011-07-01 19:47:50 +00001048 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001049 *restrict q;
1050
1051 register ssize_t
1052 x;
1053
1054 ssize_t
1055 y;
1056
1057 (void) SyncImageSettings(mogrify_info,*image);
1058 if (*option == '+')
1059 {
1060 /*
1061 Remove a mask.
1062 */
1063 (void) SetImageMask(*image,(Image *) NULL);
1064 InheritException(exception,&(*image)->exception);
1065 break;
1066 }
1067 /*
1068 Set the image mask.
1069 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1070 */
1071 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1072 if (mask_image == (Image *) NULL)
1073 break;
cristy574cc262011-08-05 01:23:58 +00001074 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001075 return(MagickFalse);
1076 mask_view=AcquireCacheView(mask_image);
1077 for (y=0; y < (ssize_t) mask_image->rows; y++)
1078 {
1079 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1080 exception);
cristy4c08aed2011-07-01 19:47:50 +00001081 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001082 break;
1083 for (x=0; x < (ssize_t) mask_image->columns; x++)
1084 {
1085 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001086 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1087 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1088 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1089 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001090 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001091 }
1092 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1093 break;
1094 }
1095 mask_view=DestroyCacheView(mask_view);
1096 mask_image->matte=MagickTrue;
1097 (void) SetImageClipMask(*image,mask_image);
1098 mask_image=DestroyImage(mask_image);
1099 InheritException(exception,&(*image)->exception);
1100 break;
1101 }
1102 if (LocaleCompare("clip-path",option+1) == 0)
1103 {
1104 (void) SyncImageSettings(mogrify_info,*image);
1105 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1106 MagickFalse);
1107 InheritException(exception,&(*image)->exception);
1108 break;
1109 }
1110 if (LocaleCompare("colorize",option+1) == 0)
1111 {
1112 /*
1113 Colorize the image.
1114 */
1115 (void) SyncImageSettings(mogrify_info,*image);
1116 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1117 exception);
1118 break;
1119 }
1120 if (LocaleCompare("color-matrix",option+1) == 0)
1121 {
1122 KernelInfo
1123 *kernel;
1124
1125 (void) SyncImageSettings(mogrify_info,*image);
1126 kernel=AcquireKernelInfo(argv[i+1]);
1127 if (kernel == (KernelInfo *) NULL)
1128 break;
1129 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1130 kernel=DestroyKernelInfo(kernel);
1131 break;
1132 }
1133 if (LocaleCompare("colors",option+1) == 0)
1134 {
1135 /*
1136 Reduce the number of colors in the image.
1137 */
1138 (void) SyncImageSettings(mogrify_info,*image);
1139 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1140 if (quantize_info->number_colors == 0)
1141 break;
1142 if (((*image)->storage_class == DirectClass) ||
1143 (*image)->colors > quantize_info->number_colors)
1144 (void) QuantizeImage(quantize_info,*image);
1145 else
1146 (void) CompressImageColormap(*image);
1147 InheritException(exception,&(*image)->exception);
1148 break;
1149 }
1150 if (LocaleCompare("colorspace",option+1) == 0)
1151 {
1152 ColorspaceType
1153 colorspace;
1154
1155 (void) SyncImageSettings(mogrify_info,*image);
1156 if (*option == '+')
1157 {
1158 (void) TransformImageColorspace(*image,RGBColorspace);
1159 InheritException(exception,&(*image)->exception);
1160 break;
1161 }
1162 colorspace=(ColorspaceType) ParseCommandOption(
1163 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1164 (void) TransformImageColorspace(*image,colorspace);
1165 InheritException(exception,&(*image)->exception);
1166 break;
1167 }
1168 if (LocaleCompare("contrast",option+1) == 0)
1169 {
1170 (void) SyncImageSettings(mogrify_info,*image);
1171 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001172 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001173 break;
1174 }
1175 if (LocaleCompare("contrast-stretch",option+1) == 0)
1176 {
1177 double
1178 black_point,
1179 white_point;
1180
1181 MagickStatusType
1182 flags;
1183
1184 /*
1185 Contrast stretch image.
1186 */
1187 (void) SyncImageSettings(mogrify_info,*image);
1188 flags=ParseGeometry(argv[i+1],&geometry_info);
1189 black_point=geometry_info.rho;
1190 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1191 black_point;
1192 if ((flags & PercentValue) != 0)
1193 {
1194 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1195 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1196 }
1197 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1198 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001199 (void) ContrastStretchImage(*image,black_point,white_point,
1200 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001201 InheritException(exception,&(*image)->exception);
1202 break;
1203 }
1204 if (LocaleCompare("convolve",option+1) == 0)
1205 {
anthonydf8ebac2011-04-27 09:03:19 +00001206 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001207 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001208
anthonydf8ebac2011-04-27 09:03:19 +00001209 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001210 kernel_info=AcquireKernelInfo(argv[i+1]);
1211 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001212 break;
cristy0a922382011-07-16 15:30:34 +00001213 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001214 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001215 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001216 break;
1217 }
1218 if (LocaleCompare("crop",option+1) == 0)
1219 {
1220 /*
1221 Crop a image to a smaller size
1222 */
1223 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001224 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001225 break;
1226 }
1227 if (LocaleCompare("cycle",option+1) == 0)
1228 {
1229 /*
1230 Cycle an image colormap.
1231 */
1232 (void) SyncImageSettings(mogrify_info,*image);
1233 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1234 InheritException(exception,&(*image)->exception);
1235 break;
1236 }
1237 break;
1238 }
1239 case 'd':
1240 {
1241 if (LocaleCompare("decipher",option+1) == 0)
1242 {
1243 StringInfo
1244 *passkey;
1245
1246 /*
1247 Decipher pixels.
1248 */
1249 (void) SyncImageSettings(mogrify_info,*image);
1250 passkey=FileToStringInfo(argv[i+1],~0,exception);
1251 if (passkey != (StringInfo *) NULL)
1252 {
1253 (void) PasskeyDecipherImage(*image,passkey,exception);
1254 passkey=DestroyStringInfo(passkey);
1255 }
1256 break;
1257 }
1258 if (LocaleCompare("density",option+1) == 0)
1259 {
1260 /*
1261 Set image density.
1262 */
1263 (void) CloneString(&draw_info->density,argv[i+1]);
1264 break;
1265 }
1266 if (LocaleCompare("depth",option+1) == 0)
1267 {
1268 (void) SyncImageSettings(mogrify_info,*image);
1269 if (*option == '+')
1270 {
1271 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1272 break;
1273 }
1274 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1275 break;
1276 }
1277 if (LocaleCompare("deskew",option+1) == 0)
1278 {
1279 double
1280 threshold;
1281
1282 /*
1283 Straighten the image.
1284 */
1285 (void) SyncImageSettings(mogrify_info,*image);
1286 if (*option == '+')
1287 threshold=40.0*QuantumRange/100.0;
1288 else
1289 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1290 mogrify_image=DeskewImage(*image,threshold,exception);
1291 break;
1292 }
1293 if (LocaleCompare("despeckle",option+1) == 0)
1294 {
1295 /*
1296 Reduce the speckles within an image.
1297 */
1298 (void) SyncImageSettings(mogrify_info,*image);
1299 mogrify_image=DespeckleImage(*image,exception);
1300 break;
1301 }
1302 if (LocaleCompare("display",option+1) == 0)
1303 {
1304 (void) CloneString(&draw_info->server_name,argv[i+1]);
1305 break;
1306 }
1307 if (LocaleCompare("distort",option+1) == 0)
1308 {
1309 char
1310 *args,
1311 token[MaxTextExtent];
1312
1313 const char
1314 *p;
1315
1316 DistortImageMethod
1317 method;
1318
1319 double
1320 *arguments;
1321
1322 register ssize_t
1323 x;
1324
1325 size_t
1326 number_arguments;
1327
1328 /*
1329 Distort image.
1330 */
1331 (void) SyncImageSettings(mogrify_info,*image);
1332 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1333 MagickFalse,argv[i+1]);
1334 if ( method == ResizeDistortion )
1335 {
1336 /* Special Case - Argument is actually a resize geometry!
1337 ** Convert that to an appropriate distortion argument array.
1338 */
1339 double
1340 resize_args[2];
1341 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1342 exception);
1343 resize_args[0]=(double)geometry.width;
1344 resize_args[1]=(double)geometry.height;
1345 mogrify_image=DistortImage(*image,method,(size_t)2,
1346 resize_args,MagickTrue,exception);
1347 break;
1348 }
1349 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1350 InheritException(exception,&(*image)->exception);
1351 if (args == (char *) NULL)
1352 break;
1353 p=(char *) args;
1354 for (x=0; *p != '\0'; x++)
1355 {
1356 GetMagickToken(p,&p,token);
1357 if (*token == ',')
1358 GetMagickToken(p,&p,token);
1359 }
1360 number_arguments=(size_t) x;
1361 arguments=(double *) AcquireQuantumMemory(number_arguments,
1362 sizeof(*arguments));
1363 if (arguments == (double *) NULL)
1364 ThrowWandFatalException(ResourceLimitFatalError,
1365 "MemoryAllocationFailed",(*image)->filename);
1366 (void) ResetMagickMemory(arguments,0,number_arguments*
1367 sizeof(*arguments));
1368 p=(char *) args;
1369 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1370 {
1371 GetMagickToken(p,&p,token);
1372 if (*token == ',')
1373 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001374 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001375 }
1376 args=DestroyString(args);
1377 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1378 (*option == '+') ? MagickTrue : MagickFalse,exception);
1379 arguments=(double *) RelinquishMagickMemory(arguments);
1380 break;
1381 }
1382 if (LocaleCompare("dither",option+1) == 0)
1383 {
1384 if (*option == '+')
1385 {
1386 quantize_info->dither=MagickFalse;
1387 break;
1388 }
1389 quantize_info->dither=MagickTrue;
1390 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1391 MagickDitherOptions,MagickFalse,argv[i+1]);
1392 if (quantize_info->dither_method == NoDitherMethod)
1393 quantize_info->dither=MagickFalse;
1394 break;
1395 }
1396 if (LocaleCompare("draw",option+1) == 0)
1397 {
1398 /*
1399 Draw image.
1400 */
1401 (void) SyncImageSettings(mogrify_info,*image);
1402 (void) CloneString(&draw_info->primitive,argv[i+1]);
1403 (void) DrawImage(*image,draw_info);
1404 InheritException(exception,&(*image)->exception);
1405 break;
1406 }
1407 break;
1408 }
1409 case 'e':
1410 {
1411 if (LocaleCompare("edge",option+1) == 0)
1412 {
1413 /*
1414 Enhance edges in the image.
1415 */
1416 (void) SyncImageSettings(mogrify_info,*image);
1417 flags=ParseGeometry(argv[i+1],&geometry_info);
1418 if ((flags & SigmaValue) == 0)
1419 geometry_info.sigma=1.0;
1420 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1421 break;
1422 }
1423 if (LocaleCompare("emboss",option+1) == 0)
1424 {
1425 /*
1426 Gaussian embossen image.
1427 */
1428 (void) SyncImageSettings(mogrify_info,*image);
1429 flags=ParseGeometry(argv[i+1],&geometry_info);
1430 if ((flags & SigmaValue) == 0)
1431 geometry_info.sigma=1.0;
1432 mogrify_image=EmbossImage(*image,geometry_info.rho,
1433 geometry_info.sigma,exception);
1434 break;
1435 }
1436 if (LocaleCompare("encipher",option+1) == 0)
1437 {
1438 StringInfo
1439 *passkey;
1440
1441 /*
1442 Encipher pixels.
1443 */
1444 (void) SyncImageSettings(mogrify_info,*image);
1445 passkey=FileToStringInfo(argv[i+1],~0,exception);
1446 if (passkey != (StringInfo *) NULL)
1447 {
1448 (void) PasskeyEncipherImage(*image,passkey,exception);
1449 passkey=DestroyStringInfo(passkey);
1450 }
1451 break;
1452 }
1453 if (LocaleCompare("encoding",option+1) == 0)
1454 {
1455 (void) CloneString(&draw_info->encoding,argv[i+1]);
1456 break;
1457 }
1458 if (LocaleCompare("enhance",option+1) == 0)
1459 {
1460 /*
1461 Enhance image.
1462 */
1463 (void) SyncImageSettings(mogrify_info,*image);
1464 mogrify_image=EnhanceImage(*image,exception);
1465 break;
1466 }
1467 if (LocaleCompare("equalize",option+1) == 0)
1468 {
1469 /*
1470 Equalize image.
1471 */
1472 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001473 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001474 break;
1475 }
1476 if (LocaleCompare("evaluate",option+1) == 0)
1477 {
1478 double
1479 constant;
1480
1481 MagickEvaluateOperator
1482 op;
1483
1484 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001485 op=(MagickEvaluateOperator) ParseCommandOption(
1486 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001487 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001488 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001489 break;
1490 }
1491 if (LocaleCompare("extent",option+1) == 0)
1492 {
1493 /*
1494 Set the image extent.
1495 */
1496 (void) SyncImageSettings(mogrify_info,*image);
1497 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1498 if (geometry.width == 0)
1499 geometry.width=(*image)->columns;
1500 if (geometry.height == 0)
1501 geometry.height=(*image)->rows;
1502 mogrify_image=ExtentImage(*image,&geometry,exception);
1503 break;
1504 }
1505 break;
1506 }
1507 case 'f':
1508 {
1509 if (LocaleCompare("family",option+1) == 0)
1510 {
1511 if (*option == '+')
1512 {
1513 if (draw_info->family != (char *) NULL)
1514 draw_info->family=DestroyString(draw_info->family);
1515 break;
1516 }
1517 (void) CloneString(&draw_info->family,argv[i+1]);
1518 break;
1519 }
1520 if (LocaleCompare("features",option+1) == 0)
1521 {
1522 if (*option == '+')
1523 {
1524 (void) DeleteImageArtifact(*image,"identify:features");
1525 break;
1526 }
1527 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1528 break;
1529 }
1530 if (LocaleCompare("fill",option+1) == 0)
1531 {
1532 ExceptionInfo
1533 *sans;
1534
cristy4c08aed2011-07-01 19:47:50 +00001535 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001536 if (*option == '+')
1537 {
1538 (void) QueryMagickColor("none",&fill,exception);
1539 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1540 if (draw_info->fill_pattern != (Image *) NULL)
1541 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1542 break;
1543 }
1544 sans=AcquireExceptionInfo();
1545 (void) QueryMagickColor(argv[i+1],&fill,sans);
1546 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1547 sans=DestroyExceptionInfo(sans);
1548 if (status == MagickFalse)
1549 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1550 exception);
1551 break;
1552 }
1553 if (LocaleCompare("flip",option+1) == 0)
1554 {
1555 /*
1556 Flip image scanlines.
1557 */
1558 (void) SyncImageSettings(mogrify_info,*image);
1559 mogrify_image=FlipImage(*image,exception);
1560 break;
1561 }
anthonydf8ebac2011-04-27 09:03:19 +00001562 if (LocaleCompare("floodfill",option+1) == 0)
1563 {
cristy4c08aed2011-07-01 19:47:50 +00001564 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001565 target;
1566
1567 /*
1568 Floodfill image.
1569 */
1570 (void) SyncImageSettings(mogrify_info,*image);
1571 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1572 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001573 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1574 geometry.y,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00001575 InheritException(exception,&(*image)->exception);
1576 break;
1577 }
anthony3d2f4862011-05-01 13:48:16 +00001578 if (LocaleCompare("flop",option+1) == 0)
1579 {
1580 /*
1581 Flop image scanlines.
1582 */
1583 (void) SyncImageSettings(mogrify_info,*image);
1584 mogrify_image=FlopImage(*image,exception);
1585 break;
1586 }
anthonydf8ebac2011-04-27 09:03:19 +00001587 if (LocaleCompare("font",option+1) == 0)
1588 {
1589 if (*option == '+')
1590 {
1591 if (draw_info->font != (char *) NULL)
1592 draw_info->font=DestroyString(draw_info->font);
1593 break;
1594 }
1595 (void) CloneString(&draw_info->font,argv[i+1]);
1596 break;
1597 }
1598 if (LocaleCompare("format",option+1) == 0)
1599 {
1600 format=argv[i+1];
1601 break;
1602 }
1603 if (LocaleCompare("frame",option+1) == 0)
1604 {
1605 FrameInfo
1606 frame_info;
1607
1608 /*
1609 Surround image with an ornamental border.
1610 */
1611 (void) SyncImageSettings(mogrify_info,*image);
1612 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1613 frame_info.width=geometry.width;
1614 frame_info.height=geometry.height;
1615 if ((flags & HeightValue) == 0)
1616 frame_info.height=geometry.width;
1617 frame_info.outer_bevel=geometry.x;
1618 frame_info.inner_bevel=geometry.y;
1619 frame_info.x=(ssize_t) frame_info.width;
1620 frame_info.y=(ssize_t) frame_info.height;
1621 frame_info.width=(*image)->columns+2*frame_info.width;
1622 frame_info.height=(*image)->rows+2*frame_info.height;
1623 mogrify_image=FrameImage(*image,&frame_info,exception);
1624 break;
1625 }
1626 if (LocaleCompare("function",option+1) == 0)
1627 {
1628 char
1629 *arguments,
1630 token[MaxTextExtent];
1631
1632 const char
1633 *p;
1634
1635 double
1636 *parameters;
1637
1638 MagickFunction
1639 function;
1640
1641 register ssize_t
1642 x;
1643
1644 size_t
1645 number_parameters;
1646
1647 /*
1648 Function Modify Image Values
1649 */
1650 (void) SyncImageSettings(mogrify_info,*image);
1651 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1652 MagickFalse,argv[i+1]);
1653 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1654 InheritException(exception,&(*image)->exception);
1655 if (arguments == (char *) NULL)
1656 break;
1657 p=(char *) arguments;
1658 for (x=0; *p != '\0'; x++)
1659 {
1660 GetMagickToken(p,&p,token);
1661 if (*token == ',')
1662 GetMagickToken(p,&p,token);
1663 }
1664 number_parameters=(size_t) x;
1665 parameters=(double *) AcquireQuantumMemory(number_parameters,
1666 sizeof(*parameters));
1667 if (parameters == (double *) NULL)
1668 ThrowWandFatalException(ResourceLimitFatalError,
1669 "MemoryAllocationFailed",(*image)->filename);
1670 (void) ResetMagickMemory(parameters,0,number_parameters*
1671 sizeof(*parameters));
1672 p=(char *) arguments;
1673 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1674 {
1675 GetMagickToken(p,&p,token);
1676 if (*token == ',')
1677 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001678 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001679 }
1680 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001681 (void) FunctionImage(*image,function,number_parameters,parameters,
1682 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001683 parameters=(double *) RelinquishMagickMemory(parameters);
1684 break;
1685 }
1686 break;
1687 }
1688 case 'g':
1689 {
1690 if (LocaleCompare("gamma",option+1) == 0)
1691 {
1692 /*
1693 Gamma image.
1694 */
1695 (void) SyncImageSettings(mogrify_info,*image);
1696 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001697 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001698 else
cristyb3e7c6c2011-07-24 01:43:55 +00001699 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1700 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001701 break;
1702 }
1703 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1704 (LocaleCompare("gaussian",option+1) == 0))
1705 {
1706 /*
1707 Gaussian blur image.
1708 */
1709 (void) SyncImageSettings(mogrify_info,*image);
1710 flags=ParseGeometry(argv[i+1],&geometry_info);
1711 if ((flags & SigmaValue) == 0)
1712 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001713 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1714 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001715 break;
1716 }
1717 if (LocaleCompare("geometry",option+1) == 0)
1718 {
1719 /*
1720 Record Image offset, Resize last image.
1721 */
1722 (void) SyncImageSettings(mogrify_info,*image);
1723 if (*option == '+')
1724 {
1725 if ((*image)->geometry != (char *) NULL)
1726 (*image)->geometry=DestroyString((*image)->geometry);
1727 break;
1728 }
1729 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1730 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1731 (void) CloneString(&(*image)->geometry,argv[i+1]);
1732 else
1733 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1734 (*image)->filter,(*image)->blur,exception);
1735 break;
1736 }
1737 if (LocaleCompare("gravity",option+1) == 0)
1738 {
1739 if (*option == '+')
1740 {
1741 draw_info->gravity=UndefinedGravity;
1742 break;
1743 }
1744 draw_info->gravity=(GravityType) ParseCommandOption(
1745 MagickGravityOptions,MagickFalse,argv[i+1]);
1746 break;
1747 }
1748 break;
1749 }
1750 case 'h':
1751 {
1752 if (LocaleCompare("highlight-color",option+1) == 0)
1753 {
1754 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1755 break;
1756 }
1757 break;
1758 }
1759 case 'i':
1760 {
1761 if (LocaleCompare("identify",option+1) == 0)
1762 {
1763 char
1764 *text;
1765
1766 (void) SyncImageSettings(mogrify_info,*image);
1767 if (format == (char *) NULL)
1768 {
1769 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1770 InheritException(exception,&(*image)->exception);
1771 break;
1772 }
1773 text=InterpretImageProperties(mogrify_info,*image,format);
1774 InheritException(exception,&(*image)->exception);
1775 if (text == (char *) NULL)
1776 break;
1777 (void) fputs(text,stdout);
1778 (void) fputc('\n',stdout);
1779 text=DestroyString(text);
1780 break;
1781 }
1782 if (LocaleCompare("implode",option+1) == 0)
1783 {
1784 /*
1785 Implode image.
1786 */
1787 (void) SyncImageSettings(mogrify_info,*image);
1788 (void) ParseGeometry(argv[i+1],&geometry_info);
1789 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1790 break;
1791 }
1792 if (LocaleCompare("interline-spacing",option+1) == 0)
1793 {
1794 if (*option == '+')
1795 (void) ParseGeometry("0",&geometry_info);
1796 else
1797 (void) ParseGeometry(argv[i+1],&geometry_info);
1798 draw_info->interline_spacing=geometry_info.rho;
1799 break;
1800 }
1801 if (LocaleCompare("interword-spacing",option+1) == 0)
1802 {
1803 if (*option == '+')
1804 (void) ParseGeometry("0",&geometry_info);
1805 else
1806 (void) ParseGeometry(argv[i+1],&geometry_info);
1807 draw_info->interword_spacing=geometry_info.rho;
1808 break;
1809 }
1810 break;
1811 }
1812 case 'k':
1813 {
1814 if (LocaleCompare("kerning",option+1) == 0)
1815 {
1816 if (*option == '+')
1817 (void) ParseGeometry("0",&geometry_info);
1818 else
1819 (void) ParseGeometry(argv[i+1],&geometry_info);
1820 draw_info->kerning=geometry_info.rho;
1821 break;
1822 }
1823 break;
1824 }
1825 case 'l':
1826 {
1827 if (LocaleCompare("lat",option+1) == 0)
1828 {
1829 /*
1830 Local adaptive threshold image.
1831 */
1832 (void) SyncImageSettings(mogrify_info,*image);
1833 flags=ParseGeometry(argv[i+1],&geometry_info);
1834 if ((flags & PercentValue) != 0)
1835 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1836 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001837 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001838 geometry_info.xi,exception);
1839 break;
1840 }
1841 if (LocaleCompare("level",option+1) == 0)
1842 {
1843 MagickRealType
1844 black_point,
1845 gamma,
1846 white_point;
1847
1848 MagickStatusType
1849 flags;
1850
1851 /*
1852 Parse levels.
1853 */
1854 (void) SyncImageSettings(mogrify_info,*image);
1855 flags=ParseGeometry(argv[i+1],&geometry_info);
1856 black_point=geometry_info.rho;
1857 white_point=(MagickRealType) QuantumRange;
1858 if ((flags & SigmaValue) != 0)
1859 white_point=geometry_info.sigma;
1860 gamma=1.0;
1861 if ((flags & XiValue) != 0)
1862 gamma=geometry_info.xi;
1863 if ((flags & PercentValue) != 0)
1864 {
1865 black_point*=(MagickRealType) (QuantumRange/100.0);
1866 white_point*=(MagickRealType) (QuantumRange/100.0);
1867 }
1868 if ((flags & SigmaValue) == 0)
1869 white_point=(MagickRealType) QuantumRange-black_point;
1870 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001871 (void) LevelizeImage(*image,black_point,white_point,gamma,
1872 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001873 else
cristy01e9afd2011-08-10 17:38:41 +00001874 (void) LevelImage(*image,black_point,white_point,gamma,
1875 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001876 InheritException(exception,&(*image)->exception);
1877 break;
1878 }
1879 if (LocaleCompare("level-colors",option+1) == 0)
1880 {
1881 char
1882 token[MaxTextExtent];
1883
1884 const char
1885 *p;
1886
cristy4c08aed2011-07-01 19:47:50 +00001887 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001888 black_point,
1889 white_point;
1890
1891 p=(const char *) argv[i+1];
1892 GetMagickToken(p,&p,token); /* get black point color */
1893 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1894 (void) QueryMagickColor(token,&black_point,exception);
1895 else
1896 (void) QueryMagickColor("#000000",&black_point,exception);
1897 if (isalpha((int) token[0]) || (token[0] == '#'))
1898 GetMagickToken(p,&p,token);
1899 if (*token == '\0')
1900 white_point=black_point; /* set everything to that color */
1901 else
1902 {
1903 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1904 GetMagickToken(p,&p,token); /* Get white point color. */
1905 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1906 (void) QueryMagickColor(token,&white_point,exception);
1907 else
1908 (void) QueryMagickColor("#ffffff",&white_point,exception);
1909 }
cristy490408a2011-07-07 14:42:05 +00001910 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001911 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001912 break;
1913 }
1914 if (LocaleCompare("linear-stretch",option+1) == 0)
1915 {
1916 double
1917 black_point,
1918 white_point;
1919
1920 MagickStatusType
1921 flags;
1922
1923 (void) SyncImageSettings(mogrify_info,*image);
1924 flags=ParseGeometry(argv[i+1],&geometry_info);
1925 black_point=geometry_info.rho;
1926 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1927 if ((flags & SigmaValue) != 0)
1928 white_point=geometry_info.sigma;
1929 if ((flags & PercentValue) != 0)
1930 {
1931 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1932 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1933 }
1934 if ((flags & SigmaValue) == 0)
1935 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1936 black_point;
1937 (void) LinearStretchImage(*image,black_point,white_point);
1938 InheritException(exception,&(*image)->exception);
1939 break;
1940 }
1941 if (LocaleCompare("linewidth",option+1) == 0)
1942 {
cristyc1acd842011-05-19 23:05:47 +00001943 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1944 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001945 break;
1946 }
1947 if (LocaleCompare("liquid-rescale",option+1) == 0)
1948 {
1949 /*
1950 Liquid rescale image.
1951 */
1952 (void) SyncImageSettings(mogrify_info,*image);
1953 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1954 if ((flags & XValue) == 0)
1955 geometry.x=1;
1956 if ((flags & YValue) == 0)
1957 geometry.y=0;
1958 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1959 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1960 break;
1961 }
1962 if (LocaleCompare("lowlight-color",option+1) == 0)
1963 {
1964 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1965 break;
1966 }
1967 break;
1968 }
1969 case 'm':
1970 {
1971 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001972 {
cristy3ed852e2009-09-05 21:47:34 +00001973 Image
anthonydf8ebac2011-04-27 09:03:19 +00001974 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001975
anthonydf8ebac2011-04-27 09:03:19 +00001976 /*
1977 Transform image colors to match this set of colors.
1978 */
1979 (void) SyncImageSettings(mogrify_info,*image);
1980 if (*option == '+')
1981 break;
1982 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1983 if (remap_image == (Image *) NULL)
1984 break;
1985 (void) RemapImage(quantize_info,*image,remap_image);
1986 InheritException(exception,&(*image)->exception);
1987 remap_image=DestroyImage(remap_image);
1988 break;
1989 }
1990 if (LocaleCompare("mask",option+1) == 0)
1991 {
1992 Image
1993 *mask;
1994
1995 (void) SyncImageSettings(mogrify_info,*image);
1996 if (*option == '+')
1997 {
1998 /*
1999 Remove a mask.
2000 */
2001 (void) SetImageMask(*image,(Image *) NULL);
2002 InheritException(exception,&(*image)->exception);
2003 break;
2004 }
2005 /*
2006 Set the image mask.
2007 */
2008 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2009 if (mask == (Image *) NULL)
2010 break;
2011 (void) SetImageMask(*image,mask);
2012 mask=DestroyImage(mask);
2013 InheritException(exception,&(*image)->exception);
2014 break;
2015 }
2016 if (LocaleCompare("matte",option+1) == 0)
2017 {
2018 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002019 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002020 break;
2021 }
2022 if (LocaleCompare("median",option+1) == 0)
2023 {
2024 /*
2025 Median filter image.
2026 */
2027 (void) SyncImageSettings(mogrify_info,*image);
2028 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002029 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2030 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002031 break;
2032 }
2033 if (LocaleCompare("mode",option+1) == 0)
2034 {
2035 /*
2036 Mode image.
2037 */
2038 (void) SyncImageSettings(mogrify_info,*image);
2039 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002040 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2041 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002042 break;
2043 }
2044 if (LocaleCompare("modulate",option+1) == 0)
2045 {
2046 (void) SyncImageSettings(mogrify_info,*image);
2047 (void) ModulateImage(*image,argv[i+1]);
2048 InheritException(exception,&(*image)->exception);
2049 break;
2050 }
2051 if (LocaleCompare("monitor",option+1) == 0)
2052 {
2053 if (*option == '+')
2054 {
2055 (void) SetImageProgressMonitor(*image,
2056 (MagickProgressMonitor) NULL,(void *) NULL);
2057 break;
2058 }
2059 (void) SetImageProgressMonitor(*image,MonitorProgress,
2060 (void *) NULL);
2061 break;
2062 }
2063 if (LocaleCompare("monochrome",option+1) == 0)
2064 {
2065 (void) SyncImageSettings(mogrify_info,*image);
2066 (void) SetImageType(*image,BilevelType);
2067 InheritException(exception,&(*image)->exception);
2068 break;
2069 }
2070 if (LocaleCompare("morphology",option+1) == 0)
2071 {
2072 char
2073 token[MaxTextExtent];
2074
2075 const char
2076 *p;
2077
2078 KernelInfo
2079 *kernel;
2080
2081 MorphologyMethod
2082 method;
2083
2084 ssize_t
2085 iterations;
2086
2087 /*
2088 Morphological Image Operation
2089 */
2090 (void) SyncImageSettings(mogrify_info,*image);
2091 p=argv[i+1];
2092 GetMagickToken(p,&p,token);
2093 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2094 MagickFalse,token);
2095 iterations=1L;
2096 GetMagickToken(p,&p,token);
2097 if ((*p == ':') || (*p == ','))
2098 GetMagickToken(p,&p,token);
2099 if ((*p != '\0'))
2100 iterations=(ssize_t) StringToLong(p);
2101 kernel=AcquireKernelInfo(argv[i+2]);
2102 if (kernel == (KernelInfo *) NULL)
2103 {
2104 (void) ThrowMagickException(exception,GetMagickModule(),
2105 OptionError,"UnabletoParseKernel","morphology");
2106 status=MagickFalse;
2107 break;
2108 }
cristyf4ad9df2011-07-08 16:49:03 +00002109 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2110 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002111 kernel=DestroyKernelInfo(kernel);
2112 break;
2113 }
2114 if (LocaleCompare("motion-blur",option+1) == 0)
2115 {
2116 /*
2117 Motion blur image.
2118 */
2119 (void) SyncImageSettings(mogrify_info,*image);
2120 flags=ParseGeometry(argv[i+1],&geometry_info);
2121 if ((flags & SigmaValue) == 0)
2122 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002123 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2124 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002125 break;
2126 }
2127 break;
2128 }
2129 case 'n':
2130 {
2131 if (LocaleCompare("negate",option+1) == 0)
2132 {
2133 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002134 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002135 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002136 break;
2137 }
2138 if (LocaleCompare("noise",option+1) == 0)
2139 {
2140 (void) SyncImageSettings(mogrify_info,*image);
2141 if (*option == '-')
2142 {
2143 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002144 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2145 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002146 }
2147 else
2148 {
2149 NoiseType
2150 noise;
2151
2152 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2153 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002154 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002155 }
2156 break;
2157 }
2158 if (LocaleCompare("normalize",option+1) == 0)
2159 {
2160 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002161 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002162 break;
2163 }
2164 break;
2165 }
2166 case 'o':
2167 {
2168 if (LocaleCompare("opaque",option+1) == 0)
2169 {
cristy4c08aed2011-07-01 19:47:50 +00002170 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002171 target;
2172
2173 (void) SyncImageSettings(mogrify_info,*image);
2174 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002175 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2176 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002177 break;
2178 }
2179 if (LocaleCompare("ordered-dither",option+1) == 0)
2180 {
2181 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002182 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002183 break;
2184 }
2185 break;
2186 }
2187 case 'p':
2188 {
2189 if (LocaleCompare("paint",option+1) == 0)
2190 {
anthonydf8ebac2011-04-27 09:03:19 +00002191 (void) SyncImageSettings(mogrify_info,*image);
2192 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002193 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002194 break;
2195 }
2196 if (LocaleCompare("pen",option+1) == 0)
2197 {
2198 if (*option == '+')
2199 {
2200 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2201 break;
2202 }
2203 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2204 break;
2205 }
2206 if (LocaleCompare("pointsize",option+1) == 0)
2207 {
2208 if (*option == '+')
2209 (void) ParseGeometry("12",&geometry_info);
2210 else
2211 (void) ParseGeometry(argv[i+1],&geometry_info);
2212 draw_info->pointsize=geometry_info.rho;
2213 break;
2214 }
2215 if (LocaleCompare("polaroid",option+1) == 0)
2216 {
2217 double
2218 angle;
2219
2220 RandomInfo
2221 *random_info;
2222
2223 /*
2224 Simulate a Polaroid picture.
2225 */
2226 (void) SyncImageSettings(mogrify_info,*image);
2227 random_info=AcquireRandomInfo();
2228 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2229 random_info=DestroyRandomInfo(random_info);
2230 if (*option == '-')
2231 {
2232 SetGeometryInfo(&geometry_info);
2233 flags=ParseGeometry(argv[i+1],&geometry_info);
2234 angle=geometry_info.rho;
2235 }
2236 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2237 break;
2238 }
2239 if (LocaleCompare("posterize",option+1) == 0)
2240 {
2241 /*
2242 Posterize image.
2243 */
2244 (void) SyncImageSettings(mogrify_info,*image);
2245 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2246 quantize_info->dither);
2247 InheritException(exception,&(*image)->exception);
2248 break;
2249 }
2250 if (LocaleCompare("preview",option+1) == 0)
2251 {
2252 PreviewType
2253 preview_type;
2254
2255 /*
2256 Preview image.
2257 */
2258 (void) SyncImageSettings(mogrify_info,*image);
2259 if (*option == '+')
2260 preview_type=UndefinedPreview;
2261 else
2262 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2263 MagickFalse,argv[i+1]);
2264 mogrify_image=PreviewImage(*image,preview_type,exception);
2265 break;
2266 }
2267 if (LocaleCompare("profile",option+1) == 0)
2268 {
2269 const char
2270 *name;
2271
2272 const StringInfo
2273 *profile;
2274
2275 Image
2276 *profile_image;
2277
2278 ImageInfo
2279 *profile_info;
2280
2281 (void) SyncImageSettings(mogrify_info,*image);
2282 if (*option == '+')
2283 {
2284 /*
2285 Remove a profile from the image.
2286 */
2287 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2288 NULL,0,MagickTrue);
2289 InheritException(exception,&(*image)->exception);
2290 break;
2291 }
2292 /*
2293 Associate a profile with the image.
2294 */
2295 profile_info=CloneImageInfo(mogrify_info);
2296 profile=GetImageProfile(*image,"iptc");
2297 if (profile != (StringInfo *) NULL)
2298 profile_info->profile=(void *) CloneStringInfo(profile);
2299 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2300 profile_info=DestroyImageInfo(profile_info);
2301 if (profile_image == (Image *) NULL)
2302 {
2303 StringInfo
2304 *profile;
2305
2306 profile_info=CloneImageInfo(mogrify_info);
2307 (void) CopyMagickString(profile_info->filename,argv[i+1],
2308 MaxTextExtent);
2309 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2310 if (profile != (StringInfo *) NULL)
2311 {
2312 (void) ProfileImage(*image,profile_info->magick,
2313 GetStringInfoDatum(profile),(size_t)
2314 GetStringInfoLength(profile),MagickFalse);
2315 profile=DestroyStringInfo(profile);
2316 }
2317 profile_info=DestroyImageInfo(profile_info);
2318 break;
2319 }
2320 ResetImageProfileIterator(profile_image);
2321 name=GetNextImageProfile(profile_image);
2322 while (name != (const char *) NULL)
2323 {
2324 profile=GetImageProfile(profile_image,name);
2325 if (profile != (StringInfo *) NULL)
2326 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2327 (size_t) GetStringInfoLength(profile),MagickFalse);
2328 name=GetNextImageProfile(profile_image);
2329 }
2330 profile_image=DestroyImage(profile_image);
2331 break;
2332 }
2333 break;
2334 }
2335 case 'q':
2336 {
2337 if (LocaleCompare("quantize",option+1) == 0)
2338 {
2339 if (*option == '+')
2340 {
2341 quantize_info->colorspace=UndefinedColorspace;
2342 break;
2343 }
2344 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2345 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2346 break;
2347 }
2348 break;
2349 }
2350 case 'r':
2351 {
2352 if (LocaleCompare("radial-blur",option+1) == 0)
2353 {
2354 /*
2355 Radial blur image.
2356 */
2357 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002358 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2359 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002360 break;
2361 }
2362 if (LocaleCompare("raise",option+1) == 0)
2363 {
2364 /*
2365 Surround image with a raise of solid color.
2366 */
2367 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2368 if ((flags & SigmaValue) == 0)
2369 geometry.height=geometry.width;
2370 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2371 MagickFalse);
2372 InheritException(exception,&(*image)->exception);
2373 break;
2374 }
2375 if (LocaleCompare("random-threshold",option+1) == 0)
2376 {
2377 /*
2378 Threshold image.
2379 */
2380 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002381 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002382 break;
2383 }
2384 if (LocaleCompare("recolor",option+1) == 0)
2385 {
2386 KernelInfo
2387 *kernel;
2388
2389 (void) SyncImageSettings(mogrify_info,*image);
2390 kernel=AcquireKernelInfo(argv[i+1]);
2391 if (kernel == (KernelInfo *) NULL)
2392 break;
2393 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2394 kernel=DestroyKernelInfo(kernel);
2395 break;
2396 }
2397 if (LocaleCompare("region",option+1) == 0)
2398 {
2399 (void) SyncImageSettings(mogrify_info,*image);
2400 if (region_image != (Image *) NULL)
2401 {
2402 /*
2403 Composite region.
2404 */
2405 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002406 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2407 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002408 InheritException(exception,&region_image->exception);
2409 *image=DestroyImage(*image);
2410 *image=region_image;
2411 region_image = (Image *) NULL;
2412 }
2413 if (*option == '+')
2414 break;
2415 /*
2416 Apply transformations to a selected region of the image.
2417 */
cristy3ed852e2009-09-05 21:47:34 +00002418 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2419 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002420 mogrify_image=CropImage(*image,&region_geometry,exception);
2421 if (mogrify_image == (Image *) NULL)
2422 break;
2423 region_image=(*image);
2424 *image=mogrify_image;
2425 mogrify_image=(Image *) NULL;
2426 break;
cristy3ed852e2009-09-05 21:47:34 +00002427 }
anthonydf8ebac2011-04-27 09:03:19 +00002428 if (LocaleCompare("render",option+1) == 0)
2429 {
2430 (void) SyncImageSettings(mogrify_info,*image);
2431 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2432 break;
2433 }
2434 if (LocaleCompare("remap",option+1) == 0)
2435 {
2436 Image
2437 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002438
anthonydf8ebac2011-04-27 09:03:19 +00002439 /*
2440 Transform image colors to match this set of colors.
2441 */
2442 (void) SyncImageSettings(mogrify_info,*image);
2443 if (*option == '+')
2444 break;
2445 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2446 if (remap_image == (Image *) NULL)
2447 break;
2448 (void) RemapImage(quantize_info,*image,remap_image);
2449 InheritException(exception,&(*image)->exception);
2450 remap_image=DestroyImage(remap_image);
2451 break;
2452 }
2453 if (LocaleCompare("repage",option+1) == 0)
2454 {
2455 if (*option == '+')
2456 {
2457 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2458 break;
2459 }
2460 (void) ResetImagePage(*image,argv[i+1]);
2461 InheritException(exception,&(*image)->exception);
2462 break;
2463 }
2464 if (LocaleCompare("resample",option+1) == 0)
2465 {
2466 /*
2467 Resample image.
2468 */
2469 (void) SyncImageSettings(mogrify_info,*image);
2470 flags=ParseGeometry(argv[i+1],&geometry_info);
2471 if ((flags & SigmaValue) == 0)
2472 geometry_info.sigma=geometry_info.rho;
2473 mogrify_image=ResampleImage(*image,geometry_info.rho,
2474 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2475 break;
2476 }
2477 if (LocaleCompare("resize",option+1) == 0)
2478 {
2479 /*
2480 Resize image.
2481 */
2482 (void) SyncImageSettings(mogrify_info,*image);
2483 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2484 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2485 (*image)->filter,(*image)->blur,exception);
2486 break;
2487 }
2488 if (LocaleCompare("roll",option+1) == 0)
2489 {
2490 /*
2491 Roll image.
2492 */
2493 (void) SyncImageSettings(mogrify_info,*image);
2494 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2495 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2496 break;
2497 }
2498 if (LocaleCompare("rotate",option+1) == 0)
2499 {
2500 char
2501 *geometry;
2502
2503 /*
2504 Check for conditional image rotation.
2505 */
2506 (void) SyncImageSettings(mogrify_info,*image);
2507 if (strchr(argv[i+1],'>') != (char *) NULL)
2508 if ((*image)->columns <= (*image)->rows)
2509 break;
2510 if (strchr(argv[i+1],'<') != (char *) NULL)
2511 if ((*image)->columns >= (*image)->rows)
2512 break;
2513 /*
2514 Rotate image.
2515 */
2516 geometry=ConstantString(argv[i+1]);
2517 (void) SubstituteString(&geometry,">","");
2518 (void) SubstituteString(&geometry,"<","");
2519 (void) ParseGeometry(geometry,&geometry_info);
2520 geometry=DestroyString(geometry);
2521 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2522 break;
2523 }
2524 break;
2525 }
2526 case 's':
2527 {
2528 if (LocaleCompare("sample",option+1) == 0)
2529 {
2530 /*
2531 Sample image with pixel replication.
2532 */
2533 (void) SyncImageSettings(mogrify_info,*image);
2534 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2535 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2536 exception);
2537 break;
2538 }
2539 if (LocaleCompare("scale",option+1) == 0)
2540 {
2541 /*
2542 Resize image.
2543 */
2544 (void) SyncImageSettings(mogrify_info,*image);
2545 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2546 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2547 exception);
2548 break;
2549 }
2550 if (LocaleCompare("selective-blur",option+1) == 0)
2551 {
2552 /*
2553 Selectively blur pixels within a contrast threshold.
2554 */
2555 (void) SyncImageSettings(mogrify_info,*image);
2556 flags=ParseGeometry(argv[i+1],&geometry_info);
2557 if ((flags & PercentValue) != 0)
2558 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002559 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2560 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002561 break;
2562 }
2563 if (LocaleCompare("separate",option+1) == 0)
2564 {
2565 /*
2566 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002567 */
2568 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002569 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002570 break;
2571 }
2572 if (LocaleCompare("sepia-tone",option+1) == 0)
2573 {
2574 double
2575 threshold;
2576
2577 /*
2578 Sepia-tone image.
2579 */
2580 (void) SyncImageSettings(mogrify_info,*image);
2581 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2582 mogrify_image=SepiaToneImage(*image,threshold,exception);
2583 break;
2584 }
2585 if (LocaleCompare("segment",option+1) == 0)
2586 {
2587 /*
2588 Segment image.
2589 */
2590 (void) SyncImageSettings(mogrify_info,*image);
2591 flags=ParseGeometry(argv[i+1],&geometry_info);
2592 if ((flags & SigmaValue) == 0)
2593 geometry_info.sigma=1.0;
2594 (void) SegmentImage(*image,(*image)->colorspace,
2595 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2596 InheritException(exception,&(*image)->exception);
2597 break;
2598 }
2599 if (LocaleCompare("set",option+1) == 0)
2600 {
2601 char
2602 *value;
2603
2604 /*
2605 Set image option.
2606 */
2607 if (*option == '+')
2608 {
2609 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2610 (void) DeleteImageRegistry(argv[i+1]+9);
2611 else
2612 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2613 {
2614 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2615 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2616 }
2617 else
2618 (void) DeleteImageProperty(*image,argv[i+1]);
2619 break;
2620 }
2621 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2622 if (value == (char *) NULL)
2623 break;
2624 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2625 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2626 exception);
2627 else
2628 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2629 {
2630 (void) SetImageOption(image_info,argv[i+1]+7,value);
2631 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2632 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2633 }
2634 else
2635 (void) SetImageProperty(*image,argv[i+1],value);
2636 value=DestroyString(value);
2637 break;
2638 }
2639 if (LocaleCompare("shade",option+1) == 0)
2640 {
2641 /*
2642 Shade image.
2643 */
2644 (void) SyncImageSettings(mogrify_info,*image);
2645 flags=ParseGeometry(argv[i+1],&geometry_info);
2646 if ((flags & SigmaValue) == 0)
2647 geometry_info.sigma=1.0;
2648 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2649 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2650 break;
2651 }
2652 if (LocaleCompare("shadow",option+1) == 0)
2653 {
2654 /*
2655 Shadow image.
2656 */
2657 (void) SyncImageSettings(mogrify_info,*image);
2658 flags=ParseGeometry(argv[i+1],&geometry_info);
2659 if ((flags & SigmaValue) == 0)
2660 geometry_info.sigma=1.0;
2661 if ((flags & XiValue) == 0)
2662 geometry_info.xi=4.0;
2663 if ((flags & PsiValue) == 0)
2664 geometry_info.psi=4.0;
2665 mogrify_image=ShadowImage(*image,geometry_info.rho,
2666 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2667 ceil(geometry_info.psi-0.5),exception);
2668 break;
2669 }
2670 if (LocaleCompare("sharpen",option+1) == 0)
2671 {
2672 /*
2673 Sharpen image.
2674 */
2675 (void) SyncImageSettings(mogrify_info,*image);
2676 flags=ParseGeometry(argv[i+1],&geometry_info);
2677 if ((flags & SigmaValue) == 0)
2678 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002679 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002680 geometry_info.sigma,exception);
2681 break;
2682 }
2683 if (LocaleCompare("shave",option+1) == 0)
2684 {
2685 /*
2686 Shave the image edges.
2687 */
2688 (void) SyncImageSettings(mogrify_info,*image);
2689 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2690 mogrify_image=ShaveImage(*image,&geometry,exception);
2691 break;
2692 }
2693 if (LocaleCompare("shear",option+1) == 0)
2694 {
2695 /*
2696 Shear image.
2697 */
2698 (void) SyncImageSettings(mogrify_info,*image);
2699 flags=ParseGeometry(argv[i+1],&geometry_info);
2700 if ((flags & SigmaValue) == 0)
2701 geometry_info.sigma=geometry_info.rho;
2702 mogrify_image=ShearImage(*image,geometry_info.rho,
2703 geometry_info.sigma,exception);
2704 break;
2705 }
2706 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2707 {
2708 /*
2709 Sigmoidal non-linearity contrast control.
2710 */
2711 (void) SyncImageSettings(mogrify_info,*image);
2712 flags=ParseGeometry(argv[i+1],&geometry_info);
2713 if ((flags & SigmaValue) == 0)
2714 geometry_info.sigma=(double) QuantumRange/2.0;
2715 if ((flags & PercentValue) != 0)
2716 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2717 100.0;
cristy9ee60942011-07-06 14:54:38 +00002718 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2719 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002720 InheritException(exception,&(*image)->exception);
2721 break;
2722 }
2723 if (LocaleCompare("sketch",option+1) == 0)
2724 {
2725 /*
2726 Sketch image.
2727 */
2728 (void) SyncImageSettings(mogrify_info,*image);
2729 flags=ParseGeometry(argv[i+1],&geometry_info);
2730 if ((flags & SigmaValue) == 0)
2731 geometry_info.sigma=1.0;
2732 mogrify_image=SketchImage(*image,geometry_info.rho,
2733 geometry_info.sigma,geometry_info.xi,exception);
2734 break;
2735 }
2736 if (LocaleCompare("solarize",option+1) == 0)
2737 {
2738 double
2739 threshold;
2740
2741 (void) SyncImageSettings(mogrify_info,*image);
2742 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2743 (void) SolarizeImage(*image,threshold);
2744 InheritException(exception,&(*image)->exception);
2745 break;
2746 }
2747 if (LocaleCompare("sparse-color",option+1) == 0)
2748 {
2749 SparseColorMethod
2750 method;
2751
2752 char
2753 *arguments;
2754
2755 /*
2756 Sparse Color Interpolated Gradient
2757 */
2758 (void) SyncImageSettings(mogrify_info,*image);
2759 method=(SparseColorMethod) ParseCommandOption(
2760 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2761 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2762 InheritException(exception,&(*image)->exception);
2763 if (arguments == (char *) NULL)
2764 break;
cristy3884f692011-07-08 18:00:18 +00002765 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002766 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2767 arguments=DestroyString(arguments);
2768 break;
2769 }
2770 if (LocaleCompare("splice",option+1) == 0)
2771 {
2772 /*
2773 Splice a solid color into the image.
2774 */
2775 (void) SyncImageSettings(mogrify_info,*image);
2776 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2777 mogrify_image=SpliceImage(*image,&geometry,exception);
2778 break;
2779 }
2780 if (LocaleCompare("spread",option+1) == 0)
2781 {
2782 /*
2783 Spread an image.
2784 */
2785 (void) SyncImageSettings(mogrify_info,*image);
2786 (void) ParseGeometry(argv[i+1],&geometry_info);
2787 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2788 break;
2789 }
2790 if (LocaleCompare("statistic",option+1) == 0)
2791 {
2792 StatisticType
2793 type;
2794
2795 (void) SyncImageSettings(mogrify_info,*image);
2796 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2797 MagickFalse,argv[i+1]);
2798 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002799 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2800 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002801 break;
2802 }
2803 if (LocaleCompare("stretch",option+1) == 0)
2804 {
2805 if (*option == '+')
2806 {
2807 draw_info->stretch=UndefinedStretch;
2808 break;
2809 }
2810 draw_info->stretch=(StretchType) ParseCommandOption(
2811 MagickStretchOptions,MagickFalse,argv[i+1]);
2812 break;
2813 }
2814 if (LocaleCompare("strip",option+1) == 0)
2815 {
2816 /*
2817 Strip image of profiles and comments.
2818 */
2819 (void) SyncImageSettings(mogrify_info,*image);
2820 (void) StripImage(*image);
2821 InheritException(exception,&(*image)->exception);
2822 break;
2823 }
2824 if (LocaleCompare("stroke",option+1) == 0)
2825 {
2826 ExceptionInfo
2827 *sans;
2828
2829 if (*option == '+')
2830 {
2831 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2832 if (draw_info->stroke_pattern != (Image *) NULL)
2833 draw_info->stroke_pattern=DestroyImage(
2834 draw_info->stroke_pattern);
2835 break;
2836 }
2837 sans=AcquireExceptionInfo();
2838 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2839 sans=DestroyExceptionInfo(sans);
2840 if (status == MagickFalse)
2841 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2842 exception);
2843 break;
2844 }
2845 if (LocaleCompare("strokewidth",option+1) == 0)
2846 {
cristyc1acd842011-05-19 23:05:47 +00002847 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2848 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002849 break;
2850 }
2851 if (LocaleCompare("style",option+1) == 0)
2852 {
2853 if (*option == '+')
2854 {
2855 draw_info->style=UndefinedStyle;
2856 break;
2857 }
2858 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2859 MagickFalse,argv[i+1]);
2860 break;
2861 }
2862 if (LocaleCompare("swirl",option+1) == 0)
2863 {
2864 /*
2865 Swirl image.
2866 */
2867 (void) SyncImageSettings(mogrify_info,*image);
2868 (void) ParseGeometry(argv[i+1],&geometry_info);
2869 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2870 break;
2871 }
2872 break;
2873 }
2874 case 't':
2875 {
2876 if (LocaleCompare("threshold",option+1) == 0)
2877 {
2878 double
2879 threshold;
2880
2881 /*
2882 Threshold image.
2883 */
2884 (void) SyncImageSettings(mogrify_info,*image);
2885 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002886 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002887 else
2888 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002889 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002890 InheritException(exception,&(*image)->exception);
2891 break;
2892 }
2893 if (LocaleCompare("thumbnail",option+1) == 0)
2894 {
2895 /*
2896 Thumbnail image.
2897 */
2898 (void) SyncImageSettings(mogrify_info,*image);
2899 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2900 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2901 exception);
2902 break;
2903 }
2904 if (LocaleCompare("tile",option+1) == 0)
2905 {
2906 if (*option == '+')
2907 {
2908 if (draw_info->fill_pattern != (Image *) NULL)
2909 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2910 break;
2911 }
2912 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2913 exception);
2914 break;
2915 }
2916 if (LocaleCompare("tint",option+1) == 0)
2917 {
2918 /*
2919 Tint the image.
2920 */
2921 (void) SyncImageSettings(mogrify_info,*image);
2922 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2923 break;
2924 }
2925 if (LocaleCompare("transform",option+1) == 0)
2926 {
2927 /*
2928 Affine transform image.
2929 */
2930 (void) SyncImageSettings(mogrify_info,*image);
2931 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2932 exception);
2933 break;
2934 }
2935 if (LocaleCompare("transparent",option+1) == 0)
2936 {
cristy4c08aed2011-07-01 19:47:50 +00002937 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002938 target;
2939
2940 (void) SyncImageSettings(mogrify_info,*image);
2941 (void) QueryMagickColor(argv[i+1],&target,exception);
2942 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002943 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002944 InheritException(exception,&(*image)->exception);
2945 break;
2946 }
2947 if (LocaleCompare("transpose",option+1) == 0)
2948 {
2949 /*
2950 Transpose image scanlines.
2951 */
2952 (void) SyncImageSettings(mogrify_info,*image);
2953 mogrify_image=TransposeImage(*image,exception);
2954 break;
2955 }
2956 if (LocaleCompare("transverse",option+1) == 0)
2957 {
2958 /*
2959 Transverse image scanlines.
2960 */
2961 (void) SyncImageSettings(mogrify_info,*image);
2962 mogrify_image=TransverseImage(*image,exception);
2963 break;
2964 }
2965 if (LocaleCompare("treedepth",option+1) == 0)
2966 {
2967 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2968 break;
2969 }
2970 if (LocaleCompare("trim",option+1) == 0)
2971 {
2972 /*
2973 Trim image.
2974 */
2975 (void) SyncImageSettings(mogrify_info,*image);
2976 mogrify_image=TrimImage(*image,exception);
2977 break;
2978 }
2979 if (LocaleCompare("type",option+1) == 0)
2980 {
2981 ImageType
2982 type;
2983
2984 (void) SyncImageSettings(mogrify_info,*image);
2985 if (*option == '+')
2986 type=UndefinedType;
2987 else
2988 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2989 argv[i+1]);
2990 (*image)->type=UndefinedType;
2991 (void) SetImageType(*image,type);
2992 InheritException(exception,&(*image)->exception);
2993 break;
2994 }
2995 break;
2996 }
2997 case 'u':
2998 {
2999 if (LocaleCompare("undercolor",option+1) == 0)
3000 {
3001 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3002 exception);
3003 break;
3004 }
3005 if (LocaleCompare("unique",option+1) == 0)
3006 {
3007 if (*option == '+')
3008 {
3009 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3010 break;
3011 }
3012 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3013 (void) SetImageArtifact(*image,"verbose","true");
3014 break;
3015 }
3016 if (LocaleCompare("unique-colors",option+1) == 0)
3017 {
3018 /*
3019 Unique image colors.
3020 */
3021 (void) SyncImageSettings(mogrify_info,*image);
3022 mogrify_image=UniqueImageColors(*image,exception);
3023 break;
3024 }
3025 if (LocaleCompare("unsharp",option+1) == 0)
3026 {
3027 /*
3028 Unsharp mask image.
3029 */
3030 (void) SyncImageSettings(mogrify_info,*image);
3031 flags=ParseGeometry(argv[i+1],&geometry_info);
3032 if ((flags & SigmaValue) == 0)
3033 geometry_info.sigma=1.0;
3034 if ((flags & XiValue) == 0)
3035 geometry_info.xi=1.0;
3036 if ((flags & PsiValue) == 0)
3037 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003038 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3039 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003040 break;
3041 }
3042 break;
3043 }
3044 case 'v':
3045 {
3046 if (LocaleCompare("verbose",option+1) == 0)
3047 {
3048 (void) SetImageArtifact(*image,option+1,
3049 *option == '+' ? "false" : "true");
3050 break;
3051 }
3052 if (LocaleCompare("vignette",option+1) == 0)
3053 {
3054 /*
3055 Vignette image.
3056 */
3057 (void) SyncImageSettings(mogrify_info,*image);
3058 flags=ParseGeometry(argv[i+1],&geometry_info);
3059 if ((flags & SigmaValue) == 0)
3060 geometry_info.sigma=1.0;
3061 if ((flags & XiValue) == 0)
3062 geometry_info.xi=0.1*(*image)->columns;
3063 if ((flags & PsiValue) == 0)
3064 geometry_info.psi=0.1*(*image)->rows;
3065 mogrify_image=VignetteImage(*image,geometry_info.rho,
3066 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3067 ceil(geometry_info.psi-0.5),exception);
3068 break;
3069 }
3070 if (LocaleCompare("virtual-pixel",option+1) == 0)
3071 {
3072 if (*option == '+')
3073 {
3074 (void) SetImageVirtualPixelMethod(*image,
3075 UndefinedVirtualPixelMethod);
3076 break;
3077 }
3078 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3079 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3080 argv[i+1]));
3081 break;
3082 }
3083 break;
3084 }
3085 case 'w':
3086 {
3087 if (LocaleCompare("wave",option+1) == 0)
3088 {
3089 /*
3090 Wave image.
3091 */
3092 (void) SyncImageSettings(mogrify_info,*image);
3093 flags=ParseGeometry(argv[i+1],&geometry_info);
3094 if ((flags & SigmaValue) == 0)
3095 geometry_info.sigma=1.0;
3096 mogrify_image=WaveImage(*image,geometry_info.rho,
3097 geometry_info.sigma,exception);
3098 break;
3099 }
3100 if (LocaleCompare("weight",option+1) == 0)
3101 {
3102 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3103 if (LocaleCompare(argv[i+1],"all") == 0)
3104 draw_info->weight=0;
3105 if (LocaleCompare(argv[i+1],"bold") == 0)
3106 draw_info->weight=700;
3107 if (LocaleCompare(argv[i+1],"bolder") == 0)
3108 if (draw_info->weight <= 800)
3109 draw_info->weight+=100;
3110 if (LocaleCompare(argv[i+1],"lighter") == 0)
3111 if (draw_info->weight >= 100)
3112 draw_info->weight-=100;
3113 if (LocaleCompare(argv[i+1],"normal") == 0)
3114 draw_info->weight=400;
3115 break;
3116 }
3117 if (LocaleCompare("white-threshold",option+1) == 0)
3118 {
3119 /*
3120 White threshold image.
3121 */
3122 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003123 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003124 InheritException(exception,&(*image)->exception);
3125 break;
3126 }
3127 break;
3128 }
3129 default:
3130 break;
3131 }
3132 /*
3133 Replace current image with any image that was generated
3134 */
3135 if (mogrify_image != (Image *) NULL)
3136 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003137 i+=count;
3138 }
3139 if (region_image != (Image *) NULL)
3140 {
anthonydf8ebac2011-04-27 09:03:19 +00003141 /*
3142 Composite transformed region onto image.
3143 */
cristy6b3da3a2010-06-20 02:21:46 +00003144 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003145 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003146 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3147 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003148 InheritException(exception,&region_image->exception);
3149 *image=DestroyImage(*image);
3150 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003151 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003152 }
3153 /*
3154 Free resources.
3155 */
anthonydf8ebac2011-04-27 09:03:19 +00003156 quantize_info=DestroyQuantizeInfo(quantize_info);
3157 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003158 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003159 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003160 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003161 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003162}
3163
3164/*
3165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3166% %
3167% %
3168% %
cristy5063d812010-10-19 16:28:10 +00003169+ 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 +00003170% %
3171% %
3172% %
3173%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3174%
3175% MogrifyImageCommand() transforms an image or a sequence of images. These
3176% transforms include image scaling, image rotation, color reduction, and
3177% others. The transmogrified image overwrites the original image.
3178%
3179% The format of the MogrifyImageCommand method is:
3180%
3181% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3182% const char **argv,char **metadata,ExceptionInfo *exception)
3183%
3184% A description of each parameter follows:
3185%
3186% o image_info: the image info.
3187%
3188% o argc: the number of elements in the argument vector.
3189%
3190% o argv: A text array containing the command line arguments.
3191%
3192% o metadata: any metadata is returned here.
3193%
3194% o exception: return any errors or warnings in this structure.
3195%
3196*/
3197
3198static MagickBooleanType MogrifyUsage(void)
3199{
3200 static const char
3201 *miscellaneous[]=
3202 {
3203 "-debug events display copious debugging information",
3204 "-help print program options",
3205 "-list type print a list of supported option arguments",
3206 "-log format format of debugging information",
3207 "-version print version information",
3208 (char *) NULL
3209 },
3210 *operators[]=
3211 {
3212 "-adaptive-blur geometry",
3213 " adaptively blur pixels; decrease effect near edges",
3214 "-adaptive-resize geometry",
3215 " adaptively resize image using 'mesh' interpolation",
3216 "-adaptive-sharpen geometry",
3217 " adaptively sharpen pixels; increase effect near edges",
3218 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3219 " transparent, extract, background, or shape",
3220 "-annotate geometry text",
3221 " annotate the image with text",
3222 "-auto-gamma automagically adjust gamma level of image",
3223 "-auto-level automagically adjust color levels of image",
3224 "-auto-orient automagically orient (rotate) image",
3225 "-bench iterations measure performance",
3226 "-black-threshold value",
3227 " force all pixels below the threshold into black",
3228 "-blue-shift simulate a scene at nighttime in the moonlight",
3229 "-blur geometry reduce image noise and reduce detail levels",
3230 "-border geometry surround image with a border of color",
3231 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003232 "-brightness-contrast geometry",
3233 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003234 "-cdl filename color correct with a color decision list",
3235 "-charcoal radius simulate a charcoal drawing",
3236 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003237 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003238 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003239 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003240 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003241 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003242 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003243 "-contrast enhance or reduce the image contrast",
3244 "-contrast-stretch geometry",
3245 " improve contrast by `stretching' the intensity range",
3246 "-convolve coefficients",
3247 " apply a convolution kernel to the image",
3248 "-cycle amount cycle the image colormap",
3249 "-decipher filename convert cipher pixels to plain pixels",
3250 "-deskew threshold straighten an image",
3251 "-despeckle reduce the speckles within an image",
3252 "-distort method args",
3253 " distort images according to given method ad args",
3254 "-draw string annotate the image with a graphic primitive",
3255 "-edge radius apply a filter to detect edges in the image",
3256 "-encipher filename convert plain pixels to cipher pixels",
3257 "-emboss radius emboss an image",
3258 "-enhance apply a digital filter to enhance a noisy image",
3259 "-equalize perform histogram equalization to an image",
3260 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003261 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003262 "-extent geometry set the image size",
3263 "-extract geometry extract area from image",
3264 "-fft implements the discrete Fourier transform (DFT)",
3265 "-flip flip image vertically",
3266 "-floodfill geometry color",
3267 " floodfill the image with color",
3268 "-flop flop image horizontally",
3269 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003270 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003271 " apply function over image values",
3272 "-gamma value level of gamma correction",
3273 "-gaussian-blur geometry",
3274 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003275 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003276 "-identify identify the format and characteristics of the image",
3277 "-ift implements the inverse discrete Fourier transform (DFT)",
3278 "-implode amount implode image pixels about the center",
3279 "-lat geometry local adaptive thresholding",
3280 "-layers method optimize, merge, or compare image layers",
3281 "-level value adjust the level of image contrast",
3282 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003283 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003284 "-linear-stretch geometry",
3285 " improve contrast by `stretching with saturation'",
3286 "-liquid-rescale geometry",
3287 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003288 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003289 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003290 "-modulate value vary the brightness, saturation, and hue",
3291 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003292 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003293 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003294 "-motion-blur geometry",
3295 " simulate motion blur",
3296 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003297 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003298 "-normalize transform image to span the full range of colors",
3299 "-opaque color change this color to the fill color",
3300 "-ordered-dither NxN",
3301 " add a noise pattern to the image with specific",
3302 " amplitudes",
3303 "-paint radius simulate an oil painting",
3304 "-polaroid angle simulate a Polaroid picture",
3305 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-profile filename add, delete, or apply an image profile",
3307 "-quantize colorspace reduce colors in this colorspace",
3308 "-radial-blur angle radial blur the image",
3309 "-raise value lighten/darken image edges to create a 3-D effect",
3310 "-random-threshold low,high",
3311 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003312 "-region geometry apply options to a portion of the image",
3313 "-render render vector graphics",
3314 "-repage geometry size and location of an image canvas",
3315 "-resample geometry change the resolution of an image",
3316 "-resize geometry resize the image",
3317 "-roll geometry roll an image vertically or horizontally",
3318 "-rotate degrees apply Paeth rotation to the image",
3319 "-sample geometry scale image with pixel sampling",
3320 "-scale geometry scale the image",
3321 "-segment values segment an image",
3322 "-selective-blur geometry",
3323 " selectively blur pixels within a contrast threshold",
3324 "-sepia-tone threshold",
3325 " simulate a sepia-toned photo",
3326 "-set property value set an image property",
3327 "-shade degrees shade the image using a distant light source",
3328 "-shadow geometry simulate an image shadow",
3329 "-sharpen geometry sharpen the image",
3330 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003331 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003332 "-sigmoidal-contrast geometry",
3333 " increase the contrast without saturating highlights or shadows",
3334 "-sketch geometry simulate a pencil sketch",
3335 "-solarize threshold negate all pixels above the threshold level",
3336 "-sparse-color method args",
3337 " fill in a image based on a few color points",
3338 "-splice geometry splice the background color into the image",
3339 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003340 "-statistic type radius",
3341 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003342 "-strip strip image of all profiles and comments",
3343 "-swirl degrees swirl image pixels about the center",
3344 "-threshold value threshold the image",
3345 "-thumbnail geometry create a thumbnail of the image",
3346 "-tile filename tile image when filling a graphic primitive",
3347 "-tint value tint the image with the fill color",
3348 "-transform affine transform image",
3349 "-transparent color make this color transparent within the image",
3350 "-transpose flip image vertically and rotate 90 degrees",
3351 "-transverse flop image horizontally and rotate 270 degrees",
3352 "-trim trim image edges",
3353 "-type type image type",
3354 "-unique-colors discard all but one of any pixel color",
3355 "-unsharp geometry sharpen the image",
3356 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003357 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003358 "-white-threshold value",
3359 " force all pixels above the threshold into white",
3360 (char *) NULL
3361 },
3362 *sequence_operators[]=
3363 {
cristy4285d782011-02-09 20:12:28 +00003364 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-clut apply a color lookup table to the image",
3366 "-coalesce merge a sequence of images",
3367 "-combine combine a sequence of images",
3368 "-composite composite image",
3369 "-crop geometry cut out a rectangular region of the image",
3370 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003371 "-evaluate-sequence operator",
3372 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003373 "-flatten flatten a sequence of images",
3374 "-fx expression apply mathematical expression to an image channel(s)",
3375 "-hald-clut apply a Hald color lookup table to the image",
3376 "-morph value morph an image sequence",
3377 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003378 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003379 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003380 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003381 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003382 "-write filename write images to this file",
3383 (char *) NULL
3384 },
3385 *settings[]=
3386 {
3387 "-adjoin join images into a single multi-image file",
3388 "-affine matrix affine transform matrix",
3389 "-alpha option activate, deactivate, reset, or set the alpha channel",
3390 "-antialias remove pixel-aliasing",
3391 "-authenticate password",
3392 " decipher image with this password",
3393 "-attenuate value lessen (or intensify) when adding noise to an image",
3394 "-background color background color",
3395 "-bias value add bias when convolving an image",
3396 "-black-point-compensation",
3397 " use black point compensation",
3398 "-blue-primary point chromaticity blue primary point",
3399 "-bordercolor color border color",
3400 "-caption string assign a caption to an image",
3401 "-channel type apply option to select image channels",
3402 "-colors value preferred number of colors in the image",
3403 "-colorspace type alternate image colorspace",
3404 "-comment string annotate image with comment",
3405 "-compose operator set image composite operator",
3406 "-compress type type of pixel compression when writing the image",
3407 "-define format:option",
3408 " define one or more image format options",
3409 "-delay value display the next image after pausing",
3410 "-density geometry horizontal and vertical density of the image",
3411 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003412 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003413 "-display server get image or font from this X server",
3414 "-dispose method layer disposal method",
3415 "-dither method apply error diffusion to image",
3416 "-encoding type text encoding type",
3417 "-endian type endianness (MSB or LSB) of the image",
3418 "-family name render text with this font family",
3419 "-fill color color to use when filling a graphic primitive",
3420 "-filter type use this filter when resizing an image",
3421 "-font name render text with this font",
3422 "-format \"string\" output formatted image characteristics",
3423 "-fuzz distance colors within this distance are considered equal",
3424 "-gravity type horizontal and vertical text placement",
3425 "-green-primary point chromaticity green primary point",
3426 "-intent type type of rendering intent when managing the image color",
3427 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003428 "-interline-spacing value",
3429 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003430 "-interpolate method pixel color interpolation method",
3431 "-interword-spacing value",
3432 " set the space between two words",
3433 "-kerning value set the space between two letters",
3434 "-label string assign a label to an image",
3435 "-limit type value pixel cache resource limit",
3436 "-loop iterations add Netscape loop extension to your GIF animation",
3437 "-mask filename associate a mask with the image",
3438 "-mattecolor color frame color",
3439 "-monitor monitor progress",
3440 "-orient type image orientation",
3441 "-page geometry size and location of an image canvas (setting)",
3442 "-ping efficiently determine image attributes",
3443 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003444 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003445 "-preview type image preview type",
3446 "-quality value JPEG/MIFF/PNG compression level",
3447 "-quiet suppress all warning messages",
3448 "-red-primary point chromaticity red primary point",
3449 "-regard-warnings pay attention to warning messages",
3450 "-remap filename transform image colors to match this set of colors",
3451 "-respect-parentheses settings remain in effect until parenthesis boundary",
3452 "-sampling-factor geometry",
3453 " horizontal and vertical sampling factor",
3454 "-scene value image scene number",
3455 "-seed value seed a new sequence of pseudo-random numbers",
3456 "-size geometry width and height of image",
3457 "-stretch type render text with this font stretch",
3458 "-stroke color graphic primitive stroke color",
3459 "-strokewidth value graphic primitive stroke width",
3460 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003461 "-synchronize synchronize image to storage device",
3462 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003463 "-texture filename name of texture to tile onto the image background",
3464 "-tile-offset geometry",
3465 " tile offset",
3466 "-treedepth value color tree depth",
3467 "-transparent-color color",
3468 " transparent color",
3469 "-undercolor color annotation bounding box color",
3470 "-units type the units of image resolution",
3471 "-verbose print detailed information about the image",
3472 "-view FlashPix viewing transforms",
3473 "-virtual-pixel method",
3474 " virtual pixel access method",
3475 "-weight type render text with this font weight",
3476 "-white-point point chromaticity white point",
3477 (char *) NULL
3478 },
3479 *stack_operators[]=
3480 {
anthonyb69c4b32011-03-23 04:37:44 +00003481 "-delete indexes delete the image from the image sequence",
3482 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003483 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003484 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003485 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003486 "-swap indexes swap two images in the image sequence",
3487 (char *) NULL
3488 };
3489
3490 const char
3491 **p;
3492
cristybb503372010-05-27 20:51:26 +00003493 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003494 (void) printf("Copyright: %s\n",GetMagickCopyright());
3495 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003496 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3497 GetClientName());
3498 (void) printf("\nImage Settings:\n");
3499 for (p=settings; *p != (char *) NULL; p++)
3500 (void) printf(" %s\n",*p);
3501 (void) printf("\nImage Operators:\n");
3502 for (p=operators; *p != (char *) NULL; p++)
3503 (void) printf(" %s\n",*p);
3504 (void) printf("\nImage Sequence Operators:\n");
3505 for (p=sequence_operators; *p != (char *) NULL; p++)
3506 (void) printf(" %s\n",*p);
3507 (void) printf("\nImage Stack Operators:\n");
3508 for (p=stack_operators; *p != (char *) NULL; p++)
3509 (void) printf(" %s\n",*p);
3510 (void) printf("\nMiscellaneous Options:\n");
3511 for (p=miscellaneous; *p != (char *) NULL; p++)
3512 (void) printf(" %s\n",*p);
3513 (void) printf(
3514 "\nBy default, the image format of `file' is determined by its magic\n");
3515 (void) printf(
3516 "number. To specify a particular image format, precede the filename\n");
3517 (void) printf(
3518 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3519 (void) printf(
3520 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3521 (void) printf("'-' for standard input or output.\n");
3522 return(MagickFalse);
3523}
3524
3525WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3526 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3527{
3528#define DestroyMogrify() \
3529{ \
3530 if (format != (char *) NULL) \
3531 format=DestroyString(format); \
3532 if (path != (char *) NULL) \
3533 path=DestroyString(path); \
3534 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003535 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003536 argv[i]=DestroyString(argv[i]); \
3537 argv=(char **) RelinquishMagickMemory(argv); \
3538}
3539#define ThrowMogrifyException(asperity,tag,option) \
3540{ \
3541 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3542 option); \
3543 DestroyMogrify(); \
3544 return(MagickFalse); \
3545}
3546#define ThrowMogrifyInvalidArgumentException(option,argument) \
3547{ \
3548 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3549 "InvalidArgument","`%s': %s",argument,option); \
3550 DestroyMogrify(); \
3551 return(MagickFalse); \
3552}
3553
3554 char
3555 *format,
3556 *option,
3557 *path;
3558
3559 Image
3560 *image;
3561
3562 ImageStack
3563 image_stack[MaxImageStackDepth+1];
3564
cristy3ed852e2009-09-05 21:47:34 +00003565 MagickBooleanType
3566 global_colormap;
3567
3568 MagickBooleanType
3569 fire,
cristyebbcfea2011-02-25 02:43:54 +00003570 pend,
3571 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003572
3573 MagickStatusType
3574 status;
3575
cristyebbcfea2011-02-25 02:43:54 +00003576 register ssize_t
3577 i;
3578
3579 ssize_t
3580 j,
3581 k;
3582
cristy3ed852e2009-09-05 21:47:34 +00003583 /*
3584 Set defaults.
3585 */
3586 assert(image_info != (ImageInfo *) NULL);
3587 assert(image_info->signature == MagickSignature);
3588 if (image_info->debug != MagickFalse)
3589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3590 assert(exception != (ExceptionInfo *) NULL);
3591 if (argc == 2)
3592 {
3593 option=argv[1];
3594 if ((LocaleCompare("version",option+1) == 0) ||
3595 (LocaleCompare("-version",option+1) == 0))
3596 {
cristyb51dff52011-05-19 16:55:47 +00003597 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003598 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003599 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3600 GetMagickCopyright());
3601 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3602 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003603 return(MagickFalse);
3604 }
3605 }
3606 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003607 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003608 format=(char *) NULL;
3609 path=(char *) NULL;
3610 global_colormap=MagickFalse;
3611 k=0;
3612 j=1;
3613 NewImageStack();
3614 option=(char *) NULL;
3615 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003616 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003617 status=MagickTrue;
3618 /*
3619 Parse command line.
3620 */
3621 ReadCommandlLine(argc,&argv);
3622 status=ExpandFilenames(&argc,&argv);
3623 if (status == MagickFalse)
3624 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3625 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003626 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003627 {
3628 option=argv[i];
3629 if (LocaleCompare(option,"(") == 0)
3630 {
3631 FireImageStack(MagickFalse,MagickTrue,pend);
3632 if (k == MaxImageStackDepth)
3633 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3634 option);
3635 PushImageStack();
3636 continue;
3637 }
3638 if (LocaleCompare(option,")") == 0)
3639 {
3640 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3641 if (k == 0)
3642 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3643 PopImageStack();
3644 continue;
3645 }
cristy042ee782011-04-22 18:48:30 +00003646 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003647 {
3648 char
3649 backup_filename[MaxTextExtent],
3650 *filename;
3651
3652 Image
3653 *images;
3654
3655 /*
3656 Option is a file name: begin by reading image from specified file.
3657 */
3658 FireImageStack(MagickFalse,MagickFalse,pend);
3659 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003660 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003661 filename=argv[++i];
3662 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3663 images=ReadImages(image_info,exception);
3664 status&=(images != (Image *) NULL) &&
3665 (exception->severity < ErrorException);
3666 if (images == (Image *) NULL)
3667 continue;
cristydaa76602010-06-30 13:05:11 +00003668 if (format != (char *) NULL)
3669 (void) CopyMagickString(images->filename,images->magick_filename,
3670 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003671 if (path != (char *) NULL)
3672 {
3673 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003674 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003675 path,*DirectorySeparator,filename);
3676 }
3677 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003678 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003679 AppendImageStack(images);
3680 FinalizeImageSettings(image_info,image,MagickFalse);
3681 if (global_colormap != MagickFalse)
3682 {
3683 QuantizeInfo
3684 *quantize_info;
3685
3686 quantize_info=AcquireQuantizeInfo(image_info);
3687 (void) RemapImages(quantize_info,images,(Image *) NULL);
3688 quantize_info=DestroyQuantizeInfo(quantize_info);
3689 }
3690 *backup_filename='\0';
3691 if ((LocaleCompare(image->filename,"-") != 0) &&
3692 (IsPathWritable(image->filename) != MagickFalse))
3693 {
cristybb503372010-05-27 20:51:26 +00003694 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003695 i;
3696
3697 /*
3698 Rename image file as backup.
3699 */
3700 (void) CopyMagickString(backup_filename,image->filename,
3701 MaxTextExtent);
3702 for (i=0; i < 6; i++)
3703 {
3704 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3705 if (IsPathAccessible(backup_filename) == MagickFalse)
3706 break;
3707 }
3708 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3709 (rename(image->filename,backup_filename) != 0))
3710 *backup_filename='\0';
3711 }
3712 /*
3713 Write transmogrified image to disk.
3714 */
3715 image_info->synchronize=MagickTrue;
3716 status&=WriteImages(image_info,image,image->filename,exception);
3717 if ((status == MagickFalse) && (*backup_filename != '\0'))
3718 (void) remove(backup_filename);
3719 RemoveAllImageStack();
3720 continue;
3721 }
3722 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3723 switch (*(option+1))
3724 {
3725 case 'a':
3726 {
3727 if (LocaleCompare("adaptive-blur",option+1) == 0)
3728 {
3729 i++;
cristybb503372010-05-27 20:51:26 +00003730 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003731 ThrowMogrifyException(OptionError,"MissingArgument",option);
3732 if (IsGeometry(argv[i]) == MagickFalse)
3733 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3734 break;
3735 }
3736 if (LocaleCompare("adaptive-resize",option+1) == 0)
3737 {
3738 i++;
cristybb503372010-05-27 20:51:26 +00003739 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003740 ThrowMogrifyException(OptionError,"MissingArgument",option);
3741 if (IsGeometry(argv[i]) == MagickFalse)
3742 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3743 break;
3744 }
3745 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3746 {
3747 i++;
cristybb503372010-05-27 20:51:26 +00003748 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003749 ThrowMogrifyException(OptionError,"MissingArgument",option);
3750 if (IsGeometry(argv[i]) == MagickFalse)
3751 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3752 break;
3753 }
3754 if (LocaleCompare("affine",option+1) == 0)
3755 {
3756 if (*option == '+')
3757 break;
3758 i++;
cristybb503372010-05-27 20:51:26 +00003759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003760 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003761 break;
3762 }
3763 if (LocaleCompare("alpha",option+1) == 0)
3764 {
cristybb503372010-05-27 20:51:26 +00003765 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003766 type;
3767
3768 if (*option == '+')
3769 break;
3770 i++;
cristybb503372010-05-27 20:51:26 +00003771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003772 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003773 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003774 if (type < 0)
3775 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3776 argv[i]);
3777 break;
3778 }
3779 if (LocaleCompare("annotate",option+1) == 0)
3780 {
3781 if (*option == '+')
3782 break;
3783 i++;
cristybb503372010-05-27 20:51:26 +00003784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003785 ThrowMogrifyException(OptionError,"MissingArgument",option);
3786 if (IsGeometry(argv[i]) == MagickFalse)
3787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003789 ThrowMogrifyException(OptionError,"MissingArgument",option);
3790 i++;
3791 break;
3792 }
3793 if (LocaleCompare("antialias",option+1) == 0)
3794 break;
3795 if (LocaleCompare("append",option+1) == 0)
3796 break;
3797 if (LocaleCompare("attenuate",option+1) == 0)
3798 {
3799 if (*option == '+')
3800 break;
3801 i++;
cristybb503372010-05-27 20:51:26 +00003802 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003803 ThrowMogrifyException(OptionError,"MissingArgument",option);
3804 if (IsGeometry(argv[i]) == MagickFalse)
3805 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3806 break;
3807 }
3808 if (LocaleCompare("authenticate",option+1) == 0)
3809 {
3810 if (*option == '+')
3811 break;
3812 i++;
cristybb503372010-05-27 20:51:26 +00003813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003814 ThrowMogrifyException(OptionError,"MissingArgument",option);
3815 break;
3816 }
3817 if (LocaleCompare("auto-gamma",option+1) == 0)
3818 break;
3819 if (LocaleCompare("auto-level",option+1) == 0)
3820 break;
3821 if (LocaleCompare("auto-orient",option+1) == 0)
3822 break;
3823 if (LocaleCompare("average",option+1) == 0)
3824 break;
3825 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3826 }
3827 case 'b':
3828 {
3829 if (LocaleCompare("background",option+1) == 0)
3830 {
3831 if (*option == '+')
3832 break;
3833 i++;
cristybb503372010-05-27 20:51:26 +00003834 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003835 ThrowMogrifyException(OptionError,"MissingArgument",option);
3836 break;
3837 }
3838 if (LocaleCompare("bias",option+1) == 0)
3839 {
3840 if (*option == '+')
3841 break;
3842 i++;
cristybb503372010-05-27 20:51:26 +00003843 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003844 ThrowMogrifyException(OptionError,"MissingArgument",option);
3845 if (IsGeometry(argv[i]) == MagickFalse)
3846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3847 break;
3848 }
3849 if (LocaleCompare("black-point-compensation",option+1) == 0)
3850 break;
3851 if (LocaleCompare("black-threshold",option+1) == 0)
3852 {
3853 if (*option == '+')
3854 break;
3855 i++;
cristybb503372010-05-27 20:51:26 +00003856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003857 ThrowMogrifyException(OptionError,"MissingArgument",option);
3858 if (IsGeometry(argv[i]) == MagickFalse)
3859 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3860 break;
3861 }
3862 if (LocaleCompare("blue-primary",option+1) == 0)
3863 {
3864 if (*option == '+')
3865 break;
3866 i++;
cristybb503372010-05-27 20:51:26 +00003867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003868 ThrowMogrifyException(OptionError,"MissingArgument",option);
3869 if (IsGeometry(argv[i]) == MagickFalse)
3870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3871 break;
3872 }
3873 if (LocaleCompare("blue-shift",option+1) == 0)
3874 {
3875 i++;
cristybb503372010-05-27 20:51:26 +00003876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003877 ThrowMogrifyException(OptionError,"MissingArgument",option);
3878 if (IsGeometry(argv[i]) == MagickFalse)
3879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3880 break;
3881 }
3882 if (LocaleCompare("blur",option+1) == 0)
3883 {
3884 i++;
cristybb503372010-05-27 20:51:26 +00003885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003886 ThrowMogrifyException(OptionError,"MissingArgument",option);
3887 if (IsGeometry(argv[i]) == MagickFalse)
3888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3889 break;
3890 }
3891 if (LocaleCompare("border",option+1) == 0)
3892 {
3893 if (*option == '+')
3894 break;
3895 i++;
cristybb503372010-05-27 20:51:26 +00003896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003897 ThrowMogrifyException(OptionError,"MissingArgument",option);
3898 if (IsGeometry(argv[i]) == MagickFalse)
3899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3900 break;
3901 }
3902 if (LocaleCompare("bordercolor",option+1) == 0)
3903 {
3904 if (*option == '+')
3905 break;
3906 i++;
cristybb503372010-05-27 20:51:26 +00003907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003908 ThrowMogrifyException(OptionError,"MissingArgument",option);
3909 break;
3910 }
3911 if (LocaleCompare("box",option+1) == 0)
3912 {
3913 if (*option == '+')
3914 break;
3915 i++;
cristybb503372010-05-27 20:51:26 +00003916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003917 ThrowMogrifyException(OptionError,"MissingArgument",option);
3918 break;
3919 }
cristya28d6b82010-01-11 20:03:47 +00003920 if (LocaleCompare("brightness-contrast",option+1) == 0)
3921 {
3922 i++;
cristybb503372010-05-27 20:51:26 +00003923 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003924 ThrowMogrifyException(OptionError,"MissingArgument",option);
3925 if (IsGeometry(argv[i]) == MagickFalse)
3926 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3927 break;
3928 }
cristy3ed852e2009-09-05 21:47:34 +00003929 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3930 }
3931 case 'c':
3932 {
3933 if (LocaleCompare("cache",option+1) == 0)
3934 {
3935 if (*option == '+')
3936 break;
3937 i++;
cristybb503372010-05-27 20:51:26 +00003938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003939 ThrowMogrifyException(OptionError,"MissingArgument",option);
3940 if (IsGeometry(argv[i]) == MagickFalse)
3941 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3942 break;
3943 }
3944 if (LocaleCompare("caption",option+1) == 0)
3945 {
3946 if (*option == '+')
3947 break;
3948 i++;
cristybb503372010-05-27 20:51:26 +00003949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003950 ThrowMogrifyException(OptionError,"MissingArgument",option);
3951 break;
3952 }
3953 if (LocaleCompare("channel",option+1) == 0)
3954 {
cristybb503372010-05-27 20:51:26 +00003955 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003956 channel;
3957
3958 if (*option == '+')
3959 break;
3960 i++;
cristybb503372010-05-27 20:51:26 +00003961 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003962 ThrowMogrifyException(OptionError,"MissingArgument",option);
3963 channel=ParseChannelOption(argv[i]);
3964 if (channel < 0)
3965 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3966 argv[i]);
3967 break;
3968 }
3969 if (LocaleCompare("cdl",option+1) == 0)
3970 {
3971 if (*option == '+')
3972 break;
3973 i++;
cristybb503372010-05-27 20:51:26 +00003974 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003975 ThrowMogrifyException(OptionError,"MissingArgument",option);
3976 break;
3977 }
3978 if (LocaleCompare("charcoal",option+1) == 0)
3979 {
3980 if (*option == '+')
3981 break;
3982 i++;
cristybb503372010-05-27 20:51:26 +00003983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003984 ThrowMogrifyException(OptionError,"MissingArgument",option);
3985 if (IsGeometry(argv[i]) == MagickFalse)
3986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3987 break;
3988 }
3989 if (LocaleCompare("chop",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 }
cristy1eb45dd2009-09-25 16:38:06 +00004000 if (LocaleCompare("clamp",option+1) == 0)
4001 break;
4002 if (LocaleCompare("clip",option+1) == 0)
4003 break;
cristy3ed852e2009-09-05 21:47:34 +00004004 if (LocaleCompare("clip-mask",option+1) == 0)
4005 {
4006 if (*option == '+')
4007 break;
4008 i++;
cristybb503372010-05-27 20:51:26 +00004009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004010 ThrowMogrifyException(OptionError,"MissingArgument",option);
4011 break;
4012 }
4013 if (LocaleCompare("clut",option+1) == 0)
4014 break;
4015 if (LocaleCompare("coalesce",option+1) == 0)
4016 break;
4017 if (LocaleCompare("colorize",option+1) == 0)
4018 {
4019 if (*option == '+')
4020 break;
4021 i++;
cristybb503372010-05-27 20:51:26 +00004022 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004023 ThrowMogrifyException(OptionError,"MissingArgument",option);
4024 if (IsGeometry(argv[i]) == MagickFalse)
4025 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4026 break;
4027 }
cristye6365592010-04-02 17:31:23 +00004028 if (LocaleCompare("color-matrix",option+1) == 0)
4029 {
cristyb6bd4ad2010-08-08 01:12:27 +00004030 KernelInfo
4031 *kernel_info;
4032
cristye6365592010-04-02 17:31:23 +00004033 if (*option == '+')
4034 break;
4035 i++;
cristybb503372010-05-27 20:51:26 +00004036 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004037 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004038 kernel_info=AcquireKernelInfo(argv[i]);
4039 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004040 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004041 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004042 break;
4043 }
cristy3ed852e2009-09-05 21:47:34 +00004044 if (LocaleCompare("colors",option+1) == 0)
4045 {
4046 if (*option == '+')
4047 break;
4048 i++;
cristybb503372010-05-27 20:51:26 +00004049 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004050 ThrowMogrifyException(OptionError,"MissingArgument",option);
4051 if (IsGeometry(argv[i]) == MagickFalse)
4052 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4053 break;
4054 }
4055 if (LocaleCompare("colorspace",option+1) == 0)
4056 {
cristybb503372010-05-27 20:51:26 +00004057 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004058 colorspace;
4059
4060 if (*option == '+')
4061 break;
4062 i++;
cristybb503372010-05-27 20:51:26 +00004063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004064 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004065 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004066 argv[i]);
4067 if (colorspace < 0)
4068 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4069 argv[i]);
4070 break;
4071 }
4072 if (LocaleCompare("combine",option+1) == 0)
4073 break;
4074 if (LocaleCompare("comment",option+1) == 0)
4075 {
4076 if (*option == '+')
4077 break;
4078 i++;
cristybb503372010-05-27 20:51:26 +00004079 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004080 ThrowMogrifyException(OptionError,"MissingArgument",option);
4081 break;
4082 }
4083 if (LocaleCompare("composite",option+1) == 0)
4084 break;
4085 if (LocaleCompare("compress",option+1) == 0)
4086 {
cristybb503372010-05-27 20:51:26 +00004087 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004088 compress;
4089
4090 if (*option == '+')
4091 break;
4092 i++;
cristybb503372010-05-27 20:51:26 +00004093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004094 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004095 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004096 argv[i]);
4097 if (compress < 0)
4098 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4099 argv[i]);
4100 break;
4101 }
cristy22879752009-10-25 23:55:40 +00004102 if (LocaleCompare("concurrent",option+1) == 0)
4103 break;
cristy3ed852e2009-09-05 21:47:34 +00004104 if (LocaleCompare("contrast",option+1) == 0)
4105 break;
4106 if (LocaleCompare("contrast-stretch",option+1) == 0)
4107 {
4108 i++;
cristybb503372010-05-27 20:51:26 +00004109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004110 ThrowMogrifyException(OptionError,"MissingArgument",option);
4111 if (IsGeometry(argv[i]) == MagickFalse)
4112 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4113 break;
4114 }
4115 if (LocaleCompare("convolve",option+1) == 0)
4116 {
cristyb6bd4ad2010-08-08 01:12:27 +00004117 KernelInfo
4118 *kernel_info;
4119
cristy3ed852e2009-09-05 21:47:34 +00004120 if (*option == '+')
4121 break;
4122 i++;
cristybb503372010-05-27 20:51:26 +00004123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004124 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004125 kernel_info=AcquireKernelInfo(argv[i]);
4126 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004127 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004128 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004129 break;
4130 }
4131 if (LocaleCompare("crop",option+1) == 0)
4132 {
4133 if (*option == '+')
4134 break;
4135 i++;
cristybb503372010-05-27 20:51:26 +00004136 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004137 ThrowMogrifyException(OptionError,"MissingArgument",option);
4138 if (IsGeometry(argv[i]) == MagickFalse)
4139 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4140 break;
4141 }
4142 if (LocaleCompare("cycle",option+1) == 0)
4143 {
4144 if (*option == '+')
4145 break;
4146 i++;
cristybb503372010-05-27 20:51:26 +00004147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004148 ThrowMogrifyException(OptionError,"MissingArgument",option);
4149 if (IsGeometry(argv[i]) == MagickFalse)
4150 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4151 break;
4152 }
4153 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4154 }
4155 case 'd':
4156 {
4157 if (LocaleCompare("decipher",option+1) == 0)
4158 {
4159 if (*option == '+')
4160 break;
4161 i++;
cristybb503372010-05-27 20:51:26 +00004162 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004163 ThrowMogrifyException(OptionError,"MissingArgument",option);
4164 break;
4165 }
4166 if (LocaleCompare("deconstruct",option+1) == 0)
4167 break;
4168 if (LocaleCompare("debug",option+1) == 0)
4169 {
cristybb503372010-05-27 20:51:26 +00004170 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004171 event;
4172
4173 if (*option == '+')
4174 break;
4175 i++;
cristybb503372010-05-27 20:51:26 +00004176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004177 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004178 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004179 if (event < 0)
4180 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4181 argv[i]);
4182 (void) SetLogEventMask(argv[i]);
4183 break;
4184 }
4185 if (LocaleCompare("define",option+1) == 0)
4186 {
4187 i++;
cristybb503372010-05-27 20:51:26 +00004188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004189 ThrowMogrifyException(OptionError,"MissingArgument",option);
4190 if (*option == '+')
4191 {
4192 const char
4193 *define;
4194
4195 define=GetImageOption(image_info,argv[i]);
4196 if (define == (const char *) NULL)
4197 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4198 break;
4199 }
4200 break;
4201 }
4202 if (LocaleCompare("delay",option+1) == 0)
4203 {
4204 if (*option == '+')
4205 break;
4206 i++;
cristybb503372010-05-27 20:51:26 +00004207 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004208 ThrowMogrifyException(OptionError,"MissingArgument",option);
4209 if (IsGeometry(argv[i]) == MagickFalse)
4210 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4211 break;
4212 }
cristyecb10ff2011-03-22 13:14:03 +00004213 if (LocaleCompare("delete",option+1) == 0)
4214 {
4215 if (*option == '+')
4216 break;
4217 i++;
4218 if (i == (ssize_t) (argc-1))
4219 ThrowMogrifyException(OptionError,"MissingArgument",option);
4220 if (IsGeometry(argv[i]) == MagickFalse)
4221 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4222 break;
4223 }
cristy3ed852e2009-09-05 21:47:34 +00004224 if (LocaleCompare("density",option+1) == 0)
4225 {
4226 if (*option == '+')
4227 break;
4228 i++;
cristybb503372010-05-27 20:51:26 +00004229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004230 ThrowMogrifyException(OptionError,"MissingArgument",option);
4231 if (IsGeometry(argv[i]) == MagickFalse)
4232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4233 break;
4234 }
4235 if (LocaleCompare("depth",option+1) == 0)
4236 {
4237 if (*option == '+')
4238 break;
4239 i++;
cristybb503372010-05-27 20:51:26 +00004240 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004241 ThrowMogrifyException(OptionError,"MissingArgument",option);
4242 if (IsGeometry(argv[i]) == MagickFalse)
4243 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4244 break;
4245 }
4246 if (LocaleCompare("deskew",option+1) == 0)
4247 {
4248 if (*option == '+')
4249 break;
4250 i++;
cristybb503372010-05-27 20:51:26 +00004251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004252 ThrowMogrifyException(OptionError,"MissingArgument",option);
4253 if (IsGeometry(argv[i]) == MagickFalse)
4254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4255 break;
4256 }
4257 if (LocaleCompare("despeckle",option+1) == 0)
4258 break;
4259 if (LocaleCompare("dft",option+1) == 0)
4260 break;
cristyc9b12952010-03-28 01:12:28 +00004261 if (LocaleCompare("direction",option+1) == 0)
4262 {
cristybb503372010-05-27 20:51:26 +00004263 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004264 direction;
4265
4266 if (*option == '+')
4267 break;
4268 i++;
cristybb503372010-05-27 20:51:26 +00004269 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004270 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004271 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004272 argv[i]);
4273 if (direction < 0)
4274 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4275 argv[i]);
4276 break;
4277 }
cristy3ed852e2009-09-05 21:47:34 +00004278 if (LocaleCompare("display",option+1) == 0)
4279 {
4280 if (*option == '+')
4281 break;
4282 i++;
cristybb503372010-05-27 20:51:26 +00004283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004284 ThrowMogrifyException(OptionError,"MissingArgument",option);
4285 break;
4286 }
4287 if (LocaleCompare("dispose",option+1) == 0)
4288 {
cristybb503372010-05-27 20:51:26 +00004289 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004290 dispose;
4291
4292 if (*option == '+')
4293 break;
4294 i++;
cristybb503372010-05-27 20:51:26 +00004295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004296 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004297 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004298 if (dispose < 0)
4299 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4300 argv[i]);
4301 break;
4302 }
4303 if (LocaleCompare("distort",option+1) == 0)
4304 {
cristybb503372010-05-27 20:51:26 +00004305 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004306 op;
4307
4308 i++;
cristybb503372010-05-27 20:51:26 +00004309 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004310 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004311 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004312 if (op < 0)
4313 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4314 argv[i]);
4315 i++;
cristybb503372010-05-27 20:51:26 +00004316 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004317 ThrowMogrifyException(OptionError,"MissingArgument",option);
4318 break;
4319 }
4320 if (LocaleCompare("dither",option+1) == 0)
4321 {
cristybb503372010-05-27 20:51:26 +00004322 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004323 method;
4324
4325 if (*option == '+')
4326 break;
4327 i++;
cristybb503372010-05-27 20:51:26 +00004328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004329 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004330 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004331 if (method < 0)
4332 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4333 argv[i]);
4334 break;
4335 }
4336 if (LocaleCompare("draw",option+1) == 0)
4337 {
4338 if (*option == '+')
4339 break;
4340 i++;
cristybb503372010-05-27 20:51:26 +00004341 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004342 ThrowMogrifyException(OptionError,"MissingArgument",option);
4343 break;
4344 }
cristyecb10ff2011-03-22 13:14:03 +00004345 if (LocaleCompare("duplicate",option+1) == 0)
4346 {
4347 if (*option == '+')
4348 break;
4349 i++;
4350 if (i == (ssize_t) (argc-1))
4351 ThrowMogrifyException(OptionError,"MissingArgument",option);
4352 if (IsGeometry(argv[i]) == MagickFalse)
4353 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4354 break;
4355 }
cristy22879752009-10-25 23:55:40 +00004356 if (LocaleCompare("duration",option+1) == 0)
4357 {
4358 if (*option == '+')
4359 break;
4360 i++;
cristybb503372010-05-27 20:51:26 +00004361 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004362 ThrowMogrifyException(OptionError,"MissingArgument",option);
4363 if (IsGeometry(argv[i]) == MagickFalse)
4364 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4365 break;
4366 }
cristy3ed852e2009-09-05 21:47:34 +00004367 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4368 }
4369 case 'e':
4370 {
4371 if (LocaleCompare("edge",option+1) == 0)
4372 {
4373 if (*option == '+')
4374 break;
4375 i++;
cristybb503372010-05-27 20:51:26 +00004376 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004377 ThrowMogrifyException(OptionError,"MissingArgument",option);
4378 if (IsGeometry(argv[i]) == MagickFalse)
4379 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4380 break;
4381 }
4382 if (LocaleCompare("emboss",option+1) == 0)
4383 {
4384 if (*option == '+')
4385 break;
4386 i++;
cristybb503372010-05-27 20:51:26 +00004387 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004388 ThrowMogrifyException(OptionError,"MissingArgument",option);
4389 if (IsGeometry(argv[i]) == MagickFalse)
4390 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4391 break;
4392 }
4393 if (LocaleCompare("encipher",option+1) == 0)
4394 {
4395 if (*option == '+')
4396 break;
4397 i++;
cristybb503372010-05-27 20:51:26 +00004398 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004399 ThrowMogrifyException(OptionError,"MissingArgument",option);
4400 break;
4401 }
4402 if (LocaleCompare("encoding",option+1) == 0)
4403 {
4404 if (*option == '+')
4405 break;
4406 i++;
cristybb503372010-05-27 20:51:26 +00004407 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004408 ThrowMogrifyException(OptionError,"MissingArgument",option);
4409 break;
4410 }
4411 if (LocaleCompare("endian",option+1) == 0)
4412 {
cristybb503372010-05-27 20:51:26 +00004413 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004414 endian;
4415
4416 if (*option == '+')
4417 break;
4418 i++;
cristybb503372010-05-27 20:51:26 +00004419 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004420 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004421 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004422 if (endian < 0)
4423 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4424 argv[i]);
4425 break;
4426 }
4427 if (LocaleCompare("enhance",option+1) == 0)
4428 break;
4429 if (LocaleCompare("equalize",option+1) == 0)
4430 break;
4431 if (LocaleCompare("evaluate",option+1) == 0)
4432 {
cristybb503372010-05-27 20:51:26 +00004433 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004434 op;
4435
4436 if (*option == '+')
4437 break;
4438 i++;
cristybb503372010-05-27 20:51:26 +00004439 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004440 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004441 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004442 if (op < 0)
4443 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4444 argv[i]);
4445 i++;
cristybb503372010-05-27 20:51:26 +00004446 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004447 ThrowMogrifyException(OptionError,"MissingArgument",option);
4448 if (IsGeometry(argv[i]) == MagickFalse)
4449 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4450 break;
4451 }
cristyd18ae7c2010-03-07 17:39:52 +00004452 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4453 {
cristybb503372010-05-27 20:51:26 +00004454 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004455 op;
4456
4457 if (*option == '+')
4458 break;
4459 i++;
cristybb503372010-05-27 20:51:26 +00004460 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004461 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004462 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004463 if (op < 0)
4464 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4465 argv[i]);
4466 break;
4467 }
cristy3ed852e2009-09-05 21:47:34 +00004468 if (LocaleCompare("extent",option+1) == 0)
4469 {
4470 if (*option == '+')
4471 break;
4472 i++;
cristybb503372010-05-27 20:51:26 +00004473 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004474 ThrowMogrifyException(OptionError,"MissingArgument",option);
4475 if (IsGeometry(argv[i]) == MagickFalse)
4476 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4477 break;
4478 }
4479 if (LocaleCompare("extract",option+1) == 0)
4480 {
4481 if (*option == '+')
4482 break;
4483 i++;
cristybb503372010-05-27 20:51:26 +00004484 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004485 ThrowMogrifyException(OptionError,"MissingArgument",option);
4486 if (IsGeometry(argv[i]) == MagickFalse)
4487 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4488 break;
4489 }
4490 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4491 }
4492 case 'f':
4493 {
4494 if (LocaleCompare("family",option+1) == 0)
4495 {
4496 if (*option == '+')
4497 break;
4498 i++;
cristybb503372010-05-27 20:51:26 +00004499 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004500 ThrowMogrifyException(OptionError,"MissingArgument",option);
4501 break;
4502 }
4503 if (LocaleCompare("fill",option+1) == 0)
4504 {
4505 if (*option == '+')
4506 break;
4507 i++;
cristybb503372010-05-27 20:51:26 +00004508 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004509 ThrowMogrifyException(OptionError,"MissingArgument",option);
4510 break;
4511 }
4512 if (LocaleCompare("filter",option+1) == 0)
4513 {
cristybb503372010-05-27 20:51:26 +00004514 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004515 filter;
4516
4517 if (*option == '+')
4518 break;
4519 i++;
cristybb503372010-05-27 20:51:26 +00004520 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004521 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004522 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004523 if (filter < 0)
4524 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4525 argv[i]);
4526 break;
4527 }
4528 if (LocaleCompare("flatten",option+1) == 0)
4529 break;
4530 if (LocaleCompare("flip",option+1) == 0)
4531 break;
4532 if (LocaleCompare("flop",option+1) == 0)
4533 break;
4534 if (LocaleCompare("floodfill",option+1) == 0)
4535 {
4536 if (*option == '+')
4537 break;
4538 i++;
cristybb503372010-05-27 20:51:26 +00004539 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004540 ThrowMogrifyException(OptionError,"MissingArgument",option);
4541 if (IsGeometry(argv[i]) == MagickFalse)
4542 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4543 i++;
cristybb503372010-05-27 20:51:26 +00004544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004545 ThrowMogrifyException(OptionError,"MissingArgument",option);
4546 break;
4547 }
4548 if (LocaleCompare("font",option+1) == 0)
4549 {
4550 if (*option == '+')
4551 break;
4552 i++;
cristybb503372010-05-27 20:51:26 +00004553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004554 ThrowMogrifyException(OptionError,"MissingArgument",option);
4555 break;
4556 }
4557 if (LocaleCompare("format",option+1) == 0)
4558 {
4559 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4560 (void) CloneString(&format,(char *) NULL);
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 (void) CloneString(&format,argv[i]);
4567 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4568 (void) ConcatenateMagickString(image_info->filename,":",
4569 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004570 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004571 if (*image_info->magick == '\0')
4572 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4573 format);
4574 break;
4575 }
4576 if (LocaleCompare("frame",option+1) == 0)
4577 {
4578 if (*option == '+')
4579 break;
4580 i++;
cristybb503372010-05-27 20:51:26 +00004581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004582 ThrowMogrifyException(OptionError,"MissingArgument",option);
4583 if (IsGeometry(argv[i]) == MagickFalse)
4584 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4585 break;
4586 }
4587 if (LocaleCompare("function",option+1) == 0)
4588 {
cristybb503372010-05-27 20:51:26 +00004589 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004590 op;
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);
cristy042ee782011-04-22 18:48:30 +00004597 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004598 if (op < 0)
4599 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4600 i++;
cristybb503372010-05-27 20:51:26 +00004601 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004602 ThrowMogrifyException(OptionError,"MissingArgument",option);
4603 break;
4604 }
4605 if (LocaleCompare("fuzz",option+1) == 0)
4606 {
4607 if (*option == '+')
4608 break;
4609 i++;
cristybb503372010-05-27 20:51:26 +00004610 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004611 ThrowMogrifyException(OptionError,"MissingArgument",option);
4612 if (IsGeometry(argv[i]) == MagickFalse)
4613 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4614 break;
4615 }
4616 if (LocaleCompare("fx",option+1) == 0)
4617 {
4618 if (*option == '+')
4619 break;
4620 i++;
cristybb503372010-05-27 20:51:26 +00004621 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004622 ThrowMogrifyException(OptionError,"MissingArgument",option);
4623 break;
4624 }
4625 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4626 }
4627 case 'g':
4628 {
4629 if (LocaleCompare("gamma",option+1) == 0)
4630 {
4631 i++;
cristybb503372010-05-27 20:51:26 +00004632 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004633 ThrowMogrifyException(OptionError,"MissingArgument",option);
4634 if (IsGeometry(argv[i]) == MagickFalse)
4635 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4636 break;
4637 }
4638 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4639 (LocaleCompare("gaussian",option+1) == 0))
4640 {
4641 i++;
cristybb503372010-05-27 20:51:26 +00004642 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004643 ThrowMogrifyException(OptionError,"MissingArgument",option);
4644 if (IsGeometry(argv[i]) == MagickFalse)
4645 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4646 break;
4647 }
4648 if (LocaleCompare("geometry",option+1) == 0)
4649 {
4650 if (*option == '+')
4651 break;
4652 i++;
cristybb503372010-05-27 20:51:26 +00004653 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004654 ThrowMogrifyException(OptionError,"MissingArgument",option);
4655 if (IsGeometry(argv[i]) == MagickFalse)
4656 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4657 break;
4658 }
4659 if (LocaleCompare("gravity",option+1) == 0)
4660 {
cristybb503372010-05-27 20:51:26 +00004661 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004662 gravity;
4663
4664 if (*option == '+')
4665 break;
4666 i++;
cristybb503372010-05-27 20:51:26 +00004667 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004668 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004669 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004670 if (gravity < 0)
4671 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4672 argv[i]);
4673 break;
4674 }
4675 if (LocaleCompare("green-primary",option+1) == 0)
4676 {
4677 if (*option == '+')
4678 break;
4679 i++;
cristybb503372010-05-27 20:51:26 +00004680 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004681 ThrowMogrifyException(OptionError,"MissingArgument",option);
4682 if (IsGeometry(argv[i]) == MagickFalse)
4683 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4684 break;
4685 }
4686 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4687 }
4688 case 'h':
4689 {
4690 if (LocaleCompare("hald-clut",option+1) == 0)
4691 break;
4692 if ((LocaleCompare("help",option+1) == 0) ||
4693 (LocaleCompare("-help",option+1) == 0))
4694 return(MogrifyUsage());
4695 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4696 }
4697 case 'i':
4698 {
4699 if (LocaleCompare("identify",option+1) == 0)
4700 break;
4701 if (LocaleCompare("idft",option+1) == 0)
4702 break;
4703 if (LocaleCompare("implode",option+1) == 0)
4704 {
4705 if (*option == '+')
4706 break;
4707 i++;
cristybb503372010-05-27 20:51:26 +00004708 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004709 ThrowMogrifyException(OptionError,"MissingArgument",option);
4710 if (IsGeometry(argv[i]) == MagickFalse)
4711 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4712 break;
4713 }
4714 if (LocaleCompare("intent",option+1) == 0)
4715 {
cristybb503372010-05-27 20:51:26 +00004716 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004717 intent;
4718
4719 if (*option == '+')
4720 break;
4721 i++;
cristybb503372010-05-27 20:51:26 +00004722 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004723 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004724 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004725 if (intent < 0)
4726 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4727 argv[i]);
4728 break;
4729 }
4730 if (LocaleCompare("interlace",option+1) == 0)
4731 {
cristybb503372010-05-27 20:51:26 +00004732 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004733 interlace;
4734
4735 if (*option == '+')
4736 break;
4737 i++;
cristybb503372010-05-27 20:51:26 +00004738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004739 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004740 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004741 argv[i]);
4742 if (interlace < 0)
4743 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4744 argv[i]);
4745 break;
4746 }
cristyb32b90a2009-09-07 21:45:48 +00004747 if (LocaleCompare("interline-spacing",option+1) == 0)
4748 {
4749 if (*option == '+')
4750 break;
4751 i++;
cristybb503372010-05-27 20:51:26 +00004752 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004753 ThrowMogrifyException(OptionError,"MissingArgument",option);
4754 if (IsGeometry(argv[i]) == MagickFalse)
4755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4756 break;
4757 }
cristy3ed852e2009-09-05 21:47:34 +00004758 if (LocaleCompare("interpolate",option+1) == 0)
4759 {
cristybb503372010-05-27 20:51:26 +00004760 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004761 interpolate;
4762
4763 if (*option == '+')
4764 break;
4765 i++;
cristybb503372010-05-27 20:51:26 +00004766 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004767 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004768 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004769 argv[i]);
4770 if (interpolate < 0)
4771 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4772 argv[i]);
4773 break;
4774 }
4775 if (LocaleCompare("interword-spacing",option+1) == 0)
4776 {
4777 if (*option == '+')
4778 break;
4779 i++;
cristybb503372010-05-27 20:51:26 +00004780 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004781 ThrowMogrifyException(OptionError,"MissingArgument",option);
4782 if (IsGeometry(argv[i]) == MagickFalse)
4783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4784 break;
4785 }
4786 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4787 }
4788 case 'k':
4789 {
4790 if (LocaleCompare("kerning",option+1) == 0)
4791 {
4792 if (*option == '+')
4793 break;
4794 i++;
cristybb503372010-05-27 20:51:26 +00004795 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004796 ThrowMogrifyException(OptionError,"MissingArgument",option);
4797 if (IsGeometry(argv[i]) == MagickFalse)
4798 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4799 break;
4800 }
4801 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4802 }
4803 case 'l':
4804 {
4805 if (LocaleCompare("label",option+1) == 0)
4806 {
4807 if (*option == '+')
4808 break;
4809 i++;
cristybb503372010-05-27 20:51:26 +00004810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004811 ThrowMogrifyException(OptionError,"MissingArgument",option);
4812 break;
4813 }
4814 if (LocaleCompare("lat",option+1) == 0)
4815 {
4816 if (*option == '+')
4817 break;
4818 i++;
cristybb503372010-05-27 20:51:26 +00004819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004820 ThrowMogrifyException(OptionError,"MissingArgument",option);
4821 if (IsGeometry(argv[i]) == MagickFalse)
4822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4823 }
4824 if (LocaleCompare("layers",option+1) == 0)
4825 {
cristybb503372010-05-27 20:51:26 +00004826 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004827 type;
4828
4829 if (*option == '+')
4830 break;
4831 i++;
cristybb503372010-05-27 20:51:26 +00004832 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004833 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004834 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004835 if (type < 0)
4836 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4837 argv[i]);
4838 break;
4839 }
4840 if (LocaleCompare("level",option+1) == 0)
4841 {
4842 i++;
cristybb503372010-05-27 20:51:26 +00004843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004844 ThrowMogrifyException(OptionError,"MissingArgument",option);
4845 if (IsGeometry(argv[i]) == MagickFalse)
4846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4847 break;
4848 }
4849 if (LocaleCompare("level-colors",option+1) == 0)
4850 {
4851 i++;
cristybb503372010-05-27 20:51:26 +00004852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004853 ThrowMogrifyException(OptionError,"MissingArgument",option);
4854 break;
4855 }
4856 if (LocaleCompare("linewidth",option+1) == 0)
4857 {
4858 if (*option == '+')
4859 break;
4860 i++;
cristybb503372010-05-27 20:51:26 +00004861 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004862 ThrowMogrifyException(OptionError,"MissingArgument",option);
4863 if (IsGeometry(argv[i]) == MagickFalse)
4864 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4865 break;
4866 }
4867 if (LocaleCompare("limit",option+1) == 0)
4868 {
4869 char
4870 *p;
4871
4872 double
4873 value;
4874
cristybb503372010-05-27 20:51:26 +00004875 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004876 resource;
4877
4878 if (*option == '+')
4879 break;
4880 i++;
cristybb503372010-05-27 20:51:26 +00004881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004882 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004883 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004884 argv[i]);
4885 if (resource < 0)
4886 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4887 argv[i]);
4888 i++;
cristybb503372010-05-27 20:51:26 +00004889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004890 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004891 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004892 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004893 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4894 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4895 break;
4896 }
4897 if (LocaleCompare("liquid-rescale",option+1) == 0)
4898 {
4899 i++;
cristybb503372010-05-27 20:51:26 +00004900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004901 ThrowMogrifyException(OptionError,"MissingArgument",option);
4902 if (IsGeometry(argv[i]) == MagickFalse)
4903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4904 break;
4905 }
4906 if (LocaleCompare("list",option+1) == 0)
4907 {
cristybb503372010-05-27 20:51:26 +00004908 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004909 list;
4910
4911 if (*option == '+')
4912 break;
4913 i++;
cristybb503372010-05-27 20:51:26 +00004914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004915 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004916 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004917 if (list < 0)
4918 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004919 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004920 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004921 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004922 }
4923 if (LocaleCompare("log",option+1) == 0)
4924 {
4925 if (*option == '+')
4926 break;
4927 i++;
cristybb503372010-05-27 20:51:26 +00004928 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004929 (strchr(argv[i],'%') == (char *) NULL))
4930 ThrowMogrifyException(OptionError,"MissingArgument",option);
4931 break;
4932 }
4933 if (LocaleCompare("loop",option+1) == 0)
4934 {
4935 if (*option == '+')
4936 break;
4937 i++;
cristybb503372010-05-27 20:51:26 +00004938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004939 ThrowMogrifyException(OptionError,"MissingArgument",option);
4940 if (IsGeometry(argv[i]) == MagickFalse)
4941 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4942 break;
4943 }
4944 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4945 }
4946 case 'm':
4947 {
4948 if (LocaleCompare("map",option+1) == 0)
4949 {
4950 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4951 if (*option == '+')
4952 break;
4953 i++;
cristybb503372010-05-27 20:51:26 +00004954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004955 ThrowMogrifyException(OptionError,"MissingArgument",option);
4956 break;
4957 }
4958 if (LocaleCompare("mask",option+1) == 0)
4959 {
4960 if (*option == '+')
4961 break;
4962 i++;
cristybb503372010-05-27 20:51:26 +00004963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004964 ThrowMogrifyException(OptionError,"MissingArgument",option);
4965 break;
4966 }
4967 if (LocaleCompare("matte",option+1) == 0)
4968 break;
4969 if (LocaleCompare("mattecolor",option+1) == 0)
4970 {
4971 if (*option == '+')
4972 break;
4973 i++;
cristybb503372010-05-27 20:51:26 +00004974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004975 ThrowMogrifyException(OptionError,"MissingArgument",option);
4976 break;
4977 }
cristyf40785b2010-03-06 02:27:27 +00004978 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004979 break;
cristyf40785b2010-03-06 02:27:27 +00004980 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004981 break;
cristy3ed852e2009-09-05 21:47:34 +00004982 if (LocaleCompare("modulate",option+1) == 0)
4983 {
4984 if (*option == '+')
4985 break;
4986 i++;
cristybb503372010-05-27 20:51:26 +00004987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004988 ThrowMogrifyException(OptionError,"MissingArgument",option);
4989 if (IsGeometry(argv[i]) == MagickFalse)
4990 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4991 break;
4992 }
4993 if (LocaleCompare("median",option+1) == 0)
4994 {
4995 if (*option == '+')
4996 break;
4997 i++;
cristybb503372010-05-27 20:51:26 +00004998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004999 ThrowMogrifyException(OptionError,"MissingArgument",option);
5000 if (IsGeometry(argv[i]) == MagickFalse)
5001 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5002 break;
5003 }
cristy69ec32d2011-02-27 23:57:09 +00005004 if (LocaleCompare("mode",option+1) == 0)
5005 {
5006 if (*option == '+')
5007 break;
5008 i++;
5009 if (i == (ssize_t) argc)
5010 ThrowMogrifyException(OptionError,"MissingArgument",option);
5011 if (IsGeometry(argv[i]) == MagickFalse)
5012 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5013 break;
5014 }
cristy3ed852e2009-09-05 21:47:34 +00005015 if (LocaleCompare("monitor",option+1) == 0)
5016 break;
5017 if (LocaleCompare("monochrome",option+1) == 0)
5018 break;
5019 if (LocaleCompare("morph",option+1) == 0)
5020 {
5021 if (*option == '+')
5022 break;
5023 i++;
cristybb503372010-05-27 20:51:26 +00005024 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005025 ThrowMogrifyException(OptionError,"MissingArgument",option);
5026 if (IsGeometry(argv[i]) == MagickFalse)
5027 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5028 break;
5029 }
anthony29188a82010-01-22 10:12:34 +00005030 if (LocaleCompare("morphology",option+1) == 0)
5031 {
anthony29188a82010-01-22 10:12:34 +00005032 char
5033 token[MaxTextExtent];
5034
cristyb6bd4ad2010-08-08 01:12:27 +00005035 KernelInfo
5036 *kernel_info;
5037
5038 ssize_t
5039 op;
5040
anthony29188a82010-01-22 10:12:34 +00005041 i++;
cristybb503372010-05-27 20:51:26 +00005042 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005043 ThrowMogrifyException(OptionError,"MissingArgument",option);
5044 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005045 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005046 if (op < 0)
5047 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005048 token);
anthony29188a82010-01-22 10:12:34 +00005049 i++;
cristybb503372010-05-27 20:51:26 +00005050 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005051 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005052 kernel_info=AcquireKernelInfo(argv[i]);
5053 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005054 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005055 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005056 break;
5057 }
cristy3ed852e2009-09-05 21:47:34 +00005058 if (LocaleCompare("mosaic",option+1) == 0)
5059 break;
5060 if (LocaleCompare("motion-blur",option+1) == 0)
5061 {
5062 if (*option == '+')
5063 break;
5064 i++;
cristybb503372010-05-27 20:51:26 +00005065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005066 ThrowMogrifyException(OptionError,"MissingArgument",option);
5067 if (IsGeometry(argv[i]) == MagickFalse)
5068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5069 break;
5070 }
5071 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5072 }
5073 case 'n':
5074 {
5075 if (LocaleCompare("negate",option+1) == 0)
5076 break;
5077 if (LocaleCompare("noise",option+1) == 0)
5078 {
5079 i++;
cristybb503372010-05-27 20:51:26 +00005080 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005081 ThrowMogrifyException(OptionError,"MissingArgument",option);
5082 if (*option == '+')
5083 {
cristybb503372010-05-27 20:51:26 +00005084 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005085 noise;
5086
cristy042ee782011-04-22 18:48:30 +00005087 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005088 if (noise < 0)
5089 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5090 argv[i]);
5091 break;
5092 }
5093 if (IsGeometry(argv[i]) == MagickFalse)
5094 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5095 break;
5096 }
5097 if (LocaleCompare("noop",option+1) == 0)
5098 break;
5099 if (LocaleCompare("normalize",option+1) == 0)
5100 break;
5101 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5102 }
5103 case 'o':
5104 {
5105 if (LocaleCompare("opaque",option+1) == 0)
5106 {
cristy3ed852e2009-09-05 21:47:34 +00005107 i++;
cristybb503372010-05-27 20:51:26 +00005108 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005109 ThrowMogrifyException(OptionError,"MissingArgument",option);
5110 break;
5111 }
5112 if (LocaleCompare("ordered-dither",option+1) == 0)
5113 {
5114 if (*option == '+')
5115 break;
5116 i++;
cristybb503372010-05-27 20:51:26 +00005117 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005118 ThrowMogrifyException(OptionError,"MissingArgument",option);
5119 break;
5120 }
5121 if (LocaleCompare("orient",option+1) == 0)
5122 {
cristybb503372010-05-27 20:51:26 +00005123 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005124 orientation;
5125
5126 orientation=UndefinedOrientation;
5127 if (*option == '+')
5128 break;
5129 i++;
cristybb503372010-05-27 20:51:26 +00005130 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005131 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005132 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005133 argv[i]);
5134 if (orientation < 0)
5135 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5136 argv[i]);
5137 break;
5138 }
5139 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5140 }
5141 case 'p':
5142 {
5143 if (LocaleCompare("page",option+1) == 0)
5144 {
5145 if (*option == '+')
5146 break;
5147 i++;
cristybb503372010-05-27 20:51:26 +00005148 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005149 ThrowMogrifyException(OptionError,"MissingArgument",option);
5150 break;
5151 }
5152 if (LocaleCompare("paint",option+1) == 0)
5153 {
5154 if (*option == '+')
5155 break;
5156 i++;
cristybb503372010-05-27 20:51:26 +00005157 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005158 ThrowMogrifyException(OptionError,"MissingArgument",option);
5159 if (IsGeometry(argv[i]) == MagickFalse)
5160 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5161 break;
5162 }
5163 if (LocaleCompare("path",option+1) == 0)
5164 {
5165 (void) CloneString(&path,(char *) NULL);
5166 if (*option == '+')
5167 break;
5168 i++;
cristybb503372010-05-27 20:51:26 +00005169 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005170 ThrowMogrifyException(OptionError,"MissingArgument",option);
5171 (void) CloneString(&path,argv[i]);
5172 break;
5173 }
5174 if (LocaleCompare("pointsize",option+1) == 0)
5175 {
5176 if (*option == '+')
5177 break;
5178 i++;
cristybb503372010-05-27 20:51:26 +00005179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005180 ThrowMogrifyException(OptionError,"MissingArgument",option);
5181 if (IsGeometry(argv[i]) == MagickFalse)
5182 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5183 break;
5184 }
5185 if (LocaleCompare("polaroid",option+1) == 0)
5186 {
5187 if (*option == '+')
5188 break;
5189 i++;
cristybb503372010-05-27 20:51:26 +00005190 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005191 ThrowMogrifyException(OptionError,"MissingArgument",option);
5192 if (IsGeometry(argv[i]) == MagickFalse)
5193 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5194 break;
5195 }
5196 if (LocaleCompare("posterize",option+1) == 0)
5197 {
5198 if (*option == '+')
5199 break;
5200 i++;
cristybb503372010-05-27 20:51:26 +00005201 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005202 ThrowMogrifyException(OptionError,"MissingArgument",option);
5203 if (IsGeometry(argv[i]) == MagickFalse)
5204 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5205 break;
5206 }
cristye7f51092010-01-17 00:39:37 +00005207 if (LocaleCompare("precision",option+1) == 0)
5208 {
5209 if (*option == '+')
5210 break;
5211 i++;
cristybb503372010-05-27 20:51:26 +00005212 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005213 ThrowMogrifyException(OptionError,"MissingArgument",option);
5214 if (IsGeometry(argv[i]) == MagickFalse)
5215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5216 break;
5217 }
cristy3ed852e2009-09-05 21:47:34 +00005218 if (LocaleCompare("print",option+1) == 0)
5219 {
5220 if (*option == '+')
5221 break;
5222 i++;
cristybb503372010-05-27 20:51:26 +00005223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005224 ThrowMogrifyException(OptionError,"MissingArgument",option);
5225 break;
5226 }
5227 if (LocaleCompare("process",option+1) == 0)
5228 {
5229 if (*option == '+')
5230 break;
5231 i++;
cristybb503372010-05-27 20:51:26 +00005232 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005233 ThrowMogrifyException(OptionError,"MissingArgument",option);
5234 break;
5235 }
5236 if (LocaleCompare("profile",option+1) == 0)
5237 {
5238 i++;
cristybb503372010-05-27 20:51:26 +00005239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005240 ThrowMogrifyException(OptionError,"MissingArgument",option);
5241 break;
5242 }
5243 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5244 }
5245 case 'q':
5246 {
5247 if (LocaleCompare("quality",option+1) == 0)
5248 {
5249 if (*option == '+')
5250 break;
5251 i++;
cristybb503372010-05-27 20:51:26 +00005252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005253 ThrowMogrifyException(OptionError,"MissingArgument",option);
5254 if (IsGeometry(argv[i]) == MagickFalse)
5255 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5256 break;
5257 }
5258 if (LocaleCompare("quantize",option+1) == 0)
5259 {
cristybb503372010-05-27 20:51:26 +00005260 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005261 colorspace;
5262
5263 if (*option == '+')
5264 break;
5265 i++;
cristybb503372010-05-27 20:51:26 +00005266 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005267 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005268 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005269 argv[i]);
5270 if (colorspace < 0)
5271 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5272 argv[i]);
5273 break;
5274 }
5275 if (LocaleCompare("quiet",option+1) == 0)
5276 break;
5277 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5278 }
5279 case 'r':
5280 {
5281 if (LocaleCompare("radial-blur",option+1) == 0)
5282 {
5283 i++;
cristybb503372010-05-27 20:51:26 +00005284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005285 ThrowMogrifyException(OptionError,"MissingArgument",option);
5286 if (IsGeometry(argv[i]) == MagickFalse)
5287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5288 break;
5289 }
5290 if (LocaleCompare("raise",option+1) == 0)
5291 {
5292 i++;
cristybb503372010-05-27 20:51:26 +00005293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005294 ThrowMogrifyException(OptionError,"MissingArgument",option);
5295 if (IsGeometry(argv[i]) == MagickFalse)
5296 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5297 break;
5298 }
5299 if (LocaleCompare("random-threshold",option+1) == 0)
5300 {
5301 if (*option == '+')
5302 break;
5303 i++;
cristybb503372010-05-27 20:51:26 +00005304 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005305 ThrowMogrifyException(OptionError,"MissingArgument",option);
5306 if (IsGeometry(argv[i]) == MagickFalse)
5307 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5308 break;
5309 }
cristye6365592010-04-02 17:31:23 +00005310 if (LocaleCompare("recolor",option+1) == 0)
5311 {
5312 if (*option == '+')
5313 break;
5314 i++;
cristybb503372010-05-27 20:51:26 +00005315 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005316 ThrowMogrifyException(OptionError,"MissingArgument",option);
5317 if (IsGeometry(argv[i]) == MagickFalse)
5318 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5319 break;
5320 }
cristy3ed852e2009-09-05 21:47:34 +00005321 if (LocaleCompare("red-primary",option+1) == 0)
5322 {
5323 if (*option == '+')
5324 break;
5325 i++;
cristybb503372010-05-27 20:51:26 +00005326 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005327 ThrowMogrifyException(OptionError,"MissingArgument",option);
5328 if (IsGeometry(argv[i]) == MagickFalse)
5329 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5330 }
cristy9f2083a2010-04-22 19:48:05 +00005331 if (LocaleCompare("regard-warnings",option+1) == 0)
5332 break;
cristy3ed852e2009-09-05 21:47:34 +00005333 if (LocaleCompare("region",option+1) == 0)
5334 {
5335 if (*option == '+')
5336 break;
5337 i++;
cristybb503372010-05-27 20:51:26 +00005338 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005339 ThrowMogrifyException(OptionError,"MissingArgument",option);
5340 if (IsGeometry(argv[i]) == MagickFalse)
5341 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5342 break;
5343 }
cristyf0c78232010-03-15 12:53:40 +00005344 if (LocaleCompare("remap",option+1) == 0)
5345 {
5346 if (*option == '+')
5347 break;
5348 i++;
cristybb503372010-05-27 20:51:26 +00005349 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005350 ThrowMogrifyException(OptionError,"MissingArgument",option);
5351 break;
5352 }
cristy3ed852e2009-09-05 21:47:34 +00005353 if (LocaleCompare("render",option+1) == 0)
5354 break;
5355 if (LocaleCompare("repage",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 }
5366 if (LocaleCompare("resample",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
cristybb503372010-05-27 20:51:26 +00005371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 break;
5376 }
5377 if (LocaleCompare("resize",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 break;
5387 }
cristyebbcfea2011-02-25 02:43:54 +00005388 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5389 {
5390 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5391 break;
5392 }
cristy3ed852e2009-09-05 21:47:34 +00005393 if (LocaleCompare("reverse",option+1) == 0)
5394 break;
5395 if (LocaleCompare("roll",option+1) == 0)
5396 {
5397 if (*option == '+')
5398 break;
5399 i++;
cristybb503372010-05-27 20:51:26 +00005400 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005401 ThrowMogrifyException(OptionError,"MissingArgument",option);
5402 if (IsGeometry(argv[i]) == MagickFalse)
5403 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5404 break;
5405 }
5406 if (LocaleCompare("rotate",option+1) == 0)
5407 {
5408 i++;
cristybb503372010-05-27 20:51:26 +00005409 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005410 ThrowMogrifyException(OptionError,"MissingArgument",option);
5411 if (IsGeometry(argv[i]) == MagickFalse)
5412 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5413 break;
5414 }
5415 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5416 }
5417 case 's':
5418 {
5419 if (LocaleCompare("sample",option+1) == 0)
5420 {
5421 if (*option == '+')
5422 break;
5423 i++;
cristybb503372010-05-27 20:51:26 +00005424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005425 ThrowMogrifyException(OptionError,"MissingArgument",option);
5426 if (IsGeometry(argv[i]) == MagickFalse)
5427 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5428 break;
5429 }
5430 if (LocaleCompare("sampling-factor",option+1) == 0)
5431 {
5432 if (*option == '+')
5433 break;
5434 i++;
cristybb503372010-05-27 20:51:26 +00005435 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005436 ThrowMogrifyException(OptionError,"MissingArgument",option);
5437 if (IsGeometry(argv[i]) == MagickFalse)
5438 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5439 break;
5440 }
5441 if (LocaleCompare("scale",option+1) == 0)
5442 {
5443 if (*option == '+')
5444 break;
5445 i++;
cristybb503372010-05-27 20:51:26 +00005446 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005447 ThrowMogrifyException(OptionError,"MissingArgument",option);
5448 if (IsGeometry(argv[i]) == MagickFalse)
5449 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5450 break;
5451 }
5452 if (LocaleCompare("scene",option+1) == 0)
5453 {
5454 if (*option == '+')
5455 break;
5456 i++;
cristybb503372010-05-27 20:51:26 +00005457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005458 ThrowMogrifyException(OptionError,"MissingArgument",option);
5459 if (IsGeometry(argv[i]) == MagickFalse)
5460 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5461 break;
5462 }
5463 if (LocaleCompare("seed",option+1) == 0)
5464 {
5465 if (*option == '+')
5466 break;
5467 i++;
cristybb503372010-05-27 20:51:26 +00005468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005469 ThrowMogrifyException(OptionError,"MissingArgument",option);
5470 if (IsGeometry(argv[i]) == MagickFalse)
5471 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5472 break;
5473 }
5474 if (LocaleCompare("segment",option+1) == 0)
5475 {
5476 if (*option == '+')
5477 break;
5478 i++;
cristybb503372010-05-27 20:51:26 +00005479 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005480 ThrowMogrifyException(OptionError,"MissingArgument",option);
5481 if (IsGeometry(argv[i]) == MagickFalse)
5482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5483 break;
5484 }
5485 if (LocaleCompare("selective-blur",option+1) == 0)
5486 {
5487 i++;
cristybb503372010-05-27 20:51:26 +00005488 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005489 ThrowMogrifyException(OptionError,"MissingArgument",option);
5490 if (IsGeometry(argv[i]) == MagickFalse)
5491 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5492 break;
5493 }
5494 if (LocaleCompare("separate",option+1) == 0)
5495 break;
5496 if (LocaleCompare("sepia-tone",option+1) == 0)
5497 {
5498 if (*option == '+')
5499 break;
5500 i++;
cristybb503372010-05-27 20:51:26 +00005501 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005502 ThrowMogrifyException(OptionError,"MissingArgument",option);
5503 if (IsGeometry(argv[i]) == MagickFalse)
5504 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5505 break;
5506 }
5507 if (LocaleCompare("set",option+1) == 0)
5508 {
5509 i++;
cristybb503372010-05-27 20:51:26 +00005510 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005511 ThrowMogrifyException(OptionError,"MissingArgument",option);
5512 if (*option == '+')
5513 break;
5514 i++;
cristybb503372010-05-27 20:51:26 +00005515 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005516 ThrowMogrifyException(OptionError,"MissingArgument",option);
5517 break;
5518 }
5519 if (LocaleCompare("shade",option+1) == 0)
5520 {
5521 i++;
cristybb503372010-05-27 20:51:26 +00005522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005523 ThrowMogrifyException(OptionError,"MissingArgument",option);
5524 if (IsGeometry(argv[i]) == MagickFalse)
5525 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5526 break;
5527 }
5528 if (LocaleCompare("shadow",option+1) == 0)
5529 {
5530 if (*option == '+')
5531 break;
5532 i++;
cristybb503372010-05-27 20:51:26 +00005533 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005534 ThrowMogrifyException(OptionError,"MissingArgument",option);
5535 if (IsGeometry(argv[i]) == MagickFalse)
5536 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5537 break;
5538 }
5539 if (LocaleCompare("sharpen",option+1) == 0)
5540 {
5541 i++;
cristybb503372010-05-27 20:51:26 +00005542 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005543 ThrowMogrifyException(OptionError,"MissingArgument",option);
5544 if (IsGeometry(argv[i]) == MagickFalse)
5545 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5546 break;
5547 }
5548 if (LocaleCompare("shave",option+1) == 0)
5549 {
5550 if (*option == '+')
5551 break;
5552 i++;
cristybb503372010-05-27 20:51:26 +00005553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005554 ThrowMogrifyException(OptionError,"MissingArgument",option);
5555 if (IsGeometry(argv[i]) == MagickFalse)
5556 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5557 break;
5558 }
5559 if (LocaleCompare("shear",option+1) == 0)
5560 {
5561 i++;
cristybb503372010-05-27 20:51:26 +00005562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005563 ThrowMogrifyException(OptionError,"MissingArgument",option);
5564 if (IsGeometry(argv[i]) == MagickFalse)
5565 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5566 break;
5567 }
5568 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5569 {
5570 i++;
cristybb503372010-05-27 20:51:26 +00005571 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005572 ThrowMogrifyException(OptionError,"MissingArgument",option);
5573 if (IsGeometry(argv[i]) == MagickFalse)
5574 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5575 break;
5576 }
5577 if (LocaleCompare("size",option+1) == 0)
5578 {
5579 if (*option == '+')
5580 break;
5581 i++;
cristybb503372010-05-27 20:51:26 +00005582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005583 ThrowMogrifyException(OptionError,"MissingArgument",option);
5584 if (IsGeometry(argv[i]) == MagickFalse)
5585 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5586 break;
5587 }
5588 if (LocaleCompare("sketch",option+1) == 0)
5589 {
5590 if (*option == '+')
5591 break;
5592 i++;
cristybb503372010-05-27 20:51:26 +00005593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005594 ThrowMogrifyException(OptionError,"MissingArgument",option);
5595 if (IsGeometry(argv[i]) == MagickFalse)
5596 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5597 break;
5598 }
cristy4285d782011-02-09 20:12:28 +00005599 if (LocaleCompare("smush",option+1) == 0)
5600 {
cristy4285d782011-02-09 20:12:28 +00005601 i++;
5602 if (i == (ssize_t) argc)
5603 ThrowMogrifyException(OptionError,"MissingArgument",option);
5604 if (IsGeometry(argv[i]) == MagickFalse)
5605 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005606 i++;
5607 break;
5608 }
cristy3ed852e2009-09-05 21:47:34 +00005609 if (LocaleCompare("solarize",option+1) == 0)
5610 {
5611 if (*option == '+')
5612 break;
5613 i++;
cristybb503372010-05-27 20:51:26 +00005614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005615 ThrowMogrifyException(OptionError,"MissingArgument",option);
5616 if (IsGeometry(argv[i]) == MagickFalse)
5617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5618 break;
5619 }
5620 if (LocaleCompare("sparse-color",option+1) == 0)
5621 {
cristybb503372010-05-27 20:51:26 +00005622 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005623 op;
5624
5625 i++;
cristybb503372010-05-27 20:51:26 +00005626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005627 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005628 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005629 if (op < 0)
5630 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5631 argv[i]);
5632 i++;
cristybb503372010-05-27 20:51:26 +00005633 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005634 ThrowMogrifyException(OptionError,"MissingArgument",option);
5635 break;
5636 }
5637 if (LocaleCompare("spread",option+1) == 0)
5638 {
5639 if (*option == '+')
5640 break;
5641 i++;
cristybb503372010-05-27 20:51:26 +00005642 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005643 ThrowMogrifyException(OptionError,"MissingArgument",option);
5644 if (IsGeometry(argv[i]) == MagickFalse)
5645 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5646 break;
5647 }
cristy0834d642011-03-18 18:26:08 +00005648 if (LocaleCompare("statistic",option+1) == 0)
5649 {
5650 ssize_t
5651 op;
5652
5653 if (*option == '+')
5654 break;
5655 i++;
5656 if (i == (ssize_t) argc)
5657 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005658 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005659 if (op < 0)
5660 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5661 argv[i]);
5662 i++;
5663 if (i == (ssize_t) (argc-1))
5664 ThrowMogrifyException(OptionError,"MissingArgument",option);
5665 if (IsGeometry(argv[i]) == MagickFalse)
5666 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5667 break;
5668 }
cristy3ed852e2009-09-05 21:47:34 +00005669 if (LocaleCompare("stretch",option+1) == 0)
5670 {
cristybb503372010-05-27 20:51:26 +00005671 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005672 stretch;
5673
5674 if (*option == '+')
5675 break;
5676 i++;
cristybb503372010-05-27 20:51:26 +00005677 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005678 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005679 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005680 if (stretch < 0)
5681 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5682 argv[i]);
5683 break;
5684 }
5685 if (LocaleCompare("strip",option+1) == 0)
5686 break;
5687 if (LocaleCompare("stroke",option+1) == 0)
5688 {
5689 if (*option == '+')
5690 break;
5691 i++;
cristybb503372010-05-27 20:51:26 +00005692 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005693 ThrowMogrifyException(OptionError,"MissingArgument",option);
5694 break;
5695 }
5696 if (LocaleCompare("strokewidth",option+1) == 0)
5697 {
5698 if (*option == '+')
5699 break;
5700 i++;
cristybb503372010-05-27 20:51:26 +00005701 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005702 ThrowMogrifyException(OptionError,"MissingArgument",option);
5703 if (IsGeometry(argv[i]) == MagickFalse)
5704 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5705 break;
5706 }
5707 if (LocaleCompare("style",option+1) == 0)
5708 {
cristybb503372010-05-27 20:51:26 +00005709 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005710 style;
5711
5712 if (*option == '+')
5713 break;
5714 i++;
cristybb503372010-05-27 20:51:26 +00005715 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005716 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005717 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005718 if (style < 0)
5719 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5720 argv[i]);
5721 break;
5722 }
cristyecb10ff2011-03-22 13:14:03 +00005723 if (LocaleCompare("swap",option+1) == 0)
5724 {
5725 if (*option == '+')
5726 break;
5727 i++;
5728 if (i == (ssize_t) (argc-1))
5729 ThrowMogrifyException(OptionError,"MissingArgument",option);
5730 if (IsGeometry(argv[i]) == MagickFalse)
5731 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5732 break;
5733 }
cristy3ed852e2009-09-05 21:47:34 +00005734 if (LocaleCompare("swirl",option+1) == 0)
5735 {
5736 if (*option == '+')
5737 break;
5738 i++;
cristybb503372010-05-27 20:51:26 +00005739 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005740 ThrowMogrifyException(OptionError,"MissingArgument",option);
5741 if (IsGeometry(argv[i]) == MagickFalse)
5742 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5743 break;
5744 }
cristyd9a29192010-10-16 16:49:53 +00005745 if (LocaleCompare("synchronize",option+1) == 0)
5746 break;
cristy3ed852e2009-09-05 21:47:34 +00005747 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5748 }
5749 case 't':
5750 {
5751 if (LocaleCompare("taint",option+1) == 0)
5752 break;
5753 if (LocaleCompare("texture",option+1) == 0)
5754 {
5755 if (*option == '+')
5756 break;
5757 i++;
cristybb503372010-05-27 20:51:26 +00005758 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005759 ThrowMogrifyException(OptionError,"MissingArgument",option);
5760 break;
5761 }
5762 if (LocaleCompare("tile",option+1) == 0)
5763 {
5764 if (*option == '+')
5765 break;
5766 i++;
cristybb503372010-05-27 20:51:26 +00005767 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005768 ThrowMogrifyException(OptionError,"MissingArgument",option);
5769 break;
5770 }
5771 if (LocaleCompare("tile-offset",option+1) == 0)
5772 {
5773 if (*option == '+')
5774 break;
5775 i++;
cristybb503372010-05-27 20:51:26 +00005776 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005777 ThrowMogrifyException(OptionError,"MissingArgument",option);
5778 if (IsGeometry(argv[i]) == MagickFalse)
5779 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5780 break;
5781 }
5782 if (LocaleCompare("tint",option+1) == 0)
5783 {
5784 if (*option == '+')
5785 break;
5786 i++;
cristybb503372010-05-27 20:51:26 +00005787 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005788 ThrowMogrifyException(OptionError,"MissingArgument",option);
5789 if (IsGeometry(argv[i]) == MagickFalse)
5790 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5791 break;
5792 }
5793 if (LocaleCompare("transform",option+1) == 0)
5794 break;
5795 if (LocaleCompare("transpose",option+1) == 0)
5796 break;
5797 if (LocaleCompare("transverse",option+1) == 0)
5798 break;
5799 if (LocaleCompare("threshold",option+1) == 0)
5800 {
5801 if (*option == '+')
5802 break;
5803 i++;
cristybb503372010-05-27 20:51:26 +00005804 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005805 ThrowMogrifyException(OptionError,"MissingArgument",option);
5806 if (IsGeometry(argv[i]) == MagickFalse)
5807 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5808 break;
5809 }
5810 if (LocaleCompare("thumbnail",option+1) == 0)
5811 {
5812 if (*option == '+')
5813 break;
5814 i++;
cristybb503372010-05-27 20:51:26 +00005815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005816 ThrowMogrifyException(OptionError,"MissingArgument",option);
5817 if (IsGeometry(argv[i]) == MagickFalse)
5818 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5819 break;
5820 }
5821 if (LocaleCompare("transparent",option+1) == 0)
5822 {
5823 i++;
cristybb503372010-05-27 20:51:26 +00005824 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005825 ThrowMogrifyException(OptionError,"MissingArgument",option);
5826 break;
5827 }
5828 if (LocaleCompare("transparent-color",option+1) == 0)
5829 {
5830 if (*option == '+')
5831 break;
5832 i++;
cristybb503372010-05-27 20:51:26 +00005833 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005834 ThrowMogrifyException(OptionError,"MissingArgument",option);
5835 break;
5836 }
5837 if (LocaleCompare("treedepth",option+1) == 0)
5838 {
5839 if (*option == '+')
5840 break;
5841 i++;
cristybb503372010-05-27 20:51:26 +00005842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005843 ThrowMogrifyException(OptionError,"MissingArgument",option);
5844 if (IsGeometry(argv[i]) == MagickFalse)
5845 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5846 break;
5847 }
5848 if (LocaleCompare("trim",option+1) == 0)
5849 break;
5850 if (LocaleCompare("type",option+1) == 0)
5851 {
cristybb503372010-05-27 20:51:26 +00005852 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005853 type;
5854
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005860 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005861 if (type < 0)
5862 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5863 argv[i]);
5864 break;
5865 }
5866 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5867 }
5868 case 'u':
5869 {
5870 if (LocaleCompare("undercolor",option+1) == 0)
5871 {
5872 if (*option == '+')
5873 break;
5874 i++;
cristybb503372010-05-27 20:51:26 +00005875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005876 ThrowMogrifyException(OptionError,"MissingArgument",option);
5877 break;
5878 }
5879 if (LocaleCompare("unique-colors",option+1) == 0)
5880 break;
5881 if (LocaleCompare("units",option+1) == 0)
5882 {
cristybb503372010-05-27 20:51:26 +00005883 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005884 units;
5885
5886 if (*option == '+')
5887 break;
5888 i++;
cristybb503372010-05-27 20:51:26 +00005889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005890 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005891 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005892 argv[i]);
5893 if (units < 0)
5894 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5895 argv[i]);
5896 break;
5897 }
5898 if (LocaleCompare("unsharp",option+1) == 0)
5899 {
5900 i++;
cristybb503372010-05-27 20:51:26 +00005901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005902 ThrowMogrifyException(OptionError,"MissingArgument",option);
5903 if (IsGeometry(argv[i]) == MagickFalse)
5904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5905 break;
5906 }
5907 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5908 }
5909 case 'v':
5910 {
5911 if (LocaleCompare("verbose",option+1) == 0)
5912 {
5913 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5914 break;
5915 }
5916 if ((LocaleCompare("version",option+1) == 0) ||
5917 (LocaleCompare("-version",option+1) == 0))
5918 {
cristyb51dff52011-05-19 16:55:47 +00005919 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005920 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005921 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5922 GetMagickCopyright());
5923 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5924 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005925 break;
5926 }
5927 if (LocaleCompare("view",option+1) == 0)
5928 {
5929 if (*option == '+')
5930 break;
5931 i++;
cristybb503372010-05-27 20:51:26 +00005932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005933 ThrowMogrifyException(OptionError,"MissingArgument",option);
5934 break;
5935 }
5936 if (LocaleCompare("vignette",option+1) == 0)
5937 {
5938 if (*option == '+')
5939 break;
5940 i++;
cristybb503372010-05-27 20:51:26 +00005941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005942 ThrowMogrifyException(OptionError,"MissingArgument",option);
5943 if (IsGeometry(argv[i]) == MagickFalse)
5944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5945 break;
5946 }
5947 if (LocaleCompare("virtual-pixel",option+1) == 0)
5948 {
cristybb503372010-05-27 20:51:26 +00005949 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005950 method;
5951
5952 if (*option == '+')
5953 break;
5954 i++;
cristybb503372010-05-27 20:51:26 +00005955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005956 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005957 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005958 argv[i]);
5959 if (method < 0)
5960 ThrowMogrifyException(OptionError,
5961 "UnrecognizedVirtualPixelMethod",argv[i]);
5962 break;
5963 }
5964 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5965 }
5966 case 'w':
5967 {
5968 if (LocaleCompare("wave",option+1) == 0)
5969 {
5970 i++;
cristybb503372010-05-27 20:51:26 +00005971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005972 ThrowMogrifyException(OptionError,"MissingArgument",option);
5973 if (IsGeometry(argv[i]) == MagickFalse)
5974 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5975 break;
5976 }
5977 if (LocaleCompare("weight",option+1) == 0)
5978 {
5979 if (*option == '+')
5980 break;
5981 i++;
cristybb503372010-05-27 20:51:26 +00005982 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005983 ThrowMogrifyException(OptionError,"MissingArgument",option);
5984 break;
5985 }
5986 if (LocaleCompare("white-point",option+1) == 0)
5987 {
5988 if (*option == '+')
5989 break;
5990 i++;
cristybb503372010-05-27 20:51:26 +00005991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005992 ThrowMogrifyException(OptionError,"MissingArgument",option);
5993 if (IsGeometry(argv[i]) == MagickFalse)
5994 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5995 break;
5996 }
5997 if (LocaleCompare("white-threshold",option+1) == 0)
5998 {
5999 if (*option == '+')
6000 break;
6001 i++;
cristybb503372010-05-27 20:51:26 +00006002 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006003 ThrowMogrifyException(OptionError,"MissingArgument",option);
6004 if (IsGeometry(argv[i]) == MagickFalse)
6005 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6006 break;
6007 }
6008 if (LocaleCompare("write",option+1) == 0)
6009 {
6010 i++;
cristybb503372010-05-27 20:51:26 +00006011 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006012 ThrowMogrifyException(OptionError,"MissingArgument",option);
6013 break;
6014 }
6015 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6016 }
6017 case '?':
6018 break;
6019 default:
6020 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6021 }
cristy042ee782011-04-22 18:48:30 +00006022 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6023 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006024 if (fire != MagickFalse)
6025 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6026 }
6027 if (k != 0)
6028 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006029 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006030 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6031 DestroyMogrify();
6032 return(status != 0 ? MagickTrue : MagickFalse);
6033}
6034
6035/*
6036%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6037% %
6038% %
6039% %
6040+ M o g r i f y I m a g e I n f o %
6041% %
6042% %
6043% %
6044%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6045%
6046% MogrifyImageInfo() applies image processing settings to the image as
6047% prescribed by command line options.
6048%
6049% The format of the MogrifyImageInfo method is:
6050%
6051% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6052% const char **argv,ExceptionInfo *exception)
6053%
6054% A description of each parameter follows:
6055%
6056% o image_info: the image info..
6057%
6058% o argc: Specifies a pointer to an integer describing the number of
6059% elements in the argument vector.
6060%
6061% o argv: Specifies a pointer to a text array containing the command line
6062% arguments.
6063%
6064% o exception: return any errors or warnings in this structure.
6065%
6066*/
6067WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6068 const int argc,const char **argv,ExceptionInfo *exception)
6069{
6070 const char
6071 *option;
6072
6073 GeometryInfo
6074 geometry_info;
6075
cristybb503372010-05-27 20:51:26 +00006076 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006077 count;
6078
cristybb503372010-05-27 20:51:26 +00006079 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006080 i;
6081
6082 /*
6083 Initialize method variables.
6084 */
6085 assert(image_info != (ImageInfo *) NULL);
6086 assert(image_info->signature == MagickSignature);
6087 if (image_info->debug != MagickFalse)
6088 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6089 image_info->filename);
6090 if (argc < 0)
6091 return(MagickTrue);
6092 /*
6093 Set the image settings.
6094 */
cristybb503372010-05-27 20:51:26 +00006095 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006096 {
6097 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006098 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006099 continue;
cristy042ee782011-04-22 18:48:30 +00006100 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006101 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006102 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006103 break;
6104 switch (*(option+1))
6105 {
6106 case 'a':
6107 {
6108 if (LocaleCompare("adjoin",option+1) == 0)
6109 {
6110 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6111 break;
6112 }
6113 if (LocaleCompare("antialias",option+1) == 0)
6114 {
6115 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6116 break;
6117 }
6118 if (LocaleCompare("attenuate",option+1) == 0)
6119 {
6120 if (*option == '+')
6121 {
6122 (void) DeleteImageOption(image_info,option+1);
6123 break;
6124 }
6125 (void) SetImageOption(image_info,option+1,argv[i+1]);
6126 break;
6127 }
6128 if (LocaleCompare("authenticate",option+1) == 0)
6129 {
6130 if (*option == '+')
6131 (void) CloneString(&image_info->authenticate,(char *) NULL);
6132 else
6133 (void) CloneString(&image_info->authenticate,argv[i+1]);
6134 break;
6135 }
6136 break;
6137 }
6138 case 'b':
6139 {
6140 if (LocaleCompare("background",option+1) == 0)
6141 {
6142 if (*option == '+')
6143 {
6144 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006145 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006146 &image_info->background_color,exception);
6147 break;
6148 }
6149 (void) SetImageOption(image_info,option+1,argv[i+1]);
6150 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6151 exception);
6152 break;
6153 }
6154 if (LocaleCompare("bias",option+1) == 0)
6155 {
6156 if (*option == '+')
6157 {
6158 (void) SetImageOption(image_info,option+1,"0.0");
6159 break;
6160 }
6161 (void) SetImageOption(image_info,option+1,argv[i+1]);
6162 break;
6163 }
6164 if (LocaleCompare("black-point-compensation",option+1) == 0)
6165 {
6166 if (*option == '+')
6167 {
6168 (void) SetImageOption(image_info,option+1,"false");
6169 break;
6170 }
6171 (void) SetImageOption(image_info,option+1,"true");
6172 break;
6173 }
6174 if (LocaleCompare("blue-primary",option+1) == 0)
6175 {
6176 if (*option == '+')
6177 {
6178 (void) SetImageOption(image_info,option+1,"0.0");
6179 break;
6180 }
6181 (void) SetImageOption(image_info,option+1,argv[i+1]);
6182 break;
6183 }
6184 if (LocaleCompare("bordercolor",option+1) == 0)
6185 {
6186 if (*option == '+')
6187 {
6188 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006189 (void) QueryColorDatabase(MogrifyBorderColor,
6190 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006191 break;
6192 }
6193 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6194 exception);
6195 (void) SetImageOption(image_info,option+1,argv[i+1]);
6196 break;
6197 }
6198 if (LocaleCompare("box",option+1) == 0)
6199 {
6200 if (*option == '+')
6201 {
6202 (void) SetImageOption(image_info,"undercolor","none");
6203 break;
6204 }
6205 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6206 break;
6207 }
6208 break;
6209 }
6210 case 'c':
6211 {
6212 if (LocaleCompare("cache",option+1) == 0)
6213 {
6214 MagickSizeType
6215 limit;
6216
6217 limit=MagickResourceInfinity;
6218 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006219 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006220 (void) SetMagickResourceLimit(MemoryResource,limit);
6221 (void) SetMagickResourceLimit(MapResource,2*limit);
6222 break;
6223 }
6224 if (LocaleCompare("caption",option+1) == 0)
6225 {
6226 if (*option == '+')
6227 {
6228 (void) DeleteImageOption(image_info,option+1);
6229 break;
6230 }
6231 (void) SetImageOption(image_info,option+1,argv[i+1]);
6232 break;
6233 }
6234 if (LocaleCompare("channel",option+1) == 0)
6235 {
6236 if (*option == '+')
6237 {
6238 image_info->channel=DefaultChannels;
6239 break;
6240 }
6241 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6242 break;
6243 }
6244 if (LocaleCompare("colors",option+1) == 0)
6245 {
cristye27293e2009-12-18 02:53:20 +00006246 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006247 break;
6248 }
6249 if (LocaleCompare("colorspace",option+1) == 0)
6250 {
6251 if (*option == '+')
6252 {
6253 image_info->colorspace=UndefinedColorspace;
6254 (void) SetImageOption(image_info,option+1,"undefined");
6255 break;
6256 }
cristy042ee782011-04-22 18:48:30 +00006257 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006258 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6259 (void) SetImageOption(image_info,option+1,argv[i+1]);
6260 break;
6261 }
cristy3ed852e2009-09-05 21:47:34 +00006262 if (LocaleCompare("comment",option+1) == 0)
6263 {
6264 if (*option == '+')
6265 {
6266 (void) DeleteImageOption(image_info,option+1);
6267 break;
6268 }
6269 (void) SetImageOption(image_info,option+1,argv[i+1]);
6270 break;
6271 }
6272 if (LocaleCompare("compose",option+1) == 0)
6273 {
6274 if (*option == '+')
6275 {
6276 (void) SetImageOption(image_info,option+1,"undefined");
6277 break;
6278 }
6279 (void) SetImageOption(image_info,option+1,argv[i+1]);
6280 break;
6281 }
6282 if (LocaleCompare("compress",option+1) == 0)
6283 {
6284 if (*option == '+')
6285 {
6286 image_info->compression=UndefinedCompression;
6287 (void) SetImageOption(image_info,option+1,"undefined");
6288 break;
6289 }
cristy042ee782011-04-22 18:48:30 +00006290 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006291 MagickCompressOptions,MagickFalse,argv[i+1]);
6292 (void) SetImageOption(image_info,option+1,argv[i+1]);
6293 break;
6294 }
6295 break;
6296 }
6297 case 'd':
6298 {
6299 if (LocaleCompare("debug",option+1) == 0)
6300 {
6301 if (*option == '+')
6302 (void) SetLogEventMask("none");
6303 else
6304 (void) SetLogEventMask(argv[i+1]);
6305 image_info->debug=IsEventLogging();
6306 break;
6307 }
6308 if (LocaleCompare("define",option+1) == 0)
6309 {
6310 if (*option == '+')
6311 {
6312 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6313 (void) DeleteImageRegistry(argv[i+1]+9);
6314 else
6315 (void) DeleteImageOption(image_info,argv[i+1]);
6316 break;
6317 }
6318 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6319 {
6320 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6321 exception);
6322 break;
6323 }
6324 (void) DefineImageOption(image_info,argv[i+1]);
6325 break;
6326 }
6327 if (LocaleCompare("delay",option+1) == 0)
6328 {
6329 if (*option == '+')
6330 {
6331 (void) SetImageOption(image_info,option+1,"0");
6332 break;
6333 }
6334 (void) SetImageOption(image_info,option+1,argv[i+1]);
6335 break;
6336 }
6337 if (LocaleCompare("density",option+1) == 0)
6338 {
6339 /*
6340 Set image density.
6341 */
6342 if (*option == '+')
6343 {
6344 if (image_info->density != (char *) NULL)
6345 image_info->density=DestroyString(image_info->density);
6346 (void) SetImageOption(image_info,option+1,"72");
6347 break;
6348 }
6349 (void) CloneString(&image_info->density,argv[i+1]);
6350 (void) SetImageOption(image_info,option+1,argv[i+1]);
6351 break;
6352 }
6353 if (LocaleCompare("depth",option+1) == 0)
6354 {
6355 if (*option == '+')
6356 {
6357 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6358 break;
6359 }
cristye27293e2009-12-18 02:53:20 +00006360 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006361 break;
6362 }
cristyc9b12952010-03-28 01:12:28 +00006363 if (LocaleCompare("direction",option+1) == 0)
6364 {
6365 if (*option == '+')
6366 {
6367 (void) SetImageOption(image_info,option+1,"undefined");
6368 break;
6369 }
6370 (void) SetImageOption(image_info,option+1,argv[i+1]);
6371 break;
6372 }
cristy3ed852e2009-09-05 21:47:34 +00006373 if (LocaleCompare("display",option+1) == 0)
6374 {
6375 if (*option == '+')
6376 {
6377 if (image_info->server_name != (char *) NULL)
6378 image_info->server_name=DestroyString(
6379 image_info->server_name);
6380 break;
6381 }
6382 (void) CloneString(&image_info->server_name,argv[i+1]);
6383 break;
6384 }
6385 if (LocaleCompare("dispose",option+1) == 0)
6386 {
6387 if (*option == '+')
6388 {
6389 (void) SetImageOption(image_info,option+1,"undefined");
6390 break;
6391 }
6392 (void) SetImageOption(image_info,option+1,argv[i+1]);
6393 break;
6394 }
6395 if (LocaleCompare("dither",option+1) == 0)
6396 {
6397 if (*option == '+')
6398 {
6399 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006400 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006401 break;
6402 }
6403 (void) SetImageOption(image_info,option+1,argv[i+1]);
6404 image_info->dither=MagickTrue;
6405 break;
6406 }
6407 break;
6408 }
6409 case 'e':
6410 {
6411 if (LocaleCompare("encoding",option+1) == 0)
6412 {
6413 if (*option == '+')
6414 {
6415 (void) SetImageOption(image_info,option+1,"undefined");
6416 break;
6417 }
6418 (void) SetImageOption(image_info,option+1,argv[i+1]);
6419 break;
6420 }
6421 if (LocaleCompare("endian",option+1) == 0)
6422 {
6423 if (*option == '+')
6424 {
6425 image_info->endian=UndefinedEndian;
6426 (void) SetImageOption(image_info,option+1,"undefined");
6427 break;
6428 }
cristy042ee782011-04-22 18:48:30 +00006429 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006430 MagickEndianOptions,MagickFalse,argv[i+1]);
6431 (void) SetImageOption(image_info,option+1,argv[i+1]);
6432 break;
6433 }
6434 if (LocaleCompare("extract",option+1) == 0)
6435 {
6436 /*
6437 Set image extract geometry.
6438 */
6439 if (*option == '+')
6440 {
6441 if (image_info->extract != (char *) NULL)
6442 image_info->extract=DestroyString(image_info->extract);
6443 break;
6444 }
6445 (void) CloneString(&image_info->extract,argv[i+1]);
6446 break;
6447 }
6448 break;
6449 }
6450 case 'f':
6451 {
6452 if (LocaleCompare("fill",option+1) == 0)
6453 {
6454 if (*option == '+')
6455 {
6456 (void) SetImageOption(image_info,option+1,"none");
6457 break;
6458 }
6459 (void) SetImageOption(image_info,option+1,argv[i+1]);
6460 break;
6461 }
6462 if (LocaleCompare("filter",option+1) == 0)
6463 {
6464 if (*option == '+')
6465 {
6466 (void) SetImageOption(image_info,option+1,"undefined");
6467 break;
6468 }
6469 (void) SetImageOption(image_info,option+1,argv[i+1]);
6470 break;
6471 }
6472 if (LocaleCompare("font",option+1) == 0)
6473 {
6474 if (*option == '+')
6475 {
6476 if (image_info->font != (char *) NULL)
6477 image_info->font=DestroyString(image_info->font);
6478 break;
6479 }
6480 (void) CloneString(&image_info->font,argv[i+1]);
6481 break;
6482 }
6483 if (LocaleCompare("format",option+1) == 0)
6484 {
6485 register const char
6486 *q;
6487
6488 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006489 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006490 image_info->ping=MagickFalse;
6491 (void) SetImageOption(image_info,option+1,argv[i+1]);
6492 break;
6493 }
6494 if (LocaleCompare("fuzz",option+1) == 0)
6495 {
6496 if (*option == '+')
6497 {
6498 image_info->fuzz=0.0;
6499 (void) SetImageOption(image_info,option+1,"0");
6500 break;
6501 }
cristyf2f27272009-12-17 14:48:46 +00006502 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006503 1.0);
6504 (void) SetImageOption(image_info,option+1,argv[i+1]);
6505 break;
6506 }
6507 break;
6508 }
6509 case 'g':
6510 {
6511 if (LocaleCompare("gravity",option+1) == 0)
6512 {
6513 if (*option == '+')
6514 {
6515 (void) SetImageOption(image_info,option+1,"undefined");
6516 break;
6517 }
6518 (void) SetImageOption(image_info,option+1,argv[i+1]);
6519 break;
6520 }
6521 if (LocaleCompare("green-primary",option+1) == 0)
6522 {
6523 if (*option == '+')
6524 {
6525 (void) SetImageOption(image_info,option+1,"0.0");
6526 break;
6527 }
6528 (void) SetImageOption(image_info,option+1,argv[i+1]);
6529 break;
6530 }
6531 break;
6532 }
6533 case 'i':
6534 {
6535 if (LocaleCompare("intent",option+1) == 0)
6536 {
6537 if (*option == '+')
6538 {
6539 (void) SetImageOption(image_info,option+1,"undefined");
6540 break;
6541 }
6542 (void) SetImageOption(image_info,option+1,argv[i+1]);
6543 break;
6544 }
6545 if (LocaleCompare("interlace",option+1) == 0)
6546 {
6547 if (*option == '+')
6548 {
6549 image_info->interlace=UndefinedInterlace;
6550 (void) SetImageOption(image_info,option+1,"undefined");
6551 break;
6552 }
cristy042ee782011-04-22 18:48:30 +00006553 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006554 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6555 (void) SetImageOption(image_info,option+1,argv[i+1]);
6556 break;
6557 }
cristyb32b90a2009-09-07 21:45:48 +00006558 if (LocaleCompare("interline-spacing",option+1) == 0)
6559 {
6560 if (*option == '+')
6561 {
6562 (void) SetImageOption(image_info,option+1,"undefined");
6563 break;
6564 }
6565 (void) SetImageOption(image_info,option+1,argv[i+1]);
6566 break;
6567 }
cristy3ed852e2009-09-05 21:47:34 +00006568 if (LocaleCompare("interpolate",option+1) == 0)
6569 {
6570 if (*option == '+')
6571 {
6572 (void) SetImageOption(image_info,option+1,"undefined");
6573 break;
6574 }
6575 (void) SetImageOption(image_info,option+1,argv[i+1]);
6576 break;
6577 }
6578 if (LocaleCompare("interword-spacing",option+1) == 0)
6579 {
6580 if (*option == '+')
6581 {
6582 (void) SetImageOption(image_info,option+1,"undefined");
6583 break;
6584 }
6585 (void) SetImageOption(image_info,option+1,argv[i+1]);
6586 break;
6587 }
6588 break;
6589 }
6590 case 'k':
6591 {
6592 if (LocaleCompare("kerning",option+1) == 0)
6593 {
6594 if (*option == '+')
6595 {
6596 (void) SetImageOption(image_info,option+1,"undefined");
6597 break;
6598 }
6599 (void) SetImageOption(image_info,option+1,argv[i+1]);
6600 break;
6601 }
6602 break;
6603 }
6604 case 'l':
6605 {
6606 if (LocaleCompare("label",option+1) == 0)
6607 {
6608 if (*option == '+')
6609 {
6610 (void) DeleteImageOption(image_info,option+1);
6611 break;
6612 }
6613 (void) SetImageOption(image_info,option+1,argv[i+1]);
6614 break;
6615 }
6616 if (LocaleCompare("limit",option+1) == 0)
6617 {
6618 MagickSizeType
6619 limit;
6620
6621 ResourceType
6622 type;
6623
6624 if (*option == '+')
6625 break;
cristy042ee782011-04-22 18:48:30 +00006626 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006627 MagickFalse,argv[i+1]);
6628 limit=MagickResourceInfinity;
6629 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006630 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006631 (void) SetMagickResourceLimit(type,limit);
6632 break;
6633 }
6634 if (LocaleCompare("list",option+1) == 0)
6635 {
cristybb503372010-05-27 20:51:26 +00006636 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006637 list;
6638
6639 /*
6640 Display configuration list.
6641 */
cristy042ee782011-04-22 18:48:30 +00006642 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006643 switch (list)
6644 {
6645 case MagickCoderOptions:
6646 {
6647 (void) ListCoderInfo((FILE *) NULL,exception);
6648 break;
6649 }
6650 case MagickColorOptions:
6651 {
6652 (void) ListColorInfo((FILE *) NULL,exception);
6653 break;
6654 }
6655 case MagickConfigureOptions:
6656 {
6657 (void) ListConfigureInfo((FILE *) NULL,exception);
6658 break;
6659 }
6660 case MagickDelegateOptions:
6661 {
6662 (void) ListDelegateInfo((FILE *) NULL,exception);
6663 break;
6664 }
6665 case MagickFontOptions:
6666 {
6667 (void) ListTypeInfo((FILE *) NULL,exception);
6668 break;
6669 }
6670 case MagickFormatOptions:
6671 {
6672 (void) ListMagickInfo((FILE *) NULL,exception);
6673 break;
6674 }
6675 case MagickLocaleOptions:
6676 {
6677 (void) ListLocaleInfo((FILE *) NULL,exception);
6678 break;
6679 }
6680 case MagickLogOptions:
6681 {
6682 (void) ListLogInfo((FILE *) NULL,exception);
6683 break;
6684 }
6685 case MagickMagicOptions:
6686 {
6687 (void) ListMagicInfo((FILE *) NULL,exception);
6688 break;
6689 }
6690 case MagickMimeOptions:
6691 {
6692 (void) ListMimeInfo((FILE *) NULL,exception);
6693 break;
6694 }
6695 case MagickModuleOptions:
6696 {
6697 (void) ListModuleInfo((FILE *) NULL,exception);
6698 break;
6699 }
6700 case MagickPolicyOptions:
6701 {
6702 (void) ListPolicyInfo((FILE *) NULL,exception);
6703 break;
6704 }
6705 case MagickResourceOptions:
6706 {
6707 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6708 break;
6709 }
6710 case MagickThresholdOptions:
6711 {
6712 (void) ListThresholdMaps((FILE *) NULL,exception);
6713 break;
6714 }
6715 default:
6716 {
cristy042ee782011-04-22 18:48:30 +00006717 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006718 exception);
6719 break;
6720 }
6721 }
cristyaeb2cbc2010-05-07 13:28:58 +00006722 break;
cristy3ed852e2009-09-05 21:47:34 +00006723 }
6724 if (LocaleCompare("log",option+1) == 0)
6725 {
6726 if (*option == '+')
6727 break;
6728 (void) SetLogFormat(argv[i+1]);
6729 break;
6730 }
6731 if (LocaleCompare("loop",option+1) == 0)
6732 {
6733 if (*option == '+')
6734 {
6735 (void) SetImageOption(image_info,option+1,"0");
6736 break;
6737 }
6738 (void) SetImageOption(image_info,option+1,argv[i+1]);
6739 break;
6740 }
6741 break;
6742 }
6743 case 'm':
6744 {
6745 if (LocaleCompare("matte",option+1) == 0)
6746 {
6747 if (*option == '+')
6748 {
6749 (void) SetImageOption(image_info,option+1,"false");
6750 break;
6751 }
6752 (void) SetImageOption(image_info,option+1,"true");
6753 break;
6754 }
6755 if (LocaleCompare("mattecolor",option+1) == 0)
6756 {
6757 if (*option == '+')
6758 {
6759 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006760 (void) QueryColorDatabase(MogrifyMatteColor,
6761 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006762 break;
6763 }
6764 (void) SetImageOption(image_info,option+1,argv[i+1]);
6765 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6766 exception);
6767 break;
6768 }
6769 if (LocaleCompare("monitor",option+1) == 0)
6770 {
6771 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6772 (void *) NULL);
6773 break;
6774 }
6775 if (LocaleCompare("monochrome",option+1) == 0)
6776 {
6777 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6778 break;
6779 }
6780 break;
6781 }
6782 case 'o':
6783 {
6784 if (LocaleCompare("orient",option+1) == 0)
6785 {
6786 if (*option == '+')
6787 {
6788 image_info->orientation=UndefinedOrientation;
6789 (void) SetImageOption(image_info,option+1,"undefined");
6790 break;
6791 }
cristy042ee782011-04-22 18:48:30 +00006792 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006793 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006794 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006795 break;
6796 }
6797 }
6798 case 'p':
6799 {
6800 if (LocaleCompare("page",option+1) == 0)
6801 {
6802 char
6803 *canonical_page,
6804 page[MaxTextExtent];
6805
6806 const char
6807 *image_option;
6808
6809 MagickStatusType
6810 flags;
6811
6812 RectangleInfo
6813 geometry;
6814
6815 if (*option == '+')
6816 {
6817 (void) DeleteImageOption(image_info,option+1);
6818 (void) CloneString(&image_info->page,(char *) NULL);
6819 break;
6820 }
6821 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6822 image_option=GetImageOption(image_info,"page");
6823 if (image_option != (const char *) NULL)
6824 flags=ParseAbsoluteGeometry(image_option,&geometry);
6825 canonical_page=GetPageGeometry(argv[i+1]);
6826 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6827 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006828 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006829 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006830 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006831 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006832 (unsigned long) geometry.width,(unsigned long) geometry.height,
6833 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006834 (void) SetImageOption(image_info,option+1,page);
6835 (void) CloneString(&image_info->page,page);
6836 break;
6837 }
6838 if (LocaleCompare("pen",option+1) == 0)
6839 {
6840 if (*option == '+')
6841 {
6842 (void) SetImageOption(image_info,option+1,"none");
6843 break;
6844 }
6845 (void) SetImageOption(image_info,option+1,argv[i+1]);
6846 break;
6847 }
6848 if (LocaleCompare("ping",option+1) == 0)
6849 {
6850 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6851 break;
6852 }
6853 if (LocaleCompare("pointsize",option+1) == 0)
6854 {
6855 if (*option == '+')
6856 geometry_info.rho=0.0;
6857 else
6858 (void) ParseGeometry(argv[i+1],&geometry_info);
6859 image_info->pointsize=geometry_info.rho;
6860 break;
6861 }
cristye7f51092010-01-17 00:39:37 +00006862 if (LocaleCompare("precision",option+1) == 0)
6863 {
cristybf2766a2010-01-17 03:33:23 +00006864 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006865 break;
6866 }
cristy3ed852e2009-09-05 21:47:34 +00006867 if (LocaleCompare("preview",option+1) == 0)
6868 {
6869 /*
6870 Preview image.
6871 */
6872 if (*option == '+')
6873 {
6874 image_info->preview_type=UndefinedPreview;
6875 break;
6876 }
cristy042ee782011-04-22 18:48:30 +00006877 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006878 MagickPreviewOptions,MagickFalse,argv[i+1]);
6879 break;
6880 }
6881 break;
6882 }
6883 case 'q':
6884 {
6885 if (LocaleCompare("quality",option+1) == 0)
6886 {
6887 /*
6888 Set image compression quality.
6889 */
6890 if (*option == '+')
6891 {
6892 image_info->quality=UndefinedCompressionQuality;
6893 (void) SetImageOption(image_info,option+1,"0");
6894 break;
6895 }
cristye27293e2009-12-18 02:53:20 +00006896 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006897 (void) SetImageOption(image_info,option+1,argv[i+1]);
6898 break;
6899 }
6900 if (LocaleCompare("quiet",option+1) == 0)
6901 {
6902 static WarningHandler
6903 warning_handler = (WarningHandler) NULL;
6904
6905 if (*option == '+')
6906 {
6907 /*
6908 Restore error or warning messages.
6909 */
6910 warning_handler=SetWarningHandler(warning_handler);
6911 break;
6912 }
6913 /*
6914 Suppress error or warning messages.
6915 */
6916 warning_handler=SetWarningHandler((WarningHandler) NULL);
6917 break;
6918 }
6919 break;
6920 }
6921 case 'r':
6922 {
6923 if (LocaleCompare("red-primary",option+1) == 0)
6924 {
6925 if (*option == '+')
6926 {
6927 (void) SetImageOption(image_info,option+1,"0.0");
6928 break;
6929 }
6930 (void) SetImageOption(image_info,option+1,argv[i+1]);
6931 break;
6932 }
6933 break;
6934 }
6935 case 's':
6936 {
6937 if (LocaleCompare("sampling-factor",option+1) == 0)
6938 {
6939 /*
6940 Set image sampling factor.
6941 */
6942 if (*option == '+')
6943 {
6944 if (image_info->sampling_factor != (char *) NULL)
6945 image_info->sampling_factor=DestroyString(
6946 image_info->sampling_factor);
6947 break;
6948 }
6949 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6950 break;
6951 }
6952 if (LocaleCompare("scene",option+1) == 0)
6953 {
6954 /*
6955 Set image scene.
6956 */
6957 if (*option == '+')
6958 {
6959 image_info->scene=0;
6960 (void) SetImageOption(image_info,option+1,"0");
6961 break;
6962 }
cristye27293e2009-12-18 02:53:20 +00006963 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006964 (void) SetImageOption(image_info,option+1,argv[i+1]);
6965 break;
6966 }
6967 if (LocaleCompare("seed",option+1) == 0)
6968 {
cristybb503372010-05-27 20:51:26 +00006969 size_t
cristy3ed852e2009-09-05 21:47:34 +00006970 seed;
6971
6972 if (*option == '+')
6973 {
cristybb503372010-05-27 20:51:26 +00006974 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006975 SeedPseudoRandomGenerator(seed);
6976 break;
6977 }
cristye27293e2009-12-18 02:53:20 +00006978 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006979 SeedPseudoRandomGenerator(seed);
6980 break;
6981 }
6982 if (LocaleCompare("size",option+1) == 0)
6983 {
6984 if (*option == '+')
6985 {
6986 if (image_info->size != (char *) NULL)
6987 image_info->size=DestroyString(image_info->size);
6988 break;
6989 }
6990 (void) CloneString(&image_info->size,argv[i+1]);
6991 break;
6992 }
6993 if (LocaleCompare("stroke",option+1) == 0)
6994 {
6995 if (*option == '+')
6996 {
6997 (void) SetImageOption(image_info,option+1,"none");
6998 break;
6999 }
7000 (void) SetImageOption(image_info,option+1,argv[i+1]);
7001 break;
7002 }
7003 if (LocaleCompare("strokewidth",option+1) == 0)
7004 {
7005 if (*option == '+')
7006 {
7007 (void) SetImageOption(image_info,option+1,"0");
7008 break;
7009 }
7010 (void) SetImageOption(image_info,option+1,argv[i+1]);
7011 break;
7012 }
cristyd9a29192010-10-16 16:49:53 +00007013 if (LocaleCompare("synchronize",option+1) == 0)
7014 {
7015 if (*option == '+')
7016 {
7017 image_info->synchronize=MagickFalse;
7018 break;
7019 }
7020 image_info->synchronize=MagickTrue;
7021 break;
7022 }
cristy3ed852e2009-09-05 21:47:34 +00007023 break;
7024 }
7025 case 't':
7026 {
7027 if (LocaleCompare("taint",option+1) == 0)
7028 {
7029 if (*option == '+')
7030 {
7031 (void) SetImageOption(image_info,option+1,"false");
7032 break;
7033 }
7034 (void) SetImageOption(image_info,option+1,"true");
7035 break;
7036 }
7037 if (LocaleCompare("texture",option+1) == 0)
7038 {
7039 if (*option == '+')
7040 {
7041 if (image_info->texture != (char *) NULL)
7042 image_info->texture=DestroyString(image_info->texture);
7043 break;
7044 }
7045 (void) CloneString(&image_info->texture,argv[i+1]);
7046 break;
7047 }
7048 if (LocaleCompare("tile-offset",option+1) == 0)
7049 {
7050 if (*option == '+')
7051 {
7052 (void) SetImageOption(image_info,option+1,"0");
7053 break;
7054 }
7055 (void) SetImageOption(image_info,option+1,argv[i+1]);
7056 break;
7057 }
7058 if (LocaleCompare("transparent-color",option+1) == 0)
7059 {
7060 if (*option == '+')
7061 {
7062 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7063 (void) SetImageOption(image_info,option+1,"none");
7064 break;
7065 }
7066 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7067 exception);
7068 (void) SetImageOption(image_info,option+1,argv[i+1]);
7069 break;
7070 }
7071 if (LocaleCompare("type",option+1) == 0)
7072 {
7073 if (*option == '+')
7074 {
cristy5f1c1ff2010-12-23 21:38:06 +00007075 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007076 (void) SetImageOption(image_info,option+1,"undefined");
7077 break;
7078 }
cristy042ee782011-04-22 18:48:30 +00007079 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007080 MagickFalse,argv[i+1]);
7081 (void) SetImageOption(image_info,option+1,argv[i+1]);
7082 break;
7083 }
7084 break;
7085 }
7086 case 'u':
7087 {
7088 if (LocaleCompare("undercolor",option+1) == 0)
7089 {
7090 if (*option == '+')
7091 {
7092 (void) DeleteImageOption(image_info,option+1);
7093 break;
7094 }
7095 (void) SetImageOption(image_info,option+1,argv[i+1]);
7096 break;
7097 }
7098 if (LocaleCompare("units",option+1) == 0)
7099 {
7100 if (*option == '+')
7101 {
7102 image_info->units=UndefinedResolution;
7103 (void) SetImageOption(image_info,option+1,"undefined");
7104 break;
7105 }
cristy042ee782011-04-22 18:48:30 +00007106 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007107 MagickResolutionOptions,MagickFalse,argv[i+1]);
7108 (void) SetImageOption(image_info,option+1,argv[i+1]);
7109 break;
7110 }
7111 break;
7112 }
7113 case 'v':
7114 {
7115 if (LocaleCompare("verbose",option+1) == 0)
7116 {
7117 if (*option == '+')
7118 {
7119 image_info->verbose=MagickFalse;
7120 break;
7121 }
7122 image_info->verbose=MagickTrue;
7123 image_info->ping=MagickFalse;
7124 break;
7125 }
7126 if (LocaleCompare("view",option+1) == 0)
7127 {
7128 if (*option == '+')
7129 {
7130 if (image_info->view != (char *) NULL)
7131 image_info->view=DestroyString(image_info->view);
7132 break;
7133 }
7134 (void) CloneString(&image_info->view,argv[i+1]);
7135 break;
7136 }
7137 if (LocaleCompare("virtual-pixel",option+1) == 0)
7138 {
7139 if (*option == '+')
7140 {
7141 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7142 (void) SetImageOption(image_info,option+1,"undefined");
7143 break;
7144 }
7145 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007146 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007147 argv[i+1]);
7148 (void) SetImageOption(image_info,option+1,argv[i+1]);
7149 break;
7150 }
7151 break;
7152 }
7153 case 'w':
7154 {
7155 if (LocaleCompare("white-point",option+1) == 0)
7156 {
7157 if (*option == '+')
7158 {
7159 (void) SetImageOption(image_info,option+1,"0.0");
7160 break;
7161 }
7162 (void) SetImageOption(image_info,option+1,argv[i+1]);
7163 break;
7164 }
7165 break;
7166 }
7167 default:
7168 break;
7169 }
7170 i+=count;
7171 }
7172 return(MagickTrue);
7173}
7174
7175/*
7176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7177% %
7178% %
7179% %
7180+ M o g r i f y I m a g e L i s t %
7181% %
7182% %
7183% %
7184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7185%
7186% MogrifyImageList() applies any command line options that might affect the
7187% entire image list (e.g. -append, -coalesce, etc.).
7188%
7189% The format of the MogrifyImage method is:
7190%
7191% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7192% const char **argv,Image **images,ExceptionInfo *exception)
7193%
7194% A description of each parameter follows:
7195%
7196% o image_info: the image info..
7197%
7198% o argc: Specifies a pointer to an integer describing the number of
7199% elements in the argument vector.
7200%
7201% o argv: Specifies a pointer to a text array containing the command line
7202% arguments.
7203%
anthonye9c27192011-03-27 08:07:06 +00007204% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007205%
7206% o exception: return any errors or warnings in this structure.
7207%
7208*/
7209WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7210 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7211{
cristy3ed852e2009-09-05 21:47:34 +00007212 const char
7213 *option;
7214
cristy6b3da3a2010-06-20 02:21:46 +00007215 ImageInfo
7216 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007217
7218 MagickStatusType
7219 status;
7220
7221 QuantizeInfo
7222 *quantize_info;
7223
cristybb503372010-05-27 20:51:26 +00007224 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007225 i;
7226
cristy6b3da3a2010-06-20 02:21:46 +00007227 ssize_t
7228 count,
7229 index;
7230
cristy3ed852e2009-09-05 21:47:34 +00007231 /*
7232 Apply options to the image list.
7233 */
7234 assert(image_info != (ImageInfo *) NULL);
7235 assert(image_info->signature == MagickSignature);
7236 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007237 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007238 assert((*images)->signature == MagickSignature);
7239 if ((*images)->debug != MagickFalse)
7240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7241 (*images)->filename);
7242 if ((argc <= 0) || (*argv == (char *) NULL))
7243 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007244 mogrify_info=CloneImageInfo(image_info);
7245 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007246 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007247 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007248 {
cristy74fe8f12009-10-03 19:09:01 +00007249 if (*images == (Image *) NULL)
7250 break;
cristy3ed852e2009-09-05 21:47:34 +00007251 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007252 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007253 continue;
cristy042ee782011-04-22 18:48:30 +00007254 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007255 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007256 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007257 break;
cristy6b3da3a2010-06-20 02:21:46 +00007258 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007259 switch (*(option+1))
7260 {
7261 case 'a':
7262 {
7263 if (LocaleCompare("affinity",option+1) == 0)
7264 {
cristy6b3da3a2010-06-20 02:21:46 +00007265 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007266 if (*option == '+')
7267 {
7268 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7269 InheritException(exception,&(*images)->exception);
7270 break;
7271 }
7272 i++;
7273 break;
7274 }
7275 if (LocaleCompare("append",option+1) == 0)
7276 {
7277 Image
7278 *append_image;
7279
cristy6b3da3a2010-06-20 02:21:46 +00007280 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007281 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7282 MagickFalse,exception);
7283 if (append_image == (Image *) NULL)
7284 {
7285 status=MagickFalse;
7286 break;
7287 }
7288 *images=DestroyImageList(*images);
7289 *images=append_image;
7290 break;
7291 }
7292 if (LocaleCompare("average",option+1) == 0)
7293 {
7294 Image
7295 *average_image;
7296
cristyd18ae7c2010-03-07 17:39:52 +00007297 /*
7298 Average an image sequence (deprecated).
7299 */
cristy6b3da3a2010-06-20 02:21:46 +00007300 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007301 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7302 exception);
cristy3ed852e2009-09-05 21:47:34 +00007303 if (average_image == (Image *) NULL)
7304 {
7305 status=MagickFalse;
7306 break;
7307 }
7308 *images=DestroyImageList(*images);
7309 *images=average_image;
7310 break;
7311 }
7312 break;
7313 }
7314 case 'c':
7315 {
7316 if (LocaleCompare("channel",option+1) == 0)
7317 {
cristyf4ad9df2011-07-08 16:49:03 +00007318 ChannelType
7319 channel;
7320
cristy3ed852e2009-09-05 21:47:34 +00007321 if (*option == '+')
7322 {
7323 channel=DefaultChannels;
7324 break;
7325 }
7326 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007327 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007328 break;
7329 }
7330 if (LocaleCompare("clut",option+1) == 0)
7331 {
7332 Image
7333 *clut_image,
7334 *image;
7335
cristy6b3da3a2010-06-20 02:21:46 +00007336 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007337 image=RemoveFirstImageFromList(images);
7338 clut_image=RemoveFirstImageFromList(images);
7339 if (clut_image == (Image *) NULL)
7340 {
7341 status=MagickFalse;
7342 break;
7343 }
cristy444eda62011-08-10 02:07:46 +00007344 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007345 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007346 *images=DestroyImageList(*images);
7347 *images=image;
7348 break;
7349 }
7350 if (LocaleCompare("coalesce",option+1) == 0)
7351 {
7352 Image
7353 *coalesce_image;
7354
cristy6b3da3a2010-06-20 02:21:46 +00007355 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007356 coalesce_image=CoalesceImages(*images,exception);
7357 if (coalesce_image == (Image *) NULL)
7358 {
7359 status=MagickFalse;
7360 break;
7361 }
7362 *images=DestroyImageList(*images);
7363 *images=coalesce_image;
7364 break;
7365 }
7366 if (LocaleCompare("combine",option+1) == 0)
7367 {
7368 Image
7369 *combine_image;
7370
cristy6b3da3a2010-06-20 02:21:46 +00007371 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007372 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007373 if (combine_image == (Image *) NULL)
7374 {
7375 status=MagickFalse;
7376 break;
7377 }
7378 *images=DestroyImageList(*images);
7379 *images=combine_image;
7380 break;
7381 }
7382 if (LocaleCompare("composite",option+1) == 0)
7383 {
7384 Image
7385 *mask_image,
7386 *composite_image,
7387 *image;
7388
7389 RectangleInfo
7390 geometry;
7391
cristy6b3da3a2010-06-20 02:21:46 +00007392 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007393 image=RemoveFirstImageFromList(images);
7394 composite_image=RemoveFirstImageFromList(images);
7395 if (composite_image == (Image *) NULL)
7396 {
7397 status=MagickFalse;
7398 break;
7399 }
7400 (void) TransformImage(&composite_image,(char *) NULL,
7401 composite_image->geometry);
7402 SetGeometry(composite_image,&geometry);
7403 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7404 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7405 &geometry);
7406 mask_image=RemoveFirstImageFromList(images);
7407 if (mask_image != (Image *) NULL)
7408 {
7409 if ((image->compose == DisplaceCompositeOp) ||
7410 (image->compose == DistortCompositeOp))
7411 {
7412 /*
7413 Merge Y displacement into X displacement image.
7414 */
7415 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7416 mask_image,0,0);
7417 mask_image=DestroyImage(mask_image);
7418 }
7419 else
7420 {
7421 /*
7422 Set a blending mask for the composition.
7423 */
anthonya129f702011-04-14 01:08:48 +00007424 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007425 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007426 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007427 }
7428 }
cristyf4ad9df2011-07-08 16:49:03 +00007429 (void) CompositeImage(image,image->compose,composite_image,
7430 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007431 if (mask_image != (Image *) NULL)
7432 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007433 composite_image=DestroyImage(composite_image);
7434 InheritException(exception,&image->exception);
7435 *images=DestroyImageList(*images);
7436 *images=image;
7437 break;
7438 }
anthony9f4f0342011-03-28 11:47:22 +00007439#if 0
7440This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007441 if (LocaleCompare("crop",option+1) == 0)
7442 {
7443 MagickStatusType
7444 flags;
7445
7446 RectangleInfo
7447 geometry;
7448
anthonye9c27192011-03-27 08:07:06 +00007449 /*
anthony9f4f0342011-03-28 11:47:22 +00007450 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007451 */
cristy6b3da3a2010-06-20 02:21:46 +00007452 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007453 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7454 if (((geometry.width == 0) && (geometry.height == 0)) ||
7455 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7456 break;
7457 (void) TransformImages(images,argv[i+1],(char *) NULL);
7458 InheritException(exception,&(*images)->exception);
7459 break;
7460 }
anthony9f4f0342011-03-28 11:47:22 +00007461#endif
cristy3ed852e2009-09-05 21:47:34 +00007462 break;
7463 }
7464 case 'd':
7465 {
7466 if (LocaleCompare("deconstruct",option+1) == 0)
7467 {
7468 Image
7469 *deconstruct_image;
7470
cristy6b3da3a2010-06-20 02:21:46 +00007471 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007472 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007473 exception);
cristy3ed852e2009-09-05 21:47:34 +00007474 if (deconstruct_image == (Image *) NULL)
7475 {
7476 status=MagickFalse;
7477 break;
7478 }
7479 *images=DestroyImageList(*images);
7480 *images=deconstruct_image;
7481 break;
7482 }
7483 if (LocaleCompare("delete",option+1) == 0)
7484 {
7485 if (*option == '+')
7486 DeleteImages(images,"-1",exception);
7487 else
7488 DeleteImages(images,argv[i+1],exception);
7489 break;
7490 }
7491 if (LocaleCompare("dither",option+1) == 0)
7492 {
7493 if (*option == '+')
7494 {
7495 quantize_info->dither=MagickFalse;
7496 break;
7497 }
7498 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007499 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007500 MagickDitherOptions,MagickFalse,argv[i+1]);
7501 break;
7502 }
cristyecb10ff2011-03-22 13:14:03 +00007503 if (LocaleCompare("duplicate",option+1) == 0)
7504 {
cristy72988482011-03-29 16:34:38 +00007505 Image
7506 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007507
anthony2b6bcae2011-03-23 13:05:34 +00007508 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007509 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7510 else
7511 {
7512 const char
7513 *p;
7514
anthony2b6bcae2011-03-23 13:05:34 +00007515 size_t
7516 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007517
anthony2b6bcae2011-03-23 13:05:34 +00007518 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007519 p=strchr(argv[i+1],',');
7520 if (p == (const char *) NULL)
7521 duplicate_images=DuplicateImages(*images,number_duplicates,
7522 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007523 else
cristy72988482011-03-29 16:34:38 +00007524 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7525 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007526 }
7527 AppendImageToList(images, duplicate_images);
7528 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007529 break;
7530 }
cristy3ed852e2009-09-05 21:47:34 +00007531 break;
7532 }
cristyd18ae7c2010-03-07 17:39:52 +00007533 case 'e':
7534 {
7535 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7536 {
7537 Image
7538 *evaluate_image;
7539
7540 MagickEvaluateOperator
7541 op;
7542
cristy6b3da3a2010-06-20 02:21:46 +00007543 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007544 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007545 MagickFalse,argv[i+1]);
7546 evaluate_image=EvaluateImages(*images,op,exception);
7547 if (evaluate_image == (Image *) NULL)
7548 {
7549 status=MagickFalse;
7550 break;
7551 }
7552 *images=DestroyImageList(*images);
7553 *images=evaluate_image;
7554 break;
7555 }
7556 break;
7557 }
cristy3ed852e2009-09-05 21:47:34 +00007558 case 'f':
7559 {
cristyf0a247f2009-10-04 00:20:03 +00007560 if (LocaleCompare("fft",option+1) == 0)
7561 {
7562 Image
7563 *fourier_image;
7564
7565 /*
7566 Implements the discrete Fourier transform (DFT).
7567 */
cristy6b3da3a2010-06-20 02:21:46 +00007568 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007569 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7570 MagickTrue : MagickFalse,exception);
7571 if (fourier_image == (Image *) NULL)
7572 break;
7573 *images=DestroyImage(*images);
7574 *images=fourier_image;
7575 break;
7576 }
cristy3ed852e2009-09-05 21:47:34 +00007577 if (LocaleCompare("flatten",option+1) == 0)
7578 {
7579 Image
7580 *flatten_image;
7581
cristy6b3da3a2010-06-20 02:21:46 +00007582 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007583 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7584 if (flatten_image == (Image *) NULL)
7585 break;
7586 *images=DestroyImageList(*images);
7587 *images=flatten_image;
7588 break;
7589 }
7590 if (LocaleCompare("fx",option+1) == 0)
7591 {
7592 Image
7593 *fx_image;
7594
cristy6b3da3a2010-06-20 02:21:46 +00007595 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007596 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007597 if (fx_image == (Image *) NULL)
7598 {
7599 status=MagickFalse;
7600 break;
7601 }
7602 *images=DestroyImageList(*images);
7603 *images=fx_image;
7604 break;
7605 }
7606 break;
7607 }
7608 case 'h':
7609 {
7610 if (LocaleCompare("hald-clut",option+1) == 0)
7611 {
7612 Image
7613 *hald_image,
7614 *image;
7615
cristy6b3da3a2010-06-20 02:21:46 +00007616 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007617 image=RemoveFirstImageFromList(images);
7618 hald_image=RemoveFirstImageFromList(images);
7619 if (hald_image == (Image *) NULL)
7620 {
7621 status=MagickFalse;
7622 break;
7623 }
cristy7c0a0a42011-08-23 17:57:25 +00007624 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007625 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007626 if (*images != (Image *) NULL)
7627 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007628 *images=image;
7629 break;
7630 }
7631 break;
7632 }
7633 case 'i':
7634 {
7635 if (LocaleCompare("ift",option+1) == 0)
7636 {
7637 Image
cristy8587f882009-11-13 20:28:49 +00007638 *fourier_image,
7639 *magnitude_image,
7640 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007641
7642 /*
7643 Implements the inverse fourier discrete Fourier transform (DFT).
7644 */
cristy6b3da3a2010-06-20 02:21:46 +00007645 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007646 magnitude_image=RemoveFirstImageFromList(images);
7647 phase_image=RemoveFirstImageFromList(images);
7648 if (phase_image == (Image *) NULL)
7649 {
7650 status=MagickFalse;
7651 break;
7652 }
7653 fourier_image=InverseFourierTransformImage(magnitude_image,
7654 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007655 if (fourier_image == (Image *) NULL)
7656 break;
cristy0aff6ea2009-11-14 01:40:53 +00007657 if (*images != (Image *) NULL)
7658 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007659 *images=fourier_image;
7660 break;
7661 }
7662 if (LocaleCompare("insert",option+1) == 0)
7663 {
7664 Image
7665 *p,
7666 *q;
7667
7668 index=0;
7669 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007670 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007671 p=RemoveLastImageFromList(images);
7672 if (p == (Image *) NULL)
7673 {
7674 (void) ThrowMagickException(exception,GetMagickModule(),
7675 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7676 status=MagickFalse;
7677 break;
7678 }
7679 q=p;
7680 if (index == 0)
7681 PrependImageToList(images,q);
7682 else
cristybb503372010-05-27 20:51:26 +00007683 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007684 AppendImageToList(images,q);
7685 else
7686 {
7687 q=GetImageFromList(*images,index-1);
7688 if (q == (Image *) NULL)
7689 {
7690 (void) ThrowMagickException(exception,GetMagickModule(),
7691 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7692 status=MagickFalse;
7693 break;
7694 }
7695 InsertImageInList(&q,p);
7696 }
7697 *images=GetFirstImageInList(q);
7698 break;
7699 }
7700 break;
7701 }
7702 case 'l':
7703 {
7704 if (LocaleCompare("layers",option+1) == 0)
7705 {
7706 Image
7707 *layers;
7708
7709 ImageLayerMethod
7710 method;
7711
cristy6b3da3a2010-06-20 02:21:46 +00007712 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007713 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007714 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007715 MagickFalse,argv[i+1]);
7716 switch (method)
7717 {
7718 case CoalesceLayer:
7719 {
7720 layers=CoalesceImages(*images,exception);
7721 break;
7722 }
7723 case CompareAnyLayer:
7724 case CompareClearLayer:
7725 case CompareOverlayLayer:
7726 default:
7727 {
cristy8a9106f2011-07-05 14:39:26 +00007728 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007729 break;
7730 }
7731 case MergeLayer:
7732 case FlattenLayer:
7733 case MosaicLayer:
7734 case TrimBoundsLayer:
7735 {
7736 layers=MergeImageLayers(*images,method,exception);
7737 break;
7738 }
7739 case DisposeLayer:
7740 {
7741 layers=DisposeImages(*images,exception);
7742 break;
7743 }
7744 case OptimizeImageLayer:
7745 {
7746 layers=OptimizeImageLayers(*images,exception);
7747 break;
7748 }
7749 case OptimizePlusLayer:
7750 {
7751 layers=OptimizePlusImageLayers(*images,exception);
7752 break;
7753 }
7754 case OptimizeTransLayer:
7755 {
7756 OptimizeImageTransparency(*images,exception);
7757 break;
7758 }
7759 case RemoveDupsLayer:
7760 {
7761 RemoveDuplicateLayers(images,exception);
7762 break;
7763 }
7764 case RemoveZeroLayer:
7765 {
7766 RemoveZeroDelayLayers(images,exception);
7767 break;
7768 }
7769 case OptimizeLayer:
7770 {
7771 /*
7772 General Purpose, GIF Animation Optimizer.
7773 */
7774 layers=CoalesceImages(*images,exception);
7775 if (layers == (Image *) NULL)
7776 {
7777 status=MagickFalse;
7778 break;
7779 }
7780 InheritException(exception,&layers->exception);
7781 *images=DestroyImageList(*images);
7782 *images=layers;
7783 layers=OptimizeImageLayers(*images,exception);
7784 if (layers == (Image *) NULL)
7785 {
7786 status=MagickFalse;
7787 break;
7788 }
7789 InheritException(exception,&layers->exception);
7790 *images=DestroyImageList(*images);
7791 *images=layers;
7792 layers=(Image *) NULL;
7793 OptimizeImageTransparency(*images,exception);
7794 InheritException(exception,&(*images)->exception);
7795 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7796 break;
7797 }
7798 case CompositeLayer:
7799 {
7800 CompositeOperator
7801 compose;
7802
7803 Image
7804 *source;
7805
7806 RectangleInfo
7807 geometry;
7808
7809 /*
7810 Split image sequence at the first 'NULL:' image.
7811 */
7812 source=(*images);
7813 while (source != (Image *) NULL)
7814 {
7815 source=GetNextImageInList(source);
7816 if ((source != (Image *) NULL) &&
7817 (LocaleCompare(source->magick,"NULL") == 0))
7818 break;
7819 }
7820 if (source != (Image *) NULL)
7821 {
7822 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7823 (GetNextImageInList(source) == (Image *) NULL))
7824 source=(Image *) NULL;
7825 else
7826 {
7827 /*
7828 Separate the two lists, junk the null: image.
7829 */
7830 source=SplitImageList(source->previous);
7831 DeleteImageFromList(&source);
7832 }
7833 }
7834 if (source == (Image *) NULL)
7835 {
7836 (void) ThrowMagickException(exception,GetMagickModule(),
7837 OptionError,"MissingNullSeparator","layers Composite");
7838 status=MagickFalse;
7839 break;
7840 }
7841 /*
7842 Adjust offset with gravity and virtual canvas.
7843 */
7844 SetGeometry(*images,&geometry);
7845 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7846 geometry.width=source->page.width != 0 ?
7847 source->page.width : source->columns;
7848 geometry.height=source->page.height != 0 ?
7849 source->page.height : source->rows;
7850 GravityAdjustGeometry((*images)->page.width != 0 ?
7851 (*images)->page.width : (*images)->columns,
7852 (*images)->page.height != 0 ? (*images)->page.height :
7853 (*images)->rows,(*images)->gravity,&geometry);
7854 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007855 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007856 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007857 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007858 MagickComposeOptions,MagickFalse,option);
7859 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7860 exception);
7861 source=DestroyImageList(source);
7862 break;
7863 }
7864 }
7865 if (layers == (Image *) NULL)
7866 break;
7867 InheritException(exception,&layers->exception);
7868 *images=DestroyImageList(*images);
7869 *images=layers;
7870 break;
7871 }
7872 break;
7873 }
7874 case 'm':
7875 {
7876 if (LocaleCompare("map",option+1) == 0)
7877 {
cristy6b3da3a2010-06-20 02:21:46 +00007878 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007879 if (*option == '+')
7880 {
7881 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7882 InheritException(exception,&(*images)->exception);
7883 break;
7884 }
7885 i++;
7886 break;
7887 }
cristyf40785b2010-03-06 02:27:27 +00007888 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007889 {
7890 Image
cristyf40785b2010-03-06 02:27:27 +00007891 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007892
cristyd18ae7c2010-03-07 17:39:52 +00007893 /*
7894 Maximum image sequence (deprecated).
7895 */
cristy6b3da3a2010-06-20 02:21:46 +00007896 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007897 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007898 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007899 {
7900 status=MagickFalse;
7901 break;
7902 }
7903 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007904 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007905 break;
7906 }
cristyf40785b2010-03-06 02:27:27 +00007907 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007908 {
7909 Image
cristyf40785b2010-03-06 02:27:27 +00007910 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007911
cristyd18ae7c2010-03-07 17:39:52 +00007912 /*
7913 Minimum image sequence (deprecated).
7914 */
cristy6b3da3a2010-06-20 02:21:46 +00007915 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007916 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007917 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007918 {
7919 status=MagickFalse;
7920 break;
7921 }
7922 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007923 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007924 break;
7925 }
cristy3ed852e2009-09-05 21:47:34 +00007926 if (LocaleCompare("morph",option+1) == 0)
7927 {
7928 Image
7929 *morph_image;
7930
cristy6b3da3a2010-06-20 02:21:46 +00007931 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007932 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007933 exception);
7934 if (morph_image == (Image *) NULL)
7935 {
7936 status=MagickFalse;
7937 break;
7938 }
7939 *images=DestroyImageList(*images);
7940 *images=morph_image;
7941 break;
7942 }
7943 if (LocaleCompare("mosaic",option+1) == 0)
7944 {
7945 Image
7946 *mosaic_image;
7947
cristy6b3da3a2010-06-20 02:21:46 +00007948 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007949 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7950 if (mosaic_image == (Image *) NULL)
7951 {
7952 status=MagickFalse;
7953 break;
7954 }
7955 *images=DestroyImageList(*images);
7956 *images=mosaic_image;
7957 break;
7958 }
7959 break;
7960 }
7961 case 'p':
7962 {
7963 if (LocaleCompare("print",option+1) == 0)
7964 {
7965 char
7966 *string;
7967
cristy6b3da3a2010-06-20 02:21:46 +00007968 (void) SyncImagesSettings(mogrify_info,*images);
7969 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007970 if (string == (char *) NULL)
7971 break;
7972 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007973 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007974 string=DestroyString(string);
7975 }
7976 if (LocaleCompare("process",option+1) == 0)
7977 {
7978 char
7979 **arguments;
7980
7981 int
7982 j,
7983 number_arguments;
7984
cristy6b3da3a2010-06-20 02:21:46 +00007985 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007986 arguments=StringToArgv(argv[i+1],&number_arguments);
7987 if (arguments == (char **) NULL)
7988 break;
7989 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7990 {
7991 char
7992 breaker,
7993 quote,
7994 *token;
7995
7996 const char
7997 *arguments;
7998
7999 int
8000 next,
8001 status;
8002
8003 size_t
8004 length;
8005
8006 TokenInfo
8007 *token_info;
8008
8009 /*
8010 Support old style syntax, filter="-option arg".
8011 */
8012 length=strlen(argv[i+1]);
8013 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008014 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008015 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8016 sizeof(*token));
8017 if (token == (char *) NULL)
8018 break;
8019 next=0;
8020 arguments=argv[i+1];
8021 token_info=AcquireTokenInfo();
8022 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8023 "\"",'\0',&breaker,&next,&quote);
8024 token_info=DestroyTokenInfo(token_info);
8025 if (status == 0)
8026 {
8027 const char
8028 *argv;
8029
8030 argv=(&(arguments[next]));
8031 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8032 exception);
8033 }
8034 token=DestroyString(token);
8035 break;
8036 }
cristy91c0da22010-05-02 01:44:07 +00008037 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008038 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8039 number_arguments-2,(const char **) arguments+2,exception);
8040 for (j=0; j < number_arguments; j++)
8041 arguments[j]=DestroyString(arguments[j]);
8042 arguments=(char **) RelinquishMagickMemory(arguments);
8043 break;
8044 }
8045 break;
8046 }
8047 case 'r':
8048 {
8049 if (LocaleCompare("reverse",option+1) == 0)
8050 {
8051 ReverseImageList(images);
8052 InheritException(exception,&(*images)->exception);
8053 break;
8054 }
8055 break;
8056 }
8057 case 's':
8058 {
cristy4285d782011-02-09 20:12:28 +00008059 if (LocaleCompare("smush",option+1) == 0)
8060 {
8061 Image
8062 *smush_image;
8063
8064 ssize_t
8065 offset;
8066
8067 (void) SyncImagesSettings(mogrify_info,*images);
8068 offset=(ssize_t) StringToLong(argv[i+1]);
8069 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8070 MagickFalse,offset,exception);
8071 if (smush_image == (Image *) NULL)
8072 {
8073 status=MagickFalse;
8074 break;
8075 }
8076 *images=DestroyImageList(*images);
8077 *images=smush_image;
8078 break;
8079 }
cristy3ed852e2009-09-05 21:47:34 +00008080 if (LocaleCompare("swap",option+1) == 0)
8081 {
8082 Image
8083 *p,
8084 *q,
8085 *swap;
8086
cristybb503372010-05-27 20:51:26 +00008087 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008088 swap_index;
8089
8090 index=(-1);
8091 swap_index=(-2);
8092 if (*option != '+')
8093 {
8094 GeometryInfo
8095 geometry_info;
8096
8097 MagickStatusType
8098 flags;
8099
8100 swap_index=(-1);
8101 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008102 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008103 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008104 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008105 }
8106 p=GetImageFromList(*images,index);
8107 q=GetImageFromList(*images,swap_index);
8108 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8109 {
8110 (void) ThrowMagickException(exception,GetMagickModule(),
8111 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8112 status=MagickFalse;
8113 break;
8114 }
8115 if (p == q)
8116 break;
8117 swap=CloneImage(p,0,0,MagickTrue,exception);
8118 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8119 ReplaceImageInList(&q,swap);
8120 *images=GetFirstImageInList(q);
8121 break;
8122 }
8123 break;
8124 }
8125 case 'w':
8126 {
8127 if (LocaleCompare("write",option+1) == 0)
8128 {
cristy071dd7b2010-04-09 13:04:54 +00008129 char
cristy06609ee2010-03-17 20:21:27 +00008130 key[MaxTextExtent];
8131
cristy3ed852e2009-09-05 21:47:34 +00008132 Image
8133 *write_images;
8134
8135 ImageInfo
8136 *write_info;
8137
cristy6b3da3a2010-06-20 02:21:46 +00008138 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008139 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008140 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008141 write_images=(*images);
8142 if (*option == '+')
8143 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008144 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008145 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8146 write_info=DestroyImageInfo(write_info);
8147 if (*option == '+')
8148 write_images=DestroyImageList(write_images);
8149 break;
8150 }
8151 break;
8152 }
8153 default:
8154 break;
8155 }
8156 i+=count;
8157 }
8158 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008159 mogrify_info=DestroyImageInfo(mogrify_info);
8160 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008161 return(status != 0 ? MagickTrue : MagickFalse);
8162}
8163
8164/*
8165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8166% %
8167% %
8168% %
8169+ M o g r i f y I m a g e s %
8170% %
8171% %
8172% %
8173%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8174%
8175% MogrifyImages() applies image processing options to a sequence of images as
8176% prescribed by command line options.
8177%
8178% The format of the MogrifyImage method is:
8179%
8180% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8181% const MagickBooleanType post,const int argc,const char **argv,
8182% Image **images,Exceptioninfo *exception)
8183%
8184% A description of each parameter follows:
8185%
8186% o image_info: the image info..
8187%
8188% o post: If true, post process image list operators otherwise pre-process.
8189%
8190% o argc: Specifies a pointer to an integer describing the number of
8191% elements in the argument vector.
8192%
8193% o argv: Specifies a pointer to a text array containing the command line
8194% arguments.
8195%
anthonye9c27192011-03-27 08:07:06 +00008196% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008197%
8198% o exception: return any errors or warnings in this structure.
8199%
8200*/
8201WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8202 const MagickBooleanType post,const int argc,const char **argv,
8203 Image **images,ExceptionInfo *exception)
8204{
8205#define MogrifyImageTag "Mogrify/Image"
8206
anthonye9c27192011-03-27 08:07:06 +00008207 MagickStatusType
8208 status;
cristy3ed852e2009-09-05 21:47:34 +00008209
cristy0e9f9c12010-02-11 03:00:47 +00008210 MagickBooleanType
8211 proceed;
8212
anthonye9c27192011-03-27 08:07:06 +00008213 size_t
8214 n;
cristy3ed852e2009-09-05 21:47:34 +00008215
cristybb503372010-05-27 20:51:26 +00008216 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008217 i;
8218
cristy3ed852e2009-09-05 21:47:34 +00008219 assert(image_info != (ImageInfo *) NULL);
8220 assert(image_info->signature == MagickSignature);
8221 if (images == (Image **) NULL)
8222 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008223 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008224 assert((*images)->signature == MagickSignature);
8225 if ((*images)->debug != MagickFalse)
8226 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8227 (*images)->filename);
8228 if ((argc <= 0) || (*argv == (char *) NULL))
8229 return(MagickTrue);
8230 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8231 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008232 status=0;
anthonye9c27192011-03-27 08:07:06 +00008233
anthonyce2716b2011-04-22 09:51:34 +00008234#if 0
cristy1e604812011-05-19 18:07:50 +00008235 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8236 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008237#endif
8238
anthonye9c27192011-03-27 08:07:06 +00008239 /*
8240 Pre-process multi-image sequence operators
8241 */
cristy3ed852e2009-09-05 21:47:34 +00008242 if (post == MagickFalse)
8243 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008244 /*
8245 For each image, process simple single image operators
8246 */
8247 i=0;
8248 n=GetImageListLength(*images);
8249 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008250 {
anthonyce2716b2011-04-22 09:51:34 +00008251#if 0
cristy1e604812011-05-19 18:07:50 +00008252 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8253 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008254#endif
anthonye9c27192011-03-27 08:07:06 +00008255 status&=MogrifyImage(image_info,argc,argv,images,exception);
8256 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008257 if (proceed == MagickFalse)
8258 break;
anthonye9c27192011-03-27 08:07:06 +00008259 if ( (*images)->next == (Image *) NULL )
8260 break;
8261 *images=(*images)->next;
8262 i++;
cristy3ed852e2009-09-05 21:47:34 +00008263 }
anthonye9c27192011-03-27 08:07:06 +00008264 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008265#if 0
cristy1e604812011-05-19 18:07:50 +00008266 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8267 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008268#endif
anthonye9c27192011-03-27 08:07:06 +00008269
8270 /*
8271 Post-process, multi-image sequence operators
8272 */
8273 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008274 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008275 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008276 return(status != 0 ? MagickTrue : MagickFalse);
8277}