blob: 7e75fbebdca16af88564ff6a14b074535941e8a5 [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;
980 (void) ColorDecisionListImage(*image,color_correction_collection);
981 InheritException(exception,&(*image)->exception);
982 break;
983 }
984 if (LocaleCompare("channel",option+1) == 0)
985 {
986 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000987 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000988 else
cristyfa806a72011-07-04 02:06:13 +0000989 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000990 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000991 break;
992 }
993 if (LocaleCompare("charcoal",option+1) == 0)
994 {
995 /*
996 Charcoal image.
997 */
998 (void) SyncImageSettings(mogrify_info,*image);
999 flags=ParseGeometry(argv[i+1],&geometry_info);
1000 if ((flags & SigmaValue) == 0)
1001 geometry_info.sigma=1.0;
1002 mogrify_image=CharcoalImage(*image,geometry_info.rho,
1003 geometry_info.sigma,exception);
1004 break;
1005 }
1006 if (LocaleCompare("chop",option+1) == 0)
1007 {
1008 /*
1009 Chop the image.
1010 */
1011 (void) SyncImageSettings(mogrify_info,*image);
1012 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1013 mogrify_image=ChopImage(*image,&geometry,exception);
1014 break;
1015 }
1016 if (LocaleCompare("clamp",option+1) == 0)
1017 {
1018 /*
1019 Clamp image.
1020 */
1021 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001022 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001023 InheritException(exception,&(*image)->exception);
1024 break;
1025 }
1026 if (LocaleCompare("clip",option+1) == 0)
1027 {
1028 (void) SyncImageSettings(mogrify_info,*image);
1029 if (*option == '+')
1030 {
1031 (void) SetImageClipMask(*image,(Image *) NULL);
1032 InheritException(exception,&(*image)->exception);
1033 break;
1034 }
1035 (void) ClipImage(*image);
1036 InheritException(exception,&(*image)->exception);
1037 break;
1038 }
1039 if (LocaleCompare("clip-mask",option+1) == 0)
1040 {
1041 CacheView
1042 *mask_view;
1043
1044 Image
1045 *mask_image;
1046
cristy4c08aed2011-07-01 19:47:50 +00001047 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001048 *restrict q;
1049
1050 register ssize_t
1051 x;
1052
1053 ssize_t
1054 y;
1055
1056 (void) SyncImageSettings(mogrify_info,*image);
1057 if (*option == '+')
1058 {
1059 /*
1060 Remove a mask.
1061 */
1062 (void) SetImageMask(*image,(Image *) NULL);
1063 InheritException(exception,&(*image)->exception);
1064 break;
1065 }
1066 /*
1067 Set the image mask.
1068 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1069 */
1070 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1071 if (mask_image == (Image *) NULL)
1072 break;
cristy574cc262011-08-05 01:23:58 +00001073 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001074 return(MagickFalse);
1075 mask_view=AcquireCacheView(mask_image);
1076 for (y=0; y < (ssize_t) mask_image->rows; y++)
1077 {
1078 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1079 exception);
cristy4c08aed2011-07-01 19:47:50 +00001080 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001081 break;
1082 for (x=0; x < (ssize_t) mask_image->columns; x++)
1083 {
1084 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001085 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1086 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1087 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1088 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001089 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001090 }
1091 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1092 break;
1093 }
1094 mask_view=DestroyCacheView(mask_view);
1095 mask_image->matte=MagickTrue;
1096 (void) SetImageClipMask(*image,mask_image);
1097 mask_image=DestroyImage(mask_image);
1098 InheritException(exception,&(*image)->exception);
1099 break;
1100 }
1101 if (LocaleCompare("clip-path",option+1) == 0)
1102 {
1103 (void) SyncImageSettings(mogrify_info,*image);
1104 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1105 MagickFalse);
1106 InheritException(exception,&(*image)->exception);
1107 break;
1108 }
1109 if (LocaleCompare("colorize",option+1) == 0)
1110 {
1111 /*
1112 Colorize the image.
1113 */
1114 (void) SyncImageSettings(mogrify_info,*image);
1115 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1116 exception);
1117 break;
1118 }
1119 if (LocaleCompare("color-matrix",option+1) == 0)
1120 {
1121 KernelInfo
1122 *kernel;
1123
1124 (void) SyncImageSettings(mogrify_info,*image);
1125 kernel=AcquireKernelInfo(argv[i+1]);
1126 if (kernel == (KernelInfo *) NULL)
1127 break;
1128 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1129 kernel=DestroyKernelInfo(kernel);
1130 break;
1131 }
1132 if (LocaleCompare("colors",option+1) == 0)
1133 {
1134 /*
1135 Reduce the number of colors in the image.
1136 */
1137 (void) SyncImageSettings(mogrify_info,*image);
1138 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1139 if (quantize_info->number_colors == 0)
1140 break;
1141 if (((*image)->storage_class == DirectClass) ||
1142 (*image)->colors > quantize_info->number_colors)
1143 (void) QuantizeImage(quantize_info,*image);
1144 else
1145 (void) CompressImageColormap(*image);
1146 InheritException(exception,&(*image)->exception);
1147 break;
1148 }
1149 if (LocaleCompare("colorspace",option+1) == 0)
1150 {
1151 ColorspaceType
1152 colorspace;
1153
1154 (void) SyncImageSettings(mogrify_info,*image);
1155 if (*option == '+')
1156 {
1157 (void) TransformImageColorspace(*image,RGBColorspace);
1158 InheritException(exception,&(*image)->exception);
1159 break;
1160 }
1161 colorspace=(ColorspaceType) ParseCommandOption(
1162 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1163 (void) TransformImageColorspace(*image,colorspace);
1164 InheritException(exception,&(*image)->exception);
1165 break;
1166 }
1167 if (LocaleCompare("contrast",option+1) == 0)
1168 {
1169 (void) SyncImageSettings(mogrify_info,*image);
1170 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1171 MagickFalse);
1172 InheritException(exception,&(*image)->exception);
1173 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;
cristy50fbc382011-07-07 02:19:17 +00001199 (void) ContrastStretchImage(*image,black_point,white_point);
anthonydf8ebac2011-04-27 09:03:19 +00001200 InheritException(exception,&(*image)->exception);
1201 break;
1202 }
1203 if (LocaleCompare("convolve",option+1) == 0)
1204 {
anthonydf8ebac2011-04-27 09:03:19 +00001205 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001206 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001207
anthonydf8ebac2011-04-27 09:03:19 +00001208 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001209 kernel_info=AcquireKernelInfo(argv[i+1]);
1210 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001211 break;
cristy0a922382011-07-16 15:30:34 +00001212 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001213 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001214 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001215 break;
1216 }
1217 if (LocaleCompare("crop",option+1) == 0)
1218 {
1219 /*
1220 Crop a image to a smaller size
1221 */
1222 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001223 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001224 break;
1225 }
1226 if (LocaleCompare("cycle",option+1) == 0)
1227 {
1228 /*
1229 Cycle an image colormap.
1230 */
1231 (void) SyncImageSettings(mogrify_info,*image);
1232 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1233 InheritException(exception,&(*image)->exception);
1234 break;
1235 }
1236 break;
1237 }
1238 case 'd':
1239 {
1240 if (LocaleCompare("decipher",option+1) == 0)
1241 {
1242 StringInfo
1243 *passkey;
1244
1245 /*
1246 Decipher pixels.
1247 */
1248 (void) SyncImageSettings(mogrify_info,*image);
1249 passkey=FileToStringInfo(argv[i+1],~0,exception);
1250 if (passkey != (StringInfo *) NULL)
1251 {
1252 (void) PasskeyDecipherImage(*image,passkey,exception);
1253 passkey=DestroyStringInfo(passkey);
1254 }
1255 break;
1256 }
1257 if (LocaleCompare("density",option+1) == 0)
1258 {
1259 /*
1260 Set image density.
1261 */
1262 (void) CloneString(&draw_info->density,argv[i+1]);
1263 break;
1264 }
1265 if (LocaleCompare("depth",option+1) == 0)
1266 {
1267 (void) SyncImageSettings(mogrify_info,*image);
1268 if (*option == '+')
1269 {
1270 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1271 break;
1272 }
1273 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1274 break;
1275 }
1276 if (LocaleCompare("deskew",option+1) == 0)
1277 {
1278 double
1279 threshold;
1280
1281 /*
1282 Straighten the image.
1283 */
1284 (void) SyncImageSettings(mogrify_info,*image);
1285 if (*option == '+')
1286 threshold=40.0*QuantumRange/100.0;
1287 else
1288 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1289 mogrify_image=DeskewImage(*image,threshold,exception);
1290 break;
1291 }
1292 if (LocaleCompare("despeckle",option+1) == 0)
1293 {
1294 /*
1295 Reduce the speckles within an image.
1296 */
1297 (void) SyncImageSettings(mogrify_info,*image);
1298 mogrify_image=DespeckleImage(*image,exception);
1299 break;
1300 }
1301 if (LocaleCompare("display",option+1) == 0)
1302 {
1303 (void) CloneString(&draw_info->server_name,argv[i+1]);
1304 break;
1305 }
1306 if (LocaleCompare("distort",option+1) == 0)
1307 {
1308 char
1309 *args,
1310 token[MaxTextExtent];
1311
1312 const char
1313 *p;
1314
1315 DistortImageMethod
1316 method;
1317
1318 double
1319 *arguments;
1320
1321 register ssize_t
1322 x;
1323
1324 size_t
1325 number_arguments;
1326
1327 /*
1328 Distort image.
1329 */
1330 (void) SyncImageSettings(mogrify_info,*image);
1331 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1332 MagickFalse,argv[i+1]);
1333 if ( method == ResizeDistortion )
1334 {
1335 /* Special Case - Argument is actually a resize geometry!
1336 ** Convert that to an appropriate distortion argument array.
1337 */
1338 double
1339 resize_args[2];
1340 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1341 exception);
1342 resize_args[0]=(double)geometry.width;
1343 resize_args[1]=(double)geometry.height;
1344 mogrify_image=DistortImage(*image,method,(size_t)2,
1345 resize_args,MagickTrue,exception);
1346 break;
1347 }
1348 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1349 InheritException(exception,&(*image)->exception);
1350 if (args == (char *) NULL)
1351 break;
1352 p=(char *) args;
1353 for (x=0; *p != '\0'; x++)
1354 {
1355 GetMagickToken(p,&p,token);
1356 if (*token == ',')
1357 GetMagickToken(p,&p,token);
1358 }
1359 number_arguments=(size_t) x;
1360 arguments=(double *) AcquireQuantumMemory(number_arguments,
1361 sizeof(*arguments));
1362 if (arguments == (double *) NULL)
1363 ThrowWandFatalException(ResourceLimitFatalError,
1364 "MemoryAllocationFailed",(*image)->filename);
1365 (void) ResetMagickMemory(arguments,0,number_arguments*
1366 sizeof(*arguments));
1367 p=(char *) args;
1368 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1369 {
1370 GetMagickToken(p,&p,token);
1371 if (*token == ',')
1372 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001373 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001374 }
1375 args=DestroyString(args);
1376 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1377 (*option == '+') ? MagickTrue : MagickFalse,exception);
1378 arguments=(double *) RelinquishMagickMemory(arguments);
1379 break;
1380 }
1381 if (LocaleCompare("dither",option+1) == 0)
1382 {
1383 if (*option == '+')
1384 {
1385 quantize_info->dither=MagickFalse;
1386 break;
1387 }
1388 quantize_info->dither=MagickTrue;
1389 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1390 MagickDitherOptions,MagickFalse,argv[i+1]);
1391 if (quantize_info->dither_method == NoDitherMethod)
1392 quantize_info->dither=MagickFalse;
1393 break;
1394 }
1395 if (LocaleCompare("draw",option+1) == 0)
1396 {
1397 /*
1398 Draw image.
1399 */
1400 (void) SyncImageSettings(mogrify_info,*image);
1401 (void) CloneString(&draw_info->primitive,argv[i+1]);
1402 (void) DrawImage(*image,draw_info);
1403 InheritException(exception,&(*image)->exception);
1404 break;
1405 }
1406 break;
1407 }
1408 case 'e':
1409 {
1410 if (LocaleCompare("edge",option+1) == 0)
1411 {
1412 /*
1413 Enhance edges in the image.
1414 */
1415 (void) SyncImageSettings(mogrify_info,*image);
1416 flags=ParseGeometry(argv[i+1],&geometry_info);
1417 if ((flags & SigmaValue) == 0)
1418 geometry_info.sigma=1.0;
1419 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1420 break;
1421 }
1422 if (LocaleCompare("emboss",option+1) == 0)
1423 {
1424 /*
1425 Gaussian embossen image.
1426 */
1427 (void) SyncImageSettings(mogrify_info,*image);
1428 flags=ParseGeometry(argv[i+1],&geometry_info);
1429 if ((flags & SigmaValue) == 0)
1430 geometry_info.sigma=1.0;
1431 mogrify_image=EmbossImage(*image,geometry_info.rho,
1432 geometry_info.sigma,exception);
1433 break;
1434 }
1435 if (LocaleCompare("encipher",option+1) == 0)
1436 {
1437 StringInfo
1438 *passkey;
1439
1440 /*
1441 Encipher pixels.
1442 */
1443 (void) SyncImageSettings(mogrify_info,*image);
1444 passkey=FileToStringInfo(argv[i+1],~0,exception);
1445 if (passkey != (StringInfo *) NULL)
1446 {
1447 (void) PasskeyEncipherImage(*image,passkey,exception);
1448 passkey=DestroyStringInfo(passkey);
1449 }
1450 break;
1451 }
1452 if (LocaleCompare("encoding",option+1) == 0)
1453 {
1454 (void) CloneString(&draw_info->encoding,argv[i+1]);
1455 break;
1456 }
1457 if (LocaleCompare("enhance",option+1) == 0)
1458 {
1459 /*
1460 Enhance image.
1461 */
1462 (void) SyncImageSettings(mogrify_info,*image);
1463 mogrify_image=EnhanceImage(*image,exception);
1464 break;
1465 }
1466 if (LocaleCompare("equalize",option+1) == 0)
1467 {
1468 /*
1469 Equalize image.
1470 */
1471 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00001472 (void) EqualizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001473 InheritException(exception,&(*image)->exception);
1474 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))
cristy50fbc382011-07-07 02:19:17 +00001871 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001872 else
cristyf89cb1d2011-07-07 01:24:37 +00001873 (void) LevelImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001874 InheritException(exception,&(*image)->exception);
1875 break;
1876 }
1877 if (LocaleCompare("level-colors",option+1) == 0)
1878 {
1879 char
1880 token[MaxTextExtent];
1881
1882 const char
1883 *p;
1884
cristy4c08aed2011-07-01 19:47:50 +00001885 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001886 black_point,
1887 white_point;
1888
1889 p=(const char *) argv[i+1];
1890 GetMagickToken(p,&p,token); /* get black point color */
1891 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1892 (void) QueryMagickColor(token,&black_point,exception);
1893 else
1894 (void) QueryMagickColor("#000000",&black_point,exception);
1895 if (isalpha((int) token[0]) || (token[0] == '#'))
1896 GetMagickToken(p,&p,token);
1897 if (*token == '\0')
1898 white_point=black_point; /* set everything to that color */
1899 else
1900 {
1901 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1902 GetMagickToken(p,&p,token); /* Get white point color. */
1903 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1904 (void) QueryMagickColor(token,&white_point,exception);
1905 else
1906 (void) QueryMagickColor("#ffffff",&white_point,exception);
1907 }
cristy490408a2011-07-07 14:42:05 +00001908 (void) LevelImageColors(*image,&black_point,&white_point,
1909 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001910 break;
1911 }
1912 if (LocaleCompare("linear-stretch",option+1) == 0)
1913 {
1914 double
1915 black_point,
1916 white_point;
1917
1918 MagickStatusType
1919 flags;
1920
1921 (void) SyncImageSettings(mogrify_info,*image);
1922 flags=ParseGeometry(argv[i+1],&geometry_info);
1923 black_point=geometry_info.rho;
1924 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1925 if ((flags & SigmaValue) != 0)
1926 white_point=geometry_info.sigma;
1927 if ((flags & PercentValue) != 0)
1928 {
1929 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1930 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1931 }
1932 if ((flags & SigmaValue) == 0)
1933 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1934 black_point;
1935 (void) LinearStretchImage(*image,black_point,white_point);
1936 InheritException(exception,&(*image)->exception);
1937 break;
1938 }
1939 if (LocaleCompare("linewidth",option+1) == 0)
1940 {
cristyc1acd842011-05-19 23:05:47 +00001941 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1942 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001943 break;
1944 }
1945 if (LocaleCompare("liquid-rescale",option+1) == 0)
1946 {
1947 /*
1948 Liquid rescale image.
1949 */
1950 (void) SyncImageSettings(mogrify_info,*image);
1951 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1952 if ((flags & XValue) == 0)
1953 geometry.x=1;
1954 if ((flags & YValue) == 0)
1955 geometry.y=0;
1956 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1957 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1958 break;
1959 }
1960 if (LocaleCompare("lowlight-color",option+1) == 0)
1961 {
1962 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1963 break;
1964 }
1965 break;
1966 }
1967 case 'm':
1968 {
1969 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001970 {
cristy3ed852e2009-09-05 21:47:34 +00001971 Image
anthonydf8ebac2011-04-27 09:03:19 +00001972 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001973
anthonydf8ebac2011-04-27 09:03:19 +00001974 /*
1975 Transform image colors to match this set of colors.
1976 */
1977 (void) SyncImageSettings(mogrify_info,*image);
1978 if (*option == '+')
1979 break;
1980 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1981 if (remap_image == (Image *) NULL)
1982 break;
1983 (void) RemapImage(quantize_info,*image,remap_image);
1984 InheritException(exception,&(*image)->exception);
1985 remap_image=DestroyImage(remap_image);
1986 break;
1987 }
1988 if (LocaleCompare("mask",option+1) == 0)
1989 {
1990 Image
1991 *mask;
1992
1993 (void) SyncImageSettings(mogrify_info,*image);
1994 if (*option == '+')
1995 {
1996 /*
1997 Remove a mask.
1998 */
1999 (void) SetImageMask(*image,(Image *) NULL);
2000 InheritException(exception,&(*image)->exception);
2001 break;
2002 }
2003 /*
2004 Set the image mask.
2005 */
2006 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2007 if (mask == (Image *) NULL)
2008 break;
2009 (void) SetImageMask(*image,mask);
2010 mask=DestroyImage(mask);
2011 InheritException(exception,&(*image)->exception);
2012 break;
2013 }
2014 if (LocaleCompare("matte",option+1) == 0)
2015 {
2016 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002017 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002018 break;
2019 }
2020 if (LocaleCompare("median",option+1) == 0)
2021 {
2022 /*
2023 Median filter image.
2024 */
2025 (void) SyncImageSettings(mogrify_info,*image);
2026 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002027 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2028 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002029 break;
2030 }
2031 if (LocaleCompare("mode",option+1) == 0)
2032 {
2033 /*
2034 Mode image.
2035 */
2036 (void) SyncImageSettings(mogrify_info,*image);
2037 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002038 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2039 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002040 break;
2041 }
2042 if (LocaleCompare("modulate",option+1) == 0)
2043 {
2044 (void) SyncImageSettings(mogrify_info,*image);
2045 (void) ModulateImage(*image,argv[i+1]);
2046 InheritException(exception,&(*image)->exception);
2047 break;
2048 }
2049 if (LocaleCompare("monitor",option+1) == 0)
2050 {
2051 if (*option == '+')
2052 {
2053 (void) SetImageProgressMonitor(*image,
2054 (MagickProgressMonitor) NULL,(void *) NULL);
2055 break;
2056 }
2057 (void) SetImageProgressMonitor(*image,MonitorProgress,
2058 (void *) NULL);
2059 break;
2060 }
2061 if (LocaleCompare("monochrome",option+1) == 0)
2062 {
2063 (void) SyncImageSettings(mogrify_info,*image);
2064 (void) SetImageType(*image,BilevelType);
2065 InheritException(exception,&(*image)->exception);
2066 break;
2067 }
2068 if (LocaleCompare("morphology",option+1) == 0)
2069 {
2070 char
2071 token[MaxTextExtent];
2072
2073 const char
2074 *p;
2075
2076 KernelInfo
2077 *kernel;
2078
2079 MorphologyMethod
2080 method;
2081
2082 ssize_t
2083 iterations;
2084
2085 /*
2086 Morphological Image Operation
2087 */
2088 (void) SyncImageSettings(mogrify_info,*image);
2089 p=argv[i+1];
2090 GetMagickToken(p,&p,token);
2091 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2092 MagickFalse,token);
2093 iterations=1L;
2094 GetMagickToken(p,&p,token);
2095 if ((*p == ':') || (*p == ','))
2096 GetMagickToken(p,&p,token);
2097 if ((*p != '\0'))
2098 iterations=(ssize_t) StringToLong(p);
2099 kernel=AcquireKernelInfo(argv[i+2]);
2100 if (kernel == (KernelInfo *) NULL)
2101 {
2102 (void) ThrowMagickException(exception,GetMagickModule(),
2103 OptionError,"UnabletoParseKernel","morphology");
2104 status=MagickFalse;
2105 break;
2106 }
cristyf4ad9df2011-07-08 16:49:03 +00002107 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2108 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002109 kernel=DestroyKernelInfo(kernel);
2110 break;
2111 }
2112 if (LocaleCompare("motion-blur",option+1) == 0)
2113 {
2114 /*
2115 Motion blur image.
2116 */
2117 (void) SyncImageSettings(mogrify_info,*image);
2118 flags=ParseGeometry(argv[i+1],&geometry_info);
2119 if ((flags & SigmaValue) == 0)
2120 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002121 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2122 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002123 break;
2124 }
2125 break;
2126 }
2127 case 'n':
2128 {
2129 if (LocaleCompare("negate",option+1) == 0)
2130 {
2131 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002132 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002133 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002134 break;
2135 }
2136 if (LocaleCompare("noise",option+1) == 0)
2137 {
2138 (void) SyncImageSettings(mogrify_info,*image);
2139 if (*option == '-')
2140 {
2141 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002142 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2143 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002144 }
2145 else
2146 {
2147 NoiseType
2148 noise;
2149
2150 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2151 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002152 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002153 }
2154 break;
2155 }
2156 if (LocaleCompare("normalize",option+1) == 0)
2157 {
2158 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002159 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002160 InheritException(exception,&(*image)->exception);
2161 break;
2162 }
2163 break;
2164 }
2165 case 'o':
2166 {
2167 if (LocaleCompare("opaque",option+1) == 0)
2168 {
cristy4c08aed2011-07-01 19:47:50 +00002169 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002170 target;
2171
2172 (void) SyncImageSettings(mogrify_info,*image);
2173 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002174 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2175 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002176 break;
2177 }
2178 if (LocaleCompare("ordered-dither",option+1) == 0)
2179 {
2180 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002181 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002182 break;
2183 }
2184 break;
2185 }
2186 case 'p':
2187 {
2188 if (LocaleCompare("paint",option+1) == 0)
2189 {
anthonydf8ebac2011-04-27 09:03:19 +00002190 (void) SyncImageSettings(mogrify_info,*image);
2191 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002192 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002193 break;
2194 }
2195 if (LocaleCompare("pen",option+1) == 0)
2196 {
2197 if (*option == '+')
2198 {
2199 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2200 break;
2201 }
2202 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2203 break;
2204 }
2205 if (LocaleCompare("pointsize",option+1) == 0)
2206 {
2207 if (*option == '+')
2208 (void) ParseGeometry("12",&geometry_info);
2209 else
2210 (void) ParseGeometry(argv[i+1],&geometry_info);
2211 draw_info->pointsize=geometry_info.rho;
2212 break;
2213 }
2214 if (LocaleCompare("polaroid",option+1) == 0)
2215 {
2216 double
2217 angle;
2218
2219 RandomInfo
2220 *random_info;
2221
2222 /*
2223 Simulate a Polaroid picture.
2224 */
2225 (void) SyncImageSettings(mogrify_info,*image);
2226 random_info=AcquireRandomInfo();
2227 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2228 random_info=DestroyRandomInfo(random_info);
2229 if (*option == '-')
2230 {
2231 SetGeometryInfo(&geometry_info);
2232 flags=ParseGeometry(argv[i+1],&geometry_info);
2233 angle=geometry_info.rho;
2234 }
2235 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2236 break;
2237 }
2238 if (LocaleCompare("posterize",option+1) == 0)
2239 {
2240 /*
2241 Posterize image.
2242 */
2243 (void) SyncImageSettings(mogrify_info,*image);
2244 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2245 quantize_info->dither);
2246 InheritException(exception,&(*image)->exception);
2247 break;
2248 }
2249 if (LocaleCompare("preview",option+1) == 0)
2250 {
2251 PreviewType
2252 preview_type;
2253
2254 /*
2255 Preview image.
2256 */
2257 (void) SyncImageSettings(mogrify_info,*image);
2258 if (*option == '+')
2259 preview_type=UndefinedPreview;
2260 else
2261 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2262 MagickFalse,argv[i+1]);
2263 mogrify_image=PreviewImage(*image,preview_type,exception);
2264 break;
2265 }
2266 if (LocaleCompare("profile",option+1) == 0)
2267 {
2268 const char
2269 *name;
2270
2271 const StringInfo
2272 *profile;
2273
2274 Image
2275 *profile_image;
2276
2277 ImageInfo
2278 *profile_info;
2279
2280 (void) SyncImageSettings(mogrify_info,*image);
2281 if (*option == '+')
2282 {
2283 /*
2284 Remove a profile from the image.
2285 */
2286 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2287 NULL,0,MagickTrue);
2288 InheritException(exception,&(*image)->exception);
2289 break;
2290 }
2291 /*
2292 Associate a profile with the image.
2293 */
2294 profile_info=CloneImageInfo(mogrify_info);
2295 profile=GetImageProfile(*image,"iptc");
2296 if (profile != (StringInfo *) NULL)
2297 profile_info->profile=(void *) CloneStringInfo(profile);
2298 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2299 profile_info=DestroyImageInfo(profile_info);
2300 if (profile_image == (Image *) NULL)
2301 {
2302 StringInfo
2303 *profile;
2304
2305 profile_info=CloneImageInfo(mogrify_info);
2306 (void) CopyMagickString(profile_info->filename,argv[i+1],
2307 MaxTextExtent);
2308 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2309 if (profile != (StringInfo *) NULL)
2310 {
2311 (void) ProfileImage(*image,profile_info->magick,
2312 GetStringInfoDatum(profile),(size_t)
2313 GetStringInfoLength(profile),MagickFalse);
2314 profile=DestroyStringInfo(profile);
2315 }
2316 profile_info=DestroyImageInfo(profile_info);
2317 break;
2318 }
2319 ResetImageProfileIterator(profile_image);
2320 name=GetNextImageProfile(profile_image);
2321 while (name != (const char *) NULL)
2322 {
2323 profile=GetImageProfile(profile_image,name);
2324 if (profile != (StringInfo *) NULL)
2325 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2326 (size_t) GetStringInfoLength(profile),MagickFalse);
2327 name=GetNextImageProfile(profile_image);
2328 }
2329 profile_image=DestroyImage(profile_image);
2330 break;
2331 }
2332 break;
2333 }
2334 case 'q':
2335 {
2336 if (LocaleCompare("quantize",option+1) == 0)
2337 {
2338 if (*option == '+')
2339 {
2340 quantize_info->colorspace=UndefinedColorspace;
2341 break;
2342 }
2343 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2344 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2345 break;
2346 }
2347 break;
2348 }
2349 case 'r':
2350 {
2351 if (LocaleCompare("radial-blur",option+1) == 0)
2352 {
2353 /*
2354 Radial blur image.
2355 */
2356 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002357 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2358 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002359 break;
2360 }
2361 if (LocaleCompare("raise",option+1) == 0)
2362 {
2363 /*
2364 Surround image with a raise of solid color.
2365 */
2366 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2367 if ((flags & SigmaValue) == 0)
2368 geometry.height=geometry.width;
2369 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2370 MagickFalse);
2371 InheritException(exception,&(*image)->exception);
2372 break;
2373 }
2374 if (LocaleCompare("random-threshold",option+1) == 0)
2375 {
2376 /*
2377 Threshold image.
2378 */
2379 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002380 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002381 break;
2382 }
2383 if (LocaleCompare("recolor",option+1) == 0)
2384 {
2385 KernelInfo
2386 *kernel;
2387
2388 (void) SyncImageSettings(mogrify_info,*image);
2389 kernel=AcquireKernelInfo(argv[i+1]);
2390 if (kernel == (KernelInfo *) NULL)
2391 break;
2392 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2393 kernel=DestroyKernelInfo(kernel);
2394 break;
2395 }
2396 if (LocaleCompare("region",option+1) == 0)
2397 {
2398 (void) SyncImageSettings(mogrify_info,*image);
2399 if (region_image != (Image *) NULL)
2400 {
2401 /*
2402 Composite region.
2403 */
2404 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002405 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2406 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002407 InheritException(exception,&region_image->exception);
2408 *image=DestroyImage(*image);
2409 *image=region_image;
2410 region_image = (Image *) NULL;
2411 }
2412 if (*option == '+')
2413 break;
2414 /*
2415 Apply transformations to a selected region of the image.
2416 */
cristy3ed852e2009-09-05 21:47:34 +00002417 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2418 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002419 mogrify_image=CropImage(*image,&region_geometry,exception);
2420 if (mogrify_image == (Image *) NULL)
2421 break;
2422 region_image=(*image);
2423 *image=mogrify_image;
2424 mogrify_image=(Image *) NULL;
2425 break;
cristy3ed852e2009-09-05 21:47:34 +00002426 }
anthonydf8ebac2011-04-27 09:03:19 +00002427 if (LocaleCompare("render",option+1) == 0)
2428 {
2429 (void) SyncImageSettings(mogrify_info,*image);
2430 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2431 break;
2432 }
2433 if (LocaleCompare("remap",option+1) == 0)
2434 {
2435 Image
2436 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002437
anthonydf8ebac2011-04-27 09:03:19 +00002438 /*
2439 Transform image colors to match this set of colors.
2440 */
2441 (void) SyncImageSettings(mogrify_info,*image);
2442 if (*option == '+')
2443 break;
2444 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2445 if (remap_image == (Image *) NULL)
2446 break;
2447 (void) RemapImage(quantize_info,*image,remap_image);
2448 InheritException(exception,&(*image)->exception);
2449 remap_image=DestroyImage(remap_image);
2450 break;
2451 }
2452 if (LocaleCompare("repage",option+1) == 0)
2453 {
2454 if (*option == '+')
2455 {
2456 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2457 break;
2458 }
2459 (void) ResetImagePage(*image,argv[i+1]);
2460 InheritException(exception,&(*image)->exception);
2461 break;
2462 }
2463 if (LocaleCompare("resample",option+1) == 0)
2464 {
2465 /*
2466 Resample image.
2467 */
2468 (void) SyncImageSettings(mogrify_info,*image);
2469 flags=ParseGeometry(argv[i+1],&geometry_info);
2470 if ((flags & SigmaValue) == 0)
2471 geometry_info.sigma=geometry_info.rho;
2472 mogrify_image=ResampleImage(*image,geometry_info.rho,
2473 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2474 break;
2475 }
2476 if (LocaleCompare("resize",option+1) == 0)
2477 {
2478 /*
2479 Resize image.
2480 */
2481 (void) SyncImageSettings(mogrify_info,*image);
2482 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2483 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2484 (*image)->filter,(*image)->blur,exception);
2485 break;
2486 }
2487 if (LocaleCompare("roll",option+1) == 0)
2488 {
2489 /*
2490 Roll image.
2491 */
2492 (void) SyncImageSettings(mogrify_info,*image);
2493 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2494 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2495 break;
2496 }
2497 if (LocaleCompare("rotate",option+1) == 0)
2498 {
2499 char
2500 *geometry;
2501
2502 /*
2503 Check for conditional image rotation.
2504 */
2505 (void) SyncImageSettings(mogrify_info,*image);
2506 if (strchr(argv[i+1],'>') != (char *) NULL)
2507 if ((*image)->columns <= (*image)->rows)
2508 break;
2509 if (strchr(argv[i+1],'<') != (char *) NULL)
2510 if ((*image)->columns >= (*image)->rows)
2511 break;
2512 /*
2513 Rotate image.
2514 */
2515 geometry=ConstantString(argv[i+1]);
2516 (void) SubstituteString(&geometry,">","");
2517 (void) SubstituteString(&geometry,"<","");
2518 (void) ParseGeometry(geometry,&geometry_info);
2519 geometry=DestroyString(geometry);
2520 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2521 break;
2522 }
2523 break;
2524 }
2525 case 's':
2526 {
2527 if (LocaleCompare("sample",option+1) == 0)
2528 {
2529 /*
2530 Sample image with pixel replication.
2531 */
2532 (void) SyncImageSettings(mogrify_info,*image);
2533 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2534 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2535 exception);
2536 break;
2537 }
2538 if (LocaleCompare("scale",option+1) == 0)
2539 {
2540 /*
2541 Resize image.
2542 */
2543 (void) SyncImageSettings(mogrify_info,*image);
2544 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2545 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2546 exception);
2547 break;
2548 }
2549 if (LocaleCompare("selective-blur",option+1) == 0)
2550 {
2551 /*
2552 Selectively blur pixels within a contrast threshold.
2553 */
2554 (void) SyncImageSettings(mogrify_info,*image);
2555 flags=ParseGeometry(argv[i+1],&geometry_info);
2556 if ((flags & PercentValue) != 0)
2557 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002558 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2559 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002560 break;
2561 }
2562 if (LocaleCompare("separate",option+1) == 0)
2563 {
2564 /*
2565 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002566 */
2567 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002568 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002569 break;
2570 }
2571 if (LocaleCompare("sepia-tone",option+1) == 0)
2572 {
2573 double
2574 threshold;
2575
2576 /*
2577 Sepia-tone image.
2578 */
2579 (void) SyncImageSettings(mogrify_info,*image);
2580 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2581 mogrify_image=SepiaToneImage(*image,threshold,exception);
2582 break;
2583 }
2584 if (LocaleCompare("segment",option+1) == 0)
2585 {
2586 /*
2587 Segment image.
2588 */
2589 (void) SyncImageSettings(mogrify_info,*image);
2590 flags=ParseGeometry(argv[i+1],&geometry_info);
2591 if ((flags & SigmaValue) == 0)
2592 geometry_info.sigma=1.0;
2593 (void) SegmentImage(*image,(*image)->colorspace,
2594 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2595 InheritException(exception,&(*image)->exception);
2596 break;
2597 }
2598 if (LocaleCompare("set",option+1) == 0)
2599 {
2600 char
2601 *value;
2602
2603 /*
2604 Set image option.
2605 */
2606 if (*option == '+')
2607 {
2608 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2609 (void) DeleteImageRegistry(argv[i+1]+9);
2610 else
2611 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2612 {
2613 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2614 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2615 }
2616 else
2617 (void) DeleteImageProperty(*image,argv[i+1]);
2618 break;
2619 }
2620 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2621 if (value == (char *) NULL)
2622 break;
2623 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2624 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2625 exception);
2626 else
2627 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2628 {
2629 (void) SetImageOption(image_info,argv[i+1]+7,value);
2630 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2631 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2632 }
2633 else
2634 (void) SetImageProperty(*image,argv[i+1],value);
2635 value=DestroyString(value);
2636 break;
2637 }
2638 if (LocaleCompare("shade",option+1) == 0)
2639 {
2640 /*
2641 Shade image.
2642 */
2643 (void) SyncImageSettings(mogrify_info,*image);
2644 flags=ParseGeometry(argv[i+1],&geometry_info);
2645 if ((flags & SigmaValue) == 0)
2646 geometry_info.sigma=1.0;
2647 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2648 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2649 break;
2650 }
2651 if (LocaleCompare("shadow",option+1) == 0)
2652 {
2653 /*
2654 Shadow image.
2655 */
2656 (void) SyncImageSettings(mogrify_info,*image);
2657 flags=ParseGeometry(argv[i+1],&geometry_info);
2658 if ((flags & SigmaValue) == 0)
2659 geometry_info.sigma=1.0;
2660 if ((flags & XiValue) == 0)
2661 geometry_info.xi=4.0;
2662 if ((flags & PsiValue) == 0)
2663 geometry_info.psi=4.0;
2664 mogrify_image=ShadowImage(*image,geometry_info.rho,
2665 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2666 ceil(geometry_info.psi-0.5),exception);
2667 break;
2668 }
2669 if (LocaleCompare("sharpen",option+1) == 0)
2670 {
2671 /*
2672 Sharpen image.
2673 */
2674 (void) SyncImageSettings(mogrify_info,*image);
2675 flags=ParseGeometry(argv[i+1],&geometry_info);
2676 if ((flags & SigmaValue) == 0)
2677 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002678 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002679 geometry_info.sigma,exception);
2680 break;
2681 }
2682 if (LocaleCompare("shave",option+1) == 0)
2683 {
2684 /*
2685 Shave the image edges.
2686 */
2687 (void) SyncImageSettings(mogrify_info,*image);
2688 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2689 mogrify_image=ShaveImage(*image,&geometry,exception);
2690 break;
2691 }
2692 if (LocaleCompare("shear",option+1) == 0)
2693 {
2694 /*
2695 Shear image.
2696 */
2697 (void) SyncImageSettings(mogrify_info,*image);
2698 flags=ParseGeometry(argv[i+1],&geometry_info);
2699 if ((flags & SigmaValue) == 0)
2700 geometry_info.sigma=geometry_info.rho;
2701 mogrify_image=ShearImage(*image,geometry_info.rho,
2702 geometry_info.sigma,exception);
2703 break;
2704 }
2705 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2706 {
2707 /*
2708 Sigmoidal non-linearity contrast control.
2709 */
2710 (void) SyncImageSettings(mogrify_info,*image);
2711 flags=ParseGeometry(argv[i+1],&geometry_info);
2712 if ((flags & SigmaValue) == 0)
2713 geometry_info.sigma=(double) QuantumRange/2.0;
2714 if ((flags & PercentValue) != 0)
2715 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2716 100.0;
cristy9ee60942011-07-06 14:54:38 +00002717 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2718 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002719 InheritException(exception,&(*image)->exception);
2720 break;
2721 }
2722 if (LocaleCompare("sketch",option+1) == 0)
2723 {
2724 /*
2725 Sketch image.
2726 */
2727 (void) SyncImageSettings(mogrify_info,*image);
2728 flags=ParseGeometry(argv[i+1],&geometry_info);
2729 if ((flags & SigmaValue) == 0)
2730 geometry_info.sigma=1.0;
2731 mogrify_image=SketchImage(*image,geometry_info.rho,
2732 geometry_info.sigma,geometry_info.xi,exception);
2733 break;
2734 }
2735 if (LocaleCompare("solarize",option+1) == 0)
2736 {
2737 double
2738 threshold;
2739
2740 (void) SyncImageSettings(mogrify_info,*image);
2741 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2742 (void) SolarizeImage(*image,threshold);
2743 InheritException(exception,&(*image)->exception);
2744 break;
2745 }
2746 if (LocaleCompare("sparse-color",option+1) == 0)
2747 {
2748 SparseColorMethod
2749 method;
2750
2751 char
2752 *arguments;
2753
2754 /*
2755 Sparse Color Interpolated Gradient
2756 */
2757 (void) SyncImageSettings(mogrify_info,*image);
2758 method=(SparseColorMethod) ParseCommandOption(
2759 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2760 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2761 InheritException(exception,&(*image)->exception);
2762 if (arguments == (char *) NULL)
2763 break;
cristy3884f692011-07-08 18:00:18 +00002764 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002765 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2766 arguments=DestroyString(arguments);
2767 break;
2768 }
2769 if (LocaleCompare("splice",option+1) == 0)
2770 {
2771 /*
2772 Splice a solid color into the image.
2773 */
2774 (void) SyncImageSettings(mogrify_info,*image);
2775 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2776 mogrify_image=SpliceImage(*image,&geometry,exception);
2777 break;
2778 }
2779 if (LocaleCompare("spread",option+1) == 0)
2780 {
2781 /*
2782 Spread an image.
2783 */
2784 (void) SyncImageSettings(mogrify_info,*image);
2785 (void) ParseGeometry(argv[i+1],&geometry_info);
2786 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2787 break;
2788 }
2789 if (LocaleCompare("statistic",option+1) == 0)
2790 {
2791 StatisticType
2792 type;
2793
2794 (void) SyncImageSettings(mogrify_info,*image);
2795 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2796 MagickFalse,argv[i+1]);
2797 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002798 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2799 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002800 break;
2801 }
2802 if (LocaleCompare("stretch",option+1) == 0)
2803 {
2804 if (*option == '+')
2805 {
2806 draw_info->stretch=UndefinedStretch;
2807 break;
2808 }
2809 draw_info->stretch=(StretchType) ParseCommandOption(
2810 MagickStretchOptions,MagickFalse,argv[i+1]);
2811 break;
2812 }
2813 if (LocaleCompare("strip",option+1) == 0)
2814 {
2815 /*
2816 Strip image of profiles and comments.
2817 */
2818 (void) SyncImageSettings(mogrify_info,*image);
2819 (void) StripImage(*image);
2820 InheritException(exception,&(*image)->exception);
2821 break;
2822 }
2823 if (LocaleCompare("stroke",option+1) == 0)
2824 {
2825 ExceptionInfo
2826 *sans;
2827
2828 if (*option == '+')
2829 {
2830 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2831 if (draw_info->stroke_pattern != (Image *) NULL)
2832 draw_info->stroke_pattern=DestroyImage(
2833 draw_info->stroke_pattern);
2834 break;
2835 }
2836 sans=AcquireExceptionInfo();
2837 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2838 sans=DestroyExceptionInfo(sans);
2839 if (status == MagickFalse)
2840 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2841 exception);
2842 break;
2843 }
2844 if (LocaleCompare("strokewidth",option+1) == 0)
2845 {
cristyc1acd842011-05-19 23:05:47 +00002846 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2847 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002848 break;
2849 }
2850 if (LocaleCompare("style",option+1) == 0)
2851 {
2852 if (*option == '+')
2853 {
2854 draw_info->style=UndefinedStyle;
2855 break;
2856 }
2857 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2858 MagickFalse,argv[i+1]);
2859 break;
2860 }
2861 if (LocaleCompare("swirl",option+1) == 0)
2862 {
2863 /*
2864 Swirl image.
2865 */
2866 (void) SyncImageSettings(mogrify_info,*image);
2867 (void) ParseGeometry(argv[i+1],&geometry_info);
2868 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2869 break;
2870 }
2871 break;
2872 }
2873 case 't':
2874 {
2875 if (LocaleCompare("threshold",option+1) == 0)
2876 {
2877 double
2878 threshold;
2879
2880 /*
2881 Threshold image.
2882 */
2883 (void) SyncImageSettings(mogrify_info,*image);
2884 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002885 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002886 else
2887 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002888 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002889 InheritException(exception,&(*image)->exception);
2890 break;
2891 }
2892 if (LocaleCompare("thumbnail",option+1) == 0)
2893 {
2894 /*
2895 Thumbnail image.
2896 */
2897 (void) SyncImageSettings(mogrify_info,*image);
2898 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2899 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2900 exception);
2901 break;
2902 }
2903 if (LocaleCompare("tile",option+1) == 0)
2904 {
2905 if (*option == '+')
2906 {
2907 if (draw_info->fill_pattern != (Image *) NULL)
2908 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2909 break;
2910 }
2911 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2912 exception);
2913 break;
2914 }
2915 if (LocaleCompare("tint",option+1) == 0)
2916 {
2917 /*
2918 Tint the image.
2919 */
2920 (void) SyncImageSettings(mogrify_info,*image);
2921 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2922 break;
2923 }
2924 if (LocaleCompare("transform",option+1) == 0)
2925 {
2926 /*
2927 Affine transform image.
2928 */
2929 (void) SyncImageSettings(mogrify_info,*image);
2930 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2931 exception);
2932 break;
2933 }
2934 if (LocaleCompare("transparent",option+1) == 0)
2935 {
cristy4c08aed2011-07-01 19:47:50 +00002936 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002937 target;
2938
2939 (void) SyncImageSettings(mogrify_info,*image);
2940 (void) QueryMagickColor(argv[i+1],&target,exception);
2941 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002942 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002943 InheritException(exception,&(*image)->exception);
2944 break;
2945 }
2946 if (LocaleCompare("transpose",option+1) == 0)
2947 {
2948 /*
2949 Transpose image scanlines.
2950 */
2951 (void) SyncImageSettings(mogrify_info,*image);
2952 mogrify_image=TransposeImage(*image,exception);
2953 break;
2954 }
2955 if (LocaleCompare("transverse",option+1) == 0)
2956 {
2957 /*
2958 Transverse image scanlines.
2959 */
2960 (void) SyncImageSettings(mogrify_info,*image);
2961 mogrify_image=TransverseImage(*image,exception);
2962 break;
2963 }
2964 if (LocaleCompare("treedepth",option+1) == 0)
2965 {
2966 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2967 break;
2968 }
2969 if (LocaleCompare("trim",option+1) == 0)
2970 {
2971 /*
2972 Trim image.
2973 */
2974 (void) SyncImageSettings(mogrify_info,*image);
2975 mogrify_image=TrimImage(*image,exception);
2976 break;
2977 }
2978 if (LocaleCompare("type",option+1) == 0)
2979 {
2980 ImageType
2981 type;
2982
2983 (void) SyncImageSettings(mogrify_info,*image);
2984 if (*option == '+')
2985 type=UndefinedType;
2986 else
2987 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2988 argv[i+1]);
2989 (*image)->type=UndefinedType;
2990 (void) SetImageType(*image,type);
2991 InheritException(exception,&(*image)->exception);
2992 break;
2993 }
2994 break;
2995 }
2996 case 'u':
2997 {
2998 if (LocaleCompare("undercolor",option+1) == 0)
2999 {
3000 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3001 exception);
3002 break;
3003 }
3004 if (LocaleCompare("unique",option+1) == 0)
3005 {
3006 if (*option == '+')
3007 {
3008 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3009 break;
3010 }
3011 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3012 (void) SetImageArtifact(*image,"verbose","true");
3013 break;
3014 }
3015 if (LocaleCompare("unique-colors",option+1) == 0)
3016 {
3017 /*
3018 Unique image colors.
3019 */
3020 (void) SyncImageSettings(mogrify_info,*image);
3021 mogrify_image=UniqueImageColors(*image,exception);
3022 break;
3023 }
3024 if (LocaleCompare("unsharp",option+1) == 0)
3025 {
3026 /*
3027 Unsharp mask image.
3028 */
3029 (void) SyncImageSettings(mogrify_info,*image);
3030 flags=ParseGeometry(argv[i+1],&geometry_info);
3031 if ((flags & SigmaValue) == 0)
3032 geometry_info.sigma=1.0;
3033 if ((flags & XiValue) == 0)
3034 geometry_info.xi=1.0;
3035 if ((flags & PsiValue) == 0)
3036 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003037 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3038 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003039 break;
3040 }
3041 break;
3042 }
3043 case 'v':
3044 {
3045 if (LocaleCompare("verbose",option+1) == 0)
3046 {
3047 (void) SetImageArtifact(*image,option+1,
3048 *option == '+' ? "false" : "true");
3049 break;
3050 }
3051 if (LocaleCompare("vignette",option+1) == 0)
3052 {
3053 /*
3054 Vignette image.
3055 */
3056 (void) SyncImageSettings(mogrify_info,*image);
3057 flags=ParseGeometry(argv[i+1],&geometry_info);
3058 if ((flags & SigmaValue) == 0)
3059 geometry_info.sigma=1.0;
3060 if ((flags & XiValue) == 0)
3061 geometry_info.xi=0.1*(*image)->columns;
3062 if ((flags & PsiValue) == 0)
3063 geometry_info.psi=0.1*(*image)->rows;
3064 mogrify_image=VignetteImage(*image,geometry_info.rho,
3065 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3066 ceil(geometry_info.psi-0.5),exception);
3067 break;
3068 }
3069 if (LocaleCompare("virtual-pixel",option+1) == 0)
3070 {
3071 if (*option == '+')
3072 {
3073 (void) SetImageVirtualPixelMethod(*image,
3074 UndefinedVirtualPixelMethod);
3075 break;
3076 }
3077 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3078 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3079 argv[i+1]));
3080 break;
3081 }
3082 break;
3083 }
3084 case 'w':
3085 {
3086 if (LocaleCompare("wave",option+1) == 0)
3087 {
3088 /*
3089 Wave image.
3090 */
3091 (void) SyncImageSettings(mogrify_info,*image);
3092 flags=ParseGeometry(argv[i+1],&geometry_info);
3093 if ((flags & SigmaValue) == 0)
3094 geometry_info.sigma=1.0;
3095 mogrify_image=WaveImage(*image,geometry_info.rho,
3096 geometry_info.sigma,exception);
3097 break;
3098 }
3099 if (LocaleCompare("weight",option+1) == 0)
3100 {
3101 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3102 if (LocaleCompare(argv[i+1],"all") == 0)
3103 draw_info->weight=0;
3104 if (LocaleCompare(argv[i+1],"bold") == 0)
3105 draw_info->weight=700;
3106 if (LocaleCompare(argv[i+1],"bolder") == 0)
3107 if (draw_info->weight <= 800)
3108 draw_info->weight+=100;
3109 if (LocaleCompare(argv[i+1],"lighter") == 0)
3110 if (draw_info->weight >= 100)
3111 draw_info->weight-=100;
3112 if (LocaleCompare(argv[i+1],"normal") == 0)
3113 draw_info->weight=400;
3114 break;
3115 }
3116 if (LocaleCompare("white-threshold",option+1) == 0)
3117 {
3118 /*
3119 White threshold image.
3120 */
3121 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003122 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003123 InheritException(exception,&(*image)->exception);
3124 break;
3125 }
3126 break;
3127 }
3128 default:
3129 break;
3130 }
3131 /*
3132 Replace current image with any image that was generated
3133 */
3134 if (mogrify_image != (Image *) NULL)
3135 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003136 i+=count;
3137 }
3138 if (region_image != (Image *) NULL)
3139 {
anthonydf8ebac2011-04-27 09:03:19 +00003140 /*
3141 Composite transformed region onto image.
3142 */
cristy6b3da3a2010-06-20 02:21:46 +00003143 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003144 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003145 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3146 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003147 InheritException(exception,&region_image->exception);
3148 *image=DestroyImage(*image);
3149 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003150 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003151 }
3152 /*
3153 Free resources.
3154 */
anthonydf8ebac2011-04-27 09:03:19 +00003155 quantize_info=DestroyQuantizeInfo(quantize_info);
3156 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003157 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003158 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003159 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003160 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003161}
3162
3163/*
3164%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3165% %
3166% %
3167% %
cristy5063d812010-10-19 16:28:10 +00003168+ 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 +00003169% %
3170% %
3171% %
3172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3173%
3174% MogrifyImageCommand() transforms an image or a sequence of images. These
3175% transforms include image scaling, image rotation, color reduction, and
3176% others. The transmogrified image overwrites the original image.
3177%
3178% The format of the MogrifyImageCommand method is:
3179%
3180% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3181% const char **argv,char **metadata,ExceptionInfo *exception)
3182%
3183% A description of each parameter follows:
3184%
3185% o image_info: the image info.
3186%
3187% o argc: the number of elements in the argument vector.
3188%
3189% o argv: A text array containing the command line arguments.
3190%
3191% o metadata: any metadata is returned here.
3192%
3193% o exception: return any errors or warnings in this structure.
3194%
3195*/
3196
3197static MagickBooleanType MogrifyUsage(void)
3198{
3199 static const char
3200 *miscellaneous[]=
3201 {
3202 "-debug events display copious debugging information",
3203 "-help print program options",
3204 "-list type print a list of supported option arguments",
3205 "-log format format of debugging information",
3206 "-version print version information",
3207 (char *) NULL
3208 },
3209 *operators[]=
3210 {
3211 "-adaptive-blur geometry",
3212 " adaptively blur pixels; decrease effect near edges",
3213 "-adaptive-resize geometry",
3214 " adaptively resize image using 'mesh' interpolation",
3215 "-adaptive-sharpen geometry",
3216 " adaptively sharpen pixels; increase effect near edges",
3217 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3218 " transparent, extract, background, or shape",
3219 "-annotate geometry text",
3220 " annotate the image with text",
3221 "-auto-gamma automagically adjust gamma level of image",
3222 "-auto-level automagically adjust color levels of image",
3223 "-auto-orient automagically orient (rotate) image",
3224 "-bench iterations measure performance",
3225 "-black-threshold value",
3226 " force all pixels below the threshold into black",
3227 "-blue-shift simulate a scene at nighttime in the moonlight",
3228 "-blur geometry reduce image noise and reduce detail levels",
3229 "-border geometry surround image with a border of color",
3230 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003231 "-brightness-contrast geometry",
3232 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003233 "-cdl filename color correct with a color decision list",
3234 "-charcoal radius simulate a charcoal drawing",
3235 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003236 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003237 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003238 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003239 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003240 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003241 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003242 "-contrast enhance or reduce the image contrast",
3243 "-contrast-stretch geometry",
3244 " improve contrast by `stretching' the intensity range",
3245 "-convolve coefficients",
3246 " apply a convolution kernel to the image",
3247 "-cycle amount cycle the image colormap",
3248 "-decipher filename convert cipher pixels to plain pixels",
3249 "-deskew threshold straighten an image",
3250 "-despeckle reduce the speckles within an image",
3251 "-distort method args",
3252 " distort images according to given method ad args",
3253 "-draw string annotate the image with a graphic primitive",
3254 "-edge radius apply a filter to detect edges in the image",
3255 "-encipher filename convert plain pixels to cipher pixels",
3256 "-emboss radius emboss an image",
3257 "-enhance apply a digital filter to enhance a noisy image",
3258 "-equalize perform histogram equalization to an image",
3259 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003260 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003261 "-extent geometry set the image size",
3262 "-extract geometry extract area from image",
3263 "-fft implements the discrete Fourier transform (DFT)",
3264 "-flip flip image vertically",
3265 "-floodfill geometry color",
3266 " floodfill the image with color",
3267 "-flop flop image horizontally",
3268 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003269 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003270 " apply function over image values",
3271 "-gamma value level of gamma correction",
3272 "-gaussian-blur geometry",
3273 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003274 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003275 "-identify identify the format and characteristics of the image",
3276 "-ift implements the inverse discrete Fourier transform (DFT)",
3277 "-implode amount implode image pixels about the center",
3278 "-lat geometry local adaptive thresholding",
3279 "-layers method optimize, merge, or compare image layers",
3280 "-level value adjust the level of image contrast",
3281 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003282 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003283 "-linear-stretch geometry",
3284 " improve contrast by `stretching with saturation'",
3285 "-liquid-rescale geometry",
3286 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003287 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003288 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003289 "-modulate value vary the brightness, saturation, and hue",
3290 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003291 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003292 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003293 "-motion-blur geometry",
3294 " simulate motion blur",
3295 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003296 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003297 "-normalize transform image to span the full range of colors",
3298 "-opaque color change this color to the fill color",
3299 "-ordered-dither NxN",
3300 " add a noise pattern to the image with specific",
3301 " amplitudes",
3302 "-paint radius simulate an oil painting",
3303 "-polaroid angle simulate a Polaroid picture",
3304 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003305 "-profile filename add, delete, or apply an image profile",
3306 "-quantize colorspace reduce colors in this colorspace",
3307 "-radial-blur angle radial blur the image",
3308 "-raise value lighten/darken image edges to create a 3-D effect",
3309 "-random-threshold low,high",
3310 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003311 "-region geometry apply options to a portion of the image",
3312 "-render render vector graphics",
3313 "-repage geometry size and location of an image canvas",
3314 "-resample geometry change the resolution of an image",
3315 "-resize geometry resize the image",
3316 "-roll geometry roll an image vertically or horizontally",
3317 "-rotate degrees apply Paeth rotation to the image",
3318 "-sample geometry scale image with pixel sampling",
3319 "-scale geometry scale the image",
3320 "-segment values segment an image",
3321 "-selective-blur geometry",
3322 " selectively blur pixels within a contrast threshold",
3323 "-sepia-tone threshold",
3324 " simulate a sepia-toned photo",
3325 "-set property value set an image property",
3326 "-shade degrees shade the image using a distant light source",
3327 "-shadow geometry simulate an image shadow",
3328 "-sharpen geometry sharpen the image",
3329 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003330 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003331 "-sigmoidal-contrast geometry",
3332 " increase the contrast without saturating highlights or shadows",
3333 "-sketch geometry simulate a pencil sketch",
3334 "-solarize threshold negate all pixels above the threshold level",
3335 "-sparse-color method args",
3336 " fill in a image based on a few color points",
3337 "-splice geometry splice the background color into the image",
3338 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003339 "-statistic type radius",
3340 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003341 "-strip strip image of all profiles and comments",
3342 "-swirl degrees swirl image pixels about the center",
3343 "-threshold value threshold the image",
3344 "-thumbnail geometry create a thumbnail of the image",
3345 "-tile filename tile image when filling a graphic primitive",
3346 "-tint value tint the image with the fill color",
3347 "-transform affine transform image",
3348 "-transparent color make this color transparent within the image",
3349 "-transpose flip image vertically and rotate 90 degrees",
3350 "-transverse flop image horizontally and rotate 270 degrees",
3351 "-trim trim image edges",
3352 "-type type image type",
3353 "-unique-colors discard all but one of any pixel color",
3354 "-unsharp geometry sharpen the image",
3355 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003356 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-white-threshold value",
3358 " force all pixels above the threshold into white",
3359 (char *) NULL
3360 },
3361 *sequence_operators[]=
3362 {
cristy4285d782011-02-09 20:12:28 +00003363 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003364 "-clut apply a color lookup table to the image",
3365 "-coalesce merge a sequence of images",
3366 "-combine combine a sequence of images",
3367 "-composite composite image",
3368 "-crop geometry cut out a rectangular region of the image",
3369 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003370 "-evaluate-sequence operator",
3371 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003372 "-flatten flatten a sequence of images",
3373 "-fx expression apply mathematical expression to an image channel(s)",
3374 "-hald-clut apply a Hald color lookup table to the image",
3375 "-morph value morph an image sequence",
3376 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003377 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003378 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003379 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003380 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-write filename write images to this file",
3382 (char *) NULL
3383 },
3384 *settings[]=
3385 {
3386 "-adjoin join images into a single multi-image file",
3387 "-affine matrix affine transform matrix",
3388 "-alpha option activate, deactivate, reset, or set the alpha channel",
3389 "-antialias remove pixel-aliasing",
3390 "-authenticate password",
3391 " decipher image with this password",
3392 "-attenuate value lessen (or intensify) when adding noise to an image",
3393 "-background color background color",
3394 "-bias value add bias when convolving an image",
3395 "-black-point-compensation",
3396 " use black point compensation",
3397 "-blue-primary point chromaticity blue primary point",
3398 "-bordercolor color border color",
3399 "-caption string assign a caption to an image",
3400 "-channel type apply option to select image channels",
3401 "-colors value preferred number of colors in the image",
3402 "-colorspace type alternate image colorspace",
3403 "-comment string annotate image with comment",
3404 "-compose operator set image composite operator",
3405 "-compress type type of pixel compression when writing the image",
3406 "-define format:option",
3407 " define one or more image format options",
3408 "-delay value display the next image after pausing",
3409 "-density geometry horizontal and vertical density of the image",
3410 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003411 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003412 "-display server get image or font from this X server",
3413 "-dispose method layer disposal method",
3414 "-dither method apply error diffusion to image",
3415 "-encoding type text encoding type",
3416 "-endian type endianness (MSB or LSB) of the image",
3417 "-family name render text with this font family",
3418 "-fill color color to use when filling a graphic primitive",
3419 "-filter type use this filter when resizing an image",
3420 "-font name render text with this font",
3421 "-format \"string\" output formatted image characteristics",
3422 "-fuzz distance colors within this distance are considered equal",
3423 "-gravity type horizontal and vertical text placement",
3424 "-green-primary point chromaticity green primary point",
3425 "-intent type type of rendering intent when managing the image color",
3426 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003427 "-interline-spacing value",
3428 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003429 "-interpolate method pixel color interpolation method",
3430 "-interword-spacing value",
3431 " set the space between two words",
3432 "-kerning value set the space between two letters",
3433 "-label string assign a label to an image",
3434 "-limit type value pixel cache resource limit",
3435 "-loop iterations add Netscape loop extension to your GIF animation",
3436 "-mask filename associate a mask with the image",
3437 "-mattecolor color frame color",
3438 "-monitor monitor progress",
3439 "-orient type image orientation",
3440 "-page geometry size and location of an image canvas (setting)",
3441 "-ping efficiently determine image attributes",
3442 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003443 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003444 "-preview type image preview type",
3445 "-quality value JPEG/MIFF/PNG compression level",
3446 "-quiet suppress all warning messages",
3447 "-red-primary point chromaticity red primary point",
3448 "-regard-warnings pay attention to warning messages",
3449 "-remap filename transform image colors to match this set of colors",
3450 "-respect-parentheses settings remain in effect until parenthesis boundary",
3451 "-sampling-factor geometry",
3452 " horizontal and vertical sampling factor",
3453 "-scene value image scene number",
3454 "-seed value seed a new sequence of pseudo-random numbers",
3455 "-size geometry width and height of image",
3456 "-stretch type render text with this font stretch",
3457 "-stroke color graphic primitive stroke color",
3458 "-strokewidth value graphic primitive stroke width",
3459 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003460 "-synchronize synchronize image to storage device",
3461 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003462 "-texture filename name of texture to tile onto the image background",
3463 "-tile-offset geometry",
3464 " tile offset",
3465 "-treedepth value color tree depth",
3466 "-transparent-color color",
3467 " transparent color",
3468 "-undercolor color annotation bounding box color",
3469 "-units type the units of image resolution",
3470 "-verbose print detailed information about the image",
3471 "-view FlashPix viewing transforms",
3472 "-virtual-pixel method",
3473 " virtual pixel access method",
3474 "-weight type render text with this font weight",
3475 "-white-point point chromaticity white point",
3476 (char *) NULL
3477 },
3478 *stack_operators[]=
3479 {
anthonyb69c4b32011-03-23 04:37:44 +00003480 "-delete indexes delete the image from the image sequence",
3481 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003482 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003483 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003484 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003485 "-swap indexes swap two images in the image sequence",
3486 (char *) NULL
3487 };
3488
3489 const char
3490 **p;
3491
cristybb503372010-05-27 20:51:26 +00003492 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003493 (void) printf("Copyright: %s\n",GetMagickCopyright());
3494 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003495 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3496 GetClientName());
3497 (void) printf("\nImage Settings:\n");
3498 for (p=settings; *p != (char *) NULL; p++)
3499 (void) printf(" %s\n",*p);
3500 (void) printf("\nImage Operators:\n");
3501 for (p=operators; *p != (char *) NULL; p++)
3502 (void) printf(" %s\n",*p);
3503 (void) printf("\nImage Sequence Operators:\n");
3504 for (p=sequence_operators; *p != (char *) NULL; p++)
3505 (void) printf(" %s\n",*p);
3506 (void) printf("\nImage Stack Operators:\n");
3507 for (p=stack_operators; *p != (char *) NULL; p++)
3508 (void) printf(" %s\n",*p);
3509 (void) printf("\nMiscellaneous Options:\n");
3510 for (p=miscellaneous; *p != (char *) NULL; p++)
3511 (void) printf(" %s\n",*p);
3512 (void) printf(
3513 "\nBy default, the image format of `file' is determined by its magic\n");
3514 (void) printf(
3515 "number. To specify a particular image format, precede the filename\n");
3516 (void) printf(
3517 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3518 (void) printf(
3519 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3520 (void) printf("'-' for standard input or output.\n");
3521 return(MagickFalse);
3522}
3523
3524WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3525 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3526{
3527#define DestroyMogrify() \
3528{ \
3529 if (format != (char *) NULL) \
3530 format=DestroyString(format); \
3531 if (path != (char *) NULL) \
3532 path=DestroyString(path); \
3533 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003534 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003535 argv[i]=DestroyString(argv[i]); \
3536 argv=(char **) RelinquishMagickMemory(argv); \
3537}
3538#define ThrowMogrifyException(asperity,tag,option) \
3539{ \
3540 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3541 option); \
3542 DestroyMogrify(); \
3543 return(MagickFalse); \
3544}
3545#define ThrowMogrifyInvalidArgumentException(option,argument) \
3546{ \
3547 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3548 "InvalidArgument","`%s': %s",argument,option); \
3549 DestroyMogrify(); \
3550 return(MagickFalse); \
3551}
3552
3553 char
3554 *format,
3555 *option,
3556 *path;
3557
3558 Image
3559 *image;
3560
3561 ImageStack
3562 image_stack[MaxImageStackDepth+1];
3563
cristy3ed852e2009-09-05 21:47:34 +00003564 MagickBooleanType
3565 global_colormap;
3566
3567 MagickBooleanType
3568 fire,
cristyebbcfea2011-02-25 02:43:54 +00003569 pend,
3570 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003571
3572 MagickStatusType
3573 status;
3574
cristyebbcfea2011-02-25 02:43:54 +00003575 register ssize_t
3576 i;
3577
3578 ssize_t
3579 j,
3580 k;
3581
cristy3ed852e2009-09-05 21:47:34 +00003582 /*
3583 Set defaults.
3584 */
3585 assert(image_info != (ImageInfo *) NULL);
3586 assert(image_info->signature == MagickSignature);
3587 if (image_info->debug != MagickFalse)
3588 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3589 assert(exception != (ExceptionInfo *) NULL);
3590 if (argc == 2)
3591 {
3592 option=argv[1];
3593 if ((LocaleCompare("version",option+1) == 0) ||
3594 (LocaleCompare("-version",option+1) == 0))
3595 {
cristyb51dff52011-05-19 16:55:47 +00003596 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003597 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003598 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3599 GetMagickCopyright());
3600 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3601 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003602 return(MagickFalse);
3603 }
3604 }
3605 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003606 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003607 format=(char *) NULL;
3608 path=(char *) NULL;
3609 global_colormap=MagickFalse;
3610 k=0;
3611 j=1;
3612 NewImageStack();
3613 option=(char *) NULL;
3614 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003615 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003616 status=MagickTrue;
3617 /*
3618 Parse command line.
3619 */
3620 ReadCommandlLine(argc,&argv);
3621 status=ExpandFilenames(&argc,&argv);
3622 if (status == MagickFalse)
3623 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3624 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003625 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003626 {
3627 option=argv[i];
3628 if (LocaleCompare(option,"(") == 0)
3629 {
3630 FireImageStack(MagickFalse,MagickTrue,pend);
3631 if (k == MaxImageStackDepth)
3632 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3633 option);
3634 PushImageStack();
3635 continue;
3636 }
3637 if (LocaleCompare(option,")") == 0)
3638 {
3639 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3640 if (k == 0)
3641 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3642 PopImageStack();
3643 continue;
3644 }
cristy042ee782011-04-22 18:48:30 +00003645 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003646 {
3647 char
3648 backup_filename[MaxTextExtent],
3649 *filename;
3650
3651 Image
3652 *images;
3653
3654 /*
3655 Option is a file name: begin by reading image from specified file.
3656 */
3657 FireImageStack(MagickFalse,MagickFalse,pend);
3658 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003659 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003660 filename=argv[++i];
3661 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3662 images=ReadImages(image_info,exception);
3663 status&=(images != (Image *) NULL) &&
3664 (exception->severity < ErrorException);
3665 if (images == (Image *) NULL)
3666 continue;
cristydaa76602010-06-30 13:05:11 +00003667 if (format != (char *) NULL)
3668 (void) CopyMagickString(images->filename,images->magick_filename,
3669 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003670 if (path != (char *) NULL)
3671 {
3672 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003673 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003674 path,*DirectorySeparator,filename);
3675 }
3676 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003677 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003678 AppendImageStack(images);
3679 FinalizeImageSettings(image_info,image,MagickFalse);
3680 if (global_colormap != MagickFalse)
3681 {
3682 QuantizeInfo
3683 *quantize_info;
3684
3685 quantize_info=AcquireQuantizeInfo(image_info);
3686 (void) RemapImages(quantize_info,images,(Image *) NULL);
3687 quantize_info=DestroyQuantizeInfo(quantize_info);
3688 }
3689 *backup_filename='\0';
3690 if ((LocaleCompare(image->filename,"-") != 0) &&
3691 (IsPathWritable(image->filename) != MagickFalse))
3692 {
cristybb503372010-05-27 20:51:26 +00003693 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003694 i;
3695
3696 /*
3697 Rename image file as backup.
3698 */
3699 (void) CopyMagickString(backup_filename,image->filename,
3700 MaxTextExtent);
3701 for (i=0; i < 6; i++)
3702 {
3703 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3704 if (IsPathAccessible(backup_filename) == MagickFalse)
3705 break;
3706 }
3707 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3708 (rename(image->filename,backup_filename) != 0))
3709 *backup_filename='\0';
3710 }
3711 /*
3712 Write transmogrified image to disk.
3713 */
3714 image_info->synchronize=MagickTrue;
3715 status&=WriteImages(image_info,image,image->filename,exception);
3716 if ((status == MagickFalse) && (*backup_filename != '\0'))
3717 (void) remove(backup_filename);
3718 RemoveAllImageStack();
3719 continue;
3720 }
3721 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3722 switch (*(option+1))
3723 {
3724 case 'a':
3725 {
3726 if (LocaleCompare("adaptive-blur",option+1) == 0)
3727 {
3728 i++;
cristybb503372010-05-27 20:51:26 +00003729 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003730 ThrowMogrifyException(OptionError,"MissingArgument",option);
3731 if (IsGeometry(argv[i]) == MagickFalse)
3732 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3733 break;
3734 }
3735 if (LocaleCompare("adaptive-resize",option+1) == 0)
3736 {
3737 i++;
cristybb503372010-05-27 20:51:26 +00003738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003739 ThrowMogrifyException(OptionError,"MissingArgument",option);
3740 if (IsGeometry(argv[i]) == MagickFalse)
3741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3742 break;
3743 }
3744 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3745 {
3746 i++;
cristybb503372010-05-27 20:51:26 +00003747 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003748 ThrowMogrifyException(OptionError,"MissingArgument",option);
3749 if (IsGeometry(argv[i]) == MagickFalse)
3750 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3751 break;
3752 }
3753 if (LocaleCompare("affine",option+1) == 0)
3754 {
3755 if (*option == '+')
3756 break;
3757 i++;
cristybb503372010-05-27 20:51:26 +00003758 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003759 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003760 break;
3761 }
3762 if (LocaleCompare("alpha",option+1) == 0)
3763 {
cristybb503372010-05-27 20:51:26 +00003764 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003765 type;
3766
3767 if (*option == '+')
3768 break;
3769 i++;
cristybb503372010-05-27 20:51:26 +00003770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003771 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003772 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003773 if (type < 0)
3774 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3775 argv[i]);
3776 break;
3777 }
3778 if (LocaleCompare("annotate",option+1) == 0)
3779 {
3780 if (*option == '+')
3781 break;
3782 i++;
cristybb503372010-05-27 20:51:26 +00003783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003784 ThrowMogrifyException(OptionError,"MissingArgument",option);
3785 if (IsGeometry(argv[i]) == MagickFalse)
3786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003787 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003788 ThrowMogrifyException(OptionError,"MissingArgument",option);
3789 i++;
3790 break;
3791 }
3792 if (LocaleCompare("antialias",option+1) == 0)
3793 break;
3794 if (LocaleCompare("append",option+1) == 0)
3795 break;
3796 if (LocaleCompare("attenuate",option+1) == 0)
3797 {
3798 if (*option == '+')
3799 break;
3800 i++;
cristybb503372010-05-27 20:51:26 +00003801 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003802 ThrowMogrifyException(OptionError,"MissingArgument",option);
3803 if (IsGeometry(argv[i]) == MagickFalse)
3804 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3805 break;
3806 }
3807 if (LocaleCompare("authenticate",option+1) == 0)
3808 {
3809 if (*option == '+')
3810 break;
3811 i++;
cristybb503372010-05-27 20:51:26 +00003812 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003813 ThrowMogrifyException(OptionError,"MissingArgument",option);
3814 break;
3815 }
3816 if (LocaleCompare("auto-gamma",option+1) == 0)
3817 break;
3818 if (LocaleCompare("auto-level",option+1) == 0)
3819 break;
3820 if (LocaleCompare("auto-orient",option+1) == 0)
3821 break;
3822 if (LocaleCompare("average",option+1) == 0)
3823 break;
3824 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3825 }
3826 case 'b':
3827 {
3828 if (LocaleCompare("background",option+1) == 0)
3829 {
3830 if (*option == '+')
3831 break;
3832 i++;
cristybb503372010-05-27 20:51:26 +00003833 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003834 ThrowMogrifyException(OptionError,"MissingArgument",option);
3835 break;
3836 }
3837 if (LocaleCompare("bias",option+1) == 0)
3838 {
3839 if (*option == '+')
3840 break;
3841 i++;
cristybb503372010-05-27 20:51:26 +00003842 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003843 ThrowMogrifyException(OptionError,"MissingArgument",option);
3844 if (IsGeometry(argv[i]) == MagickFalse)
3845 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3846 break;
3847 }
3848 if (LocaleCompare("black-point-compensation",option+1) == 0)
3849 break;
3850 if (LocaleCompare("black-threshold",option+1) == 0)
3851 {
3852 if (*option == '+')
3853 break;
3854 i++;
cristybb503372010-05-27 20:51:26 +00003855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003856 ThrowMogrifyException(OptionError,"MissingArgument",option);
3857 if (IsGeometry(argv[i]) == MagickFalse)
3858 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3859 break;
3860 }
3861 if (LocaleCompare("blue-primary",option+1) == 0)
3862 {
3863 if (*option == '+')
3864 break;
3865 i++;
cristybb503372010-05-27 20:51:26 +00003866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003867 ThrowMogrifyException(OptionError,"MissingArgument",option);
3868 if (IsGeometry(argv[i]) == MagickFalse)
3869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3870 break;
3871 }
3872 if (LocaleCompare("blue-shift",option+1) == 0)
3873 {
3874 i++;
cristybb503372010-05-27 20:51:26 +00003875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003876 ThrowMogrifyException(OptionError,"MissingArgument",option);
3877 if (IsGeometry(argv[i]) == MagickFalse)
3878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3879 break;
3880 }
3881 if (LocaleCompare("blur",option+1) == 0)
3882 {
3883 i++;
cristybb503372010-05-27 20:51:26 +00003884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003885 ThrowMogrifyException(OptionError,"MissingArgument",option);
3886 if (IsGeometry(argv[i]) == MagickFalse)
3887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3888 break;
3889 }
3890 if (LocaleCompare("border",option+1) == 0)
3891 {
3892 if (*option == '+')
3893 break;
3894 i++;
cristybb503372010-05-27 20:51:26 +00003895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003896 ThrowMogrifyException(OptionError,"MissingArgument",option);
3897 if (IsGeometry(argv[i]) == MagickFalse)
3898 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3899 break;
3900 }
3901 if (LocaleCompare("bordercolor",option+1) == 0)
3902 {
3903 if (*option == '+')
3904 break;
3905 i++;
cristybb503372010-05-27 20:51:26 +00003906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003907 ThrowMogrifyException(OptionError,"MissingArgument",option);
3908 break;
3909 }
3910 if (LocaleCompare("box",option+1) == 0)
3911 {
3912 if (*option == '+')
3913 break;
3914 i++;
cristybb503372010-05-27 20:51:26 +00003915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003916 ThrowMogrifyException(OptionError,"MissingArgument",option);
3917 break;
3918 }
cristya28d6b82010-01-11 20:03:47 +00003919 if (LocaleCompare("brightness-contrast",option+1) == 0)
3920 {
3921 i++;
cristybb503372010-05-27 20:51:26 +00003922 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003923 ThrowMogrifyException(OptionError,"MissingArgument",option);
3924 if (IsGeometry(argv[i]) == MagickFalse)
3925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3926 break;
3927 }
cristy3ed852e2009-09-05 21:47:34 +00003928 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3929 }
3930 case 'c':
3931 {
3932 if (LocaleCompare("cache",option+1) == 0)
3933 {
3934 if (*option == '+')
3935 break;
3936 i++;
cristybb503372010-05-27 20:51:26 +00003937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003938 ThrowMogrifyException(OptionError,"MissingArgument",option);
3939 if (IsGeometry(argv[i]) == MagickFalse)
3940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3941 break;
3942 }
3943 if (LocaleCompare("caption",option+1) == 0)
3944 {
3945 if (*option == '+')
3946 break;
3947 i++;
cristybb503372010-05-27 20:51:26 +00003948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003949 ThrowMogrifyException(OptionError,"MissingArgument",option);
3950 break;
3951 }
3952 if (LocaleCompare("channel",option+1) == 0)
3953 {
cristybb503372010-05-27 20:51:26 +00003954 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003955 channel;
3956
3957 if (*option == '+')
3958 break;
3959 i++;
cristybb503372010-05-27 20:51:26 +00003960 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003961 ThrowMogrifyException(OptionError,"MissingArgument",option);
3962 channel=ParseChannelOption(argv[i]);
3963 if (channel < 0)
3964 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3965 argv[i]);
3966 break;
3967 }
3968 if (LocaleCompare("cdl",option+1) == 0)
3969 {
3970 if (*option == '+')
3971 break;
3972 i++;
cristybb503372010-05-27 20:51:26 +00003973 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003974 ThrowMogrifyException(OptionError,"MissingArgument",option);
3975 break;
3976 }
3977 if (LocaleCompare("charcoal",option+1) == 0)
3978 {
3979 if (*option == '+')
3980 break;
3981 i++;
cristybb503372010-05-27 20:51:26 +00003982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003983 ThrowMogrifyException(OptionError,"MissingArgument",option);
3984 if (IsGeometry(argv[i]) == MagickFalse)
3985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3986 break;
3987 }
3988 if (LocaleCompare("chop",option+1) == 0)
3989 {
3990 if (*option == '+')
3991 break;
3992 i++;
cristybb503372010-05-27 20:51:26 +00003993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003994 ThrowMogrifyException(OptionError,"MissingArgument",option);
3995 if (IsGeometry(argv[i]) == MagickFalse)
3996 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3997 break;
3998 }
cristy1eb45dd2009-09-25 16:38:06 +00003999 if (LocaleCompare("clamp",option+1) == 0)
4000 break;
4001 if (LocaleCompare("clip",option+1) == 0)
4002 break;
cristy3ed852e2009-09-05 21:47:34 +00004003 if (LocaleCompare("clip-mask",option+1) == 0)
4004 {
4005 if (*option == '+')
4006 break;
4007 i++;
cristybb503372010-05-27 20:51:26 +00004008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004009 ThrowMogrifyException(OptionError,"MissingArgument",option);
4010 break;
4011 }
4012 if (LocaleCompare("clut",option+1) == 0)
4013 break;
4014 if (LocaleCompare("coalesce",option+1) == 0)
4015 break;
4016 if (LocaleCompare("colorize",option+1) == 0)
4017 {
4018 if (*option == '+')
4019 break;
4020 i++;
cristybb503372010-05-27 20:51:26 +00004021 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004022 ThrowMogrifyException(OptionError,"MissingArgument",option);
4023 if (IsGeometry(argv[i]) == MagickFalse)
4024 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4025 break;
4026 }
cristye6365592010-04-02 17:31:23 +00004027 if (LocaleCompare("color-matrix",option+1) == 0)
4028 {
cristyb6bd4ad2010-08-08 01:12:27 +00004029 KernelInfo
4030 *kernel_info;
4031
cristye6365592010-04-02 17:31:23 +00004032 if (*option == '+')
4033 break;
4034 i++;
cristybb503372010-05-27 20:51:26 +00004035 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004036 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004037 kernel_info=AcquireKernelInfo(argv[i]);
4038 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004039 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004040 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004041 break;
4042 }
cristy3ed852e2009-09-05 21:47:34 +00004043 if (LocaleCompare("colors",option+1) == 0)
4044 {
4045 if (*option == '+')
4046 break;
4047 i++;
cristybb503372010-05-27 20:51:26 +00004048 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004049 ThrowMogrifyException(OptionError,"MissingArgument",option);
4050 if (IsGeometry(argv[i]) == MagickFalse)
4051 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4052 break;
4053 }
4054 if (LocaleCompare("colorspace",option+1) == 0)
4055 {
cristybb503372010-05-27 20:51:26 +00004056 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004057 colorspace;
4058
4059 if (*option == '+')
4060 break;
4061 i++;
cristybb503372010-05-27 20:51:26 +00004062 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004063 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004064 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004065 argv[i]);
4066 if (colorspace < 0)
4067 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4068 argv[i]);
4069 break;
4070 }
4071 if (LocaleCompare("combine",option+1) == 0)
4072 break;
4073 if (LocaleCompare("comment",option+1) == 0)
4074 {
4075 if (*option == '+')
4076 break;
4077 i++;
cristybb503372010-05-27 20:51:26 +00004078 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004079 ThrowMogrifyException(OptionError,"MissingArgument",option);
4080 break;
4081 }
4082 if (LocaleCompare("composite",option+1) == 0)
4083 break;
4084 if (LocaleCompare("compress",option+1) == 0)
4085 {
cristybb503372010-05-27 20:51:26 +00004086 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004087 compress;
4088
4089 if (*option == '+')
4090 break;
4091 i++;
cristybb503372010-05-27 20:51:26 +00004092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004093 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004094 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004095 argv[i]);
4096 if (compress < 0)
4097 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4098 argv[i]);
4099 break;
4100 }
cristy22879752009-10-25 23:55:40 +00004101 if (LocaleCompare("concurrent",option+1) == 0)
4102 break;
cristy3ed852e2009-09-05 21:47:34 +00004103 if (LocaleCompare("contrast",option+1) == 0)
4104 break;
4105 if (LocaleCompare("contrast-stretch",option+1) == 0)
4106 {
4107 i++;
cristybb503372010-05-27 20:51:26 +00004108 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004109 ThrowMogrifyException(OptionError,"MissingArgument",option);
4110 if (IsGeometry(argv[i]) == MagickFalse)
4111 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4112 break;
4113 }
4114 if (LocaleCompare("convolve",option+1) == 0)
4115 {
cristyb6bd4ad2010-08-08 01:12:27 +00004116 KernelInfo
4117 *kernel_info;
4118
cristy3ed852e2009-09-05 21:47:34 +00004119 if (*option == '+')
4120 break;
4121 i++;
cristybb503372010-05-27 20:51:26 +00004122 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004123 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004124 kernel_info=AcquireKernelInfo(argv[i]);
4125 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004126 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004127 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004128 break;
4129 }
4130 if (LocaleCompare("crop",option+1) == 0)
4131 {
4132 if (*option == '+')
4133 break;
4134 i++;
cristybb503372010-05-27 20:51:26 +00004135 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004136 ThrowMogrifyException(OptionError,"MissingArgument",option);
4137 if (IsGeometry(argv[i]) == MagickFalse)
4138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4139 break;
4140 }
4141 if (LocaleCompare("cycle",option+1) == 0)
4142 {
4143 if (*option == '+')
4144 break;
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
4148 if (IsGeometry(argv[i]) == MagickFalse)
4149 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4150 break;
4151 }
4152 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4153 }
4154 case 'd':
4155 {
4156 if (LocaleCompare("decipher",option+1) == 0)
4157 {
4158 if (*option == '+')
4159 break;
4160 i++;
cristybb503372010-05-27 20:51:26 +00004161 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004162 ThrowMogrifyException(OptionError,"MissingArgument",option);
4163 break;
4164 }
4165 if (LocaleCompare("deconstruct",option+1) == 0)
4166 break;
4167 if (LocaleCompare("debug",option+1) == 0)
4168 {
cristybb503372010-05-27 20:51:26 +00004169 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004170 event;
4171
4172 if (*option == '+')
4173 break;
4174 i++;
cristybb503372010-05-27 20:51:26 +00004175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004176 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004177 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004178 if (event < 0)
4179 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4180 argv[i]);
4181 (void) SetLogEventMask(argv[i]);
4182 break;
4183 }
4184 if (LocaleCompare("define",option+1) == 0)
4185 {
4186 i++;
cristybb503372010-05-27 20:51:26 +00004187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004188 ThrowMogrifyException(OptionError,"MissingArgument",option);
4189 if (*option == '+')
4190 {
4191 const char
4192 *define;
4193
4194 define=GetImageOption(image_info,argv[i]);
4195 if (define == (const char *) NULL)
4196 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4197 break;
4198 }
4199 break;
4200 }
4201 if (LocaleCompare("delay",option+1) == 0)
4202 {
4203 if (*option == '+')
4204 break;
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
4208 if (IsGeometry(argv[i]) == MagickFalse)
4209 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4210 break;
4211 }
cristyecb10ff2011-03-22 13:14:03 +00004212 if (LocaleCompare("delete",option+1) == 0)
4213 {
4214 if (*option == '+')
4215 break;
4216 i++;
4217 if (i == (ssize_t) (argc-1))
4218 ThrowMogrifyException(OptionError,"MissingArgument",option);
4219 if (IsGeometry(argv[i]) == MagickFalse)
4220 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4221 break;
4222 }
cristy3ed852e2009-09-05 21:47:34 +00004223 if (LocaleCompare("density",option+1) == 0)
4224 {
4225 if (*option == '+')
4226 break;
4227 i++;
cristybb503372010-05-27 20:51:26 +00004228 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004229 ThrowMogrifyException(OptionError,"MissingArgument",option);
4230 if (IsGeometry(argv[i]) == MagickFalse)
4231 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4232 break;
4233 }
4234 if (LocaleCompare("depth",option+1) == 0)
4235 {
4236 if (*option == '+')
4237 break;
4238 i++;
cristybb503372010-05-27 20:51:26 +00004239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004240 ThrowMogrifyException(OptionError,"MissingArgument",option);
4241 if (IsGeometry(argv[i]) == MagickFalse)
4242 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4243 break;
4244 }
4245 if (LocaleCompare("deskew",option+1) == 0)
4246 {
4247 if (*option == '+')
4248 break;
4249 i++;
cristybb503372010-05-27 20:51:26 +00004250 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004251 ThrowMogrifyException(OptionError,"MissingArgument",option);
4252 if (IsGeometry(argv[i]) == MagickFalse)
4253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4254 break;
4255 }
4256 if (LocaleCompare("despeckle",option+1) == 0)
4257 break;
4258 if (LocaleCompare("dft",option+1) == 0)
4259 break;
cristyc9b12952010-03-28 01:12:28 +00004260 if (LocaleCompare("direction",option+1) == 0)
4261 {
cristybb503372010-05-27 20:51:26 +00004262 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004263 direction;
4264
4265 if (*option == '+')
4266 break;
4267 i++;
cristybb503372010-05-27 20:51:26 +00004268 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004269 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004270 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004271 argv[i]);
4272 if (direction < 0)
4273 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4274 argv[i]);
4275 break;
4276 }
cristy3ed852e2009-09-05 21:47:34 +00004277 if (LocaleCompare("display",option+1) == 0)
4278 {
4279 if (*option == '+')
4280 break;
4281 i++;
cristybb503372010-05-27 20:51:26 +00004282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004283 ThrowMogrifyException(OptionError,"MissingArgument",option);
4284 break;
4285 }
4286 if (LocaleCompare("dispose",option+1) == 0)
4287 {
cristybb503372010-05-27 20:51:26 +00004288 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004289 dispose;
4290
4291 if (*option == '+')
4292 break;
4293 i++;
cristybb503372010-05-27 20:51:26 +00004294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004295 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004296 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004297 if (dispose < 0)
4298 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4299 argv[i]);
4300 break;
4301 }
4302 if (LocaleCompare("distort",option+1) == 0)
4303 {
cristybb503372010-05-27 20:51:26 +00004304 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004305 op;
4306
4307 i++;
cristybb503372010-05-27 20:51:26 +00004308 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004309 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004310 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004311 if (op < 0)
4312 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4313 argv[i]);
4314 i++;
cristybb503372010-05-27 20:51:26 +00004315 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004316 ThrowMogrifyException(OptionError,"MissingArgument",option);
4317 break;
4318 }
4319 if (LocaleCompare("dither",option+1) == 0)
4320 {
cristybb503372010-05-27 20:51:26 +00004321 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004322 method;
4323
4324 if (*option == '+')
4325 break;
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004329 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004330 if (method < 0)
4331 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4332 argv[i]);
4333 break;
4334 }
4335 if (LocaleCompare("draw",option+1) == 0)
4336 {
4337 if (*option == '+')
4338 break;
4339 i++;
cristybb503372010-05-27 20:51:26 +00004340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004341 ThrowMogrifyException(OptionError,"MissingArgument",option);
4342 break;
4343 }
cristyecb10ff2011-03-22 13:14:03 +00004344 if (LocaleCompare("duplicate",option+1) == 0)
4345 {
4346 if (*option == '+')
4347 break;
4348 i++;
4349 if (i == (ssize_t) (argc-1))
4350 ThrowMogrifyException(OptionError,"MissingArgument",option);
4351 if (IsGeometry(argv[i]) == MagickFalse)
4352 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4353 break;
4354 }
cristy22879752009-10-25 23:55:40 +00004355 if (LocaleCompare("duration",option+1) == 0)
4356 {
4357 if (*option == '+')
4358 break;
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
4362 if (IsGeometry(argv[i]) == MagickFalse)
4363 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4364 break;
4365 }
cristy3ed852e2009-09-05 21:47:34 +00004366 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4367 }
4368 case 'e':
4369 {
4370 if (LocaleCompare("edge",option+1) == 0)
4371 {
4372 if (*option == '+')
4373 break;
4374 i++;
cristybb503372010-05-27 20:51:26 +00004375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004376 ThrowMogrifyException(OptionError,"MissingArgument",option);
4377 if (IsGeometry(argv[i]) == MagickFalse)
4378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4379 break;
4380 }
4381 if (LocaleCompare("emboss",option+1) == 0)
4382 {
4383 if (*option == '+')
4384 break;
4385 i++;
cristybb503372010-05-27 20:51:26 +00004386 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004387 ThrowMogrifyException(OptionError,"MissingArgument",option);
4388 if (IsGeometry(argv[i]) == MagickFalse)
4389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4390 break;
4391 }
4392 if (LocaleCompare("encipher",option+1) == 0)
4393 {
4394 if (*option == '+')
4395 break;
4396 i++;
cristybb503372010-05-27 20:51:26 +00004397 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004398 ThrowMogrifyException(OptionError,"MissingArgument",option);
4399 break;
4400 }
4401 if (LocaleCompare("encoding",option+1) == 0)
4402 {
4403 if (*option == '+')
4404 break;
4405 i++;
cristybb503372010-05-27 20:51:26 +00004406 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004407 ThrowMogrifyException(OptionError,"MissingArgument",option);
4408 break;
4409 }
4410 if (LocaleCompare("endian",option+1) == 0)
4411 {
cristybb503372010-05-27 20:51:26 +00004412 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004413 endian;
4414
4415 if (*option == '+')
4416 break;
4417 i++;
cristybb503372010-05-27 20:51:26 +00004418 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004419 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004420 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004421 if (endian < 0)
4422 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4423 argv[i]);
4424 break;
4425 }
4426 if (LocaleCompare("enhance",option+1) == 0)
4427 break;
4428 if (LocaleCompare("equalize",option+1) == 0)
4429 break;
4430 if (LocaleCompare("evaluate",option+1) == 0)
4431 {
cristybb503372010-05-27 20:51:26 +00004432 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004433 op;
4434
4435 if (*option == '+')
4436 break;
4437 i++;
cristybb503372010-05-27 20:51:26 +00004438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004439 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004440 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004441 if (op < 0)
4442 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4443 argv[i]);
4444 i++;
cristybb503372010-05-27 20:51:26 +00004445 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004446 ThrowMogrifyException(OptionError,"MissingArgument",option);
4447 if (IsGeometry(argv[i]) == MagickFalse)
4448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4449 break;
4450 }
cristyd18ae7c2010-03-07 17:39:52 +00004451 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4452 {
cristybb503372010-05-27 20:51:26 +00004453 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004454 op;
4455
4456 if (*option == '+')
4457 break;
4458 i++;
cristybb503372010-05-27 20:51:26 +00004459 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004460 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004461 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004462 if (op < 0)
4463 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4464 argv[i]);
4465 break;
4466 }
cristy3ed852e2009-09-05 21:47:34 +00004467 if (LocaleCompare("extent",option+1) == 0)
4468 {
4469 if (*option == '+')
4470 break;
4471 i++;
cristybb503372010-05-27 20:51:26 +00004472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004473 ThrowMogrifyException(OptionError,"MissingArgument",option);
4474 if (IsGeometry(argv[i]) == MagickFalse)
4475 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4476 break;
4477 }
4478 if (LocaleCompare("extract",option+1) == 0)
4479 {
4480 if (*option == '+')
4481 break;
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 if (IsGeometry(argv[i]) == MagickFalse)
4486 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4487 break;
4488 }
4489 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4490 }
4491 case 'f':
4492 {
4493 if (LocaleCompare("family",option+1) == 0)
4494 {
4495 if (*option == '+')
4496 break;
4497 i++;
cristybb503372010-05-27 20:51:26 +00004498 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004499 ThrowMogrifyException(OptionError,"MissingArgument",option);
4500 break;
4501 }
4502 if (LocaleCompare("fill",option+1) == 0)
4503 {
4504 if (*option == '+')
4505 break;
4506 i++;
cristybb503372010-05-27 20:51:26 +00004507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004508 ThrowMogrifyException(OptionError,"MissingArgument",option);
4509 break;
4510 }
4511 if (LocaleCompare("filter",option+1) == 0)
4512 {
cristybb503372010-05-27 20:51:26 +00004513 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004514 filter;
4515
4516 if (*option == '+')
4517 break;
4518 i++;
cristybb503372010-05-27 20:51:26 +00004519 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004520 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004521 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004522 if (filter < 0)
4523 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4524 argv[i]);
4525 break;
4526 }
4527 if (LocaleCompare("flatten",option+1) == 0)
4528 break;
4529 if (LocaleCompare("flip",option+1) == 0)
4530 break;
4531 if (LocaleCompare("flop",option+1) == 0)
4532 break;
4533 if (LocaleCompare("floodfill",option+1) == 0)
4534 {
4535 if (*option == '+')
4536 break;
4537 i++;
cristybb503372010-05-27 20:51:26 +00004538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004539 ThrowMogrifyException(OptionError,"MissingArgument",option);
4540 if (IsGeometry(argv[i]) == MagickFalse)
4541 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
4545 break;
4546 }
4547 if (LocaleCompare("font",option+1) == 0)
4548 {
4549 if (*option == '+')
4550 break;
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 break;
4555 }
4556 if (LocaleCompare("format",option+1) == 0)
4557 {
4558 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4559 (void) CloneString(&format,(char *) NULL);
4560 if (*option == '+')
4561 break;
4562 i++;
cristybb503372010-05-27 20:51:26 +00004563 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004564 ThrowMogrifyException(OptionError,"MissingArgument",option);
4565 (void) CloneString(&format,argv[i]);
4566 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4567 (void) ConcatenateMagickString(image_info->filename,":",
4568 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004569 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004570 if (*image_info->magick == '\0')
4571 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4572 format);
4573 break;
4574 }
4575 if (LocaleCompare("frame",option+1) == 0)
4576 {
4577 if (*option == '+')
4578 break;
4579 i++;
cristybb503372010-05-27 20:51:26 +00004580 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004581 ThrowMogrifyException(OptionError,"MissingArgument",option);
4582 if (IsGeometry(argv[i]) == MagickFalse)
4583 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4584 break;
4585 }
4586 if (LocaleCompare("function",option+1) == 0)
4587 {
cristybb503372010-05-27 20:51:26 +00004588 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004589 op;
4590
4591 if (*option == '+')
4592 break;
4593 i++;
cristybb503372010-05-27 20:51:26 +00004594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004595 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004596 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004597 if (op < 0)
4598 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4599 i++;
cristybb503372010-05-27 20:51:26 +00004600 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004601 ThrowMogrifyException(OptionError,"MissingArgument",option);
4602 break;
4603 }
4604 if (LocaleCompare("fuzz",option+1) == 0)
4605 {
4606 if (*option == '+')
4607 break;
4608 i++;
cristybb503372010-05-27 20:51:26 +00004609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004610 ThrowMogrifyException(OptionError,"MissingArgument",option);
4611 if (IsGeometry(argv[i]) == MagickFalse)
4612 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4613 break;
4614 }
4615 if (LocaleCompare("fx",option+1) == 0)
4616 {
4617 if (*option == '+')
4618 break;
4619 i++;
cristybb503372010-05-27 20:51:26 +00004620 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 break;
4623 }
4624 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4625 }
4626 case 'g':
4627 {
4628 if (LocaleCompare("gamma",option+1) == 0)
4629 {
4630 i++;
cristybb503372010-05-27 20:51:26 +00004631 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004632 ThrowMogrifyException(OptionError,"MissingArgument",option);
4633 if (IsGeometry(argv[i]) == MagickFalse)
4634 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4635 break;
4636 }
4637 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4638 (LocaleCompare("gaussian",option+1) == 0))
4639 {
4640 i++;
cristybb503372010-05-27 20:51:26 +00004641 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004642 ThrowMogrifyException(OptionError,"MissingArgument",option);
4643 if (IsGeometry(argv[i]) == MagickFalse)
4644 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4645 break;
4646 }
4647 if (LocaleCompare("geometry",option+1) == 0)
4648 {
4649 if (*option == '+')
4650 break;
4651 i++;
cristybb503372010-05-27 20:51:26 +00004652 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004653 ThrowMogrifyException(OptionError,"MissingArgument",option);
4654 if (IsGeometry(argv[i]) == MagickFalse)
4655 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4656 break;
4657 }
4658 if (LocaleCompare("gravity",option+1) == 0)
4659 {
cristybb503372010-05-27 20:51:26 +00004660 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004661 gravity;
4662
4663 if (*option == '+')
4664 break;
4665 i++;
cristybb503372010-05-27 20:51:26 +00004666 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004667 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004668 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004669 if (gravity < 0)
4670 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4671 argv[i]);
4672 break;
4673 }
4674 if (LocaleCompare("green-primary",option+1) == 0)
4675 {
4676 if (*option == '+')
4677 break;
4678 i++;
cristybb503372010-05-27 20:51:26 +00004679 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004680 ThrowMogrifyException(OptionError,"MissingArgument",option);
4681 if (IsGeometry(argv[i]) == MagickFalse)
4682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4683 break;
4684 }
4685 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4686 }
4687 case 'h':
4688 {
4689 if (LocaleCompare("hald-clut",option+1) == 0)
4690 break;
4691 if ((LocaleCompare("help",option+1) == 0) ||
4692 (LocaleCompare("-help",option+1) == 0))
4693 return(MogrifyUsage());
4694 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4695 }
4696 case 'i':
4697 {
4698 if (LocaleCompare("identify",option+1) == 0)
4699 break;
4700 if (LocaleCompare("idft",option+1) == 0)
4701 break;
4702 if (LocaleCompare("implode",option+1) == 0)
4703 {
4704 if (*option == '+')
4705 break;
4706 i++;
cristybb503372010-05-27 20:51:26 +00004707 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004708 ThrowMogrifyException(OptionError,"MissingArgument",option);
4709 if (IsGeometry(argv[i]) == MagickFalse)
4710 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4711 break;
4712 }
4713 if (LocaleCompare("intent",option+1) == 0)
4714 {
cristybb503372010-05-27 20:51:26 +00004715 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004716 intent;
4717
4718 if (*option == '+')
4719 break;
4720 i++;
cristybb503372010-05-27 20:51:26 +00004721 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004722 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004723 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004724 if (intent < 0)
4725 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4726 argv[i]);
4727 break;
4728 }
4729 if (LocaleCompare("interlace",option+1) == 0)
4730 {
cristybb503372010-05-27 20:51:26 +00004731 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004732 interlace;
4733
4734 if (*option == '+')
4735 break;
4736 i++;
cristybb503372010-05-27 20:51:26 +00004737 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004738 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004739 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004740 argv[i]);
4741 if (interlace < 0)
4742 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4743 argv[i]);
4744 break;
4745 }
cristyb32b90a2009-09-07 21:45:48 +00004746 if (LocaleCompare("interline-spacing",option+1) == 0)
4747 {
4748 if (*option == '+')
4749 break;
4750 i++;
cristybb503372010-05-27 20:51:26 +00004751 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004752 ThrowMogrifyException(OptionError,"MissingArgument",option);
4753 if (IsGeometry(argv[i]) == MagickFalse)
4754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4755 break;
4756 }
cristy3ed852e2009-09-05 21:47:34 +00004757 if (LocaleCompare("interpolate",option+1) == 0)
4758 {
cristybb503372010-05-27 20:51:26 +00004759 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004760 interpolate;
4761
4762 if (*option == '+')
4763 break;
4764 i++;
cristybb503372010-05-27 20:51:26 +00004765 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004766 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004767 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004768 argv[i]);
4769 if (interpolate < 0)
4770 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4771 argv[i]);
4772 break;
4773 }
4774 if (LocaleCompare("interword-spacing",option+1) == 0)
4775 {
4776 if (*option == '+')
4777 break;
4778 i++;
cristybb503372010-05-27 20:51:26 +00004779 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004780 ThrowMogrifyException(OptionError,"MissingArgument",option);
4781 if (IsGeometry(argv[i]) == MagickFalse)
4782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4783 break;
4784 }
4785 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4786 }
4787 case 'k':
4788 {
4789 if (LocaleCompare("kerning",option+1) == 0)
4790 {
4791 if (*option == '+')
4792 break;
4793 i++;
cristybb503372010-05-27 20:51:26 +00004794 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004795 ThrowMogrifyException(OptionError,"MissingArgument",option);
4796 if (IsGeometry(argv[i]) == MagickFalse)
4797 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4798 break;
4799 }
4800 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4801 }
4802 case 'l':
4803 {
4804 if (LocaleCompare("label",option+1) == 0)
4805 {
4806 if (*option == '+')
4807 break;
4808 i++;
cristybb503372010-05-27 20:51:26 +00004809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004810 ThrowMogrifyException(OptionError,"MissingArgument",option);
4811 break;
4812 }
4813 if (LocaleCompare("lat",option+1) == 0)
4814 {
4815 if (*option == '+')
4816 break;
4817 i++;
cristybb503372010-05-27 20:51:26 +00004818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004819 ThrowMogrifyException(OptionError,"MissingArgument",option);
4820 if (IsGeometry(argv[i]) == MagickFalse)
4821 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4822 }
4823 if (LocaleCompare("layers",option+1) == 0)
4824 {
cristybb503372010-05-27 20:51:26 +00004825 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004826 type;
4827
4828 if (*option == '+')
4829 break;
4830 i++;
cristybb503372010-05-27 20:51:26 +00004831 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004832 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004833 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004834 if (type < 0)
4835 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4836 argv[i]);
4837 break;
4838 }
4839 if (LocaleCompare("level",option+1) == 0)
4840 {
4841 i++;
cristybb503372010-05-27 20:51:26 +00004842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004843 ThrowMogrifyException(OptionError,"MissingArgument",option);
4844 if (IsGeometry(argv[i]) == MagickFalse)
4845 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4846 break;
4847 }
4848 if (LocaleCompare("level-colors",option+1) == 0)
4849 {
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 break;
4854 }
4855 if (LocaleCompare("linewidth",option+1) == 0)
4856 {
4857 if (*option == '+')
4858 break;
4859 i++;
cristybb503372010-05-27 20:51:26 +00004860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004861 ThrowMogrifyException(OptionError,"MissingArgument",option);
4862 if (IsGeometry(argv[i]) == MagickFalse)
4863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4864 break;
4865 }
4866 if (LocaleCompare("limit",option+1) == 0)
4867 {
4868 char
4869 *p;
4870
4871 double
4872 value;
4873
cristybb503372010-05-27 20:51:26 +00004874 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004875 resource;
4876
4877 if (*option == '+')
4878 break;
4879 i++;
cristybb503372010-05-27 20:51:26 +00004880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004881 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004882 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004883 argv[i]);
4884 if (resource < 0)
4885 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4886 argv[i]);
4887 i++;
cristybb503372010-05-27 20:51:26 +00004888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004889 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004890 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004891 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004892 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4893 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4894 break;
4895 }
4896 if (LocaleCompare("liquid-rescale",option+1) == 0)
4897 {
4898 i++;
cristybb503372010-05-27 20:51:26 +00004899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004900 ThrowMogrifyException(OptionError,"MissingArgument",option);
4901 if (IsGeometry(argv[i]) == MagickFalse)
4902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4903 break;
4904 }
4905 if (LocaleCompare("list",option+1) == 0)
4906 {
cristybb503372010-05-27 20:51:26 +00004907 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004908 list;
4909
4910 if (*option == '+')
4911 break;
4912 i++;
cristybb503372010-05-27 20:51:26 +00004913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004914 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004915 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004916 if (list < 0)
4917 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004918 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004919 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004920 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004921 }
4922 if (LocaleCompare("log",option+1) == 0)
4923 {
4924 if (*option == '+')
4925 break;
4926 i++;
cristybb503372010-05-27 20:51:26 +00004927 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004928 (strchr(argv[i],'%') == (char *) NULL))
4929 ThrowMogrifyException(OptionError,"MissingArgument",option);
4930 break;
4931 }
4932 if (LocaleCompare("loop",option+1) == 0)
4933 {
4934 if (*option == '+')
4935 break;
4936 i++;
cristybb503372010-05-27 20:51:26 +00004937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004938 ThrowMogrifyException(OptionError,"MissingArgument",option);
4939 if (IsGeometry(argv[i]) == MagickFalse)
4940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4941 break;
4942 }
4943 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4944 }
4945 case 'm':
4946 {
4947 if (LocaleCompare("map",option+1) == 0)
4948 {
4949 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4950 if (*option == '+')
4951 break;
4952 i++;
cristybb503372010-05-27 20:51:26 +00004953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004954 ThrowMogrifyException(OptionError,"MissingArgument",option);
4955 break;
4956 }
4957 if (LocaleCompare("mask",option+1) == 0)
4958 {
4959 if (*option == '+')
4960 break;
4961 i++;
cristybb503372010-05-27 20:51:26 +00004962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004963 ThrowMogrifyException(OptionError,"MissingArgument",option);
4964 break;
4965 }
4966 if (LocaleCompare("matte",option+1) == 0)
4967 break;
4968 if (LocaleCompare("mattecolor",option+1) == 0)
4969 {
4970 if (*option == '+')
4971 break;
4972 i++;
cristybb503372010-05-27 20:51:26 +00004973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004974 ThrowMogrifyException(OptionError,"MissingArgument",option);
4975 break;
4976 }
cristyf40785b2010-03-06 02:27:27 +00004977 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004978 break;
cristyf40785b2010-03-06 02:27:27 +00004979 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004980 break;
cristy3ed852e2009-09-05 21:47:34 +00004981 if (LocaleCompare("modulate",option+1) == 0)
4982 {
4983 if (*option == '+')
4984 break;
4985 i++;
cristybb503372010-05-27 20:51:26 +00004986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004987 ThrowMogrifyException(OptionError,"MissingArgument",option);
4988 if (IsGeometry(argv[i]) == MagickFalse)
4989 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4990 break;
4991 }
4992 if (LocaleCompare("median",option+1) == 0)
4993 {
4994 if (*option == '+')
4995 break;
4996 i++;
cristybb503372010-05-27 20:51:26 +00004997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004998 ThrowMogrifyException(OptionError,"MissingArgument",option);
4999 if (IsGeometry(argv[i]) == MagickFalse)
5000 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5001 break;
5002 }
cristy69ec32d2011-02-27 23:57:09 +00005003 if (LocaleCompare("mode",option+1) == 0)
5004 {
5005 if (*option == '+')
5006 break;
5007 i++;
5008 if (i == (ssize_t) argc)
5009 ThrowMogrifyException(OptionError,"MissingArgument",option);
5010 if (IsGeometry(argv[i]) == MagickFalse)
5011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5012 break;
5013 }
cristy3ed852e2009-09-05 21:47:34 +00005014 if (LocaleCompare("monitor",option+1) == 0)
5015 break;
5016 if (LocaleCompare("monochrome",option+1) == 0)
5017 break;
5018 if (LocaleCompare("morph",option+1) == 0)
5019 {
5020 if (*option == '+')
5021 break;
5022 i++;
cristybb503372010-05-27 20:51:26 +00005023 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005024 ThrowMogrifyException(OptionError,"MissingArgument",option);
5025 if (IsGeometry(argv[i]) == MagickFalse)
5026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5027 break;
5028 }
anthony29188a82010-01-22 10:12:34 +00005029 if (LocaleCompare("morphology",option+1) == 0)
5030 {
anthony29188a82010-01-22 10:12:34 +00005031 char
5032 token[MaxTextExtent];
5033
cristyb6bd4ad2010-08-08 01:12:27 +00005034 KernelInfo
5035 *kernel_info;
5036
5037 ssize_t
5038 op;
5039
anthony29188a82010-01-22 10:12:34 +00005040 i++;
cristybb503372010-05-27 20:51:26 +00005041 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005042 ThrowMogrifyException(OptionError,"MissingArgument",option);
5043 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005044 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005045 if (op < 0)
5046 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005047 token);
anthony29188a82010-01-22 10:12:34 +00005048 i++;
cristybb503372010-05-27 20:51:26 +00005049 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005050 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005051 kernel_info=AcquireKernelInfo(argv[i]);
5052 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005054 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005055 break;
5056 }
cristy3ed852e2009-09-05 21:47:34 +00005057 if (LocaleCompare("mosaic",option+1) == 0)
5058 break;
5059 if (LocaleCompare("motion-blur",option+1) == 0)
5060 {
5061 if (*option == '+')
5062 break;
5063 i++;
cristybb503372010-05-27 20:51:26 +00005064 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005065 ThrowMogrifyException(OptionError,"MissingArgument",option);
5066 if (IsGeometry(argv[i]) == MagickFalse)
5067 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5068 break;
5069 }
5070 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5071 }
5072 case 'n':
5073 {
5074 if (LocaleCompare("negate",option+1) == 0)
5075 break;
5076 if (LocaleCompare("noise",option+1) == 0)
5077 {
5078 i++;
cristybb503372010-05-27 20:51:26 +00005079 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005080 ThrowMogrifyException(OptionError,"MissingArgument",option);
5081 if (*option == '+')
5082 {
cristybb503372010-05-27 20:51:26 +00005083 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005084 noise;
5085
cristy042ee782011-04-22 18:48:30 +00005086 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005087 if (noise < 0)
5088 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5089 argv[i]);
5090 break;
5091 }
5092 if (IsGeometry(argv[i]) == MagickFalse)
5093 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5094 break;
5095 }
5096 if (LocaleCompare("noop",option+1) == 0)
5097 break;
5098 if (LocaleCompare("normalize",option+1) == 0)
5099 break;
5100 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5101 }
5102 case 'o':
5103 {
5104 if (LocaleCompare("opaque",option+1) == 0)
5105 {
cristy3ed852e2009-09-05 21:47:34 +00005106 i++;
cristybb503372010-05-27 20:51:26 +00005107 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005108 ThrowMogrifyException(OptionError,"MissingArgument",option);
5109 break;
5110 }
5111 if (LocaleCompare("ordered-dither",option+1) == 0)
5112 {
5113 if (*option == '+')
5114 break;
5115 i++;
cristybb503372010-05-27 20:51:26 +00005116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005117 ThrowMogrifyException(OptionError,"MissingArgument",option);
5118 break;
5119 }
5120 if (LocaleCompare("orient",option+1) == 0)
5121 {
cristybb503372010-05-27 20:51:26 +00005122 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005123 orientation;
5124
5125 orientation=UndefinedOrientation;
5126 if (*option == '+')
5127 break;
5128 i++;
cristybb503372010-05-27 20:51:26 +00005129 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005130 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005131 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005132 argv[i]);
5133 if (orientation < 0)
5134 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5135 argv[i]);
5136 break;
5137 }
5138 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5139 }
5140 case 'p':
5141 {
5142 if (LocaleCompare("page",option+1) == 0)
5143 {
5144 if (*option == '+')
5145 break;
5146 i++;
cristybb503372010-05-27 20:51:26 +00005147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005148 ThrowMogrifyException(OptionError,"MissingArgument",option);
5149 break;
5150 }
5151 if (LocaleCompare("paint",option+1) == 0)
5152 {
5153 if (*option == '+')
5154 break;
5155 i++;
cristybb503372010-05-27 20:51:26 +00005156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005157 ThrowMogrifyException(OptionError,"MissingArgument",option);
5158 if (IsGeometry(argv[i]) == MagickFalse)
5159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5160 break;
5161 }
5162 if (LocaleCompare("path",option+1) == 0)
5163 {
5164 (void) CloneString(&path,(char *) NULL);
5165 if (*option == '+')
5166 break;
5167 i++;
cristybb503372010-05-27 20:51:26 +00005168 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005169 ThrowMogrifyException(OptionError,"MissingArgument",option);
5170 (void) CloneString(&path,argv[i]);
5171 break;
5172 }
5173 if (LocaleCompare("pointsize",option+1) == 0)
5174 {
5175 if (*option == '+')
5176 break;
5177 i++;
cristybb503372010-05-27 20:51:26 +00005178 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005179 ThrowMogrifyException(OptionError,"MissingArgument",option);
5180 if (IsGeometry(argv[i]) == MagickFalse)
5181 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5182 break;
5183 }
5184 if (LocaleCompare("polaroid",option+1) == 0)
5185 {
5186 if (*option == '+')
5187 break;
5188 i++;
cristybb503372010-05-27 20:51:26 +00005189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005190 ThrowMogrifyException(OptionError,"MissingArgument",option);
5191 if (IsGeometry(argv[i]) == MagickFalse)
5192 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5193 break;
5194 }
5195 if (LocaleCompare("posterize",option+1) == 0)
5196 {
5197 if (*option == '+')
5198 break;
5199 i++;
cristybb503372010-05-27 20:51:26 +00005200 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005201 ThrowMogrifyException(OptionError,"MissingArgument",option);
5202 if (IsGeometry(argv[i]) == MagickFalse)
5203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5204 break;
5205 }
cristye7f51092010-01-17 00:39:37 +00005206 if (LocaleCompare("precision",option+1) == 0)
5207 {
5208 if (*option == '+')
5209 break;
5210 i++;
cristybb503372010-05-27 20:51:26 +00005211 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005212 ThrowMogrifyException(OptionError,"MissingArgument",option);
5213 if (IsGeometry(argv[i]) == MagickFalse)
5214 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5215 break;
5216 }
cristy3ed852e2009-09-05 21:47:34 +00005217 if (LocaleCompare("print",option+1) == 0)
5218 {
5219 if (*option == '+')
5220 break;
5221 i++;
cristybb503372010-05-27 20:51:26 +00005222 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005223 ThrowMogrifyException(OptionError,"MissingArgument",option);
5224 break;
5225 }
5226 if (LocaleCompare("process",option+1) == 0)
5227 {
5228 if (*option == '+')
5229 break;
5230 i++;
cristybb503372010-05-27 20:51:26 +00005231 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005232 ThrowMogrifyException(OptionError,"MissingArgument",option);
5233 break;
5234 }
5235 if (LocaleCompare("profile",option+1) == 0)
5236 {
5237 i++;
cristybb503372010-05-27 20:51:26 +00005238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005239 ThrowMogrifyException(OptionError,"MissingArgument",option);
5240 break;
5241 }
5242 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5243 }
5244 case 'q':
5245 {
5246 if (LocaleCompare("quality",option+1) == 0)
5247 {
5248 if (*option == '+')
5249 break;
5250 i++;
cristybb503372010-05-27 20:51:26 +00005251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005252 ThrowMogrifyException(OptionError,"MissingArgument",option);
5253 if (IsGeometry(argv[i]) == MagickFalse)
5254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5255 break;
5256 }
5257 if (LocaleCompare("quantize",option+1) == 0)
5258 {
cristybb503372010-05-27 20:51:26 +00005259 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005260 colorspace;
5261
5262 if (*option == '+')
5263 break;
5264 i++;
cristybb503372010-05-27 20:51:26 +00005265 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005266 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005267 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005268 argv[i]);
5269 if (colorspace < 0)
5270 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5271 argv[i]);
5272 break;
5273 }
5274 if (LocaleCompare("quiet",option+1) == 0)
5275 break;
5276 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5277 }
5278 case 'r':
5279 {
5280 if (LocaleCompare("radial-blur",option+1) == 0)
5281 {
5282 i++;
cristybb503372010-05-27 20:51:26 +00005283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005284 ThrowMogrifyException(OptionError,"MissingArgument",option);
5285 if (IsGeometry(argv[i]) == MagickFalse)
5286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5287 break;
5288 }
5289 if (LocaleCompare("raise",option+1) == 0)
5290 {
5291 i++;
cristybb503372010-05-27 20:51:26 +00005292 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005293 ThrowMogrifyException(OptionError,"MissingArgument",option);
5294 if (IsGeometry(argv[i]) == MagickFalse)
5295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5296 break;
5297 }
5298 if (LocaleCompare("random-threshold",option+1) == 0)
5299 {
5300 if (*option == '+')
5301 break;
5302 i++;
cristybb503372010-05-27 20:51:26 +00005303 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005304 ThrowMogrifyException(OptionError,"MissingArgument",option);
5305 if (IsGeometry(argv[i]) == MagickFalse)
5306 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5307 break;
5308 }
cristye6365592010-04-02 17:31:23 +00005309 if (LocaleCompare("recolor",option+1) == 0)
5310 {
5311 if (*option == '+')
5312 break;
5313 i++;
cristybb503372010-05-27 20:51:26 +00005314 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005315 ThrowMogrifyException(OptionError,"MissingArgument",option);
5316 if (IsGeometry(argv[i]) == MagickFalse)
5317 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5318 break;
5319 }
cristy3ed852e2009-09-05 21:47:34 +00005320 if (LocaleCompare("red-primary",option+1) == 0)
5321 {
5322 if (*option == '+')
5323 break;
5324 i++;
cristybb503372010-05-27 20:51:26 +00005325 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005326 ThrowMogrifyException(OptionError,"MissingArgument",option);
5327 if (IsGeometry(argv[i]) == MagickFalse)
5328 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5329 }
cristy9f2083a2010-04-22 19:48:05 +00005330 if (LocaleCompare("regard-warnings",option+1) == 0)
5331 break;
cristy3ed852e2009-09-05 21:47:34 +00005332 if (LocaleCompare("region",option+1) == 0)
5333 {
5334 if (*option == '+')
5335 break;
5336 i++;
cristybb503372010-05-27 20:51:26 +00005337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005338 ThrowMogrifyException(OptionError,"MissingArgument",option);
5339 if (IsGeometry(argv[i]) == MagickFalse)
5340 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5341 break;
5342 }
cristyf0c78232010-03-15 12:53:40 +00005343 if (LocaleCompare("remap",option+1) == 0)
5344 {
5345 if (*option == '+')
5346 break;
5347 i++;
cristybb503372010-05-27 20:51:26 +00005348 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005349 ThrowMogrifyException(OptionError,"MissingArgument",option);
5350 break;
5351 }
cristy3ed852e2009-09-05 21:47:34 +00005352 if (LocaleCompare("render",option+1) == 0)
5353 break;
5354 if (LocaleCompare("repage",option+1) == 0)
5355 {
5356 if (*option == '+')
5357 break;
5358 i++;
cristybb503372010-05-27 20:51:26 +00005359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005360 ThrowMogrifyException(OptionError,"MissingArgument",option);
5361 if (IsGeometry(argv[i]) == MagickFalse)
5362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5363 break;
5364 }
5365 if (LocaleCompare("resample",option+1) == 0)
5366 {
5367 if (*option == '+')
5368 break;
5369 i++;
cristybb503372010-05-27 20:51:26 +00005370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005371 ThrowMogrifyException(OptionError,"MissingArgument",option);
5372 if (IsGeometry(argv[i]) == MagickFalse)
5373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5374 break;
5375 }
5376 if (LocaleCompare("resize",option+1) == 0)
5377 {
5378 if (*option == '+')
5379 break;
5380 i++;
cristybb503372010-05-27 20:51:26 +00005381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005382 ThrowMogrifyException(OptionError,"MissingArgument",option);
5383 if (IsGeometry(argv[i]) == MagickFalse)
5384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5385 break;
5386 }
cristyebbcfea2011-02-25 02:43:54 +00005387 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5388 {
5389 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5390 break;
5391 }
cristy3ed852e2009-09-05 21:47:34 +00005392 if (LocaleCompare("reverse",option+1) == 0)
5393 break;
5394 if (LocaleCompare("roll",option+1) == 0)
5395 {
5396 if (*option == '+')
5397 break;
5398 i++;
cristybb503372010-05-27 20:51:26 +00005399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005400 ThrowMogrifyException(OptionError,"MissingArgument",option);
5401 if (IsGeometry(argv[i]) == MagickFalse)
5402 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5403 break;
5404 }
5405 if (LocaleCompare("rotate",option+1) == 0)
5406 {
5407 i++;
cristybb503372010-05-27 20:51:26 +00005408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005409 ThrowMogrifyException(OptionError,"MissingArgument",option);
5410 if (IsGeometry(argv[i]) == MagickFalse)
5411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5412 break;
5413 }
5414 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5415 }
5416 case 's':
5417 {
5418 if (LocaleCompare("sample",option+1) == 0)
5419 {
5420 if (*option == '+')
5421 break;
5422 i++;
cristybb503372010-05-27 20:51:26 +00005423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005424 ThrowMogrifyException(OptionError,"MissingArgument",option);
5425 if (IsGeometry(argv[i]) == MagickFalse)
5426 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5427 break;
5428 }
5429 if (LocaleCompare("sampling-factor",option+1) == 0)
5430 {
5431 if (*option == '+')
5432 break;
5433 i++;
cristybb503372010-05-27 20:51:26 +00005434 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005435 ThrowMogrifyException(OptionError,"MissingArgument",option);
5436 if (IsGeometry(argv[i]) == MagickFalse)
5437 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5438 break;
5439 }
5440 if (LocaleCompare("scale",option+1) == 0)
5441 {
5442 if (*option == '+')
5443 break;
5444 i++;
cristybb503372010-05-27 20:51:26 +00005445 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005446 ThrowMogrifyException(OptionError,"MissingArgument",option);
5447 if (IsGeometry(argv[i]) == MagickFalse)
5448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5449 break;
5450 }
5451 if (LocaleCompare("scene",option+1) == 0)
5452 {
5453 if (*option == '+')
5454 break;
5455 i++;
cristybb503372010-05-27 20:51:26 +00005456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005457 ThrowMogrifyException(OptionError,"MissingArgument",option);
5458 if (IsGeometry(argv[i]) == MagickFalse)
5459 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5460 break;
5461 }
5462 if (LocaleCompare("seed",option+1) == 0)
5463 {
5464 if (*option == '+')
5465 break;
5466 i++;
cristybb503372010-05-27 20:51:26 +00005467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005468 ThrowMogrifyException(OptionError,"MissingArgument",option);
5469 if (IsGeometry(argv[i]) == MagickFalse)
5470 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5471 break;
5472 }
5473 if (LocaleCompare("segment",option+1) == 0)
5474 {
5475 if (*option == '+')
5476 break;
5477 i++;
cristybb503372010-05-27 20:51:26 +00005478 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005479 ThrowMogrifyException(OptionError,"MissingArgument",option);
5480 if (IsGeometry(argv[i]) == MagickFalse)
5481 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5482 break;
5483 }
5484 if (LocaleCompare("selective-blur",option+1) == 0)
5485 {
5486 i++;
cristybb503372010-05-27 20:51:26 +00005487 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005488 ThrowMogrifyException(OptionError,"MissingArgument",option);
5489 if (IsGeometry(argv[i]) == MagickFalse)
5490 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5491 break;
5492 }
5493 if (LocaleCompare("separate",option+1) == 0)
5494 break;
5495 if (LocaleCompare("sepia-tone",option+1) == 0)
5496 {
5497 if (*option == '+')
5498 break;
5499 i++;
cristybb503372010-05-27 20:51:26 +00005500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005501 ThrowMogrifyException(OptionError,"MissingArgument",option);
5502 if (IsGeometry(argv[i]) == MagickFalse)
5503 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5504 break;
5505 }
5506 if (LocaleCompare("set",option+1) == 0)
5507 {
5508 i++;
cristybb503372010-05-27 20:51:26 +00005509 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005510 ThrowMogrifyException(OptionError,"MissingArgument",option);
5511 if (*option == '+')
5512 break;
5513 i++;
cristybb503372010-05-27 20:51:26 +00005514 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005515 ThrowMogrifyException(OptionError,"MissingArgument",option);
5516 break;
5517 }
5518 if (LocaleCompare("shade",option+1) == 0)
5519 {
5520 i++;
cristybb503372010-05-27 20:51:26 +00005521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005522 ThrowMogrifyException(OptionError,"MissingArgument",option);
5523 if (IsGeometry(argv[i]) == MagickFalse)
5524 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5525 break;
5526 }
5527 if (LocaleCompare("shadow",option+1) == 0)
5528 {
5529 if (*option == '+')
5530 break;
5531 i++;
cristybb503372010-05-27 20:51:26 +00005532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005533 ThrowMogrifyException(OptionError,"MissingArgument",option);
5534 if (IsGeometry(argv[i]) == MagickFalse)
5535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5536 break;
5537 }
5538 if (LocaleCompare("sharpen",option+1) == 0)
5539 {
5540 i++;
cristybb503372010-05-27 20:51:26 +00005541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005542 ThrowMogrifyException(OptionError,"MissingArgument",option);
5543 if (IsGeometry(argv[i]) == MagickFalse)
5544 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5545 break;
5546 }
5547 if (LocaleCompare("shave",option+1) == 0)
5548 {
5549 if (*option == '+')
5550 break;
5551 i++;
cristybb503372010-05-27 20:51:26 +00005552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005553 ThrowMogrifyException(OptionError,"MissingArgument",option);
5554 if (IsGeometry(argv[i]) == MagickFalse)
5555 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5556 break;
5557 }
5558 if (LocaleCompare("shear",option+1) == 0)
5559 {
5560 i++;
cristybb503372010-05-27 20:51:26 +00005561 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005562 ThrowMogrifyException(OptionError,"MissingArgument",option);
5563 if (IsGeometry(argv[i]) == MagickFalse)
5564 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5565 break;
5566 }
5567 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5568 {
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005571 ThrowMogrifyException(OptionError,"MissingArgument",option);
5572 if (IsGeometry(argv[i]) == MagickFalse)
5573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574 break;
5575 }
5576 if (LocaleCompare("size",option+1) == 0)
5577 {
5578 if (*option == '+')
5579 break;
5580 i++;
cristybb503372010-05-27 20:51:26 +00005581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005582 ThrowMogrifyException(OptionError,"MissingArgument",option);
5583 if (IsGeometry(argv[i]) == MagickFalse)
5584 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5585 break;
5586 }
5587 if (LocaleCompare("sketch",option+1) == 0)
5588 {
5589 if (*option == '+')
5590 break;
5591 i++;
cristybb503372010-05-27 20:51:26 +00005592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005593 ThrowMogrifyException(OptionError,"MissingArgument",option);
5594 if (IsGeometry(argv[i]) == MagickFalse)
5595 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5596 break;
5597 }
cristy4285d782011-02-09 20:12:28 +00005598 if (LocaleCompare("smush",option+1) == 0)
5599 {
cristy4285d782011-02-09 20:12:28 +00005600 i++;
5601 if (i == (ssize_t) argc)
5602 ThrowMogrifyException(OptionError,"MissingArgument",option);
5603 if (IsGeometry(argv[i]) == MagickFalse)
5604 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005605 i++;
5606 break;
5607 }
cristy3ed852e2009-09-05 21:47:34 +00005608 if (LocaleCompare("solarize",option+1) == 0)
5609 {
5610 if (*option == '+')
5611 break;
5612 i++;
cristybb503372010-05-27 20:51:26 +00005613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005614 ThrowMogrifyException(OptionError,"MissingArgument",option);
5615 if (IsGeometry(argv[i]) == MagickFalse)
5616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5617 break;
5618 }
5619 if (LocaleCompare("sparse-color",option+1) == 0)
5620 {
cristybb503372010-05-27 20:51:26 +00005621 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005622 op;
5623
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005627 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005628 if (op < 0)
5629 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5630 argv[i]);
5631 i++;
cristybb503372010-05-27 20:51:26 +00005632 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005633 ThrowMogrifyException(OptionError,"MissingArgument",option);
5634 break;
5635 }
5636 if (LocaleCompare("spread",option+1) == 0)
5637 {
5638 if (*option == '+')
5639 break;
5640 i++;
cristybb503372010-05-27 20:51:26 +00005641 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005642 ThrowMogrifyException(OptionError,"MissingArgument",option);
5643 if (IsGeometry(argv[i]) == MagickFalse)
5644 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5645 break;
5646 }
cristy0834d642011-03-18 18:26:08 +00005647 if (LocaleCompare("statistic",option+1) == 0)
5648 {
5649 ssize_t
5650 op;
5651
5652 if (*option == '+')
5653 break;
5654 i++;
5655 if (i == (ssize_t) argc)
5656 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005657 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005658 if (op < 0)
5659 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5660 argv[i]);
5661 i++;
5662 if (i == (ssize_t) (argc-1))
5663 ThrowMogrifyException(OptionError,"MissingArgument",option);
5664 if (IsGeometry(argv[i]) == MagickFalse)
5665 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5666 break;
5667 }
cristy3ed852e2009-09-05 21:47:34 +00005668 if (LocaleCompare("stretch",option+1) == 0)
5669 {
cristybb503372010-05-27 20:51:26 +00005670 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005671 stretch;
5672
5673 if (*option == '+')
5674 break;
5675 i++;
cristybb503372010-05-27 20:51:26 +00005676 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005677 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005678 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005679 if (stretch < 0)
5680 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5681 argv[i]);
5682 break;
5683 }
5684 if (LocaleCompare("strip",option+1) == 0)
5685 break;
5686 if (LocaleCompare("stroke",option+1) == 0)
5687 {
5688 if (*option == '+')
5689 break;
5690 i++;
cristybb503372010-05-27 20:51:26 +00005691 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005692 ThrowMogrifyException(OptionError,"MissingArgument",option);
5693 break;
5694 }
5695 if (LocaleCompare("strokewidth",option+1) == 0)
5696 {
5697 if (*option == '+')
5698 break;
5699 i++;
cristybb503372010-05-27 20:51:26 +00005700 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 if (IsGeometry(argv[i]) == MagickFalse)
5703 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5704 break;
5705 }
5706 if (LocaleCompare("style",option+1) == 0)
5707 {
cristybb503372010-05-27 20:51:26 +00005708 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005709 style;
5710
5711 if (*option == '+')
5712 break;
5713 i++;
cristybb503372010-05-27 20:51:26 +00005714 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005715 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005716 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005717 if (style < 0)
5718 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5719 argv[i]);
5720 break;
5721 }
cristyecb10ff2011-03-22 13:14:03 +00005722 if (LocaleCompare("swap",option+1) == 0)
5723 {
5724 if (*option == '+')
5725 break;
5726 i++;
5727 if (i == (ssize_t) (argc-1))
5728 ThrowMogrifyException(OptionError,"MissingArgument",option);
5729 if (IsGeometry(argv[i]) == MagickFalse)
5730 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5731 break;
5732 }
cristy3ed852e2009-09-05 21:47:34 +00005733 if (LocaleCompare("swirl",option+1) == 0)
5734 {
5735 if (*option == '+')
5736 break;
5737 i++;
cristybb503372010-05-27 20:51:26 +00005738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005739 ThrowMogrifyException(OptionError,"MissingArgument",option);
5740 if (IsGeometry(argv[i]) == MagickFalse)
5741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5742 break;
5743 }
cristyd9a29192010-10-16 16:49:53 +00005744 if (LocaleCompare("synchronize",option+1) == 0)
5745 break;
cristy3ed852e2009-09-05 21:47:34 +00005746 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5747 }
5748 case 't':
5749 {
5750 if (LocaleCompare("taint",option+1) == 0)
5751 break;
5752 if (LocaleCompare("texture",option+1) == 0)
5753 {
5754 if (*option == '+')
5755 break;
5756 i++;
cristybb503372010-05-27 20:51:26 +00005757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005758 ThrowMogrifyException(OptionError,"MissingArgument",option);
5759 break;
5760 }
5761 if (LocaleCompare("tile",option+1) == 0)
5762 {
5763 if (*option == '+')
5764 break;
5765 i++;
cristybb503372010-05-27 20:51:26 +00005766 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005767 ThrowMogrifyException(OptionError,"MissingArgument",option);
5768 break;
5769 }
5770 if (LocaleCompare("tile-offset",option+1) == 0)
5771 {
5772 if (*option == '+')
5773 break;
5774 i++;
cristybb503372010-05-27 20:51:26 +00005775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005776 ThrowMogrifyException(OptionError,"MissingArgument",option);
5777 if (IsGeometry(argv[i]) == MagickFalse)
5778 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5779 break;
5780 }
5781 if (LocaleCompare("tint",option+1) == 0)
5782 {
5783 if (*option == '+')
5784 break;
5785 i++;
cristybb503372010-05-27 20:51:26 +00005786 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005787 ThrowMogrifyException(OptionError,"MissingArgument",option);
5788 if (IsGeometry(argv[i]) == MagickFalse)
5789 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5790 break;
5791 }
5792 if (LocaleCompare("transform",option+1) == 0)
5793 break;
5794 if (LocaleCompare("transpose",option+1) == 0)
5795 break;
5796 if (LocaleCompare("transverse",option+1) == 0)
5797 break;
5798 if (LocaleCompare("threshold",option+1) == 0)
5799 {
5800 if (*option == '+')
5801 break;
5802 i++;
cristybb503372010-05-27 20:51:26 +00005803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005804 ThrowMogrifyException(OptionError,"MissingArgument",option);
5805 if (IsGeometry(argv[i]) == MagickFalse)
5806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5807 break;
5808 }
5809 if (LocaleCompare("thumbnail",option+1) == 0)
5810 {
5811 if (*option == '+')
5812 break;
5813 i++;
cristybb503372010-05-27 20:51:26 +00005814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005815 ThrowMogrifyException(OptionError,"MissingArgument",option);
5816 if (IsGeometry(argv[i]) == MagickFalse)
5817 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5818 break;
5819 }
5820 if (LocaleCompare("transparent",option+1) == 0)
5821 {
5822 i++;
cristybb503372010-05-27 20:51:26 +00005823 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005824 ThrowMogrifyException(OptionError,"MissingArgument",option);
5825 break;
5826 }
5827 if (LocaleCompare("transparent-color",option+1) == 0)
5828 {
5829 if (*option == '+')
5830 break;
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 break;
5835 }
5836 if (LocaleCompare("treedepth",option+1) == 0)
5837 {
5838 if (*option == '+')
5839 break;
5840 i++;
cristybb503372010-05-27 20:51:26 +00005841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005842 ThrowMogrifyException(OptionError,"MissingArgument",option);
5843 if (IsGeometry(argv[i]) == MagickFalse)
5844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5845 break;
5846 }
5847 if (LocaleCompare("trim",option+1) == 0)
5848 break;
5849 if (LocaleCompare("type",option+1) == 0)
5850 {
cristybb503372010-05-27 20:51:26 +00005851 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005852 type;
5853
5854 if (*option == '+')
5855 break;
5856 i++;
cristybb503372010-05-27 20:51:26 +00005857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005858 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005859 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005860 if (type < 0)
5861 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5862 argv[i]);
5863 break;
5864 }
5865 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5866 }
5867 case 'u':
5868 {
5869 if (LocaleCompare("undercolor",option+1) == 0)
5870 {
5871 if (*option == '+')
5872 break;
5873 i++;
cristybb503372010-05-27 20:51:26 +00005874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005875 ThrowMogrifyException(OptionError,"MissingArgument",option);
5876 break;
5877 }
5878 if (LocaleCompare("unique-colors",option+1) == 0)
5879 break;
5880 if (LocaleCompare("units",option+1) == 0)
5881 {
cristybb503372010-05-27 20:51:26 +00005882 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005883 units;
5884
5885 if (*option == '+')
5886 break;
5887 i++;
cristybb503372010-05-27 20:51:26 +00005888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005889 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005890 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005891 argv[i]);
5892 if (units < 0)
5893 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5894 argv[i]);
5895 break;
5896 }
5897 if (LocaleCompare("unsharp",option+1) == 0)
5898 {
5899 i++;
cristybb503372010-05-27 20:51:26 +00005900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005901 ThrowMogrifyException(OptionError,"MissingArgument",option);
5902 if (IsGeometry(argv[i]) == MagickFalse)
5903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5904 break;
5905 }
5906 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5907 }
5908 case 'v':
5909 {
5910 if (LocaleCompare("verbose",option+1) == 0)
5911 {
5912 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5913 break;
5914 }
5915 if ((LocaleCompare("version",option+1) == 0) ||
5916 (LocaleCompare("-version",option+1) == 0))
5917 {
cristyb51dff52011-05-19 16:55:47 +00005918 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005919 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005920 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5921 GetMagickCopyright());
5922 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5923 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005924 break;
5925 }
5926 if (LocaleCompare("view",option+1) == 0)
5927 {
5928 if (*option == '+')
5929 break;
5930 i++;
cristybb503372010-05-27 20:51:26 +00005931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 break;
5934 }
5935 if (LocaleCompare("vignette",option+1) == 0)
5936 {
5937 if (*option == '+')
5938 break;
5939 i++;
cristybb503372010-05-27 20:51:26 +00005940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005941 ThrowMogrifyException(OptionError,"MissingArgument",option);
5942 if (IsGeometry(argv[i]) == MagickFalse)
5943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5944 break;
5945 }
5946 if (LocaleCompare("virtual-pixel",option+1) == 0)
5947 {
cristybb503372010-05-27 20:51:26 +00005948 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005949 method;
5950
5951 if (*option == '+')
5952 break;
5953 i++;
cristybb503372010-05-27 20:51:26 +00005954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005955 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005956 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005957 argv[i]);
5958 if (method < 0)
5959 ThrowMogrifyException(OptionError,
5960 "UnrecognizedVirtualPixelMethod",argv[i]);
5961 break;
5962 }
5963 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5964 }
5965 case 'w':
5966 {
5967 if (LocaleCompare("wave",option+1) == 0)
5968 {
5969 i++;
cristybb503372010-05-27 20:51:26 +00005970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005971 ThrowMogrifyException(OptionError,"MissingArgument",option);
5972 if (IsGeometry(argv[i]) == MagickFalse)
5973 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5974 break;
5975 }
5976 if (LocaleCompare("weight",option+1) == 0)
5977 {
5978 if (*option == '+')
5979 break;
5980 i++;
cristybb503372010-05-27 20:51:26 +00005981 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005982 ThrowMogrifyException(OptionError,"MissingArgument",option);
5983 break;
5984 }
5985 if (LocaleCompare("white-point",option+1) == 0)
5986 {
5987 if (*option == '+')
5988 break;
5989 i++;
cristybb503372010-05-27 20:51:26 +00005990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005991 ThrowMogrifyException(OptionError,"MissingArgument",option);
5992 if (IsGeometry(argv[i]) == MagickFalse)
5993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5994 break;
5995 }
5996 if (LocaleCompare("white-threshold",option+1) == 0)
5997 {
5998 if (*option == '+')
5999 break;
6000 i++;
cristybb503372010-05-27 20:51:26 +00006001 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006002 ThrowMogrifyException(OptionError,"MissingArgument",option);
6003 if (IsGeometry(argv[i]) == MagickFalse)
6004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6005 break;
6006 }
6007 if (LocaleCompare("write",option+1) == 0)
6008 {
6009 i++;
cristybb503372010-05-27 20:51:26 +00006010 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006011 ThrowMogrifyException(OptionError,"MissingArgument",option);
6012 break;
6013 }
6014 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6015 }
6016 case '?':
6017 break;
6018 default:
6019 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6020 }
cristy042ee782011-04-22 18:48:30 +00006021 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6022 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006023 if (fire != MagickFalse)
6024 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6025 }
6026 if (k != 0)
6027 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006028 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006029 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6030 DestroyMogrify();
6031 return(status != 0 ? MagickTrue : MagickFalse);
6032}
6033
6034/*
6035%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6036% %
6037% %
6038% %
6039+ M o g r i f y I m a g e I n f o %
6040% %
6041% %
6042% %
6043%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6044%
6045% MogrifyImageInfo() applies image processing settings to the image as
6046% prescribed by command line options.
6047%
6048% The format of the MogrifyImageInfo method is:
6049%
6050% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6051% const char **argv,ExceptionInfo *exception)
6052%
6053% A description of each parameter follows:
6054%
6055% o image_info: the image info..
6056%
6057% o argc: Specifies a pointer to an integer describing the number of
6058% elements in the argument vector.
6059%
6060% o argv: Specifies a pointer to a text array containing the command line
6061% arguments.
6062%
6063% o exception: return any errors or warnings in this structure.
6064%
6065*/
6066WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6067 const int argc,const char **argv,ExceptionInfo *exception)
6068{
6069 const char
6070 *option;
6071
6072 GeometryInfo
6073 geometry_info;
6074
cristybb503372010-05-27 20:51:26 +00006075 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006076 count;
6077
cristybb503372010-05-27 20:51:26 +00006078 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006079 i;
6080
6081 /*
6082 Initialize method variables.
6083 */
6084 assert(image_info != (ImageInfo *) NULL);
6085 assert(image_info->signature == MagickSignature);
6086 if (image_info->debug != MagickFalse)
6087 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6088 image_info->filename);
6089 if (argc < 0)
6090 return(MagickTrue);
6091 /*
6092 Set the image settings.
6093 */
cristybb503372010-05-27 20:51:26 +00006094 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006095 {
6096 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006097 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006098 continue;
cristy042ee782011-04-22 18:48:30 +00006099 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006100 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006101 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006102 break;
6103 switch (*(option+1))
6104 {
6105 case 'a':
6106 {
6107 if (LocaleCompare("adjoin",option+1) == 0)
6108 {
6109 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6110 break;
6111 }
6112 if (LocaleCompare("antialias",option+1) == 0)
6113 {
6114 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6115 break;
6116 }
6117 if (LocaleCompare("attenuate",option+1) == 0)
6118 {
6119 if (*option == '+')
6120 {
6121 (void) DeleteImageOption(image_info,option+1);
6122 break;
6123 }
6124 (void) SetImageOption(image_info,option+1,argv[i+1]);
6125 break;
6126 }
6127 if (LocaleCompare("authenticate",option+1) == 0)
6128 {
6129 if (*option == '+')
6130 (void) CloneString(&image_info->authenticate,(char *) NULL);
6131 else
6132 (void) CloneString(&image_info->authenticate,argv[i+1]);
6133 break;
6134 }
6135 break;
6136 }
6137 case 'b':
6138 {
6139 if (LocaleCompare("background",option+1) == 0)
6140 {
6141 if (*option == '+')
6142 {
6143 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006144 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006145 &image_info->background_color,exception);
6146 break;
6147 }
6148 (void) SetImageOption(image_info,option+1,argv[i+1]);
6149 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6150 exception);
6151 break;
6152 }
6153 if (LocaleCompare("bias",option+1) == 0)
6154 {
6155 if (*option == '+')
6156 {
6157 (void) SetImageOption(image_info,option+1,"0.0");
6158 break;
6159 }
6160 (void) SetImageOption(image_info,option+1,argv[i+1]);
6161 break;
6162 }
6163 if (LocaleCompare("black-point-compensation",option+1) == 0)
6164 {
6165 if (*option == '+')
6166 {
6167 (void) SetImageOption(image_info,option+1,"false");
6168 break;
6169 }
6170 (void) SetImageOption(image_info,option+1,"true");
6171 break;
6172 }
6173 if (LocaleCompare("blue-primary",option+1) == 0)
6174 {
6175 if (*option == '+')
6176 {
6177 (void) SetImageOption(image_info,option+1,"0.0");
6178 break;
6179 }
6180 (void) SetImageOption(image_info,option+1,argv[i+1]);
6181 break;
6182 }
6183 if (LocaleCompare("bordercolor",option+1) == 0)
6184 {
6185 if (*option == '+')
6186 {
6187 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006188 (void) QueryColorDatabase(MogrifyBorderColor,
6189 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006190 break;
6191 }
6192 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6193 exception);
6194 (void) SetImageOption(image_info,option+1,argv[i+1]);
6195 break;
6196 }
6197 if (LocaleCompare("box",option+1) == 0)
6198 {
6199 if (*option == '+')
6200 {
6201 (void) SetImageOption(image_info,"undercolor","none");
6202 break;
6203 }
6204 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6205 break;
6206 }
6207 break;
6208 }
6209 case 'c':
6210 {
6211 if (LocaleCompare("cache",option+1) == 0)
6212 {
6213 MagickSizeType
6214 limit;
6215
6216 limit=MagickResourceInfinity;
6217 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006218 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006219 (void) SetMagickResourceLimit(MemoryResource,limit);
6220 (void) SetMagickResourceLimit(MapResource,2*limit);
6221 break;
6222 }
6223 if (LocaleCompare("caption",option+1) == 0)
6224 {
6225 if (*option == '+')
6226 {
6227 (void) DeleteImageOption(image_info,option+1);
6228 break;
6229 }
6230 (void) SetImageOption(image_info,option+1,argv[i+1]);
6231 break;
6232 }
6233 if (LocaleCompare("channel",option+1) == 0)
6234 {
6235 if (*option == '+')
6236 {
6237 image_info->channel=DefaultChannels;
6238 break;
6239 }
6240 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6241 break;
6242 }
6243 if (LocaleCompare("colors",option+1) == 0)
6244 {
cristye27293e2009-12-18 02:53:20 +00006245 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006246 break;
6247 }
6248 if (LocaleCompare("colorspace",option+1) == 0)
6249 {
6250 if (*option == '+')
6251 {
6252 image_info->colorspace=UndefinedColorspace;
6253 (void) SetImageOption(image_info,option+1,"undefined");
6254 break;
6255 }
cristy042ee782011-04-22 18:48:30 +00006256 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006257 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6258 (void) SetImageOption(image_info,option+1,argv[i+1]);
6259 break;
6260 }
cristy3ed852e2009-09-05 21:47:34 +00006261 if (LocaleCompare("comment",option+1) == 0)
6262 {
6263 if (*option == '+')
6264 {
6265 (void) DeleteImageOption(image_info,option+1);
6266 break;
6267 }
6268 (void) SetImageOption(image_info,option+1,argv[i+1]);
6269 break;
6270 }
6271 if (LocaleCompare("compose",option+1) == 0)
6272 {
6273 if (*option == '+')
6274 {
6275 (void) SetImageOption(image_info,option+1,"undefined");
6276 break;
6277 }
6278 (void) SetImageOption(image_info,option+1,argv[i+1]);
6279 break;
6280 }
6281 if (LocaleCompare("compress",option+1) == 0)
6282 {
6283 if (*option == '+')
6284 {
6285 image_info->compression=UndefinedCompression;
6286 (void) SetImageOption(image_info,option+1,"undefined");
6287 break;
6288 }
cristy042ee782011-04-22 18:48:30 +00006289 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006290 MagickCompressOptions,MagickFalse,argv[i+1]);
6291 (void) SetImageOption(image_info,option+1,argv[i+1]);
6292 break;
6293 }
6294 break;
6295 }
6296 case 'd':
6297 {
6298 if (LocaleCompare("debug",option+1) == 0)
6299 {
6300 if (*option == '+')
6301 (void) SetLogEventMask("none");
6302 else
6303 (void) SetLogEventMask(argv[i+1]);
6304 image_info->debug=IsEventLogging();
6305 break;
6306 }
6307 if (LocaleCompare("define",option+1) == 0)
6308 {
6309 if (*option == '+')
6310 {
6311 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6312 (void) DeleteImageRegistry(argv[i+1]+9);
6313 else
6314 (void) DeleteImageOption(image_info,argv[i+1]);
6315 break;
6316 }
6317 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6318 {
6319 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6320 exception);
6321 break;
6322 }
6323 (void) DefineImageOption(image_info,argv[i+1]);
6324 break;
6325 }
6326 if (LocaleCompare("delay",option+1) == 0)
6327 {
6328 if (*option == '+')
6329 {
6330 (void) SetImageOption(image_info,option+1,"0");
6331 break;
6332 }
6333 (void) SetImageOption(image_info,option+1,argv[i+1]);
6334 break;
6335 }
6336 if (LocaleCompare("density",option+1) == 0)
6337 {
6338 /*
6339 Set image density.
6340 */
6341 if (*option == '+')
6342 {
6343 if (image_info->density != (char *) NULL)
6344 image_info->density=DestroyString(image_info->density);
6345 (void) SetImageOption(image_info,option+1,"72");
6346 break;
6347 }
6348 (void) CloneString(&image_info->density,argv[i+1]);
6349 (void) SetImageOption(image_info,option+1,argv[i+1]);
6350 break;
6351 }
6352 if (LocaleCompare("depth",option+1) == 0)
6353 {
6354 if (*option == '+')
6355 {
6356 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6357 break;
6358 }
cristye27293e2009-12-18 02:53:20 +00006359 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006360 break;
6361 }
cristyc9b12952010-03-28 01:12:28 +00006362 if (LocaleCompare("direction",option+1) == 0)
6363 {
6364 if (*option == '+')
6365 {
6366 (void) SetImageOption(image_info,option+1,"undefined");
6367 break;
6368 }
6369 (void) SetImageOption(image_info,option+1,argv[i+1]);
6370 break;
6371 }
cristy3ed852e2009-09-05 21:47:34 +00006372 if (LocaleCompare("display",option+1) == 0)
6373 {
6374 if (*option == '+')
6375 {
6376 if (image_info->server_name != (char *) NULL)
6377 image_info->server_name=DestroyString(
6378 image_info->server_name);
6379 break;
6380 }
6381 (void) CloneString(&image_info->server_name,argv[i+1]);
6382 break;
6383 }
6384 if (LocaleCompare("dispose",option+1) == 0)
6385 {
6386 if (*option == '+')
6387 {
6388 (void) SetImageOption(image_info,option+1,"undefined");
6389 break;
6390 }
6391 (void) SetImageOption(image_info,option+1,argv[i+1]);
6392 break;
6393 }
6394 if (LocaleCompare("dither",option+1) == 0)
6395 {
6396 if (*option == '+')
6397 {
6398 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006399 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006400 break;
6401 }
6402 (void) SetImageOption(image_info,option+1,argv[i+1]);
6403 image_info->dither=MagickTrue;
6404 break;
6405 }
6406 break;
6407 }
6408 case 'e':
6409 {
6410 if (LocaleCompare("encoding",option+1) == 0)
6411 {
6412 if (*option == '+')
6413 {
6414 (void) SetImageOption(image_info,option+1,"undefined");
6415 break;
6416 }
6417 (void) SetImageOption(image_info,option+1,argv[i+1]);
6418 break;
6419 }
6420 if (LocaleCompare("endian",option+1) == 0)
6421 {
6422 if (*option == '+')
6423 {
6424 image_info->endian=UndefinedEndian;
6425 (void) SetImageOption(image_info,option+1,"undefined");
6426 break;
6427 }
cristy042ee782011-04-22 18:48:30 +00006428 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006429 MagickEndianOptions,MagickFalse,argv[i+1]);
6430 (void) SetImageOption(image_info,option+1,argv[i+1]);
6431 break;
6432 }
6433 if (LocaleCompare("extract",option+1) == 0)
6434 {
6435 /*
6436 Set image extract geometry.
6437 */
6438 if (*option == '+')
6439 {
6440 if (image_info->extract != (char *) NULL)
6441 image_info->extract=DestroyString(image_info->extract);
6442 break;
6443 }
6444 (void) CloneString(&image_info->extract,argv[i+1]);
6445 break;
6446 }
6447 break;
6448 }
6449 case 'f':
6450 {
6451 if (LocaleCompare("fill",option+1) == 0)
6452 {
6453 if (*option == '+')
6454 {
6455 (void) SetImageOption(image_info,option+1,"none");
6456 break;
6457 }
6458 (void) SetImageOption(image_info,option+1,argv[i+1]);
6459 break;
6460 }
6461 if (LocaleCompare("filter",option+1) == 0)
6462 {
6463 if (*option == '+')
6464 {
6465 (void) SetImageOption(image_info,option+1,"undefined");
6466 break;
6467 }
6468 (void) SetImageOption(image_info,option+1,argv[i+1]);
6469 break;
6470 }
6471 if (LocaleCompare("font",option+1) == 0)
6472 {
6473 if (*option == '+')
6474 {
6475 if (image_info->font != (char *) NULL)
6476 image_info->font=DestroyString(image_info->font);
6477 break;
6478 }
6479 (void) CloneString(&image_info->font,argv[i+1]);
6480 break;
6481 }
6482 if (LocaleCompare("format",option+1) == 0)
6483 {
6484 register const char
6485 *q;
6486
6487 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006488 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006489 image_info->ping=MagickFalse;
6490 (void) SetImageOption(image_info,option+1,argv[i+1]);
6491 break;
6492 }
6493 if (LocaleCompare("fuzz",option+1) == 0)
6494 {
6495 if (*option == '+')
6496 {
6497 image_info->fuzz=0.0;
6498 (void) SetImageOption(image_info,option+1,"0");
6499 break;
6500 }
cristyf2f27272009-12-17 14:48:46 +00006501 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006502 1.0);
6503 (void) SetImageOption(image_info,option+1,argv[i+1]);
6504 break;
6505 }
6506 break;
6507 }
6508 case 'g':
6509 {
6510 if (LocaleCompare("gravity",option+1) == 0)
6511 {
6512 if (*option == '+')
6513 {
6514 (void) SetImageOption(image_info,option+1,"undefined");
6515 break;
6516 }
6517 (void) SetImageOption(image_info,option+1,argv[i+1]);
6518 break;
6519 }
6520 if (LocaleCompare("green-primary",option+1) == 0)
6521 {
6522 if (*option == '+')
6523 {
6524 (void) SetImageOption(image_info,option+1,"0.0");
6525 break;
6526 }
6527 (void) SetImageOption(image_info,option+1,argv[i+1]);
6528 break;
6529 }
6530 break;
6531 }
6532 case 'i':
6533 {
6534 if (LocaleCompare("intent",option+1) == 0)
6535 {
6536 if (*option == '+')
6537 {
6538 (void) SetImageOption(image_info,option+1,"undefined");
6539 break;
6540 }
6541 (void) SetImageOption(image_info,option+1,argv[i+1]);
6542 break;
6543 }
6544 if (LocaleCompare("interlace",option+1) == 0)
6545 {
6546 if (*option == '+')
6547 {
6548 image_info->interlace=UndefinedInterlace;
6549 (void) SetImageOption(image_info,option+1,"undefined");
6550 break;
6551 }
cristy042ee782011-04-22 18:48:30 +00006552 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006553 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6554 (void) SetImageOption(image_info,option+1,argv[i+1]);
6555 break;
6556 }
cristyb32b90a2009-09-07 21:45:48 +00006557 if (LocaleCompare("interline-spacing",option+1) == 0)
6558 {
6559 if (*option == '+')
6560 {
6561 (void) SetImageOption(image_info,option+1,"undefined");
6562 break;
6563 }
6564 (void) SetImageOption(image_info,option+1,argv[i+1]);
6565 break;
6566 }
cristy3ed852e2009-09-05 21:47:34 +00006567 if (LocaleCompare("interpolate",option+1) == 0)
6568 {
6569 if (*option == '+')
6570 {
6571 (void) SetImageOption(image_info,option+1,"undefined");
6572 break;
6573 }
6574 (void) SetImageOption(image_info,option+1,argv[i+1]);
6575 break;
6576 }
6577 if (LocaleCompare("interword-spacing",option+1) == 0)
6578 {
6579 if (*option == '+')
6580 {
6581 (void) SetImageOption(image_info,option+1,"undefined");
6582 break;
6583 }
6584 (void) SetImageOption(image_info,option+1,argv[i+1]);
6585 break;
6586 }
6587 break;
6588 }
6589 case 'k':
6590 {
6591 if (LocaleCompare("kerning",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 (void) SetImageOption(image_info,option+1,"undefined");
6596 break;
6597 }
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
6601 break;
6602 }
6603 case 'l':
6604 {
6605 if (LocaleCompare("label",option+1) == 0)
6606 {
6607 if (*option == '+')
6608 {
6609 (void) DeleteImageOption(image_info,option+1);
6610 break;
6611 }
6612 (void) SetImageOption(image_info,option+1,argv[i+1]);
6613 break;
6614 }
6615 if (LocaleCompare("limit",option+1) == 0)
6616 {
6617 MagickSizeType
6618 limit;
6619
6620 ResourceType
6621 type;
6622
6623 if (*option == '+')
6624 break;
cristy042ee782011-04-22 18:48:30 +00006625 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006626 MagickFalse,argv[i+1]);
6627 limit=MagickResourceInfinity;
6628 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006629 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006630 (void) SetMagickResourceLimit(type,limit);
6631 break;
6632 }
6633 if (LocaleCompare("list",option+1) == 0)
6634 {
cristybb503372010-05-27 20:51:26 +00006635 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006636 list;
6637
6638 /*
6639 Display configuration list.
6640 */
cristy042ee782011-04-22 18:48:30 +00006641 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006642 switch (list)
6643 {
6644 case MagickCoderOptions:
6645 {
6646 (void) ListCoderInfo((FILE *) NULL,exception);
6647 break;
6648 }
6649 case MagickColorOptions:
6650 {
6651 (void) ListColorInfo((FILE *) NULL,exception);
6652 break;
6653 }
6654 case MagickConfigureOptions:
6655 {
6656 (void) ListConfigureInfo((FILE *) NULL,exception);
6657 break;
6658 }
6659 case MagickDelegateOptions:
6660 {
6661 (void) ListDelegateInfo((FILE *) NULL,exception);
6662 break;
6663 }
6664 case MagickFontOptions:
6665 {
6666 (void) ListTypeInfo((FILE *) NULL,exception);
6667 break;
6668 }
6669 case MagickFormatOptions:
6670 {
6671 (void) ListMagickInfo((FILE *) NULL,exception);
6672 break;
6673 }
6674 case MagickLocaleOptions:
6675 {
6676 (void) ListLocaleInfo((FILE *) NULL,exception);
6677 break;
6678 }
6679 case MagickLogOptions:
6680 {
6681 (void) ListLogInfo((FILE *) NULL,exception);
6682 break;
6683 }
6684 case MagickMagicOptions:
6685 {
6686 (void) ListMagicInfo((FILE *) NULL,exception);
6687 break;
6688 }
6689 case MagickMimeOptions:
6690 {
6691 (void) ListMimeInfo((FILE *) NULL,exception);
6692 break;
6693 }
6694 case MagickModuleOptions:
6695 {
6696 (void) ListModuleInfo((FILE *) NULL,exception);
6697 break;
6698 }
6699 case MagickPolicyOptions:
6700 {
6701 (void) ListPolicyInfo((FILE *) NULL,exception);
6702 break;
6703 }
6704 case MagickResourceOptions:
6705 {
6706 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6707 break;
6708 }
6709 case MagickThresholdOptions:
6710 {
6711 (void) ListThresholdMaps((FILE *) NULL,exception);
6712 break;
6713 }
6714 default:
6715 {
cristy042ee782011-04-22 18:48:30 +00006716 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006717 exception);
6718 break;
6719 }
6720 }
cristyaeb2cbc2010-05-07 13:28:58 +00006721 break;
cristy3ed852e2009-09-05 21:47:34 +00006722 }
6723 if (LocaleCompare("log",option+1) == 0)
6724 {
6725 if (*option == '+')
6726 break;
6727 (void) SetLogFormat(argv[i+1]);
6728 break;
6729 }
6730 if (LocaleCompare("loop",option+1) == 0)
6731 {
6732 if (*option == '+')
6733 {
6734 (void) SetImageOption(image_info,option+1,"0");
6735 break;
6736 }
6737 (void) SetImageOption(image_info,option+1,argv[i+1]);
6738 break;
6739 }
6740 break;
6741 }
6742 case 'm':
6743 {
6744 if (LocaleCompare("matte",option+1) == 0)
6745 {
6746 if (*option == '+')
6747 {
6748 (void) SetImageOption(image_info,option+1,"false");
6749 break;
6750 }
6751 (void) SetImageOption(image_info,option+1,"true");
6752 break;
6753 }
6754 if (LocaleCompare("mattecolor",option+1) == 0)
6755 {
6756 if (*option == '+')
6757 {
6758 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006759 (void) QueryColorDatabase(MogrifyMatteColor,
6760 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006761 break;
6762 }
6763 (void) SetImageOption(image_info,option+1,argv[i+1]);
6764 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6765 exception);
6766 break;
6767 }
6768 if (LocaleCompare("monitor",option+1) == 0)
6769 {
6770 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6771 (void *) NULL);
6772 break;
6773 }
6774 if (LocaleCompare("monochrome",option+1) == 0)
6775 {
6776 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6777 break;
6778 }
6779 break;
6780 }
6781 case 'o':
6782 {
6783 if (LocaleCompare("orient",option+1) == 0)
6784 {
6785 if (*option == '+')
6786 {
6787 image_info->orientation=UndefinedOrientation;
6788 (void) SetImageOption(image_info,option+1,"undefined");
6789 break;
6790 }
cristy042ee782011-04-22 18:48:30 +00006791 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006792 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006793 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006794 break;
6795 }
6796 }
6797 case 'p':
6798 {
6799 if (LocaleCompare("page",option+1) == 0)
6800 {
6801 char
6802 *canonical_page,
6803 page[MaxTextExtent];
6804
6805 const char
6806 *image_option;
6807
6808 MagickStatusType
6809 flags;
6810
6811 RectangleInfo
6812 geometry;
6813
6814 if (*option == '+')
6815 {
6816 (void) DeleteImageOption(image_info,option+1);
6817 (void) CloneString(&image_info->page,(char *) NULL);
6818 break;
6819 }
6820 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6821 image_option=GetImageOption(image_info,"page");
6822 if (image_option != (const char *) NULL)
6823 flags=ParseAbsoluteGeometry(image_option,&geometry);
6824 canonical_page=GetPageGeometry(argv[i+1]);
6825 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6826 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006827 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006828 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006829 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006830 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006831 (unsigned long) geometry.width,(unsigned long) geometry.height,
6832 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006833 (void) SetImageOption(image_info,option+1,page);
6834 (void) CloneString(&image_info->page,page);
6835 break;
6836 }
6837 if (LocaleCompare("pen",option+1) == 0)
6838 {
6839 if (*option == '+')
6840 {
6841 (void) SetImageOption(image_info,option+1,"none");
6842 break;
6843 }
6844 (void) SetImageOption(image_info,option+1,argv[i+1]);
6845 break;
6846 }
6847 if (LocaleCompare("ping",option+1) == 0)
6848 {
6849 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6850 break;
6851 }
6852 if (LocaleCompare("pointsize",option+1) == 0)
6853 {
6854 if (*option == '+')
6855 geometry_info.rho=0.0;
6856 else
6857 (void) ParseGeometry(argv[i+1],&geometry_info);
6858 image_info->pointsize=geometry_info.rho;
6859 break;
6860 }
cristye7f51092010-01-17 00:39:37 +00006861 if (LocaleCompare("precision",option+1) == 0)
6862 {
cristybf2766a2010-01-17 03:33:23 +00006863 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006864 break;
6865 }
cristy3ed852e2009-09-05 21:47:34 +00006866 if (LocaleCompare("preview",option+1) == 0)
6867 {
6868 /*
6869 Preview image.
6870 */
6871 if (*option == '+')
6872 {
6873 image_info->preview_type=UndefinedPreview;
6874 break;
6875 }
cristy042ee782011-04-22 18:48:30 +00006876 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006877 MagickPreviewOptions,MagickFalse,argv[i+1]);
6878 break;
6879 }
6880 break;
6881 }
6882 case 'q':
6883 {
6884 if (LocaleCompare("quality",option+1) == 0)
6885 {
6886 /*
6887 Set image compression quality.
6888 */
6889 if (*option == '+')
6890 {
6891 image_info->quality=UndefinedCompressionQuality;
6892 (void) SetImageOption(image_info,option+1,"0");
6893 break;
6894 }
cristye27293e2009-12-18 02:53:20 +00006895 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006896 (void) SetImageOption(image_info,option+1,argv[i+1]);
6897 break;
6898 }
6899 if (LocaleCompare("quiet",option+1) == 0)
6900 {
6901 static WarningHandler
6902 warning_handler = (WarningHandler) NULL;
6903
6904 if (*option == '+')
6905 {
6906 /*
6907 Restore error or warning messages.
6908 */
6909 warning_handler=SetWarningHandler(warning_handler);
6910 break;
6911 }
6912 /*
6913 Suppress error or warning messages.
6914 */
6915 warning_handler=SetWarningHandler((WarningHandler) NULL);
6916 break;
6917 }
6918 break;
6919 }
6920 case 'r':
6921 {
6922 if (LocaleCompare("red-primary",option+1) == 0)
6923 {
6924 if (*option == '+')
6925 {
6926 (void) SetImageOption(image_info,option+1,"0.0");
6927 break;
6928 }
6929 (void) SetImageOption(image_info,option+1,argv[i+1]);
6930 break;
6931 }
6932 break;
6933 }
6934 case 's':
6935 {
6936 if (LocaleCompare("sampling-factor",option+1) == 0)
6937 {
6938 /*
6939 Set image sampling factor.
6940 */
6941 if (*option == '+')
6942 {
6943 if (image_info->sampling_factor != (char *) NULL)
6944 image_info->sampling_factor=DestroyString(
6945 image_info->sampling_factor);
6946 break;
6947 }
6948 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6949 break;
6950 }
6951 if (LocaleCompare("scene",option+1) == 0)
6952 {
6953 /*
6954 Set image scene.
6955 */
6956 if (*option == '+')
6957 {
6958 image_info->scene=0;
6959 (void) SetImageOption(image_info,option+1,"0");
6960 break;
6961 }
cristye27293e2009-12-18 02:53:20 +00006962 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006963 (void) SetImageOption(image_info,option+1,argv[i+1]);
6964 break;
6965 }
6966 if (LocaleCompare("seed",option+1) == 0)
6967 {
cristybb503372010-05-27 20:51:26 +00006968 size_t
cristy3ed852e2009-09-05 21:47:34 +00006969 seed;
6970
6971 if (*option == '+')
6972 {
cristybb503372010-05-27 20:51:26 +00006973 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006974 SeedPseudoRandomGenerator(seed);
6975 break;
6976 }
cristye27293e2009-12-18 02:53:20 +00006977 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006978 SeedPseudoRandomGenerator(seed);
6979 break;
6980 }
6981 if (LocaleCompare("size",option+1) == 0)
6982 {
6983 if (*option == '+')
6984 {
6985 if (image_info->size != (char *) NULL)
6986 image_info->size=DestroyString(image_info->size);
6987 break;
6988 }
6989 (void) CloneString(&image_info->size,argv[i+1]);
6990 break;
6991 }
6992 if (LocaleCompare("stroke",option+1) == 0)
6993 {
6994 if (*option == '+')
6995 {
6996 (void) SetImageOption(image_info,option+1,"none");
6997 break;
6998 }
6999 (void) SetImageOption(image_info,option+1,argv[i+1]);
7000 break;
7001 }
7002 if (LocaleCompare("strokewidth",option+1) == 0)
7003 {
7004 if (*option == '+')
7005 {
7006 (void) SetImageOption(image_info,option+1,"0");
7007 break;
7008 }
7009 (void) SetImageOption(image_info,option+1,argv[i+1]);
7010 break;
7011 }
cristyd9a29192010-10-16 16:49:53 +00007012 if (LocaleCompare("synchronize",option+1) == 0)
7013 {
7014 if (*option == '+')
7015 {
7016 image_info->synchronize=MagickFalse;
7017 break;
7018 }
7019 image_info->synchronize=MagickTrue;
7020 break;
7021 }
cristy3ed852e2009-09-05 21:47:34 +00007022 break;
7023 }
7024 case 't':
7025 {
7026 if (LocaleCompare("taint",option+1) == 0)
7027 {
7028 if (*option == '+')
7029 {
7030 (void) SetImageOption(image_info,option+1,"false");
7031 break;
7032 }
7033 (void) SetImageOption(image_info,option+1,"true");
7034 break;
7035 }
7036 if (LocaleCompare("texture",option+1) == 0)
7037 {
7038 if (*option == '+')
7039 {
7040 if (image_info->texture != (char *) NULL)
7041 image_info->texture=DestroyString(image_info->texture);
7042 break;
7043 }
7044 (void) CloneString(&image_info->texture,argv[i+1]);
7045 break;
7046 }
7047 if (LocaleCompare("tile-offset",option+1) == 0)
7048 {
7049 if (*option == '+')
7050 {
7051 (void) SetImageOption(image_info,option+1,"0");
7052 break;
7053 }
7054 (void) SetImageOption(image_info,option+1,argv[i+1]);
7055 break;
7056 }
7057 if (LocaleCompare("transparent-color",option+1) == 0)
7058 {
7059 if (*option == '+')
7060 {
7061 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7062 (void) SetImageOption(image_info,option+1,"none");
7063 break;
7064 }
7065 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7066 exception);
7067 (void) SetImageOption(image_info,option+1,argv[i+1]);
7068 break;
7069 }
7070 if (LocaleCompare("type",option+1) == 0)
7071 {
7072 if (*option == '+')
7073 {
cristy5f1c1ff2010-12-23 21:38:06 +00007074 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007075 (void) SetImageOption(image_info,option+1,"undefined");
7076 break;
7077 }
cristy042ee782011-04-22 18:48:30 +00007078 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007079 MagickFalse,argv[i+1]);
7080 (void) SetImageOption(image_info,option+1,argv[i+1]);
7081 break;
7082 }
7083 break;
7084 }
7085 case 'u':
7086 {
7087 if (LocaleCompare("undercolor",option+1) == 0)
7088 {
7089 if (*option == '+')
7090 {
7091 (void) DeleteImageOption(image_info,option+1);
7092 break;
7093 }
7094 (void) SetImageOption(image_info,option+1,argv[i+1]);
7095 break;
7096 }
7097 if (LocaleCompare("units",option+1) == 0)
7098 {
7099 if (*option == '+')
7100 {
7101 image_info->units=UndefinedResolution;
7102 (void) SetImageOption(image_info,option+1,"undefined");
7103 break;
7104 }
cristy042ee782011-04-22 18:48:30 +00007105 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007106 MagickResolutionOptions,MagickFalse,argv[i+1]);
7107 (void) SetImageOption(image_info,option+1,argv[i+1]);
7108 break;
7109 }
7110 break;
7111 }
7112 case 'v':
7113 {
7114 if (LocaleCompare("verbose",option+1) == 0)
7115 {
7116 if (*option == '+')
7117 {
7118 image_info->verbose=MagickFalse;
7119 break;
7120 }
7121 image_info->verbose=MagickTrue;
7122 image_info->ping=MagickFalse;
7123 break;
7124 }
7125 if (LocaleCompare("view",option+1) == 0)
7126 {
7127 if (*option == '+')
7128 {
7129 if (image_info->view != (char *) NULL)
7130 image_info->view=DestroyString(image_info->view);
7131 break;
7132 }
7133 (void) CloneString(&image_info->view,argv[i+1]);
7134 break;
7135 }
7136 if (LocaleCompare("virtual-pixel",option+1) == 0)
7137 {
7138 if (*option == '+')
7139 {
7140 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7141 (void) SetImageOption(image_info,option+1,"undefined");
7142 break;
7143 }
7144 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007145 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007146 argv[i+1]);
7147 (void) SetImageOption(image_info,option+1,argv[i+1]);
7148 break;
7149 }
7150 break;
7151 }
7152 case 'w':
7153 {
7154 if (LocaleCompare("white-point",option+1) == 0)
7155 {
7156 if (*option == '+')
7157 {
7158 (void) SetImageOption(image_info,option+1,"0.0");
7159 break;
7160 }
7161 (void) SetImageOption(image_info,option+1,argv[i+1]);
7162 break;
7163 }
7164 break;
7165 }
7166 default:
7167 break;
7168 }
7169 i+=count;
7170 }
7171 return(MagickTrue);
7172}
7173
7174/*
7175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7176% %
7177% %
7178% %
7179+ M o g r i f y I m a g e L i s t %
7180% %
7181% %
7182% %
7183%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7184%
7185% MogrifyImageList() applies any command line options that might affect the
7186% entire image list (e.g. -append, -coalesce, etc.).
7187%
7188% The format of the MogrifyImage method is:
7189%
7190% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7191% const char **argv,Image **images,ExceptionInfo *exception)
7192%
7193% A description of each parameter follows:
7194%
7195% o image_info: the image info..
7196%
7197% o argc: Specifies a pointer to an integer describing the number of
7198% elements in the argument vector.
7199%
7200% o argv: Specifies a pointer to a text array containing the command line
7201% arguments.
7202%
anthonye9c27192011-03-27 08:07:06 +00007203% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007204%
7205% o exception: return any errors or warnings in this structure.
7206%
7207*/
7208WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7209 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7210{
cristy3ed852e2009-09-05 21:47:34 +00007211 const char
7212 *option;
7213
cristy6b3da3a2010-06-20 02:21:46 +00007214 ImageInfo
7215 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007216
7217 MagickStatusType
7218 status;
7219
7220 QuantizeInfo
7221 *quantize_info;
7222
cristybb503372010-05-27 20:51:26 +00007223 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007224 i;
7225
cristy6b3da3a2010-06-20 02:21:46 +00007226 ssize_t
7227 count,
7228 index;
7229
cristy3ed852e2009-09-05 21:47:34 +00007230 /*
7231 Apply options to the image list.
7232 */
7233 assert(image_info != (ImageInfo *) NULL);
7234 assert(image_info->signature == MagickSignature);
7235 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007236 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007237 assert((*images)->signature == MagickSignature);
7238 if ((*images)->debug != MagickFalse)
7239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7240 (*images)->filename);
7241 if ((argc <= 0) || (*argv == (char *) NULL))
7242 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007243 mogrify_info=CloneImageInfo(image_info);
7244 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007245 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007246 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007247 {
cristy74fe8f12009-10-03 19:09:01 +00007248 if (*images == (Image *) NULL)
7249 break;
cristy3ed852e2009-09-05 21:47:34 +00007250 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007251 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007252 continue;
cristy042ee782011-04-22 18:48:30 +00007253 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007254 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007255 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007256 break;
cristy6b3da3a2010-06-20 02:21:46 +00007257 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007258 switch (*(option+1))
7259 {
7260 case 'a':
7261 {
7262 if (LocaleCompare("affinity",option+1) == 0)
7263 {
cristy6b3da3a2010-06-20 02:21:46 +00007264 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007265 if (*option == '+')
7266 {
7267 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7268 InheritException(exception,&(*images)->exception);
7269 break;
7270 }
7271 i++;
7272 break;
7273 }
7274 if (LocaleCompare("append",option+1) == 0)
7275 {
7276 Image
7277 *append_image;
7278
cristy6b3da3a2010-06-20 02:21:46 +00007279 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007280 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7281 MagickFalse,exception);
7282 if (append_image == (Image *) NULL)
7283 {
7284 status=MagickFalse;
7285 break;
7286 }
7287 *images=DestroyImageList(*images);
7288 *images=append_image;
7289 break;
7290 }
7291 if (LocaleCompare("average",option+1) == 0)
7292 {
7293 Image
7294 *average_image;
7295
cristyd18ae7c2010-03-07 17:39:52 +00007296 /*
7297 Average an image sequence (deprecated).
7298 */
cristy6b3da3a2010-06-20 02:21:46 +00007299 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007300 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7301 exception);
cristy3ed852e2009-09-05 21:47:34 +00007302 if (average_image == (Image *) NULL)
7303 {
7304 status=MagickFalse;
7305 break;
7306 }
7307 *images=DestroyImageList(*images);
7308 *images=average_image;
7309 break;
7310 }
7311 break;
7312 }
7313 case 'c':
7314 {
7315 if (LocaleCompare("channel",option+1) == 0)
7316 {
cristyf4ad9df2011-07-08 16:49:03 +00007317 ChannelType
7318 channel;
7319
cristy3ed852e2009-09-05 21:47:34 +00007320 if (*option == '+')
7321 {
7322 channel=DefaultChannels;
7323 break;
7324 }
7325 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007326 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007327 break;
7328 }
7329 if (LocaleCompare("clut",option+1) == 0)
7330 {
7331 Image
7332 *clut_image,
7333 *image;
7334
cristy6b3da3a2010-06-20 02:21:46 +00007335 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007336 image=RemoveFirstImageFromList(images);
7337 clut_image=RemoveFirstImageFromList(images);
7338 if (clut_image == (Image *) NULL)
7339 {
7340 status=MagickFalse;
7341 break;
7342 }
cristy444eda62011-08-10 02:07:46 +00007343 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007344 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007345 *images=DestroyImageList(*images);
7346 *images=image;
7347 break;
7348 }
7349 if (LocaleCompare("coalesce",option+1) == 0)
7350 {
7351 Image
7352 *coalesce_image;
7353
cristy6b3da3a2010-06-20 02:21:46 +00007354 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007355 coalesce_image=CoalesceImages(*images,exception);
7356 if (coalesce_image == (Image *) NULL)
7357 {
7358 status=MagickFalse;
7359 break;
7360 }
7361 *images=DestroyImageList(*images);
7362 *images=coalesce_image;
7363 break;
7364 }
7365 if (LocaleCompare("combine",option+1) == 0)
7366 {
7367 Image
7368 *combine_image;
7369
cristy6b3da3a2010-06-20 02:21:46 +00007370 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007371 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007372 if (combine_image == (Image *) NULL)
7373 {
7374 status=MagickFalse;
7375 break;
7376 }
7377 *images=DestroyImageList(*images);
7378 *images=combine_image;
7379 break;
7380 }
7381 if (LocaleCompare("composite",option+1) == 0)
7382 {
7383 Image
7384 *mask_image,
7385 *composite_image,
7386 *image;
7387
7388 RectangleInfo
7389 geometry;
7390
cristy6b3da3a2010-06-20 02:21:46 +00007391 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007392 image=RemoveFirstImageFromList(images);
7393 composite_image=RemoveFirstImageFromList(images);
7394 if (composite_image == (Image *) NULL)
7395 {
7396 status=MagickFalse;
7397 break;
7398 }
7399 (void) TransformImage(&composite_image,(char *) NULL,
7400 composite_image->geometry);
7401 SetGeometry(composite_image,&geometry);
7402 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7403 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7404 &geometry);
7405 mask_image=RemoveFirstImageFromList(images);
7406 if (mask_image != (Image *) NULL)
7407 {
7408 if ((image->compose == DisplaceCompositeOp) ||
7409 (image->compose == DistortCompositeOp))
7410 {
7411 /*
7412 Merge Y displacement into X displacement image.
7413 */
7414 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7415 mask_image,0,0);
7416 mask_image=DestroyImage(mask_image);
7417 }
7418 else
7419 {
7420 /*
7421 Set a blending mask for the composition.
7422 */
anthonya129f702011-04-14 01:08:48 +00007423 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007424 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007425 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007426 }
7427 }
cristyf4ad9df2011-07-08 16:49:03 +00007428 (void) CompositeImage(image,image->compose,composite_image,
7429 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007430 if (mask_image != (Image *) NULL)
7431 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007432 composite_image=DestroyImage(composite_image);
7433 InheritException(exception,&image->exception);
7434 *images=DestroyImageList(*images);
7435 *images=image;
7436 break;
7437 }
anthony9f4f0342011-03-28 11:47:22 +00007438#if 0
7439This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007440 if (LocaleCompare("crop",option+1) == 0)
7441 {
7442 MagickStatusType
7443 flags;
7444
7445 RectangleInfo
7446 geometry;
7447
anthonye9c27192011-03-27 08:07:06 +00007448 /*
anthony9f4f0342011-03-28 11:47:22 +00007449 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007450 */
cristy6b3da3a2010-06-20 02:21:46 +00007451 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007452 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7453 if (((geometry.width == 0) && (geometry.height == 0)) ||
7454 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7455 break;
7456 (void) TransformImages(images,argv[i+1],(char *) NULL);
7457 InheritException(exception,&(*images)->exception);
7458 break;
7459 }
anthony9f4f0342011-03-28 11:47:22 +00007460#endif
cristy3ed852e2009-09-05 21:47:34 +00007461 break;
7462 }
7463 case 'd':
7464 {
7465 if (LocaleCompare("deconstruct",option+1) == 0)
7466 {
7467 Image
7468 *deconstruct_image;
7469
cristy6b3da3a2010-06-20 02:21:46 +00007470 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007471 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007472 exception);
cristy3ed852e2009-09-05 21:47:34 +00007473 if (deconstruct_image == (Image *) NULL)
7474 {
7475 status=MagickFalse;
7476 break;
7477 }
7478 *images=DestroyImageList(*images);
7479 *images=deconstruct_image;
7480 break;
7481 }
7482 if (LocaleCompare("delete",option+1) == 0)
7483 {
7484 if (*option == '+')
7485 DeleteImages(images,"-1",exception);
7486 else
7487 DeleteImages(images,argv[i+1],exception);
7488 break;
7489 }
7490 if (LocaleCompare("dither",option+1) == 0)
7491 {
7492 if (*option == '+')
7493 {
7494 quantize_info->dither=MagickFalse;
7495 break;
7496 }
7497 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007498 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007499 MagickDitherOptions,MagickFalse,argv[i+1]);
7500 break;
7501 }
cristyecb10ff2011-03-22 13:14:03 +00007502 if (LocaleCompare("duplicate",option+1) == 0)
7503 {
cristy72988482011-03-29 16:34:38 +00007504 Image
7505 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007506
anthony2b6bcae2011-03-23 13:05:34 +00007507 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007508 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7509 else
7510 {
7511 const char
7512 *p;
7513
anthony2b6bcae2011-03-23 13:05:34 +00007514 size_t
7515 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007516
anthony2b6bcae2011-03-23 13:05:34 +00007517 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007518 p=strchr(argv[i+1],',');
7519 if (p == (const char *) NULL)
7520 duplicate_images=DuplicateImages(*images,number_duplicates,
7521 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007522 else
cristy72988482011-03-29 16:34:38 +00007523 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7524 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007525 }
7526 AppendImageToList(images, duplicate_images);
7527 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007528 break;
7529 }
cristy3ed852e2009-09-05 21:47:34 +00007530 break;
7531 }
cristyd18ae7c2010-03-07 17:39:52 +00007532 case 'e':
7533 {
7534 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7535 {
7536 Image
7537 *evaluate_image;
7538
7539 MagickEvaluateOperator
7540 op;
7541
cristy6b3da3a2010-06-20 02:21:46 +00007542 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007543 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007544 MagickFalse,argv[i+1]);
7545 evaluate_image=EvaluateImages(*images,op,exception);
7546 if (evaluate_image == (Image *) NULL)
7547 {
7548 status=MagickFalse;
7549 break;
7550 }
7551 *images=DestroyImageList(*images);
7552 *images=evaluate_image;
7553 break;
7554 }
7555 break;
7556 }
cristy3ed852e2009-09-05 21:47:34 +00007557 case 'f':
7558 {
cristyf0a247f2009-10-04 00:20:03 +00007559 if (LocaleCompare("fft",option+1) == 0)
7560 {
7561 Image
7562 *fourier_image;
7563
7564 /*
7565 Implements the discrete Fourier transform (DFT).
7566 */
cristy6b3da3a2010-06-20 02:21:46 +00007567 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007568 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7569 MagickTrue : MagickFalse,exception);
7570 if (fourier_image == (Image *) NULL)
7571 break;
7572 *images=DestroyImage(*images);
7573 *images=fourier_image;
7574 break;
7575 }
cristy3ed852e2009-09-05 21:47:34 +00007576 if (LocaleCompare("flatten",option+1) == 0)
7577 {
7578 Image
7579 *flatten_image;
7580
cristy6b3da3a2010-06-20 02:21:46 +00007581 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007582 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7583 if (flatten_image == (Image *) NULL)
7584 break;
7585 *images=DestroyImageList(*images);
7586 *images=flatten_image;
7587 break;
7588 }
7589 if (LocaleCompare("fx",option+1) == 0)
7590 {
7591 Image
7592 *fx_image;
7593
cristy6b3da3a2010-06-20 02:21:46 +00007594 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007595 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007596 if (fx_image == (Image *) NULL)
7597 {
7598 status=MagickFalse;
7599 break;
7600 }
7601 *images=DestroyImageList(*images);
7602 *images=fx_image;
7603 break;
7604 }
7605 break;
7606 }
7607 case 'h':
7608 {
7609 if (LocaleCompare("hald-clut",option+1) == 0)
7610 {
7611 Image
7612 *hald_image,
7613 *image;
7614
cristy6b3da3a2010-06-20 02:21:46 +00007615 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007616 image=RemoveFirstImageFromList(images);
7617 hald_image=RemoveFirstImageFromList(images);
7618 if (hald_image == (Image *) NULL)
7619 {
7620 status=MagickFalse;
7621 break;
7622 }
cristyf89cb1d2011-07-07 01:24:37 +00007623 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007624 hald_image=DestroyImage(hald_image);
7625 InheritException(exception,&image->exception);
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}