blob: 085dc12c2374a3097a2e8ad0f1ecd380f238fe23 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
cristy4c08aed2011-07-01 19:47:50 +000054#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000055#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000056#include "MagickCore/utility-private.h"
cristy3ed852e2009-09-05 21:47:34 +000057
58/*
cristy154fa9d2011-08-05 14:25:15 +000059 Constant declaration.
60*/
cristy3a557c02011-08-06 19:48:02 +000061static const char
cristy638895a2011-08-06 23:19:14 +000062 MogrifyBackgroundColor[] = "#ffffff", /* white */
63 MogrifyBorderColor[] = "#dfdfdf", /* gray */
64 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000065
66/*
cristy3ed852e2009-09-05 21:47:34 +000067 Define declarations.
68*/
69#define UndefinedCompressionQuality 0UL
70
71/*
cristy3ed852e2009-09-05 21:47:34 +000072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
cristy5063d812010-10-19 16:28:10 +000076% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000077% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% MagickCommandGenesis() applies image processing options to an image as
83% prescribed by command line options.
84%
85% The format of the MagickCommandGenesis method is:
86%
87% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000088% MagickCommand command,int argc,char **argv,char **metadata,
89% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000090%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
cristy5063d812010-10-19 16:28:10 +000095% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000096% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000097% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000099%
100% o argc: Specifies a pointer to an integer describing the number of
101% elements in the argument vector.
102%
103% o argv: Specifies a pointer to a text array containing the command line
104% arguments.
105%
cristy5063d812010-10-19 16:28:10 +0000106% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000107%
108% o exception: return any errors or warnings in this structure.
109%
110*/
cristyc2e3aeb2011-12-09 11:09:38 +0000111
112static inline double MagickMin(const double x,const double y)
113{
114 if (x < y)
115 return(x);
116 return(y);
117}
118
cristy3980b0d2009-10-25 14:37:13 +0000119WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
120 MagickCommand command,int argc,char **argv,char **metadata,
121 ExceptionInfo *exception)
122{
123 char
124 *option;
125
126 double
127 duration,
cristyc2e3aeb2011-12-09 11:09:38 +0000128 standard;
cristy3980b0d2009-10-25 14:37:13 +0000129
cristy3980b0d2009-10-25 14:37:13 +0000130 MagickBooleanType
131 concurrent,
132 regard_warnings,
133 status;
134
cristybb503372010-05-27 20:51:26 +0000135 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000136 i;
137
cristybb503372010-05-27 20:51:26 +0000138 size_t
cristyc2e3aeb2011-12-09 11:09:38 +0000139 iterations,
140 n,
141 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000142
cristyd0a94fa2010-03-12 14:18:11 +0000143 (void) setlocale(LC_ALL,"");
144 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000145 concurrent=MagickFalse;
146 duration=(-1.0);
147 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000148 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000149 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000150 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000151 {
152 option=argv[i];
153 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
154 continue;
155 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000156 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000157 if (LocaleCompare("concurrent",option+1) == 0)
158 concurrent=MagickTrue;
159 if (LocaleCompare("debug",option+1) == 0)
160 (void) SetLogEventMask(argv[++i]);
161 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000162 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000163 if (LocaleCompare("regard-warnings",option+1) == 0)
164 regard_warnings=MagickTrue;
165 }
cristyc2e3aeb2011-12-09 11:09:38 +0000166 number_threads=GetOpenMPMaximumThreads();
167 standard=0.0;
168 for (n=1; n <= number_threads; n++)
169 {
170 double
171 efficiency,
172 elapsed_time,
173 user_time;
174
175 TimerInfo
176 *timer;
177
178 SetOpenMPMaximumThreads(n);
179 timer=AcquireTimerInfo();
180 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000181 {
cristyc2e3aeb2011-12-09 11:09:38 +0000182 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000183 {
cristyc2e3aeb2011-12-09 11:09:38 +0000184 if (status != MagickFalse)
185 continue;
186 if (duration > 0)
187 {
188 if (GetElapsedTime(timer) > duration)
189 continue;
190 (void) ContinueTimer(timer);
191 }
192 status=command(image_info,argc,argv,metadata,exception);
cristyceae09d2009-10-28 17:18:47 +0000193 if (exception->severity != UndefinedException)
194 {
195 if ((exception->severity > ErrorException) ||
196 (regard_warnings != MagickFalse))
197 status=MagickTrue;
198 CatchException(exception);
199 }
200 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
201 {
202 (void) fputs(*metadata,stdout);
203 (void) fputc('\n',stdout);
204 *metadata=DestroyString(*metadata);
205 }
206 }
207 }
cristyc2e3aeb2011-12-09 11:09:38 +0000208 else
209 {
210 SetOpenMPNested(1);
211#if defined(MAGICKCORE_OPENMP_SUPPORT)
212 # pragma omp parallel for shared(status)
213#endif
214 for (i=0; i < (ssize_t) iterations; i++)
215 {
216 if (status != MagickFalse)
217 continue;
218 if (duration > 0)
219 {
220 if (GetElapsedTime(timer) > duration)
221 continue;
222 (void) ContinueTimer(timer);
223 }
224 status=command(image_info,argc,argv,metadata,exception);
225#if defined(MAGICKCORE_OPENMP_SUPPORT)
226 # pragma omp critical (MagickCore_CommandGenesis)
227#endif
228 {
229 if (exception->severity != UndefinedException)
230 {
231 if ((exception->severity > ErrorException) ||
232 (regard_warnings != MagickFalse))
233 status=MagickTrue;
234 CatchException(exception);
235 }
236 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
237 {
238 (void) fputs(*metadata,stdout);
239 (void) fputc('\n',stdout);
240 *metadata=DestroyString(*metadata);
241 }
242 }
243 }
244 }
245 elapsed_time=GetElapsedTime(timer);
246 if (n == 1)
247 standard=elapsed_time;
248 user_time=GetUserTime(timer);
249 efficiency=((1.0/MagickMin((double) number_threads,standard/elapsed_time))-
250 (1.0/number_threads))/(1.0-(1.0/number_threads));
251 (void) FormatLocaleFile(stderr,
252 "Performance[%.20g]: %.20gi %gips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
253 (double) n,(double) iterations,(double) iterations/elapsed_time,
254 efficiency,user_time,(unsigned long) (elapsed_time/60.0),(unsigned long)
255 floor(fmod(elapsed_time,60.0)),(unsigned long)
256 (1000.0*(elapsed_time-floor(elapsed_time))+0.5));
257 timer=DestroyTimerInfo(timer);
258 }
cristy1f9e1ed2009-11-18 04:09:38 +0000259 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000260}
261
262/*
263%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264% %
265% %
266% %
cristy3ed852e2009-09-05 21:47:34 +0000267+ M o g r i f y I m a g e %
268% %
269% %
270% %
271%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272%
anthonye9c27192011-03-27 08:07:06 +0000273% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000274% image that may be part of a large list, but also handles any 'region'
275% image handling.
anthonye9c27192011-03-27 08:07:06 +0000276%
277% The image in the list may be modified in three different ways...
278%
279% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
280% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
281% * replace by a list of images (only the -separate option!)
282%
283% In each case the result is returned into the list, and a pointer to the
284% modified image (last image added if replaced by a list of images) is
285% returned.
286%
287% ASIDE: The -crop is present but restricted to non-tile single image crops
288%
289% This means if all the images are being processed (such as by
290% MogrifyImages(), next image to be processed will be as per the pointer
291% (*image)->next. Also the image list may grow as a result of some specific
292% operations but as images are never merged or deleted, it will never shrink
293% in length. Typically the list will remain the same length.
294%
295% WARNING: As the image pointed to may be replaced, the first image in the
296% list may also change. GetFirstImageInList() should be used by caller if
297% they wish return the Image pointer to the first image in list.
298%
cristy3ed852e2009-09-05 21:47:34 +0000299%
300% The format of the MogrifyImage method is:
301%
302% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
303% const char **argv,Image **image)
304%
305% A description of each parameter follows:
306%
307% o image_info: the image info..
308%
309% o argc: Specifies a pointer to an integer describing the number of
310% elements in the argument vector.
311%
312% o argv: Specifies a pointer to a text array containing the command line
313% arguments.
314%
315% o image: the image.
316%
317% o exception: return any errors or warnings in this structure.
318%
319*/
320
anthonydf8ebac2011-04-27 09:03:19 +0000321static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
322 ExceptionInfo *exception)
323{
324 char
325 key[MaxTextExtent];
326
327 ExceptionInfo
328 *sans_exception;
329
330 Image
331 *image;
332
333 ImageInfo
334 *read_info;
335
cristyfcd785b2011-11-08 01:48:33 +0000336 /*
337 Read an image into a image cache if not already present. Return the image
338 that is in the cache under that filename.
339 */
cristyb51dff52011-05-19 16:55:47 +0000340 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000341 sans_exception=AcquireExceptionInfo();
342 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
343 sans_exception=DestroyExceptionInfo(sans_exception);
344 if (image != (Image *) NULL)
345 return(image);
346 read_info=CloneImageInfo(image_info);
347 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
348 image=ReadImage(read_info,exception);
349 read_info=DestroyImageInfo(read_info);
350 if (image != (Image *) NULL)
351 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
352 return(image);
353}
354
cristy3ed852e2009-09-05 21:47:34 +0000355static MagickBooleanType IsPathWritable(const char *path)
356{
357 if (IsPathAccessible(path) == MagickFalse)
358 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000359 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000360 return(MagickFalse);
361 return(MagickTrue);
362}
363
cristybb503372010-05-27 20:51:26 +0000364static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000365{
366 if (x > y)
367 return(x);
368 return(y);
369}
370
anthonydf8ebac2011-04-27 09:03:19 +0000371static MagickBooleanType MonitorProgress(const char *text,
372 const MagickOffsetType offset,const MagickSizeType extent,
373 void *wand_unused(client_data))
374{
375 char
376 message[MaxTextExtent],
377 tag[MaxTextExtent];
378
379 const char
380 *locale_message;
381
382 register char
383 *p;
384
385 if (extent < 2)
386 return(MagickTrue);
387 (void) CopyMagickMemory(tag,text,MaxTextExtent);
388 p=strrchr(tag,'/');
389 if (p != (char *) NULL)
390 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000391 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000392 locale_message=GetLocaleMessage(message);
393 if (locale_message == message)
394 locale_message=tag;
395 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000396 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
397 locale_message,(long) offset,(unsigned long) extent,(long)
398 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000399 else
cristyb51dff52011-05-19 16:55:47 +0000400 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000401 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
402 (100L*offset/(extent-1)));
403 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000404 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000405 (void) fflush(stderr);
406 return(MagickTrue);
407}
408
cristy3884f692011-07-08 18:00:18 +0000409static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000410 const SparseColorMethod method,const char *arguments,
411 const MagickBooleanType color_from_image,ExceptionInfo *exception)
412{
anthonydf8ebac2011-04-27 09:03:19 +0000413 char
414 token[MaxTextExtent];
415
416 const char
417 *p;
418
419 double
420 *sparse_arguments;
421
anthonydf8ebac2011-04-27 09:03:19 +0000422 Image
423 *sparse_image;
424
cristy4c08aed2011-07-01 19:47:50 +0000425 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000426 color;
427
428 MagickBooleanType
429 error;
430
cristy5f09d852011-05-29 01:39:29 +0000431 register size_t
432 x;
433
434 size_t
435 number_arguments,
436 number_colors;
437
cristyf4425a72011-11-08 01:52:04 +0000438 /*
439 SparseColorOption() parses the complex -sparse-color argument into an an
440 array of floating point values then calls SparseColorImage(). Argument is
441 a complex mix of floating-point pixel coodinates, and color specifications
442 (or direct floating point numbers). The number of floats needed to
443 represent a color varies depending on the current channel setting.
444 */
anthonydf8ebac2011-04-27 09:03:19 +0000445 assert(image != (Image *) NULL);
446 assert(image->signature == MagickSignature);
447 if (image->debug != MagickFalse)
448 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
449 assert(exception != (ExceptionInfo *) NULL);
450 assert(exception->signature == MagickSignature);
451 /*
452 Limit channels according to image - and add up number of color channel.
453 */
anthonydf8ebac2011-04-27 09:03:19 +0000454 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000455 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000456 number_colors++;
cristyed231572011-07-14 02:18:59 +0000457 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000458 number_colors++;
cristyed231572011-07-14 02:18:59 +0000459 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000460 number_colors++;
cristyed231572011-07-14 02:18:59 +0000461 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000462 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000463 number_colors++;
cristyed231572011-07-14 02:18:59 +0000464 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000465 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000466 number_colors++;
467
468 /*
469 Read string, to determine number of arguments needed,
470 */
471 p=arguments;
472 x=0;
473 while( *p != '\0' )
474 {
475 GetMagickToken(p,&p,token);
476 if ( token[0] == ',' ) continue;
477 if ( isalpha((int) token[0]) || token[0] == '#' ) {
478 if ( color_from_image ) {
479 (void) ThrowMagickException(exception,GetMagickModule(),
480 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
481 "Color arg given, when colors are coming from image");
482 return( (Image *)NULL);
483 }
484 x += number_colors; /* color argument */
485 }
486 else {
487 x++; /* floating point argument */
488 }
489 }
490 error=MagickTrue;
491 if ( color_from_image ) {
492 /* just the control points are being given */
493 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
494 number_arguments=(x/2)*(2+number_colors);
495 }
496 else {
497 /* control points and color values */
498 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
499 number_arguments=x;
500 }
501 if ( error ) {
502 (void) ThrowMagickException(exception,GetMagickModule(),
503 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
504 "Invalid number of Arguments");
505 return( (Image *)NULL);
506 }
507
508 /* Allocate and fill in the floating point arguments */
509 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
510 sizeof(*sparse_arguments));
511 if (sparse_arguments == (double *) NULL) {
512 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
513 "MemoryAllocationFailed","%s","SparseColorOption");
514 return( (Image *)NULL);
515 }
516 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
517 sizeof(*sparse_arguments));
518 p=arguments;
519 x=0;
520 while( *p != '\0' && x < number_arguments ) {
521 /* X coordinate */
522 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
523 if ( token[0] == '\0' ) break;
524 if ( isalpha((int) token[0]) || token[0] == '#' ) {
525 (void) ThrowMagickException(exception,GetMagickModule(),
526 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
527 "Color found, instead of X-coord");
528 error = MagickTrue;
529 break;
530 }
cristydbdd0e32011-11-04 23:29:40 +0000531 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000532 /* Y coordinate */
533 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
534 if ( token[0] == '\0' ) break;
535 if ( isalpha((int) token[0]) || token[0] == '#' ) {
536 (void) ThrowMagickException(exception,GetMagickModule(),
537 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
538 "Color found, instead of Y-coord");
539 error = MagickTrue;
540 break;
541 }
cristydbdd0e32011-11-04 23:29:40 +0000542 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000543 /* color values for this control point */
544#if 0
545 if ( (color_from_image ) {
546 /* get color from image */
547 /* HOW??? */
548 }
549 else
550#endif
551 {
552 /* color name or function given in string argument */
553 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
554 if ( token[0] == '\0' ) break;
555 if ( isalpha((int) token[0]) || token[0] == '#' ) {
556 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000557 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000558 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000559 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000560 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000561 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000562 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000563 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000564 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000565 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000566 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000567 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000568 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000569 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000570 }
571 else {
572 /* Colors given as a set of floating point values - experimental */
573 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000574 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000575 {
anthonydf8ebac2011-04-27 09:03:19 +0000576 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
577 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
578 break;
cristydbdd0e32011-11-04 23:29:40 +0000579 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000580 token[0] = ','; /* used this token - get another */
581 }
cristyed231572011-07-14 02:18:59 +0000582 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000583 {
anthonydf8ebac2011-04-27 09:03:19 +0000584 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
585 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
586 break;
cristydbdd0e32011-11-04 23:29:40 +0000587 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000588 token[0] = ','; /* used this token - get another */
589 }
cristyed231572011-07-14 02:18:59 +0000590 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000591 {
anthonydf8ebac2011-04-27 09:03:19 +0000592 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
593 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
594 break;
cristydbdd0e32011-11-04 23:29:40 +0000595 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000596 token[0] = ','; /* used this token - get another */
597 }
cristyed231572011-07-14 02:18:59 +0000598 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000599 (image->colorspace == CMYKColorspace))
600 {
anthonydf8ebac2011-04-27 09:03:19 +0000601 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
602 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
603 break;
cristydbdd0e32011-11-04 23:29:40 +0000604 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000605 token[0] = ','; /* used this token - get another */
606 }
cristyed231572011-07-14 02:18:59 +0000607 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000608 (image->matte != MagickFalse))
609 {
anthonydf8ebac2011-04-27 09:03:19 +0000610 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
611 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
612 break;
cristydbdd0e32011-11-04 23:29:40 +0000613 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000614 token[0] = ','; /* used this token - get another */
615 }
616 }
617 }
618 }
619 if ( number_arguments != x && !error ) {
620 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
621 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
622 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
623 return( (Image *)NULL);
624 }
625 if ( error )
626 return( (Image *)NULL);
627
628 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000629 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
630 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000631 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
632 return( sparse_image );
633}
634
cristy3ed852e2009-09-05 21:47:34 +0000635WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
636 const char **argv,Image **image,ExceptionInfo *exception)
637{
anthonydf8ebac2011-04-27 09:03:19 +0000638 ChannelType
639 channel;
640
cristy633f0c62011-09-15 13:27:36 +0000641 CompositeOperator
642 compose;
643
anthonydf8ebac2011-04-27 09:03:19 +0000644 const char
645 *format,
646 *option;
647
cristy9ed1f812011-10-08 02:00:08 +0000648 double
649 attenuate;
650
anthonydf8ebac2011-04-27 09:03:19 +0000651 DrawInfo
652 *draw_info;
653
654 GeometryInfo
655 geometry_info;
656
cristy3ed852e2009-09-05 21:47:34 +0000657 Image
658 *region_image;
659
anthonydf8ebac2011-04-27 09:03:19 +0000660 ImageInfo
661 *mogrify_info;
662
cristyebbcfea2011-02-25 02:43:54 +0000663 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000664 status;
665
cristy4c08aed2011-07-01 19:47:50 +0000666 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000667 fill;
cristy3ed852e2009-09-05 21:47:34 +0000668
anthonydf8ebac2011-04-27 09:03:19 +0000669 MagickStatusType
670 flags;
671
cristy28474bf2011-09-11 23:32:52 +0000672 PixelInterpolateMethod
673 interpolate_method;
674
anthonydf8ebac2011-04-27 09:03:19 +0000675 QuantizeInfo
676 *quantize_info;
677
678 RectangleInfo
679 geometry,
680 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000681
cristybb503372010-05-27 20:51:26 +0000682 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000683 i;
684
685 /*
686 Initialize method variables.
687 */
688 assert(image_info != (const ImageInfo *) NULL);
689 assert(image_info->signature == MagickSignature);
690 assert(image != (Image **) NULL);
691 assert((*image)->signature == MagickSignature);
692 if ((*image)->debug != MagickFalse)
693 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
694 if (argc < 0)
695 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000696 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000697 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
698 quantize_info=AcquireQuantizeInfo(mogrify_info);
699 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000700 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000701 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000702 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000703 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000704 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000705 channel=mogrify_info->channel;
706 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000707 SetGeometry(*image,&region_geometry);
708 region_image=NewImageList();
709 /*
710 Transmogrify the image.
711 */
cristybb503372010-05-27 20:51:26 +0000712 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000713 {
anthonydf8ebac2011-04-27 09:03:19 +0000714 Image
715 *mogrify_image;
716
anthonye9c27192011-03-27 08:07:06 +0000717 ssize_t
718 count;
719
anthonydf8ebac2011-04-27 09:03:19 +0000720 option=argv[i];
721 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000722 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000723 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
724 0L);
cristycee97112010-05-28 00:44:52 +0000725 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000726 break;
cristy6b3da3a2010-06-20 02:21:46 +0000727 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000728 mogrify_image=(Image *)NULL;
729 switch (*(option+1))
730 {
731 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000732 {
anthonydf8ebac2011-04-27 09:03:19 +0000733 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000734 {
anthonydf8ebac2011-04-27 09:03:19 +0000735 /*
736 Adaptive blur image.
737 */
cristy6fccee12011-10-20 18:43:18 +0000738 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000739 flags=ParseGeometry(argv[i+1],&geometry_info);
740 if ((flags & SigmaValue) == 0)
741 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000742 if ((flags & XiValue) == 0)
743 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000744 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000745 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000746 break;
cristy3ed852e2009-09-05 21:47:34 +0000747 }
anthonydf8ebac2011-04-27 09:03:19 +0000748 if (LocaleCompare("adaptive-resize",option+1) == 0)
749 {
750 /*
751 Adaptive resize image.
752 */
cristy6fccee12011-10-20 18:43:18 +0000753 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000754 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
755 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000756 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000757 break;
758 }
759 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
760 {
761 /*
762 Adaptive sharpen image.
763 */
cristy6fccee12011-10-20 18:43:18 +0000764 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000765 flags=ParseGeometry(argv[i+1],&geometry_info);
766 if ((flags & SigmaValue) == 0)
767 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000768 if ((flags & XiValue) == 0)
769 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000770 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000771 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000772 break;
773 }
774 if (LocaleCompare("affine",option+1) == 0)
775 {
776 /*
777 Affine matrix.
778 */
779 if (*option == '+')
780 {
781 GetAffineMatrix(&draw_info->affine);
782 break;
783 }
784 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
785 break;
786 }
787 if (LocaleCompare("alpha",option+1) == 0)
788 {
789 AlphaChannelType
790 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000791
cristy6fccee12011-10-20 18:43:18 +0000792 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000793 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
794 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000795 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000796 break;
797 }
798 if (LocaleCompare("annotate",option+1) == 0)
799 {
800 char
801 *text,
802 geometry[MaxTextExtent];
803
804 /*
805 Annotate image.
806 */
cristy6fccee12011-10-20 18:43:18 +0000807 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000808 SetGeometryInfo(&geometry_info);
809 flags=ParseGeometry(argv[i+1],&geometry_info);
810 if ((flags & SigmaValue) == 0)
811 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000812 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
813 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000814 if (text == (char *) NULL)
815 break;
816 (void) CloneString(&draw_info->text,text);
817 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000818 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000819 geometry_info.xi,geometry_info.psi);
820 (void) CloneString(&draw_info->geometry,geometry);
821 draw_info->affine.sx=cos(DegreesToRadians(
822 fmod(geometry_info.rho,360.0)));
823 draw_info->affine.rx=sin(DegreesToRadians(
824 fmod(geometry_info.rho,360.0)));
825 draw_info->affine.ry=(-sin(DegreesToRadians(
826 fmod(geometry_info.sigma,360.0))));
827 draw_info->affine.sy=cos(DegreesToRadians(
828 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000829 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000830 break;
831 }
832 if (LocaleCompare("antialias",option+1) == 0)
833 {
834 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
835 MagickFalse;
836 draw_info->text_antialias=(*option == '-') ? MagickTrue :
837 MagickFalse;
838 break;
839 }
cristy9ed1f812011-10-08 02:00:08 +0000840 if (LocaleCompare("attenuate",option+1) == 0)
841 {
842 if (*option == '+')
843 {
844 attenuate=1.0;
845 break;
846 }
cristydbdd0e32011-11-04 23:29:40 +0000847 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000848 break;
849 }
anthonydf8ebac2011-04-27 09:03:19 +0000850 if (LocaleCompare("auto-gamma",option+1) == 0)
851 {
852 /*
853 Auto Adjust Gamma of image based on its mean
854 */
cristy6fccee12011-10-20 18:43:18 +0000855 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000856 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000857 break;
858 }
859 if (LocaleCompare("auto-level",option+1) == 0)
860 {
861 /*
862 Perfectly Normalize (max/min stretch) the image
863 */
cristy6fccee12011-10-20 18:43:18 +0000864 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000865 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000866 break;
867 }
868 if (LocaleCompare("auto-orient",option+1) == 0)
869 {
cristy6fccee12011-10-20 18:43:18 +0000870 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000871 switch ((*image)->orientation)
872 {
873 case TopRightOrientation:
874 {
875 mogrify_image=FlopImage(*image,exception);
876 break;
877 }
878 case BottomRightOrientation:
879 {
880 mogrify_image=RotateImage(*image,180.0,exception);
881 break;
882 }
883 case BottomLeftOrientation:
884 {
885 mogrify_image=FlipImage(*image,exception);
886 break;
887 }
888 case LeftTopOrientation:
889 {
890 mogrify_image=TransposeImage(*image,exception);
891 break;
892 }
893 case RightTopOrientation:
894 {
895 mogrify_image=RotateImage(*image,90.0,exception);
896 break;
897 }
898 case RightBottomOrientation:
899 {
900 mogrify_image=TransverseImage(*image,exception);
901 break;
902 }
903 case LeftBottomOrientation:
904 {
905 mogrify_image=RotateImage(*image,270.0,exception);
906 break;
907 }
908 default:
909 break;
910 }
911 if (mogrify_image != (Image *) NULL)
912 mogrify_image->orientation=TopLeftOrientation;
913 break;
914 }
915 break;
916 }
917 case 'b':
918 {
919 if (LocaleCompare("black-threshold",option+1) == 0)
920 {
921 /*
922 Black threshold image.
923 */
cristy6fccee12011-10-20 18:43:18 +0000924 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000925 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000926 break;
927 }
928 if (LocaleCompare("blue-shift",option+1) == 0)
929 {
930 /*
931 Blue shift image.
932 */
cristy6fccee12011-10-20 18:43:18 +0000933 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000934 geometry_info.rho=1.5;
935 if (*option == '-')
936 flags=ParseGeometry(argv[i+1],&geometry_info);
937 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
938 break;
939 }
940 if (LocaleCompare("blur",option+1) == 0)
941 {
942 /*
943 Gaussian blur image.
944 */
cristy6fccee12011-10-20 18:43:18 +0000945 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000946 flags=ParseGeometry(argv[i+1],&geometry_info);
947 if ((flags & SigmaValue) == 0)
948 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000949 if ((flags & XiValue) == 0)
950 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000951 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000952 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000953 break;
954 }
955 if (LocaleCompare("border",option+1) == 0)
956 {
957 /*
958 Surround image with a border of solid color.
959 */
cristy6fccee12011-10-20 18:43:18 +0000960 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000961 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
962 if ((flags & SigmaValue) == 0)
963 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000964 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000965 break;
966 }
967 if (LocaleCompare("bordercolor",option+1) == 0)
968 {
969 if (*option == '+')
970 {
cristy9950d572011-10-01 18:22:35 +0000971 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000972 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000973 break;
974 }
cristy9950d572011-10-01 18:22:35 +0000975 (void) QueryColorCompliance(argv[i+1],AllCompliance,
976 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000977 break;
978 }
979 if (LocaleCompare("box",option+1) == 0)
980 {
cristy9950d572011-10-01 18:22:35 +0000981 (void) QueryColorCompliance(argv[i+1],AllCompliance,
982 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000983 break;
984 }
985 if (LocaleCompare("brightness-contrast",option+1) == 0)
986 {
987 double
988 brightness,
989 contrast;
990
991 GeometryInfo
992 geometry_info;
993
994 MagickStatusType
995 flags;
996
997 /*
998 Brightness / contrast image.
999 */
cristy6fccee12011-10-20 18:43:18 +00001000 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001001 flags=ParseGeometry(argv[i+1],&geometry_info);
1002 brightness=geometry_info.rho;
1003 contrast=0.0;
1004 if ((flags & SigmaValue) != 0)
1005 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001006 (void) BrightnessContrastImage(*image,brightness,contrast,
1007 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001008 break;
1009 }
1010 break;
1011 }
1012 case 'c':
1013 {
1014 if (LocaleCompare("cdl",option+1) == 0)
1015 {
1016 char
1017 *color_correction_collection;
1018
1019 /*
1020 Color correct with a color decision list.
1021 */
cristy6fccee12011-10-20 18:43:18 +00001022 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001023 color_correction_collection=FileToString(argv[i+1],~0,exception);
1024 if (color_correction_collection == (char *) NULL)
1025 break;
cristy1bfa9f02011-08-11 02:35:43 +00001026 (void) ColorDecisionListImage(*image,color_correction_collection,
1027 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001028 break;
1029 }
1030 if (LocaleCompare("channel",option+1) == 0)
1031 {
1032 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001033 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001034 else
cristyfa806a72011-07-04 02:06:13 +00001035 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00001036 SetPixelChannelMapMask(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001037 break;
1038 }
1039 if (LocaleCompare("charcoal",option+1) == 0)
1040 {
1041 /*
1042 Charcoal image.
1043 */
cristy6fccee12011-10-20 18:43:18 +00001044 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001045 flags=ParseGeometry(argv[i+1],&geometry_info);
1046 if ((flags & SigmaValue) == 0)
1047 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001048 if ((flags & XiValue) == 0)
1049 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001050 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001051 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001052 break;
1053 }
1054 if (LocaleCompare("chop",option+1) == 0)
1055 {
1056 /*
1057 Chop the image.
1058 */
cristy6fccee12011-10-20 18:43:18 +00001059 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001060 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1061 mogrify_image=ChopImage(*image,&geometry,exception);
1062 break;
1063 }
1064 if (LocaleCompare("clamp",option+1) == 0)
1065 {
1066 /*
1067 Clamp image.
1068 */
cristy6fccee12011-10-20 18:43:18 +00001069 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001070 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001071 break;
1072 }
1073 if (LocaleCompare("clip",option+1) == 0)
1074 {
cristy6fccee12011-10-20 18:43:18 +00001075 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001076 if (*option == '+')
1077 {
cristy018f07f2011-09-04 21:15:19 +00001078 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001079 break;
1080 }
cristy018f07f2011-09-04 21:15:19 +00001081 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001082 break;
1083 }
1084 if (LocaleCompare("clip-mask",option+1) == 0)
1085 {
1086 CacheView
1087 *mask_view;
1088
1089 Image
1090 *mask_image;
1091
cristy4c08aed2011-07-01 19:47:50 +00001092 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001093 *restrict q;
1094
1095 register ssize_t
1096 x;
1097
1098 ssize_t
1099 y;
1100
cristy6fccee12011-10-20 18:43:18 +00001101 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001102 if (*option == '+')
1103 {
1104 /*
1105 Remove a mask.
1106 */
cristy018f07f2011-09-04 21:15:19 +00001107 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001108 break;
1109 }
1110 /*
1111 Set the image mask.
1112 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1113 */
1114 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1115 if (mask_image == (Image *) NULL)
1116 break;
cristy574cc262011-08-05 01:23:58 +00001117 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001118 return(MagickFalse);
1119 mask_view=AcquireCacheView(mask_image);
1120 for (y=0; y < (ssize_t) mask_image->rows; y++)
1121 {
1122 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1123 exception);
cristyacd2ed22011-08-30 01:44:23 +00001124 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001125 break;
1126 for (x=0; x < (ssize_t) mask_image->columns; x++)
1127 {
1128 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001129 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1130 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1131 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1132 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001133 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001134 }
1135 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1136 break;
1137 }
1138 mask_view=DestroyCacheView(mask_view);
1139 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001140 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001141 break;
1142 }
1143 if (LocaleCompare("clip-path",option+1) == 0)
1144 {
cristy6fccee12011-10-20 18:43:18 +00001145 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001146 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001147 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001148 break;
1149 }
1150 if (LocaleCompare("colorize",option+1) == 0)
1151 {
1152 /*
1153 Colorize the image.
1154 */
cristy6fccee12011-10-20 18:43:18 +00001155 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001156 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001157 break;
1158 }
1159 if (LocaleCompare("color-matrix",option+1) == 0)
1160 {
1161 KernelInfo
1162 *kernel;
1163
cristy6fccee12011-10-20 18:43:18 +00001164 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001165 kernel=AcquireKernelInfo(argv[i+1]);
1166 if (kernel == (KernelInfo *) NULL)
1167 break;
1168 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1169 kernel=DestroyKernelInfo(kernel);
1170 break;
1171 }
1172 if (LocaleCompare("colors",option+1) == 0)
1173 {
1174 /*
1175 Reduce the number of colors in the image.
1176 */
cristy6fccee12011-10-20 18:43:18 +00001177 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001178 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1179 if (quantize_info->number_colors == 0)
1180 break;
1181 if (((*image)->storage_class == DirectClass) ||
1182 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001183 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001184 else
cristy018f07f2011-09-04 21:15:19 +00001185 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001186 break;
1187 }
1188 if (LocaleCompare("colorspace",option+1) == 0)
1189 {
1190 ColorspaceType
1191 colorspace;
1192
cristy6fccee12011-10-20 18:43:18 +00001193 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001194 if (*option == '+')
1195 {
cristye941a752011-10-15 01:52:48 +00001196 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001197 break;
1198 }
1199 colorspace=(ColorspaceType) ParseCommandOption(
1200 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001201 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001202 break;
1203 }
cristy633f0c62011-09-15 13:27:36 +00001204 if (LocaleCompare("compose",option+1) == 0)
1205 {
cristy6fccee12011-10-20 18:43:18 +00001206 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001207 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1208 MagickFalse,argv[i+1]);
1209 break;
1210 }
anthonydf8ebac2011-04-27 09:03:19 +00001211 if (LocaleCompare("contrast",option+1) == 0)
1212 {
cristy6fccee12011-10-20 18:43:18 +00001213 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001214 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001215 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001216 break;
1217 }
1218 if (LocaleCompare("contrast-stretch",option+1) == 0)
1219 {
1220 double
1221 black_point,
1222 white_point;
1223
1224 MagickStatusType
1225 flags;
1226
1227 /*
1228 Contrast stretch image.
1229 */
cristy6fccee12011-10-20 18:43:18 +00001230 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001231 flags=ParseGeometry(argv[i+1],&geometry_info);
1232 black_point=geometry_info.rho;
1233 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1234 black_point;
1235 if ((flags & PercentValue) != 0)
1236 {
1237 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1238 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1239 }
1240 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1241 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001242 (void) ContrastStretchImage(*image,black_point,white_point,
1243 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001244 break;
1245 }
1246 if (LocaleCompare("convolve",option+1) == 0)
1247 {
anthonydf8ebac2011-04-27 09:03:19 +00001248 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001249 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001250
cristy6fccee12011-10-20 18:43:18 +00001251 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001252 kernel_info=AcquireKernelInfo(argv[i+1]);
1253 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001254 break;
cristy0a922382011-07-16 15:30:34 +00001255 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001256 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001257 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001258 break;
1259 }
1260 if (LocaleCompare("crop",option+1) == 0)
1261 {
1262 /*
1263 Crop a image to a smaller size
1264 */
cristy6fccee12011-10-20 18:43:18 +00001265 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001266 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001267 break;
1268 }
1269 if (LocaleCompare("cycle",option+1) == 0)
1270 {
1271 /*
1272 Cycle an image colormap.
1273 */
cristy6fccee12011-10-20 18:43:18 +00001274 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001275 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1276 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001277 break;
1278 }
1279 break;
1280 }
1281 case 'd':
1282 {
1283 if (LocaleCompare("decipher",option+1) == 0)
1284 {
1285 StringInfo
1286 *passkey;
1287
1288 /*
1289 Decipher pixels.
1290 */
cristy6fccee12011-10-20 18:43:18 +00001291 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001292 passkey=FileToStringInfo(argv[i+1],~0,exception);
1293 if (passkey != (StringInfo *) NULL)
1294 {
1295 (void) PasskeyDecipherImage(*image,passkey,exception);
1296 passkey=DestroyStringInfo(passkey);
1297 }
1298 break;
1299 }
1300 if (LocaleCompare("density",option+1) == 0)
1301 {
1302 /*
1303 Set image density.
1304 */
1305 (void) CloneString(&draw_info->density,argv[i+1]);
1306 break;
1307 }
1308 if (LocaleCompare("depth",option+1) == 0)
1309 {
cristy6fccee12011-10-20 18:43:18 +00001310 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001311 if (*option == '+')
1312 {
cristy8a11cb12011-10-19 23:53:34 +00001313 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001314 break;
1315 }
cristy8a11cb12011-10-19 23:53:34 +00001316 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1317 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001318 break;
1319 }
1320 if (LocaleCompare("deskew",option+1) == 0)
1321 {
1322 double
1323 threshold;
1324
1325 /*
1326 Straighten the image.
1327 */
cristy6fccee12011-10-20 18:43:18 +00001328 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001329 if (*option == '+')
1330 threshold=40.0*QuantumRange/100.0;
1331 else
cristy9b34e302011-11-05 02:15:45 +00001332 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1333 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001334 mogrify_image=DeskewImage(*image,threshold,exception);
1335 break;
1336 }
1337 if (LocaleCompare("despeckle",option+1) == 0)
1338 {
1339 /*
1340 Reduce the speckles within an image.
1341 */
cristy6fccee12011-10-20 18:43:18 +00001342 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001343 mogrify_image=DespeckleImage(*image,exception);
1344 break;
1345 }
1346 if (LocaleCompare("display",option+1) == 0)
1347 {
1348 (void) CloneString(&draw_info->server_name,argv[i+1]);
1349 break;
1350 }
1351 if (LocaleCompare("distort",option+1) == 0)
1352 {
1353 char
1354 *args,
1355 token[MaxTextExtent];
1356
1357 const char
1358 *p;
1359
1360 DistortImageMethod
1361 method;
1362
1363 double
1364 *arguments;
1365
1366 register ssize_t
1367 x;
1368
1369 size_t
1370 number_arguments;
1371
1372 /*
1373 Distort image.
1374 */
cristy6fccee12011-10-20 18:43:18 +00001375 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001376 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1377 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001378 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001379 {
anthonydf8ebac2011-04-27 09:03:19 +00001380 double
1381 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001382
1383 /*
1384 Special Case - Argument is actually a resize geometry!
1385 Convert that to an appropriate distortion argument array.
1386 */
anthonydf8ebac2011-04-27 09:03:19 +00001387 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001388 exception);
1389 resize_args[0]=(double) geometry.width;
1390 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001391 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001392 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001393 break;
1394 }
cristy018f07f2011-09-04 21:15:19 +00001395 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1396 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001397 if (args == (char *) NULL)
1398 break;
1399 p=(char *) args;
1400 for (x=0; *p != '\0'; x++)
1401 {
1402 GetMagickToken(p,&p,token);
1403 if (*token == ',')
1404 GetMagickToken(p,&p,token);
1405 }
1406 number_arguments=(size_t) x;
1407 arguments=(double *) AcquireQuantumMemory(number_arguments,
1408 sizeof(*arguments));
1409 if (arguments == (double *) NULL)
1410 ThrowWandFatalException(ResourceLimitFatalError,
1411 "MemoryAllocationFailed",(*image)->filename);
1412 (void) ResetMagickMemory(arguments,0,number_arguments*
1413 sizeof(*arguments));
1414 p=(char *) args;
1415 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1416 {
1417 GetMagickToken(p,&p,token);
1418 if (*token == ',')
1419 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001420 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001421 }
1422 args=DestroyString(args);
1423 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1424 (*option == '+') ? MagickTrue : MagickFalse,exception);
1425 arguments=(double *) RelinquishMagickMemory(arguments);
1426 break;
1427 }
1428 if (LocaleCompare("dither",option+1) == 0)
1429 {
1430 if (*option == '+')
1431 {
1432 quantize_info->dither=MagickFalse;
1433 break;
1434 }
1435 quantize_info->dither=MagickTrue;
1436 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1437 MagickDitherOptions,MagickFalse,argv[i+1]);
1438 if (quantize_info->dither_method == NoDitherMethod)
1439 quantize_info->dither=MagickFalse;
1440 break;
1441 }
1442 if (LocaleCompare("draw",option+1) == 0)
1443 {
1444 /*
1445 Draw image.
1446 */
cristy6fccee12011-10-20 18:43:18 +00001447 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001448 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001449 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001450 break;
1451 }
1452 break;
1453 }
1454 case 'e':
1455 {
1456 if (LocaleCompare("edge",option+1) == 0)
1457 {
1458 /*
1459 Enhance edges in the image.
1460 */
cristy6fccee12011-10-20 18:43:18 +00001461 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001462 flags=ParseGeometry(argv[i+1],&geometry_info);
1463 if ((flags & SigmaValue) == 0)
1464 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001465 mogrify_image=EdgeImage(*image,geometry_info.rho,
1466 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001467 break;
1468 }
1469 if (LocaleCompare("emboss",option+1) == 0)
1470 {
1471 /*
1472 Gaussian embossen image.
1473 */
cristy6fccee12011-10-20 18:43:18 +00001474 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001475 flags=ParseGeometry(argv[i+1],&geometry_info);
1476 if ((flags & SigmaValue) == 0)
1477 geometry_info.sigma=1.0;
1478 mogrify_image=EmbossImage(*image,geometry_info.rho,
1479 geometry_info.sigma,exception);
1480 break;
1481 }
1482 if (LocaleCompare("encipher",option+1) == 0)
1483 {
1484 StringInfo
1485 *passkey;
1486
1487 /*
1488 Encipher pixels.
1489 */
cristy6fccee12011-10-20 18:43:18 +00001490 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001491 passkey=FileToStringInfo(argv[i+1],~0,exception);
1492 if (passkey != (StringInfo *) NULL)
1493 {
1494 (void) PasskeyEncipherImage(*image,passkey,exception);
1495 passkey=DestroyStringInfo(passkey);
1496 }
1497 break;
1498 }
1499 if (LocaleCompare("encoding",option+1) == 0)
1500 {
1501 (void) CloneString(&draw_info->encoding,argv[i+1]);
1502 break;
1503 }
1504 if (LocaleCompare("enhance",option+1) == 0)
1505 {
1506 /*
1507 Enhance image.
1508 */
cristy6fccee12011-10-20 18:43:18 +00001509 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001510 mogrify_image=EnhanceImage(*image,exception);
1511 break;
1512 }
1513 if (LocaleCompare("equalize",option+1) == 0)
1514 {
1515 /*
1516 Equalize image.
1517 */
cristy6fccee12011-10-20 18:43:18 +00001518 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001519 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001520 break;
1521 }
1522 if (LocaleCompare("evaluate",option+1) == 0)
1523 {
1524 double
1525 constant;
1526
1527 MagickEvaluateOperator
1528 op;
1529
cristy6fccee12011-10-20 18:43:18 +00001530 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001531 op=(MagickEvaluateOperator) ParseCommandOption(
1532 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001533 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1534 1.0);
cristyd42d9952011-07-08 14:21:50 +00001535 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001536 break;
1537 }
1538 if (LocaleCompare("extent",option+1) == 0)
1539 {
1540 /*
1541 Set the image extent.
1542 */
cristy6fccee12011-10-20 18:43:18 +00001543 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001544 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1545 if (geometry.width == 0)
1546 geometry.width=(*image)->columns;
1547 if (geometry.height == 0)
1548 geometry.height=(*image)->rows;
1549 mogrify_image=ExtentImage(*image,&geometry,exception);
1550 break;
1551 }
1552 break;
1553 }
1554 case 'f':
1555 {
1556 if (LocaleCompare("family",option+1) == 0)
1557 {
1558 if (*option == '+')
1559 {
1560 if (draw_info->family != (char *) NULL)
1561 draw_info->family=DestroyString(draw_info->family);
1562 break;
1563 }
1564 (void) CloneString(&draw_info->family,argv[i+1]);
1565 break;
1566 }
1567 if (LocaleCompare("features",option+1) == 0)
1568 {
1569 if (*option == '+')
1570 {
1571 (void) DeleteImageArtifact(*image,"identify:features");
1572 break;
1573 }
1574 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1575 break;
1576 }
1577 if (LocaleCompare("fill",option+1) == 0)
1578 {
1579 ExceptionInfo
1580 *sans;
1581
cristy4c08aed2011-07-01 19:47:50 +00001582 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001583 if (*option == '+')
1584 {
cristy269c9412011-10-13 23:41:15 +00001585 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001586 exception);
1587 (void) QueryColorCompliance("none",AllCompliance,
1588 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001589 if (draw_info->fill_pattern != (Image *) NULL)
1590 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1591 break;
1592 }
1593 sans=AcquireExceptionInfo();
cristy269c9412011-10-13 23:41:15 +00001594 (void) QueryColorCompliance(argv[i+1],AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001595 sans);
1596 status=QueryColorCompliance(argv[i+1],AllCompliance,
1597 &draw_info->fill,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001598 sans=DestroyExceptionInfo(sans);
1599 if (status == MagickFalse)
1600 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1601 exception);
1602 break;
1603 }
1604 if (LocaleCompare("flip",option+1) == 0)
1605 {
1606 /*
1607 Flip image scanlines.
1608 */
cristy6fccee12011-10-20 18:43:18 +00001609 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001610 mogrify_image=FlipImage(*image,exception);
1611 break;
1612 }
anthonydf8ebac2011-04-27 09:03:19 +00001613 if (LocaleCompare("floodfill",option+1) == 0)
1614 {
cristy4c08aed2011-07-01 19:47:50 +00001615 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001616 target;
1617
1618 /*
1619 Floodfill image.
1620 */
cristy6fccee12011-10-20 18:43:18 +00001621 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001622 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001623 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001624 exception);
cristyd42d9952011-07-08 14:21:50 +00001625 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001626 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001627 break;
1628 }
anthony3d2f4862011-05-01 13:48:16 +00001629 if (LocaleCompare("flop",option+1) == 0)
1630 {
1631 /*
1632 Flop image scanlines.
1633 */
cristy6fccee12011-10-20 18:43:18 +00001634 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001635 mogrify_image=FlopImage(*image,exception);
1636 break;
1637 }
anthonydf8ebac2011-04-27 09:03:19 +00001638 if (LocaleCompare("font",option+1) == 0)
1639 {
1640 if (*option == '+')
1641 {
1642 if (draw_info->font != (char *) NULL)
1643 draw_info->font=DestroyString(draw_info->font);
1644 break;
1645 }
1646 (void) CloneString(&draw_info->font,argv[i+1]);
1647 break;
1648 }
1649 if (LocaleCompare("format",option+1) == 0)
1650 {
1651 format=argv[i+1];
1652 break;
1653 }
1654 if (LocaleCompare("frame",option+1) == 0)
1655 {
1656 FrameInfo
1657 frame_info;
1658
1659 /*
1660 Surround image with an ornamental border.
1661 */
cristy6fccee12011-10-20 18:43:18 +00001662 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001663 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1664 frame_info.width=geometry.width;
1665 frame_info.height=geometry.height;
1666 if ((flags & HeightValue) == 0)
1667 frame_info.height=geometry.width;
1668 frame_info.outer_bevel=geometry.x;
1669 frame_info.inner_bevel=geometry.y;
1670 frame_info.x=(ssize_t) frame_info.width;
1671 frame_info.y=(ssize_t) frame_info.height;
1672 frame_info.width=(*image)->columns+2*frame_info.width;
1673 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001674 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001675 break;
1676 }
1677 if (LocaleCompare("function",option+1) == 0)
1678 {
1679 char
1680 *arguments,
1681 token[MaxTextExtent];
1682
1683 const char
1684 *p;
1685
1686 double
1687 *parameters;
1688
1689 MagickFunction
1690 function;
1691
1692 register ssize_t
1693 x;
1694
1695 size_t
1696 number_parameters;
1697
1698 /*
1699 Function Modify Image Values
1700 */
cristy6fccee12011-10-20 18:43:18 +00001701 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001702 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1703 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001704 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1705 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001706 if (arguments == (char *) NULL)
1707 break;
1708 p=(char *) arguments;
1709 for (x=0; *p != '\0'; x++)
1710 {
1711 GetMagickToken(p,&p,token);
1712 if (*token == ',')
1713 GetMagickToken(p,&p,token);
1714 }
1715 number_parameters=(size_t) x;
1716 parameters=(double *) AcquireQuantumMemory(number_parameters,
1717 sizeof(*parameters));
1718 if (parameters == (double *) NULL)
1719 ThrowWandFatalException(ResourceLimitFatalError,
1720 "MemoryAllocationFailed",(*image)->filename);
1721 (void) ResetMagickMemory(parameters,0,number_parameters*
1722 sizeof(*parameters));
1723 p=(char *) arguments;
1724 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1725 {
1726 GetMagickToken(p,&p,token);
1727 if (*token == ',')
1728 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001729 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001730 }
1731 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001732 (void) FunctionImage(*image,function,number_parameters,parameters,
1733 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001734 parameters=(double *) RelinquishMagickMemory(parameters);
1735 break;
1736 }
1737 break;
1738 }
1739 case 'g':
1740 {
1741 if (LocaleCompare("gamma",option+1) == 0)
1742 {
1743 /*
1744 Gamma image.
1745 */
cristy6fccee12011-10-20 18:43:18 +00001746 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001747 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001748 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001749 else
cristydbdd0e32011-11-04 23:29:40 +00001750 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001751 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001752 break;
1753 }
1754 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1755 (LocaleCompare("gaussian",option+1) == 0))
1756 {
1757 /*
1758 Gaussian blur image.
1759 */
cristy6fccee12011-10-20 18:43:18 +00001760 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001761 flags=ParseGeometry(argv[i+1],&geometry_info);
1762 if ((flags & SigmaValue) == 0)
1763 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001764 if ((flags & XiValue) == 0)
1765 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001766 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001767 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001768 break;
1769 }
1770 if (LocaleCompare("geometry",option+1) == 0)
1771 {
1772 /*
1773 Record Image offset, Resize last image.
1774 */
cristy6fccee12011-10-20 18:43:18 +00001775 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001776 if (*option == '+')
1777 {
1778 if ((*image)->geometry != (char *) NULL)
1779 (*image)->geometry=DestroyString((*image)->geometry);
1780 break;
1781 }
1782 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1783 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1784 (void) CloneString(&(*image)->geometry,argv[i+1]);
1785 else
1786 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1787 (*image)->filter,(*image)->blur,exception);
1788 break;
1789 }
1790 if (LocaleCompare("gravity",option+1) == 0)
1791 {
1792 if (*option == '+')
1793 {
1794 draw_info->gravity=UndefinedGravity;
1795 break;
1796 }
1797 draw_info->gravity=(GravityType) ParseCommandOption(
1798 MagickGravityOptions,MagickFalse,argv[i+1]);
1799 break;
1800 }
1801 break;
1802 }
1803 case 'h':
1804 {
1805 if (LocaleCompare("highlight-color",option+1) == 0)
1806 {
1807 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1808 break;
1809 }
1810 break;
1811 }
1812 case 'i':
1813 {
1814 if (LocaleCompare("identify",option+1) == 0)
1815 {
1816 char
1817 *text;
1818
cristy6fccee12011-10-20 18:43:18 +00001819 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001820 if (format == (char *) NULL)
1821 {
cristya4037272011-08-28 15:11:39 +00001822 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1823 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001824 break;
1825 }
cristy018f07f2011-09-04 21:15:19 +00001826 text=InterpretImageProperties(mogrify_info,*image,format,
1827 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001828 if (text == (char *) NULL)
1829 break;
1830 (void) fputs(text,stdout);
1831 (void) fputc('\n',stdout);
1832 text=DestroyString(text);
1833 break;
1834 }
1835 if (LocaleCompare("implode",option+1) == 0)
1836 {
1837 /*
1838 Implode image.
1839 */
cristy6fccee12011-10-20 18:43:18 +00001840 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001841 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001842 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1843 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001844 break;
1845 }
1846 if (LocaleCompare("interline-spacing",option+1) == 0)
1847 {
1848 if (*option == '+')
1849 (void) ParseGeometry("0",&geometry_info);
1850 else
1851 (void) ParseGeometry(argv[i+1],&geometry_info);
1852 draw_info->interline_spacing=geometry_info.rho;
1853 break;
1854 }
cristy28474bf2011-09-11 23:32:52 +00001855 if (LocaleCompare("interpolate",option+1) == 0)
1856 {
1857 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1858 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1859 break;
1860 }
anthonydf8ebac2011-04-27 09:03:19 +00001861 if (LocaleCompare("interword-spacing",option+1) == 0)
1862 {
1863 if (*option == '+')
1864 (void) ParseGeometry("0",&geometry_info);
1865 else
1866 (void) ParseGeometry(argv[i+1],&geometry_info);
1867 draw_info->interword_spacing=geometry_info.rho;
1868 break;
1869 }
1870 break;
1871 }
1872 case 'k':
1873 {
1874 if (LocaleCompare("kerning",option+1) == 0)
1875 {
1876 if (*option == '+')
1877 (void) ParseGeometry("0",&geometry_info);
1878 else
1879 (void) ParseGeometry(argv[i+1],&geometry_info);
1880 draw_info->kerning=geometry_info.rho;
1881 break;
1882 }
1883 break;
1884 }
1885 case 'l':
1886 {
1887 if (LocaleCompare("lat",option+1) == 0)
1888 {
1889 /*
1890 Local adaptive threshold image.
1891 */
cristy6fccee12011-10-20 18:43:18 +00001892 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001893 flags=ParseGeometry(argv[i+1],&geometry_info);
1894 if ((flags & PercentValue) != 0)
1895 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1896 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001897 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001898 geometry_info.xi,exception);
1899 break;
1900 }
1901 if (LocaleCompare("level",option+1) == 0)
1902 {
1903 MagickRealType
1904 black_point,
1905 gamma,
1906 white_point;
1907
1908 MagickStatusType
1909 flags;
1910
1911 /*
1912 Parse levels.
1913 */
cristy6fccee12011-10-20 18:43:18 +00001914 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001915 flags=ParseGeometry(argv[i+1],&geometry_info);
1916 black_point=geometry_info.rho;
1917 white_point=(MagickRealType) QuantumRange;
1918 if ((flags & SigmaValue) != 0)
1919 white_point=geometry_info.sigma;
1920 gamma=1.0;
1921 if ((flags & XiValue) != 0)
1922 gamma=geometry_info.xi;
1923 if ((flags & PercentValue) != 0)
1924 {
1925 black_point*=(MagickRealType) (QuantumRange/100.0);
1926 white_point*=(MagickRealType) (QuantumRange/100.0);
1927 }
1928 if ((flags & SigmaValue) == 0)
1929 white_point=(MagickRealType) QuantumRange-black_point;
1930 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001931 (void) LevelizeImage(*image,black_point,white_point,gamma,
1932 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001933 else
cristy01e9afd2011-08-10 17:38:41 +00001934 (void) LevelImage(*image,black_point,white_point,gamma,
1935 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001936 break;
1937 }
1938 if (LocaleCompare("level-colors",option+1) == 0)
1939 {
1940 char
1941 token[MaxTextExtent];
1942
1943 const char
1944 *p;
1945
cristy4c08aed2011-07-01 19:47:50 +00001946 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001947 black_point,
1948 white_point;
1949
1950 p=(const char *) argv[i+1];
1951 GetMagickToken(p,&p,token); /* get black point color */
1952 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001953 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001954 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001955 else
cristy269c9412011-10-13 23:41:15 +00001956 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001957 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001958 if (isalpha((int) token[0]) || (token[0] == '#'))
1959 GetMagickToken(p,&p,token);
1960 if (*token == '\0')
1961 white_point=black_point; /* set everything to that color */
1962 else
1963 {
1964 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1965 GetMagickToken(p,&p,token); /* Get white point color. */
1966 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001967 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001968 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001969 else
cristy269c9412011-10-13 23:41:15 +00001970 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001971 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001972 }
cristy490408a2011-07-07 14:42:05 +00001973 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001974 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001975 break;
1976 }
1977 if (LocaleCompare("linear-stretch",option+1) == 0)
1978 {
1979 double
1980 black_point,
1981 white_point;
1982
1983 MagickStatusType
1984 flags;
1985
cristy6fccee12011-10-20 18:43:18 +00001986 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001987 flags=ParseGeometry(argv[i+1],&geometry_info);
1988 black_point=geometry_info.rho;
1989 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1990 if ((flags & SigmaValue) != 0)
1991 white_point=geometry_info.sigma;
1992 if ((flags & PercentValue) != 0)
1993 {
1994 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1995 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1996 }
1997 if ((flags & SigmaValue) == 0)
1998 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1999 black_point;
cristy33bd5152011-08-24 01:42:24 +00002000 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002001 break;
2002 }
2003 if (LocaleCompare("linewidth",option+1) == 0)
2004 {
cristy9b34e302011-11-05 02:15:45 +00002005 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002006 break;
2007 }
2008 if (LocaleCompare("liquid-rescale",option+1) == 0)
2009 {
2010 /*
2011 Liquid rescale image.
2012 */
cristy6fccee12011-10-20 18:43:18 +00002013 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002014 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2015 if ((flags & XValue) == 0)
2016 geometry.x=1;
2017 if ((flags & YValue) == 0)
2018 geometry.y=0;
2019 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2020 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2021 break;
2022 }
2023 if (LocaleCompare("lowlight-color",option+1) == 0)
2024 {
2025 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2026 break;
2027 }
2028 break;
2029 }
2030 case 'm':
2031 {
2032 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002033 {
cristy3ed852e2009-09-05 21:47:34 +00002034 Image
anthonydf8ebac2011-04-27 09:03:19 +00002035 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002036
anthonydf8ebac2011-04-27 09:03:19 +00002037 /*
2038 Transform image colors to match this set of colors.
2039 */
cristy6fccee12011-10-20 18:43:18 +00002040 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002041 if (*option == '+')
2042 break;
2043 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2044 if (remap_image == (Image *) NULL)
2045 break;
cristy018f07f2011-09-04 21:15:19 +00002046 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002047 remap_image=DestroyImage(remap_image);
2048 break;
2049 }
2050 if (LocaleCompare("mask",option+1) == 0)
2051 {
2052 Image
2053 *mask;
2054
cristy6fccee12011-10-20 18:43:18 +00002055 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002056 if (*option == '+')
2057 {
2058 /*
2059 Remove a mask.
2060 */
cristy018f07f2011-09-04 21:15:19 +00002061 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002062 break;
2063 }
2064 /*
2065 Set the image mask.
2066 */
2067 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2068 if (mask == (Image *) NULL)
2069 break;
cristy018f07f2011-09-04 21:15:19 +00002070 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002071 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002072 break;
2073 }
2074 if (LocaleCompare("matte",option+1) == 0)
2075 {
2076 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002077 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002078 break;
2079 }
2080 if (LocaleCompare("median",option+1) == 0)
2081 {
2082 /*
2083 Median filter image.
2084 */
cristy6fccee12011-10-20 18:43:18 +00002085 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002086 flags=ParseGeometry(argv[i+1],&geometry_info);
2087 if ((flags & SigmaValue) == 0)
2088 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002089 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002090 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002091 break;
2092 }
2093 if (LocaleCompare("mode",option+1) == 0)
2094 {
2095 /*
2096 Mode image.
2097 */
cristy6fccee12011-10-20 18:43:18 +00002098 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002099 flags=ParseGeometry(argv[i+1],&geometry_info);
2100 if ((flags & SigmaValue) == 0)
2101 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002102 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002103 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002104 break;
2105 }
2106 if (LocaleCompare("modulate",option+1) == 0)
2107 {
cristy6fccee12011-10-20 18:43:18 +00002108 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002109 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002110 break;
2111 }
2112 if (LocaleCompare("monitor",option+1) == 0)
2113 {
2114 if (*option == '+')
2115 {
2116 (void) SetImageProgressMonitor(*image,
2117 (MagickProgressMonitor) NULL,(void *) NULL);
2118 break;
2119 }
2120 (void) SetImageProgressMonitor(*image,MonitorProgress,
2121 (void *) NULL);
2122 break;
2123 }
2124 if (LocaleCompare("monochrome",option+1) == 0)
2125 {
cristy6fccee12011-10-20 18:43:18 +00002126 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002127 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002128 break;
2129 }
2130 if (LocaleCompare("morphology",option+1) == 0)
2131 {
2132 char
2133 token[MaxTextExtent];
2134
2135 const char
2136 *p;
2137
2138 KernelInfo
2139 *kernel;
2140
2141 MorphologyMethod
2142 method;
2143
2144 ssize_t
2145 iterations;
2146
2147 /*
2148 Morphological Image Operation
2149 */
cristy6fccee12011-10-20 18:43:18 +00002150 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002151 p=argv[i+1];
2152 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002153 method=(MorphologyMethod) ParseCommandOption(
2154 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002155 iterations=1L;
2156 GetMagickToken(p,&p,token);
2157 if ((*p == ':') || (*p == ','))
2158 GetMagickToken(p,&p,token);
2159 if ((*p != '\0'))
2160 iterations=(ssize_t) StringToLong(p);
2161 kernel=AcquireKernelInfo(argv[i+2]);
2162 if (kernel == (KernelInfo *) NULL)
2163 {
2164 (void) ThrowMagickException(exception,GetMagickModule(),
2165 OptionError,"UnabletoParseKernel","morphology");
2166 status=MagickFalse;
2167 break;
2168 }
cristyf4ad9df2011-07-08 16:49:03 +00002169 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2170 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002171 kernel=DestroyKernelInfo(kernel);
2172 break;
2173 }
2174 if (LocaleCompare("motion-blur",option+1) == 0)
2175 {
2176 /*
2177 Motion blur image.
2178 */
cristy6fccee12011-10-20 18:43:18 +00002179 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002180 flags=ParseGeometry(argv[i+1],&geometry_info);
2181 if ((flags & SigmaValue) == 0)
2182 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002183 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002184 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002185 break;
2186 }
2187 break;
2188 }
2189 case 'n':
2190 {
2191 if (LocaleCompare("negate",option+1) == 0)
2192 {
cristy6fccee12011-10-20 18:43:18 +00002193 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002194 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002195 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002196 break;
2197 }
2198 if (LocaleCompare("noise",option+1) == 0)
2199 {
cristy6fccee12011-10-20 18:43:18 +00002200 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002201 if (*option == '-')
2202 {
cristyf36cbcb2011-09-07 13:28:22 +00002203 flags=ParseGeometry(argv[i+1],&geometry_info);
2204 if ((flags & SigmaValue) == 0)
2205 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002206 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002207 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002208 }
2209 else
2210 {
2211 NoiseType
2212 noise;
2213
2214 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2215 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002216 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002217 }
2218 break;
2219 }
2220 if (LocaleCompare("normalize",option+1) == 0)
2221 {
cristy6fccee12011-10-20 18:43:18 +00002222 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002223 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002224 break;
2225 }
2226 break;
2227 }
2228 case 'o':
2229 {
2230 if (LocaleCompare("opaque",option+1) == 0)
2231 {
cristy4c08aed2011-07-01 19:47:50 +00002232 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002233 target;
2234
cristy6fccee12011-10-20 18:43:18 +00002235 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002236 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002237 exception);
cristyd42d9952011-07-08 14:21:50 +00002238 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002239 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002240 break;
2241 }
2242 if (LocaleCompare("ordered-dither",option+1) == 0)
2243 {
cristy6fccee12011-10-20 18:43:18 +00002244 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002245 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002246 break;
2247 }
2248 break;
2249 }
2250 case 'p':
2251 {
2252 if (LocaleCompare("paint",option+1) == 0)
2253 {
cristy6fccee12011-10-20 18:43:18 +00002254 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002255 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002256 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2257 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002258 break;
2259 }
2260 if (LocaleCompare("pen",option+1) == 0)
2261 {
2262 if (*option == '+')
2263 {
cristy9950d572011-10-01 18:22:35 +00002264 (void) QueryColorCompliance("none",AllCompliance,
2265 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002266 break;
2267 }
cristy9950d572011-10-01 18:22:35 +00002268 (void) QueryColorCompliance(argv[i+1],AllCompliance,
2269 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002270 break;
2271 }
2272 if (LocaleCompare("pointsize",option+1) == 0)
2273 {
2274 if (*option == '+')
2275 (void) ParseGeometry("12",&geometry_info);
2276 else
2277 (void) ParseGeometry(argv[i+1],&geometry_info);
2278 draw_info->pointsize=geometry_info.rho;
2279 break;
2280 }
2281 if (LocaleCompare("polaroid",option+1) == 0)
2282 {
2283 double
2284 angle;
2285
2286 RandomInfo
2287 *random_info;
2288
2289 /*
2290 Simulate a Polaroid picture.
2291 */
cristy6fccee12011-10-20 18:43:18 +00002292 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002293 random_info=AcquireRandomInfo();
2294 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2295 random_info=DestroyRandomInfo(random_info);
2296 if (*option == '-')
2297 {
2298 SetGeometryInfo(&geometry_info);
2299 flags=ParseGeometry(argv[i+1],&geometry_info);
2300 angle=geometry_info.rho;
2301 }
cristy5c4e2582011-09-11 19:21:03 +00002302 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002303 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002304 break;
2305 }
2306 if (LocaleCompare("posterize",option+1) == 0)
2307 {
2308 /*
2309 Posterize image.
2310 */
cristy6fccee12011-10-20 18:43:18 +00002311 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002312 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002313 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002314 break;
2315 }
2316 if (LocaleCompare("preview",option+1) == 0)
2317 {
2318 PreviewType
2319 preview_type;
2320
2321 /*
2322 Preview image.
2323 */
cristy6fccee12011-10-20 18:43:18 +00002324 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002325 if (*option == '+')
2326 preview_type=UndefinedPreview;
2327 else
cristy28474bf2011-09-11 23:32:52 +00002328 preview_type=(PreviewType) ParseCommandOption(
2329 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002330 mogrify_image=PreviewImage(*image,preview_type,exception);
2331 break;
2332 }
2333 if (LocaleCompare("profile",option+1) == 0)
2334 {
2335 const char
2336 *name;
2337
2338 const StringInfo
2339 *profile;
2340
2341 Image
2342 *profile_image;
2343
2344 ImageInfo
2345 *profile_info;
2346
cristy6fccee12011-10-20 18:43:18 +00002347 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002348 if (*option == '+')
2349 {
2350 /*
2351 Remove a profile from the image.
2352 */
2353 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002354 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002355 break;
2356 }
2357 /*
2358 Associate a profile with the image.
2359 */
2360 profile_info=CloneImageInfo(mogrify_info);
2361 profile=GetImageProfile(*image,"iptc");
2362 if (profile != (StringInfo *) NULL)
2363 profile_info->profile=(void *) CloneStringInfo(profile);
2364 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2365 profile_info=DestroyImageInfo(profile_info);
2366 if (profile_image == (Image *) NULL)
2367 {
2368 StringInfo
2369 *profile;
2370
2371 profile_info=CloneImageInfo(mogrify_info);
2372 (void) CopyMagickString(profile_info->filename,argv[i+1],
2373 MaxTextExtent);
2374 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2375 if (profile != (StringInfo *) NULL)
2376 {
2377 (void) ProfileImage(*image,profile_info->magick,
2378 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002379 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002380 profile=DestroyStringInfo(profile);
2381 }
2382 profile_info=DestroyImageInfo(profile_info);
2383 break;
2384 }
2385 ResetImageProfileIterator(profile_image);
2386 name=GetNextImageProfile(profile_image);
2387 while (name != (const char *) NULL)
2388 {
2389 profile=GetImageProfile(profile_image,name);
2390 if (profile != (StringInfo *) NULL)
2391 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002392 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002393 name=GetNextImageProfile(profile_image);
2394 }
2395 profile_image=DestroyImage(profile_image);
2396 break;
2397 }
2398 break;
2399 }
2400 case 'q':
2401 {
2402 if (LocaleCompare("quantize",option+1) == 0)
2403 {
2404 if (*option == '+')
2405 {
2406 quantize_info->colorspace=UndefinedColorspace;
2407 break;
2408 }
2409 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2410 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2411 break;
2412 }
2413 break;
2414 }
2415 case 'r':
2416 {
2417 if (LocaleCompare("radial-blur",option+1) == 0)
2418 {
2419 /*
2420 Radial blur image.
2421 */
cristy6fccee12011-10-20 18:43:18 +00002422 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002423 flags=ParseGeometry(argv[i+1],&geometry_info);
2424 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2425 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002426 break;
2427 }
2428 if (LocaleCompare("raise",option+1) == 0)
2429 {
2430 /*
2431 Surround image with a raise of solid color.
2432 */
2433 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2434 if ((flags & SigmaValue) == 0)
2435 geometry.height=geometry.width;
2436 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002437 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002438 break;
2439 }
2440 if (LocaleCompare("random-threshold",option+1) == 0)
2441 {
2442 /*
2443 Threshold image.
2444 */
cristy6fccee12011-10-20 18:43:18 +00002445 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002446 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002447 break;
2448 }
2449 if (LocaleCompare("recolor",option+1) == 0)
2450 {
2451 KernelInfo
2452 *kernel;
2453
cristy6fccee12011-10-20 18:43:18 +00002454 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002455 kernel=AcquireKernelInfo(argv[i+1]);
2456 if (kernel == (KernelInfo *) NULL)
2457 break;
2458 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2459 kernel=DestroyKernelInfo(kernel);
2460 break;
2461 }
2462 if (LocaleCompare("region",option+1) == 0)
2463 {
cristy6fccee12011-10-20 18:43:18 +00002464 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002465 if (region_image != (Image *) NULL)
2466 {
2467 /*
2468 Composite region.
2469 */
2470 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002471 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002472 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002473 *image=DestroyImage(*image);
2474 *image=region_image;
2475 region_image = (Image *) NULL;
2476 }
2477 if (*option == '+')
2478 break;
2479 /*
2480 Apply transformations to a selected region of the image.
2481 */
cristy3ed852e2009-09-05 21:47:34 +00002482 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2483 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002484 mogrify_image=CropImage(*image,&region_geometry,exception);
2485 if (mogrify_image == (Image *) NULL)
2486 break;
2487 region_image=(*image);
2488 *image=mogrify_image;
2489 mogrify_image=(Image *) NULL;
2490 break;
cristy3ed852e2009-09-05 21:47:34 +00002491 }
anthonydf8ebac2011-04-27 09:03:19 +00002492 if (LocaleCompare("render",option+1) == 0)
2493 {
cristy6fccee12011-10-20 18:43:18 +00002494 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002495 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2496 break;
2497 }
2498 if (LocaleCompare("remap",option+1) == 0)
2499 {
2500 Image
2501 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002502
anthonydf8ebac2011-04-27 09:03:19 +00002503 /*
2504 Transform image colors to match this set of colors.
2505 */
cristy6fccee12011-10-20 18:43:18 +00002506 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002507 if (*option == '+')
2508 break;
2509 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2510 if (remap_image == (Image *) NULL)
2511 break;
cristy018f07f2011-09-04 21:15:19 +00002512 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002513 remap_image=DestroyImage(remap_image);
2514 break;
2515 }
2516 if (LocaleCompare("repage",option+1) == 0)
2517 {
2518 if (*option == '+')
2519 {
2520 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2521 break;
2522 }
2523 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002524 break;
2525 }
2526 if (LocaleCompare("resample",option+1) == 0)
2527 {
2528 /*
2529 Resample image.
2530 */
cristy6fccee12011-10-20 18:43:18 +00002531 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002532 flags=ParseGeometry(argv[i+1],&geometry_info);
2533 if ((flags & SigmaValue) == 0)
2534 geometry_info.sigma=geometry_info.rho;
2535 mogrify_image=ResampleImage(*image,geometry_info.rho,
2536 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2537 break;
2538 }
2539 if (LocaleCompare("resize",option+1) == 0)
2540 {
2541 /*
2542 Resize image.
2543 */
cristy6fccee12011-10-20 18:43:18 +00002544 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002545 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2546 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2547 (*image)->filter,(*image)->blur,exception);
2548 break;
2549 }
2550 if (LocaleCompare("roll",option+1) == 0)
2551 {
2552 /*
2553 Roll image.
2554 */
cristy6fccee12011-10-20 18:43:18 +00002555 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002556 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2557 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2558 break;
2559 }
2560 if (LocaleCompare("rotate",option+1) == 0)
2561 {
2562 char
2563 *geometry;
2564
2565 /*
2566 Check for conditional image rotation.
2567 */
cristy6fccee12011-10-20 18:43:18 +00002568 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002569 if (strchr(argv[i+1],'>') != (char *) NULL)
2570 if ((*image)->columns <= (*image)->rows)
2571 break;
2572 if (strchr(argv[i+1],'<') != (char *) NULL)
2573 if ((*image)->columns >= (*image)->rows)
2574 break;
2575 /*
2576 Rotate image.
2577 */
2578 geometry=ConstantString(argv[i+1]);
2579 (void) SubstituteString(&geometry,">","");
2580 (void) SubstituteString(&geometry,"<","");
2581 (void) ParseGeometry(geometry,&geometry_info);
2582 geometry=DestroyString(geometry);
2583 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2584 break;
2585 }
2586 break;
2587 }
2588 case 's':
2589 {
2590 if (LocaleCompare("sample",option+1) == 0)
2591 {
2592 /*
2593 Sample image with pixel replication.
2594 */
cristy6fccee12011-10-20 18:43:18 +00002595 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002596 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2597 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2598 exception);
2599 break;
2600 }
2601 if (LocaleCompare("scale",option+1) == 0)
2602 {
2603 /*
2604 Resize image.
2605 */
cristy6fccee12011-10-20 18:43:18 +00002606 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002607 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2608 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2609 exception);
2610 break;
2611 }
2612 if (LocaleCompare("selective-blur",option+1) == 0)
2613 {
2614 /*
2615 Selectively blur pixels within a contrast threshold.
2616 */
cristy6fccee12011-10-20 18:43:18 +00002617 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002618 flags=ParseGeometry(argv[i+1],&geometry_info);
2619 if ((flags & PercentValue) != 0)
2620 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002621 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002622 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002623 break;
2624 }
2625 if (LocaleCompare("separate",option+1) == 0)
2626 {
2627 /*
2628 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002629 */
cristy6fccee12011-10-20 18:43:18 +00002630 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002631 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002632 break;
2633 }
2634 if (LocaleCompare("sepia-tone",option+1) == 0)
2635 {
2636 double
2637 threshold;
2638
2639 /*
2640 Sepia-tone image.
2641 */
cristy6fccee12011-10-20 18:43:18 +00002642 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002643 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2644 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002645 mogrify_image=SepiaToneImage(*image,threshold,exception);
2646 break;
2647 }
2648 if (LocaleCompare("segment",option+1) == 0)
2649 {
2650 /*
2651 Segment image.
2652 */
cristy6fccee12011-10-20 18:43:18 +00002653 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002654 flags=ParseGeometry(argv[i+1],&geometry_info);
2655 if ((flags & SigmaValue) == 0)
2656 geometry_info.sigma=1.0;
2657 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002658 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2659 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002660 break;
2661 }
2662 if (LocaleCompare("set",option+1) == 0)
2663 {
2664 char
2665 *value;
2666
2667 /*
2668 Set image option.
2669 */
2670 if (*option == '+')
2671 {
2672 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2673 (void) DeleteImageRegistry(argv[i+1]+9);
2674 else
2675 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2676 {
2677 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2678 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2679 }
2680 else
2681 (void) DeleteImageProperty(*image,argv[i+1]);
2682 break;
2683 }
cristy018f07f2011-09-04 21:15:19 +00002684 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2685 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002686 if (value == (char *) NULL)
2687 break;
2688 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2689 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2690 exception);
2691 else
2692 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2693 {
2694 (void) SetImageOption(image_info,argv[i+1]+7,value);
2695 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2696 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2697 }
2698 else
cristyd15e6592011-10-15 00:13:06 +00002699 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002700 value=DestroyString(value);
2701 break;
2702 }
2703 if (LocaleCompare("shade",option+1) == 0)
2704 {
2705 /*
2706 Shade image.
2707 */
cristy6fccee12011-10-20 18:43:18 +00002708 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002709 flags=ParseGeometry(argv[i+1],&geometry_info);
2710 if ((flags & SigmaValue) == 0)
2711 geometry_info.sigma=1.0;
2712 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2713 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2714 break;
2715 }
2716 if (LocaleCompare("shadow",option+1) == 0)
2717 {
2718 /*
2719 Shadow image.
2720 */
cristy6fccee12011-10-20 18:43:18 +00002721 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002722 flags=ParseGeometry(argv[i+1],&geometry_info);
2723 if ((flags & SigmaValue) == 0)
2724 geometry_info.sigma=1.0;
2725 if ((flags & XiValue) == 0)
2726 geometry_info.xi=4.0;
2727 if ((flags & PsiValue) == 0)
2728 geometry_info.psi=4.0;
2729 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002730 geometry_info.sigma,(*image)->bias,(ssize_t)
2731 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2732 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002733 break;
2734 }
2735 if (LocaleCompare("sharpen",option+1) == 0)
2736 {
2737 /*
2738 Sharpen image.
2739 */
cristy6fccee12011-10-20 18:43:18 +00002740 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002741 flags=ParseGeometry(argv[i+1],&geometry_info);
2742 if ((flags & SigmaValue) == 0)
2743 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002744 if ((flags & XiValue) == 0)
2745 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002746 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002747 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002748 break;
2749 }
2750 if (LocaleCompare("shave",option+1) == 0)
2751 {
2752 /*
2753 Shave the image edges.
2754 */
cristy6fccee12011-10-20 18:43:18 +00002755 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002756 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2757 mogrify_image=ShaveImage(*image,&geometry,exception);
2758 break;
2759 }
2760 if (LocaleCompare("shear",option+1) == 0)
2761 {
2762 /*
2763 Shear image.
2764 */
cristy6fccee12011-10-20 18:43:18 +00002765 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002766 flags=ParseGeometry(argv[i+1],&geometry_info);
2767 if ((flags & SigmaValue) == 0)
2768 geometry_info.sigma=geometry_info.rho;
2769 mogrify_image=ShearImage(*image,geometry_info.rho,
2770 geometry_info.sigma,exception);
2771 break;
2772 }
2773 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2774 {
2775 /*
2776 Sigmoidal non-linearity contrast control.
2777 */
cristy6fccee12011-10-20 18:43:18 +00002778 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002779 flags=ParseGeometry(argv[i+1],&geometry_info);
2780 if ((flags & SigmaValue) == 0)
2781 geometry_info.sigma=(double) QuantumRange/2.0;
2782 if ((flags & PercentValue) != 0)
2783 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2784 100.0;
cristy9ee60942011-07-06 14:54:38 +00002785 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002786 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2787 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002788 break;
2789 }
2790 if (LocaleCompare("sketch",option+1) == 0)
2791 {
2792 /*
2793 Sketch image.
2794 */
cristy6fccee12011-10-20 18:43:18 +00002795 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002796 flags=ParseGeometry(argv[i+1],&geometry_info);
2797 if ((flags & SigmaValue) == 0)
2798 geometry_info.sigma=1.0;
2799 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002800 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002801 break;
2802 }
2803 if (LocaleCompare("solarize",option+1) == 0)
2804 {
2805 double
2806 threshold;
2807
cristy6fccee12011-10-20 18:43:18 +00002808 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002809 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2810 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002811 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002812 break;
2813 }
2814 if (LocaleCompare("sparse-color",option+1) == 0)
2815 {
2816 SparseColorMethod
2817 method;
2818
2819 char
2820 *arguments;
2821
2822 /*
2823 Sparse Color Interpolated Gradient
2824 */
cristy6fccee12011-10-20 18:43:18 +00002825 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002826 method=(SparseColorMethod) ParseCommandOption(
2827 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002828 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2829 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002830 if (arguments == (char *) NULL)
2831 break;
cristy3884f692011-07-08 18:00:18 +00002832 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002833 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2834 arguments=DestroyString(arguments);
2835 break;
2836 }
2837 if (LocaleCompare("splice",option+1) == 0)
2838 {
2839 /*
2840 Splice a solid color into the image.
2841 */
cristy6fccee12011-10-20 18:43:18 +00002842 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002843 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2844 mogrify_image=SpliceImage(*image,&geometry,exception);
2845 break;
2846 }
2847 if (LocaleCompare("spread",option+1) == 0)
2848 {
2849 /*
2850 Spread an image.
2851 */
cristy6fccee12011-10-20 18:43:18 +00002852 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002853 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002854 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002855 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002856 break;
2857 }
2858 if (LocaleCompare("statistic",option+1) == 0)
2859 {
2860 StatisticType
2861 type;
2862
cristy6fccee12011-10-20 18:43:18 +00002863 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002864 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2865 MagickFalse,argv[i+1]);
2866 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002867 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2868 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002869 break;
2870 }
2871 if (LocaleCompare("stretch",option+1) == 0)
2872 {
2873 if (*option == '+')
2874 {
2875 draw_info->stretch=UndefinedStretch;
2876 break;
2877 }
2878 draw_info->stretch=(StretchType) ParseCommandOption(
2879 MagickStretchOptions,MagickFalse,argv[i+1]);
2880 break;
2881 }
2882 if (LocaleCompare("strip",option+1) == 0)
2883 {
2884 /*
2885 Strip image of profiles and comments.
2886 */
cristy6fccee12011-10-20 18:43:18 +00002887 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002888 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002889 break;
2890 }
2891 if (LocaleCompare("stroke",option+1) == 0)
2892 {
2893 ExceptionInfo
2894 *sans;
2895
2896 if (*option == '+')
2897 {
cristy9950d572011-10-01 18:22:35 +00002898 (void) QueryColorCompliance("none",AllCompliance,
2899 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002900 if (draw_info->stroke_pattern != (Image *) NULL)
2901 draw_info->stroke_pattern=DestroyImage(
2902 draw_info->stroke_pattern);
2903 break;
2904 }
2905 sans=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00002906 status=QueryColorCompliance(argv[i+1],AllCompliance,
2907 &draw_info->stroke,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002908 sans=DestroyExceptionInfo(sans);
2909 if (status == MagickFalse)
2910 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2911 exception);
2912 break;
2913 }
2914 if (LocaleCompare("strokewidth",option+1) == 0)
2915 {
cristy9b34e302011-11-05 02:15:45 +00002916 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002917 break;
2918 }
2919 if (LocaleCompare("style",option+1) == 0)
2920 {
2921 if (*option == '+')
2922 {
2923 draw_info->style=UndefinedStyle;
2924 break;
2925 }
2926 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2927 MagickFalse,argv[i+1]);
2928 break;
2929 }
2930 if (LocaleCompare("swirl",option+1) == 0)
2931 {
2932 /*
2933 Swirl image.
2934 */
cristy6fccee12011-10-20 18:43:18 +00002935 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002936 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002937 mogrify_image=SwirlImage(*image,geometry_info.rho,
2938 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002939 break;
2940 }
2941 break;
2942 }
2943 case 't':
2944 {
2945 if (LocaleCompare("threshold",option+1) == 0)
2946 {
2947 double
2948 threshold;
2949
2950 /*
2951 Threshold image.
2952 */
cristy6fccee12011-10-20 18:43:18 +00002953 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002954 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002955 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002956 else
cristy9b34e302011-11-05 02:15:45 +00002957 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2958 1.0);
cristye941a752011-10-15 01:52:48 +00002959 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002960 break;
2961 }
2962 if (LocaleCompare("thumbnail",option+1) == 0)
2963 {
2964 /*
2965 Thumbnail image.
2966 */
cristy6fccee12011-10-20 18:43:18 +00002967 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002968 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2969 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2970 exception);
2971 break;
2972 }
2973 if (LocaleCompare("tile",option+1) == 0)
2974 {
2975 if (*option == '+')
2976 {
2977 if (draw_info->fill_pattern != (Image *) NULL)
2978 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2979 break;
2980 }
2981 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2982 exception);
2983 break;
2984 }
2985 if (LocaleCompare("tint",option+1) == 0)
2986 {
2987 /*
2988 Tint the image.
2989 */
cristy6fccee12011-10-20 18:43:18 +00002990 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002991 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002992 break;
2993 }
2994 if (LocaleCompare("transform",option+1) == 0)
2995 {
2996 /*
2997 Affine transform image.
2998 */
cristy6fccee12011-10-20 18:43:18 +00002999 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003000 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3001 exception);
3002 break;
3003 }
3004 if (LocaleCompare("transparent",option+1) == 0)
3005 {
cristy4c08aed2011-07-01 19:47:50 +00003006 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00003007 target;
3008
cristy6fccee12011-10-20 18:43:18 +00003009 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003010 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003011 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003012 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003013 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003014 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003015 break;
3016 }
3017 if (LocaleCompare("transpose",option+1) == 0)
3018 {
3019 /*
3020 Transpose image scanlines.
3021 */
cristy6fccee12011-10-20 18:43:18 +00003022 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003023 mogrify_image=TransposeImage(*image,exception);
3024 break;
3025 }
3026 if (LocaleCompare("transverse",option+1) == 0)
3027 {
3028 /*
3029 Transverse image scanlines.
3030 */
cristy6fccee12011-10-20 18:43:18 +00003031 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003032 mogrify_image=TransverseImage(*image,exception);
3033 break;
3034 }
3035 if (LocaleCompare("treedepth",option+1) == 0)
3036 {
3037 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3038 break;
3039 }
3040 if (LocaleCompare("trim",option+1) == 0)
3041 {
3042 /*
3043 Trim image.
3044 */
cristy6fccee12011-10-20 18:43:18 +00003045 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003046 mogrify_image=TrimImage(*image,exception);
3047 break;
3048 }
3049 if (LocaleCompare("type",option+1) == 0)
3050 {
3051 ImageType
3052 type;
3053
cristy6fccee12011-10-20 18:43:18 +00003054 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003055 if (*option == '+')
3056 type=UndefinedType;
3057 else
3058 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3059 argv[i+1]);
3060 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003061 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003062 break;
3063 }
3064 break;
3065 }
3066 case 'u':
3067 {
3068 if (LocaleCompare("undercolor",option+1) == 0)
3069 {
cristy9950d572011-10-01 18:22:35 +00003070 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3071 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003072 break;
3073 }
3074 if (LocaleCompare("unique",option+1) == 0)
3075 {
3076 if (*option == '+')
3077 {
3078 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3079 break;
3080 }
3081 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3082 (void) SetImageArtifact(*image,"verbose","true");
3083 break;
3084 }
3085 if (LocaleCompare("unique-colors",option+1) == 0)
3086 {
3087 /*
3088 Unique image colors.
3089 */
cristy6fccee12011-10-20 18:43:18 +00003090 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003091 mogrify_image=UniqueImageColors(*image,exception);
3092 break;
3093 }
3094 if (LocaleCompare("unsharp",option+1) == 0)
3095 {
3096 /*
3097 Unsharp mask image.
3098 */
cristy6fccee12011-10-20 18:43:18 +00003099 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003100 flags=ParseGeometry(argv[i+1],&geometry_info);
3101 if ((flags & SigmaValue) == 0)
3102 geometry_info.sigma=1.0;
3103 if ((flags & XiValue) == 0)
3104 geometry_info.xi=1.0;
3105 if ((flags & PsiValue) == 0)
3106 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003107 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3108 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003109 break;
3110 }
3111 break;
3112 }
3113 case 'v':
3114 {
3115 if (LocaleCompare("verbose",option+1) == 0)
3116 {
3117 (void) SetImageArtifact(*image,option+1,
3118 *option == '+' ? "false" : "true");
3119 break;
3120 }
3121 if (LocaleCompare("vignette",option+1) == 0)
3122 {
3123 /*
3124 Vignette image.
3125 */
cristy6fccee12011-10-20 18:43:18 +00003126 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003127 flags=ParseGeometry(argv[i+1],&geometry_info);
3128 if ((flags & SigmaValue) == 0)
3129 geometry_info.sigma=1.0;
3130 if ((flags & XiValue) == 0)
3131 geometry_info.xi=0.1*(*image)->columns;
3132 if ((flags & PsiValue) == 0)
3133 geometry_info.psi=0.1*(*image)->rows;
3134 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003135 geometry_info.sigma,(*image)->bias,(ssize_t)
3136 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3137 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003138 break;
3139 }
3140 if (LocaleCompare("virtual-pixel",option+1) == 0)
3141 {
3142 if (*option == '+')
3143 {
3144 (void) SetImageVirtualPixelMethod(*image,
3145 UndefinedVirtualPixelMethod);
3146 break;
3147 }
3148 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3149 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3150 argv[i+1]));
3151 break;
3152 }
3153 break;
3154 }
3155 case 'w':
3156 {
3157 if (LocaleCompare("wave",option+1) == 0)
3158 {
3159 /*
3160 Wave image.
3161 */
cristy6fccee12011-10-20 18:43:18 +00003162 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003163 flags=ParseGeometry(argv[i+1],&geometry_info);
3164 if ((flags & SigmaValue) == 0)
3165 geometry_info.sigma=1.0;
3166 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003167 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003168 break;
3169 }
3170 if (LocaleCompare("weight",option+1) == 0)
3171 {
3172 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3173 if (LocaleCompare(argv[i+1],"all") == 0)
3174 draw_info->weight=0;
3175 if (LocaleCompare(argv[i+1],"bold") == 0)
3176 draw_info->weight=700;
3177 if (LocaleCompare(argv[i+1],"bolder") == 0)
3178 if (draw_info->weight <= 800)
3179 draw_info->weight+=100;
3180 if (LocaleCompare(argv[i+1],"lighter") == 0)
3181 if (draw_info->weight >= 100)
3182 draw_info->weight-=100;
3183 if (LocaleCompare(argv[i+1],"normal") == 0)
3184 draw_info->weight=400;
3185 break;
3186 }
3187 if (LocaleCompare("white-threshold",option+1) == 0)
3188 {
3189 /*
3190 White threshold image.
3191 */
cristy6fccee12011-10-20 18:43:18 +00003192 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003193 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003194 break;
3195 }
3196 break;
3197 }
3198 default:
3199 break;
3200 }
3201 /*
3202 Replace current image with any image that was generated
3203 */
3204 if (mogrify_image != (Image *) NULL)
3205 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003206 i+=count;
3207 }
3208 if (region_image != (Image *) NULL)
3209 {
anthonydf8ebac2011-04-27 09:03:19 +00003210 /*
3211 Composite transformed region onto image.
3212 */
cristy6fccee12011-10-20 18:43:18 +00003213 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003214 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003215 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003216 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003217 *image=DestroyImage(*image);
3218 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003219 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003220 }
3221 /*
3222 Free resources.
3223 */
anthonydf8ebac2011-04-27 09:03:19 +00003224 quantize_info=DestroyQuantizeInfo(quantize_info);
3225 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003226 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003227 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003228 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003229}
3230
3231/*
3232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3233% %
3234% %
3235% %
cristy5063d812010-10-19 16:28:10 +00003236+ 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 +00003237% %
3238% %
3239% %
3240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3241%
3242% MogrifyImageCommand() transforms an image or a sequence of images. These
3243% transforms include image scaling, image rotation, color reduction, and
3244% others. The transmogrified image overwrites the original image.
3245%
3246% The format of the MogrifyImageCommand method is:
3247%
3248% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3249% const char **argv,char **metadata,ExceptionInfo *exception)
3250%
3251% A description of each parameter follows:
3252%
3253% o image_info: the image info.
3254%
3255% o argc: the number of elements in the argument vector.
3256%
3257% o argv: A text array containing the command line arguments.
3258%
3259% o metadata: any metadata is returned here.
3260%
3261% o exception: return any errors or warnings in this structure.
3262%
3263*/
3264
3265static MagickBooleanType MogrifyUsage(void)
3266{
3267 static const char
3268 *miscellaneous[]=
3269 {
3270 "-debug events display copious debugging information",
3271 "-help print program options",
3272 "-list type print a list of supported option arguments",
3273 "-log format format of debugging information",
3274 "-version print version information",
3275 (char *) NULL
3276 },
3277 *operators[]=
3278 {
3279 "-adaptive-blur geometry",
3280 " adaptively blur pixels; decrease effect near edges",
3281 "-adaptive-resize geometry",
3282 " adaptively resize image using 'mesh' interpolation",
3283 "-adaptive-sharpen geometry",
3284 " adaptively sharpen pixels; increase effect near edges",
3285 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3286 " transparent, extract, background, or shape",
3287 "-annotate geometry text",
3288 " annotate the image with text",
3289 "-auto-gamma automagically adjust gamma level of image",
3290 "-auto-level automagically adjust color levels of image",
3291 "-auto-orient automagically orient (rotate) image",
3292 "-bench iterations measure performance",
3293 "-black-threshold value",
3294 " force all pixels below the threshold into black",
3295 "-blue-shift simulate a scene at nighttime in the moonlight",
3296 "-blur geometry reduce image noise and reduce detail levels",
3297 "-border geometry surround image with a border of color",
3298 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003299 "-brightness-contrast geometry",
3300 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003301 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003302 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003303 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003304 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003305 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003307 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003308 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003309 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003310 "-contrast enhance or reduce the image contrast",
3311 "-contrast-stretch geometry",
3312 " improve contrast by `stretching' the intensity range",
3313 "-convolve coefficients",
3314 " apply a convolution kernel to the image",
3315 "-cycle amount cycle the image colormap",
3316 "-decipher filename convert cipher pixels to plain pixels",
3317 "-deskew threshold straighten an image",
3318 "-despeckle reduce the speckles within an image",
3319 "-distort method args",
3320 " distort images according to given method ad args",
3321 "-draw string annotate the image with a graphic primitive",
3322 "-edge radius apply a filter to detect edges in the image",
3323 "-encipher filename convert plain pixels to cipher pixels",
3324 "-emboss radius emboss an image",
3325 "-enhance apply a digital filter to enhance a noisy image",
3326 "-equalize perform histogram equalization to an image",
3327 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003328 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003329 "-extent geometry set the image size",
3330 "-extract geometry extract area from image",
3331 "-fft implements the discrete Fourier transform (DFT)",
3332 "-flip flip image vertically",
3333 "-floodfill geometry color",
3334 " floodfill the image with color",
3335 "-flop flop image horizontally",
3336 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003337 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003338 " apply function over image values",
3339 "-gamma value level of gamma correction",
3340 "-gaussian-blur geometry",
3341 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003342 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-identify identify the format and characteristics of the image",
3344 "-ift implements the inverse discrete Fourier transform (DFT)",
3345 "-implode amount implode image pixels about the center",
3346 "-lat geometry local adaptive thresholding",
3347 "-layers method optimize, merge, or compare image layers",
3348 "-level value adjust the level of image contrast",
3349 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003350 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003351 "-linear-stretch geometry",
3352 " improve contrast by `stretching with saturation'",
3353 "-liquid-rescale geometry",
3354 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003355 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003356 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-modulate value vary the brightness, saturation, and hue",
3358 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003359 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003360 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003361 "-motion-blur geometry",
3362 " simulate motion blur",
3363 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003364 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-normalize transform image to span the full range of colors",
3366 "-opaque color change this color to the fill color",
3367 "-ordered-dither NxN",
3368 " add a noise pattern to the image with specific",
3369 " amplitudes",
3370 "-paint radius simulate an oil painting",
3371 "-polaroid angle simulate a Polaroid picture",
3372 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003373 "-profile filename add, delete, or apply an image profile",
3374 "-quantize colorspace reduce colors in this colorspace",
3375 "-radial-blur angle radial blur the image",
3376 "-raise value lighten/darken image edges to create a 3-D effect",
3377 "-random-threshold low,high",
3378 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003379 "-region geometry apply options to a portion of the image",
3380 "-render render vector graphics",
3381 "-repage geometry size and location of an image canvas",
3382 "-resample geometry change the resolution of an image",
3383 "-resize geometry resize the image",
3384 "-roll geometry roll an image vertically or horizontally",
3385 "-rotate degrees apply Paeth rotation to the image",
3386 "-sample geometry scale image with pixel sampling",
3387 "-scale geometry scale the image",
3388 "-segment values segment an image",
3389 "-selective-blur geometry",
3390 " selectively blur pixels within a contrast threshold",
3391 "-sepia-tone threshold",
3392 " simulate a sepia-toned photo",
3393 "-set property value set an image property",
3394 "-shade degrees shade the image using a distant light source",
3395 "-shadow geometry simulate an image shadow",
3396 "-sharpen geometry sharpen the image",
3397 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003398 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003399 "-sigmoidal-contrast geometry",
3400 " increase the contrast without saturating highlights or shadows",
3401 "-sketch geometry simulate a pencil sketch",
3402 "-solarize threshold negate all pixels above the threshold level",
3403 "-sparse-color method args",
3404 " fill in a image based on a few color points",
3405 "-splice geometry splice the background color into the image",
3406 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003407 "-statistic type radius",
3408 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003409 "-strip strip image of all profiles and comments",
3410 "-swirl degrees swirl image pixels about the center",
3411 "-threshold value threshold the image",
3412 "-thumbnail geometry create a thumbnail of the image",
3413 "-tile filename tile image when filling a graphic primitive",
3414 "-tint value tint the image with the fill color",
3415 "-transform affine transform image",
3416 "-transparent color make this color transparent within the image",
3417 "-transpose flip image vertically and rotate 90 degrees",
3418 "-transverse flop image horizontally and rotate 270 degrees",
3419 "-trim trim image edges",
3420 "-type type image type",
3421 "-unique-colors discard all but one of any pixel color",
3422 "-unsharp geometry sharpen the image",
3423 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003424 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003425 "-white-threshold value",
3426 " force all pixels above the threshold into white",
3427 (char *) NULL
3428 },
3429 *sequence_operators[]=
3430 {
cristy4285d782011-02-09 20:12:28 +00003431 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003432 "-clut apply a color lookup table to the image",
3433 "-coalesce merge a sequence of images",
3434 "-combine combine a sequence of images",
3435 "-composite composite image",
3436 "-crop geometry cut out a rectangular region of the image",
3437 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003438 "-evaluate-sequence operator",
3439 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003440 "-flatten flatten a sequence of images",
3441 "-fx expression apply mathematical expression to an image channel(s)",
3442 "-hald-clut apply a Hald color lookup table to the image",
3443 "-morph value morph an image sequence",
3444 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003445 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003446 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003447 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003448 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003449 "-write filename write images to this file",
3450 (char *) NULL
3451 },
3452 *settings[]=
3453 {
3454 "-adjoin join images into a single multi-image file",
3455 "-affine matrix affine transform matrix",
3456 "-alpha option activate, deactivate, reset, or set the alpha channel",
3457 "-antialias remove pixel-aliasing",
3458 "-authenticate password",
3459 " decipher image with this password",
3460 "-attenuate value lessen (or intensify) when adding noise to an image",
3461 "-background color background color",
3462 "-bias value add bias when convolving an image",
3463 "-black-point-compensation",
3464 " use black point compensation",
3465 "-blue-primary point chromaticity blue primary point",
3466 "-bordercolor color border color",
3467 "-caption string assign a caption to an image",
3468 "-channel type apply option to select image channels",
3469 "-colors value preferred number of colors in the image",
3470 "-colorspace type alternate image colorspace",
3471 "-comment string annotate image with comment",
3472 "-compose operator set image composite operator",
3473 "-compress type type of pixel compression when writing the image",
3474 "-define format:option",
3475 " define one or more image format options",
3476 "-delay value display the next image after pausing",
3477 "-density geometry horizontal and vertical density of the image",
3478 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003479 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003480 "-display server get image or font from this X server",
3481 "-dispose method layer disposal method",
3482 "-dither method apply error diffusion to image",
3483 "-encoding type text encoding type",
3484 "-endian type endianness (MSB or LSB) of the image",
3485 "-family name render text with this font family",
3486 "-fill color color to use when filling a graphic primitive",
3487 "-filter type use this filter when resizing an image",
3488 "-font name render text with this font",
3489 "-format \"string\" output formatted image characteristics",
3490 "-fuzz distance colors within this distance are considered equal",
3491 "-gravity type horizontal and vertical text placement",
3492 "-green-primary point chromaticity green primary point",
3493 "-intent type type of rendering intent when managing the image color",
3494 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003495 "-interline-spacing value",
3496 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003497 "-interpolate method pixel color interpolation method",
3498 "-interword-spacing value",
3499 " set the space between two words",
3500 "-kerning value set the space between two letters",
3501 "-label string assign a label to an image",
3502 "-limit type value pixel cache resource limit",
3503 "-loop iterations add Netscape loop extension to your GIF animation",
3504 "-mask filename associate a mask with the image",
3505 "-mattecolor color frame color",
3506 "-monitor monitor progress",
3507 "-orient type image orientation",
3508 "-page geometry size and location of an image canvas (setting)",
3509 "-ping efficiently determine image attributes",
3510 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003511 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003512 "-preview type image preview type",
3513 "-quality value JPEG/MIFF/PNG compression level",
3514 "-quiet suppress all warning messages",
3515 "-red-primary point chromaticity red primary point",
3516 "-regard-warnings pay attention to warning messages",
3517 "-remap filename transform image colors to match this set of colors",
3518 "-respect-parentheses settings remain in effect until parenthesis boundary",
3519 "-sampling-factor geometry",
3520 " horizontal and vertical sampling factor",
3521 "-scene value image scene number",
3522 "-seed value seed a new sequence of pseudo-random numbers",
3523 "-size geometry width and height of image",
3524 "-stretch type render text with this font stretch",
3525 "-stroke color graphic primitive stroke color",
3526 "-strokewidth value graphic primitive stroke width",
3527 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003528 "-synchronize synchronize image to storage device",
3529 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003530 "-texture filename name of texture to tile onto the image background",
3531 "-tile-offset geometry",
3532 " tile offset",
3533 "-treedepth value color tree depth",
3534 "-transparent-color color",
3535 " transparent color",
3536 "-undercolor color annotation bounding box color",
3537 "-units type the units of image resolution",
3538 "-verbose print detailed information about the image",
3539 "-view FlashPix viewing transforms",
3540 "-virtual-pixel method",
3541 " virtual pixel access method",
3542 "-weight type render text with this font weight",
3543 "-white-point point chromaticity white point",
3544 (char *) NULL
3545 },
3546 *stack_operators[]=
3547 {
anthonyb69c4b32011-03-23 04:37:44 +00003548 "-delete indexes delete the image from the image sequence",
3549 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003550 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003551 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003552 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003553 "-swap indexes swap two images in the image sequence",
3554 (char *) NULL
3555 };
3556
3557 const char
3558 **p;
3559
cristybb503372010-05-27 20:51:26 +00003560 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003561 (void) printf("Copyright: %s\n",GetMagickCopyright());
3562 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003563 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3564 GetClientName());
3565 (void) printf("\nImage Settings:\n");
3566 for (p=settings; *p != (char *) NULL; p++)
3567 (void) printf(" %s\n",*p);
3568 (void) printf("\nImage Operators:\n");
3569 for (p=operators; *p != (char *) NULL; p++)
3570 (void) printf(" %s\n",*p);
3571 (void) printf("\nImage Sequence Operators:\n");
3572 for (p=sequence_operators; *p != (char *) NULL; p++)
3573 (void) printf(" %s\n",*p);
3574 (void) printf("\nImage Stack Operators:\n");
3575 for (p=stack_operators; *p != (char *) NULL; p++)
3576 (void) printf(" %s\n",*p);
3577 (void) printf("\nMiscellaneous Options:\n");
3578 for (p=miscellaneous; *p != (char *) NULL; p++)
3579 (void) printf(" %s\n",*p);
3580 (void) printf(
3581 "\nBy default, the image format of `file' is determined by its magic\n");
3582 (void) printf(
3583 "number. To specify a particular image format, precede the filename\n");
3584 (void) printf(
3585 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3586 (void) printf(
3587 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3588 (void) printf("'-' for standard input or output.\n");
3589 return(MagickFalse);
3590}
3591
3592WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3593 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3594{
3595#define DestroyMogrify() \
3596{ \
3597 if (format != (char *) NULL) \
3598 format=DestroyString(format); \
3599 if (path != (char *) NULL) \
3600 path=DestroyString(path); \
3601 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003602 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003603 argv[i]=DestroyString(argv[i]); \
3604 argv=(char **) RelinquishMagickMemory(argv); \
3605}
3606#define ThrowMogrifyException(asperity,tag,option) \
3607{ \
3608 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3609 option); \
3610 DestroyMogrify(); \
3611 return(MagickFalse); \
3612}
3613#define ThrowMogrifyInvalidArgumentException(option,argument) \
3614{ \
3615 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3616 "InvalidArgument","`%s': %s",argument,option); \
3617 DestroyMogrify(); \
3618 return(MagickFalse); \
3619}
3620
3621 char
3622 *format,
3623 *option,
3624 *path;
3625
3626 Image
3627 *image;
3628
3629 ImageStack
3630 image_stack[MaxImageStackDepth+1];
3631
cristy3ed852e2009-09-05 21:47:34 +00003632 MagickBooleanType
3633 global_colormap;
3634
3635 MagickBooleanType
3636 fire,
cristyebbcfea2011-02-25 02:43:54 +00003637 pend,
3638 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003639
3640 MagickStatusType
3641 status;
3642
cristyebbcfea2011-02-25 02:43:54 +00003643 register ssize_t
3644 i;
3645
3646 ssize_t
3647 j,
3648 k;
3649
cristy3ed852e2009-09-05 21:47:34 +00003650 /*
3651 Set defaults.
3652 */
3653 assert(image_info != (ImageInfo *) NULL);
3654 assert(image_info->signature == MagickSignature);
3655 if (image_info->debug != MagickFalse)
3656 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3657 assert(exception != (ExceptionInfo *) NULL);
3658 if (argc == 2)
3659 {
3660 option=argv[1];
3661 if ((LocaleCompare("version",option+1) == 0) ||
3662 (LocaleCompare("-version",option+1) == 0))
3663 {
cristyb51dff52011-05-19 16:55:47 +00003664 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003665 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003666 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3667 GetMagickCopyright());
3668 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3669 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003670 return(MagickFalse);
3671 }
3672 }
3673 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003674 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003675 format=(char *) NULL;
3676 path=(char *) NULL;
3677 global_colormap=MagickFalse;
3678 k=0;
3679 j=1;
3680 NewImageStack();
3681 option=(char *) NULL;
3682 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003683 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003684 status=MagickTrue;
3685 /*
3686 Parse command line.
3687 */
3688 ReadCommandlLine(argc,&argv);
3689 status=ExpandFilenames(&argc,&argv);
3690 if (status == MagickFalse)
3691 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3692 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003693 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003694 {
3695 option=argv[i];
3696 if (LocaleCompare(option,"(") == 0)
3697 {
3698 FireImageStack(MagickFalse,MagickTrue,pend);
3699 if (k == MaxImageStackDepth)
3700 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3701 option);
3702 PushImageStack();
3703 continue;
3704 }
3705 if (LocaleCompare(option,")") == 0)
3706 {
3707 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3708 if (k == 0)
3709 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3710 PopImageStack();
3711 continue;
3712 }
cristy042ee782011-04-22 18:48:30 +00003713 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003714 {
3715 char
3716 backup_filename[MaxTextExtent],
3717 *filename;
3718
3719 Image
3720 *images;
3721
3722 /*
3723 Option is a file name: begin by reading image from specified file.
3724 */
3725 FireImageStack(MagickFalse,MagickFalse,pend);
3726 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003727 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003728 filename=argv[++i];
3729 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3730 images=ReadImages(image_info,exception);
3731 status&=(images != (Image *) NULL) &&
3732 (exception->severity < ErrorException);
3733 if (images == (Image *) NULL)
3734 continue;
cristydaa76602010-06-30 13:05:11 +00003735 if (format != (char *) NULL)
3736 (void) CopyMagickString(images->filename,images->magick_filename,
3737 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003738 if (path != (char *) NULL)
3739 {
3740 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003741 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003742 path,*DirectorySeparator,filename);
3743 }
3744 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003745 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003746 AppendImageStack(images);
3747 FinalizeImageSettings(image_info,image,MagickFalse);
3748 if (global_colormap != MagickFalse)
3749 {
3750 QuantizeInfo
3751 *quantize_info;
3752
3753 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003754 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003755 quantize_info=DestroyQuantizeInfo(quantize_info);
3756 }
3757 *backup_filename='\0';
3758 if ((LocaleCompare(image->filename,"-") != 0) &&
3759 (IsPathWritable(image->filename) != MagickFalse))
3760 {
cristybb503372010-05-27 20:51:26 +00003761 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003762 i;
3763
3764 /*
3765 Rename image file as backup.
3766 */
3767 (void) CopyMagickString(backup_filename,image->filename,
3768 MaxTextExtent);
3769 for (i=0; i < 6; i++)
3770 {
3771 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3772 if (IsPathAccessible(backup_filename) == MagickFalse)
3773 break;
3774 }
3775 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003776 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003777 *backup_filename='\0';
3778 }
3779 /*
3780 Write transmogrified image to disk.
3781 */
3782 image_info->synchronize=MagickTrue;
3783 status&=WriteImages(image_info,image,image->filename,exception);
3784 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003785 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003786 RemoveAllImageStack();
3787 continue;
3788 }
3789 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3790 switch (*(option+1))
3791 {
3792 case 'a':
3793 {
3794 if (LocaleCompare("adaptive-blur",option+1) == 0)
3795 {
3796 i++;
cristybb503372010-05-27 20:51:26 +00003797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003798 ThrowMogrifyException(OptionError,"MissingArgument",option);
3799 if (IsGeometry(argv[i]) == MagickFalse)
3800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3801 break;
3802 }
3803 if (LocaleCompare("adaptive-resize",option+1) == 0)
3804 {
3805 i++;
cristybb503372010-05-27 20:51:26 +00003806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003807 ThrowMogrifyException(OptionError,"MissingArgument",option);
3808 if (IsGeometry(argv[i]) == MagickFalse)
3809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3810 break;
3811 }
3812 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3813 {
3814 i++;
cristybb503372010-05-27 20:51:26 +00003815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003816 ThrowMogrifyException(OptionError,"MissingArgument",option);
3817 if (IsGeometry(argv[i]) == MagickFalse)
3818 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3819 break;
3820 }
3821 if (LocaleCompare("affine",option+1) == 0)
3822 {
3823 if (*option == '+')
3824 break;
3825 i++;
cristybb503372010-05-27 20:51:26 +00003826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003827 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003828 break;
3829 }
3830 if (LocaleCompare("alpha",option+1) == 0)
3831 {
cristybb503372010-05-27 20:51:26 +00003832 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003833 type;
3834
3835 if (*option == '+')
3836 break;
3837 i++;
cristybb503372010-05-27 20:51:26 +00003838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003839 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003840 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003841 if (type < 0)
3842 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3843 argv[i]);
3844 break;
3845 }
3846 if (LocaleCompare("annotate",option+1) == 0)
3847 {
3848 if (*option == '+')
3849 break;
3850 i++;
cristybb503372010-05-27 20:51:26 +00003851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003852 ThrowMogrifyException(OptionError,"MissingArgument",option);
3853 if (IsGeometry(argv[i]) == MagickFalse)
3854 ThrowMogrifyInvalidArgumentException(option,argv[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 i++;
3858 break;
3859 }
3860 if (LocaleCompare("antialias",option+1) == 0)
3861 break;
3862 if (LocaleCompare("append",option+1) == 0)
3863 break;
3864 if (LocaleCompare("attenuate",option+1) == 0)
3865 {
3866 if (*option == '+')
3867 break;
3868 i++;
cristybb503372010-05-27 20:51:26 +00003869 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003870 ThrowMogrifyException(OptionError,"MissingArgument",option);
3871 if (IsGeometry(argv[i]) == MagickFalse)
3872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3873 break;
3874 }
3875 if (LocaleCompare("authenticate",option+1) == 0)
3876 {
3877 if (*option == '+')
3878 break;
3879 i++;
cristybb503372010-05-27 20:51:26 +00003880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003881 ThrowMogrifyException(OptionError,"MissingArgument",option);
3882 break;
3883 }
3884 if (LocaleCompare("auto-gamma",option+1) == 0)
3885 break;
3886 if (LocaleCompare("auto-level",option+1) == 0)
3887 break;
3888 if (LocaleCompare("auto-orient",option+1) == 0)
3889 break;
3890 if (LocaleCompare("average",option+1) == 0)
3891 break;
3892 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3893 }
3894 case 'b':
3895 {
3896 if (LocaleCompare("background",option+1) == 0)
3897 {
3898 if (*option == '+')
3899 break;
3900 i++;
cristybb503372010-05-27 20:51:26 +00003901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003902 ThrowMogrifyException(OptionError,"MissingArgument",option);
3903 break;
3904 }
3905 if (LocaleCompare("bias",option+1) == 0)
3906 {
3907 if (*option == '+')
3908 break;
3909 i++;
cristybb503372010-05-27 20:51:26 +00003910 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003911 ThrowMogrifyException(OptionError,"MissingArgument",option);
3912 if (IsGeometry(argv[i]) == MagickFalse)
3913 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3914 break;
3915 }
3916 if (LocaleCompare("black-point-compensation",option+1) == 0)
3917 break;
3918 if (LocaleCompare("black-threshold",option+1) == 0)
3919 {
3920 if (*option == '+')
3921 break;
3922 i++;
cristybb503372010-05-27 20:51:26 +00003923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003924 ThrowMogrifyException(OptionError,"MissingArgument",option);
3925 if (IsGeometry(argv[i]) == MagickFalse)
3926 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3927 break;
3928 }
3929 if (LocaleCompare("blue-primary",option+1) == 0)
3930 {
3931 if (*option == '+')
3932 break;
3933 i++;
cristybb503372010-05-27 20:51:26 +00003934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003935 ThrowMogrifyException(OptionError,"MissingArgument",option);
3936 if (IsGeometry(argv[i]) == MagickFalse)
3937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3938 break;
3939 }
3940 if (LocaleCompare("blue-shift",option+1) == 0)
3941 {
3942 i++;
cristybb503372010-05-27 20:51:26 +00003943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003944 ThrowMogrifyException(OptionError,"MissingArgument",option);
3945 if (IsGeometry(argv[i]) == MagickFalse)
3946 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3947 break;
3948 }
3949 if (LocaleCompare("blur",option+1) == 0)
3950 {
3951 i++;
cristybb503372010-05-27 20:51:26 +00003952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003953 ThrowMogrifyException(OptionError,"MissingArgument",option);
3954 if (IsGeometry(argv[i]) == MagickFalse)
3955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3956 break;
3957 }
3958 if (LocaleCompare("border",option+1) == 0)
3959 {
3960 if (*option == '+')
3961 break;
3962 i++;
cristybb503372010-05-27 20:51:26 +00003963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003964 ThrowMogrifyException(OptionError,"MissingArgument",option);
3965 if (IsGeometry(argv[i]) == MagickFalse)
3966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3967 break;
3968 }
3969 if (LocaleCompare("bordercolor",option+1) == 0)
3970 {
3971 if (*option == '+')
3972 break;
3973 i++;
cristybb503372010-05-27 20:51:26 +00003974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003975 ThrowMogrifyException(OptionError,"MissingArgument",option);
3976 break;
3977 }
3978 if (LocaleCompare("box",option+1) == 0)
3979 {
3980 if (*option == '+')
3981 break;
3982 i++;
cristybb503372010-05-27 20:51:26 +00003983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003984 ThrowMogrifyException(OptionError,"MissingArgument",option);
3985 break;
3986 }
cristya28d6b82010-01-11 20:03:47 +00003987 if (LocaleCompare("brightness-contrast",option+1) == 0)
3988 {
3989 i++;
cristybb503372010-05-27 20:51:26 +00003990 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003991 ThrowMogrifyException(OptionError,"MissingArgument",option);
3992 if (IsGeometry(argv[i]) == MagickFalse)
3993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3994 break;
3995 }
cristy3ed852e2009-09-05 21:47:34 +00003996 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3997 }
3998 case 'c':
3999 {
4000 if (LocaleCompare("cache",option+1) == 0)
4001 {
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 if (IsGeometry(argv[i]) == MagickFalse)
4008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4009 break;
4010 }
4011 if (LocaleCompare("caption",option+1) == 0)
4012 {
4013 if (*option == '+')
4014 break;
4015 i++;
cristybb503372010-05-27 20:51:26 +00004016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004017 ThrowMogrifyException(OptionError,"MissingArgument",option);
4018 break;
4019 }
4020 if (LocaleCompare("channel",option+1) == 0)
4021 {
cristybb503372010-05-27 20:51:26 +00004022 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004023 channel;
4024
4025 if (*option == '+')
4026 break;
4027 i++;
cristybb503372010-05-27 20:51:26 +00004028 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004029 ThrowMogrifyException(OptionError,"MissingArgument",option);
4030 channel=ParseChannelOption(argv[i]);
4031 if (channel < 0)
4032 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4033 argv[i]);
4034 break;
4035 }
4036 if (LocaleCompare("cdl",option+1) == 0)
4037 {
4038 if (*option == '+')
4039 break;
4040 i++;
cristybb503372010-05-27 20:51:26 +00004041 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004042 ThrowMogrifyException(OptionError,"MissingArgument",option);
4043 break;
4044 }
4045 if (LocaleCompare("charcoal",option+1) == 0)
4046 {
4047 if (*option == '+')
4048 break;
4049 i++;
cristybb503372010-05-27 20:51:26 +00004050 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004051 ThrowMogrifyException(OptionError,"MissingArgument",option);
4052 if (IsGeometry(argv[i]) == MagickFalse)
4053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4054 break;
4055 }
4056 if (LocaleCompare("chop",option+1) == 0)
4057 {
4058 if (*option == '+')
4059 break;
4060 i++;
cristybb503372010-05-27 20:51:26 +00004061 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004062 ThrowMogrifyException(OptionError,"MissingArgument",option);
4063 if (IsGeometry(argv[i]) == MagickFalse)
4064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4065 break;
4066 }
cristy1eb45dd2009-09-25 16:38:06 +00004067 if (LocaleCompare("clamp",option+1) == 0)
4068 break;
4069 if (LocaleCompare("clip",option+1) == 0)
4070 break;
cristy3ed852e2009-09-05 21:47:34 +00004071 if (LocaleCompare("clip-mask",option+1) == 0)
4072 {
4073 if (*option == '+')
4074 break;
4075 i++;
cristybb503372010-05-27 20:51:26 +00004076 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004077 ThrowMogrifyException(OptionError,"MissingArgument",option);
4078 break;
4079 }
4080 if (LocaleCompare("clut",option+1) == 0)
4081 break;
4082 if (LocaleCompare("coalesce",option+1) == 0)
4083 break;
4084 if (LocaleCompare("colorize",option+1) == 0)
4085 {
4086 if (*option == '+')
4087 break;
4088 i++;
cristybb503372010-05-27 20:51:26 +00004089 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004090 ThrowMogrifyException(OptionError,"MissingArgument",option);
4091 if (IsGeometry(argv[i]) == MagickFalse)
4092 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4093 break;
4094 }
cristye6365592010-04-02 17:31:23 +00004095 if (LocaleCompare("color-matrix",option+1) == 0)
4096 {
cristyb6bd4ad2010-08-08 01:12:27 +00004097 KernelInfo
4098 *kernel_info;
4099
cristye6365592010-04-02 17:31:23 +00004100 if (*option == '+')
4101 break;
4102 i++;
cristybb503372010-05-27 20:51:26 +00004103 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004104 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004105 kernel_info=AcquireKernelInfo(argv[i]);
4106 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004107 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004108 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004109 break;
4110 }
cristy3ed852e2009-09-05 21:47:34 +00004111 if (LocaleCompare("colors",option+1) == 0)
4112 {
4113 if (*option == '+')
4114 break;
4115 i++;
cristybb503372010-05-27 20:51:26 +00004116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004117 ThrowMogrifyException(OptionError,"MissingArgument",option);
4118 if (IsGeometry(argv[i]) == MagickFalse)
4119 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4120 break;
4121 }
4122 if (LocaleCompare("colorspace",option+1) == 0)
4123 {
cristybb503372010-05-27 20:51:26 +00004124 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004125 colorspace;
4126
4127 if (*option == '+')
4128 break;
4129 i++;
cristybb503372010-05-27 20:51:26 +00004130 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004131 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004132 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004133 argv[i]);
4134 if (colorspace < 0)
4135 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4136 argv[i]);
4137 break;
4138 }
4139 if (LocaleCompare("combine",option+1) == 0)
4140 break;
4141 if (LocaleCompare("comment",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 break;
4149 }
4150 if (LocaleCompare("composite",option+1) == 0)
4151 break;
4152 if (LocaleCompare("compress",option+1) == 0)
4153 {
cristybb503372010-05-27 20:51:26 +00004154 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004155 compress;
4156
4157 if (*option == '+')
4158 break;
4159 i++;
cristybb503372010-05-27 20:51:26 +00004160 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004161 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004162 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004163 argv[i]);
4164 if (compress < 0)
4165 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4166 argv[i]);
4167 break;
4168 }
cristy22879752009-10-25 23:55:40 +00004169 if (LocaleCompare("concurrent",option+1) == 0)
4170 break;
cristy3ed852e2009-09-05 21:47:34 +00004171 if (LocaleCompare("contrast",option+1) == 0)
4172 break;
4173 if (LocaleCompare("contrast-stretch",option+1) == 0)
4174 {
4175 i++;
cristybb503372010-05-27 20:51:26 +00004176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004177 ThrowMogrifyException(OptionError,"MissingArgument",option);
4178 if (IsGeometry(argv[i]) == MagickFalse)
4179 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4180 break;
4181 }
4182 if (LocaleCompare("convolve",option+1) == 0)
4183 {
cristyb6bd4ad2010-08-08 01:12:27 +00004184 KernelInfo
4185 *kernel_info;
4186
cristy3ed852e2009-09-05 21:47:34 +00004187 if (*option == '+')
4188 break;
4189 i++;
cristybb503372010-05-27 20:51:26 +00004190 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004191 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004192 kernel_info=AcquireKernelInfo(argv[i]);
4193 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004194 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004195 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004196 break;
4197 }
4198 if (LocaleCompare("crop",option+1) == 0)
4199 {
4200 if (*option == '+')
4201 break;
4202 i++;
cristybb503372010-05-27 20:51:26 +00004203 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004204 ThrowMogrifyException(OptionError,"MissingArgument",option);
4205 if (IsGeometry(argv[i]) == MagickFalse)
4206 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4207 break;
4208 }
4209 if (LocaleCompare("cycle",option+1) == 0)
4210 {
4211 if (*option == '+')
4212 break;
4213 i++;
cristybb503372010-05-27 20:51:26 +00004214 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004215 ThrowMogrifyException(OptionError,"MissingArgument",option);
4216 if (IsGeometry(argv[i]) == MagickFalse)
4217 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4218 break;
4219 }
4220 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4221 }
4222 case 'd':
4223 {
4224 if (LocaleCompare("decipher",option+1) == 0)
4225 {
4226 if (*option == '+')
4227 break;
4228 i++;
cristybb503372010-05-27 20:51:26 +00004229 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004230 ThrowMogrifyException(OptionError,"MissingArgument",option);
4231 break;
4232 }
4233 if (LocaleCompare("deconstruct",option+1) == 0)
4234 break;
4235 if (LocaleCompare("debug",option+1) == 0)
4236 {
cristybb503372010-05-27 20:51:26 +00004237 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004238 event;
4239
4240 if (*option == '+')
4241 break;
4242 i++;
cristybb503372010-05-27 20:51:26 +00004243 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004244 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004245 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004246 if (event < 0)
4247 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4248 argv[i]);
4249 (void) SetLogEventMask(argv[i]);
4250 break;
4251 }
4252 if (LocaleCompare("define",option+1) == 0)
4253 {
4254 i++;
cristybb503372010-05-27 20:51:26 +00004255 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004256 ThrowMogrifyException(OptionError,"MissingArgument",option);
4257 if (*option == '+')
4258 {
4259 const char
4260 *define;
4261
4262 define=GetImageOption(image_info,argv[i]);
4263 if (define == (const char *) NULL)
4264 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4265 break;
4266 }
4267 break;
4268 }
4269 if (LocaleCompare("delay",option+1) == 0)
4270 {
4271 if (*option == '+')
4272 break;
4273 i++;
cristybb503372010-05-27 20:51:26 +00004274 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004275 ThrowMogrifyException(OptionError,"MissingArgument",option);
4276 if (IsGeometry(argv[i]) == MagickFalse)
4277 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4278 break;
4279 }
cristyecb10ff2011-03-22 13:14:03 +00004280 if (LocaleCompare("delete",option+1) == 0)
4281 {
4282 if (*option == '+')
4283 break;
4284 i++;
4285 if (i == (ssize_t) (argc-1))
4286 ThrowMogrifyException(OptionError,"MissingArgument",option);
4287 if (IsGeometry(argv[i]) == MagickFalse)
4288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4289 break;
4290 }
cristy3ed852e2009-09-05 21:47:34 +00004291 if (LocaleCompare("density",option+1) == 0)
4292 {
4293 if (*option == '+')
4294 break;
4295 i++;
cristybb503372010-05-27 20:51:26 +00004296 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004297 ThrowMogrifyException(OptionError,"MissingArgument",option);
4298 if (IsGeometry(argv[i]) == MagickFalse)
4299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4300 break;
4301 }
4302 if (LocaleCompare("depth",option+1) == 0)
4303 {
4304 if (*option == '+')
4305 break;
4306 i++;
cristybb503372010-05-27 20:51:26 +00004307 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004308 ThrowMogrifyException(OptionError,"MissingArgument",option);
4309 if (IsGeometry(argv[i]) == MagickFalse)
4310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4311 break;
4312 }
4313 if (LocaleCompare("deskew",option+1) == 0)
4314 {
4315 if (*option == '+')
4316 break;
4317 i++;
cristybb503372010-05-27 20:51:26 +00004318 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004319 ThrowMogrifyException(OptionError,"MissingArgument",option);
4320 if (IsGeometry(argv[i]) == MagickFalse)
4321 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4322 break;
4323 }
4324 if (LocaleCompare("despeckle",option+1) == 0)
4325 break;
4326 if (LocaleCompare("dft",option+1) == 0)
4327 break;
cristyc9b12952010-03-28 01:12:28 +00004328 if (LocaleCompare("direction",option+1) == 0)
4329 {
cristybb503372010-05-27 20:51:26 +00004330 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004331 direction;
4332
4333 if (*option == '+')
4334 break;
4335 i++;
cristybb503372010-05-27 20:51:26 +00004336 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004337 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004338 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004339 argv[i]);
4340 if (direction < 0)
4341 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4342 argv[i]);
4343 break;
4344 }
cristy3ed852e2009-09-05 21:47:34 +00004345 if (LocaleCompare("display",option+1) == 0)
4346 {
4347 if (*option == '+')
4348 break;
4349 i++;
cristybb503372010-05-27 20:51:26 +00004350 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004351 ThrowMogrifyException(OptionError,"MissingArgument",option);
4352 break;
4353 }
4354 if (LocaleCompare("dispose",option+1) == 0)
4355 {
cristybb503372010-05-27 20:51:26 +00004356 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004357 dispose;
4358
4359 if (*option == '+')
4360 break;
4361 i++;
cristybb503372010-05-27 20:51:26 +00004362 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004363 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004364 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004365 if (dispose < 0)
4366 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4367 argv[i]);
4368 break;
4369 }
4370 if (LocaleCompare("distort",option+1) == 0)
4371 {
cristybb503372010-05-27 20:51:26 +00004372 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004373 op;
4374
4375 i++;
cristybb503372010-05-27 20:51:26 +00004376 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004377 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004378 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004379 if (op < 0)
4380 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4381 argv[i]);
4382 i++;
cristybb503372010-05-27 20:51:26 +00004383 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004384 ThrowMogrifyException(OptionError,"MissingArgument",option);
4385 break;
4386 }
4387 if (LocaleCompare("dither",option+1) == 0)
4388 {
cristybb503372010-05-27 20:51:26 +00004389 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004390 method;
4391
4392 if (*option == '+')
4393 break;
4394 i++;
cristybb503372010-05-27 20:51:26 +00004395 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004396 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004397 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004398 if (method < 0)
4399 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4400 argv[i]);
4401 break;
4402 }
4403 if (LocaleCompare("draw",option+1) == 0)
4404 {
4405 if (*option == '+')
4406 break;
4407 i++;
cristybb503372010-05-27 20:51:26 +00004408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004409 ThrowMogrifyException(OptionError,"MissingArgument",option);
4410 break;
4411 }
cristyecb10ff2011-03-22 13:14:03 +00004412 if (LocaleCompare("duplicate",option+1) == 0)
4413 {
4414 if (*option == '+')
4415 break;
4416 i++;
4417 if (i == (ssize_t) (argc-1))
4418 ThrowMogrifyException(OptionError,"MissingArgument",option);
4419 if (IsGeometry(argv[i]) == MagickFalse)
4420 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4421 break;
4422 }
cristy22879752009-10-25 23:55:40 +00004423 if (LocaleCompare("duration",option+1) == 0)
4424 {
4425 if (*option == '+')
4426 break;
4427 i++;
cristybb503372010-05-27 20:51:26 +00004428 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004429 ThrowMogrifyException(OptionError,"MissingArgument",option);
4430 if (IsGeometry(argv[i]) == MagickFalse)
4431 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4432 break;
4433 }
cristy3ed852e2009-09-05 21:47:34 +00004434 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4435 }
4436 case 'e':
4437 {
4438 if (LocaleCompare("edge",option+1) == 0)
4439 {
4440 if (*option == '+')
4441 break;
4442 i++;
cristybb503372010-05-27 20:51:26 +00004443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004444 ThrowMogrifyException(OptionError,"MissingArgument",option);
4445 if (IsGeometry(argv[i]) == MagickFalse)
4446 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4447 break;
4448 }
4449 if (LocaleCompare("emboss",option+1) == 0)
4450 {
4451 if (*option == '+')
4452 break;
4453 i++;
cristybb503372010-05-27 20:51:26 +00004454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004455 ThrowMogrifyException(OptionError,"MissingArgument",option);
4456 if (IsGeometry(argv[i]) == MagickFalse)
4457 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4458 break;
4459 }
4460 if (LocaleCompare("encipher",option+1) == 0)
4461 {
4462 if (*option == '+')
4463 break;
4464 i++;
cristybb503372010-05-27 20:51:26 +00004465 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004466 ThrowMogrifyException(OptionError,"MissingArgument",option);
4467 break;
4468 }
4469 if (LocaleCompare("encoding",option+1) == 0)
4470 {
4471 if (*option == '+')
4472 break;
4473 i++;
cristybb503372010-05-27 20:51:26 +00004474 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004475 ThrowMogrifyException(OptionError,"MissingArgument",option);
4476 break;
4477 }
4478 if (LocaleCompare("endian",option+1) == 0)
4479 {
cristybb503372010-05-27 20:51:26 +00004480 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004481 endian;
4482
4483 if (*option == '+')
4484 break;
4485 i++;
cristybb503372010-05-27 20:51:26 +00004486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004487 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004488 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004489 if (endian < 0)
4490 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4491 argv[i]);
4492 break;
4493 }
4494 if (LocaleCompare("enhance",option+1) == 0)
4495 break;
4496 if (LocaleCompare("equalize",option+1) == 0)
4497 break;
4498 if (LocaleCompare("evaluate",option+1) == 0)
4499 {
cristybb503372010-05-27 20:51:26 +00004500 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004501 op;
4502
4503 if (*option == '+')
4504 break;
4505 i++;
cristybb503372010-05-27 20:51:26 +00004506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004507 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004508 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004509 if (op < 0)
4510 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4511 argv[i]);
4512 i++;
cristybb503372010-05-27 20:51:26 +00004513 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004514 ThrowMogrifyException(OptionError,"MissingArgument",option);
4515 if (IsGeometry(argv[i]) == MagickFalse)
4516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4517 break;
4518 }
cristyd18ae7c2010-03-07 17:39:52 +00004519 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4520 {
cristybb503372010-05-27 20:51:26 +00004521 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004522 op;
4523
4524 if (*option == '+')
4525 break;
4526 i++;
cristybb503372010-05-27 20:51:26 +00004527 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004528 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004529 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004530 if (op < 0)
4531 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4532 argv[i]);
4533 break;
4534 }
cristy3ed852e2009-09-05 21:47:34 +00004535 if (LocaleCompare("extent",option+1) == 0)
4536 {
4537 if (*option == '+')
4538 break;
4539 i++;
cristybb503372010-05-27 20:51:26 +00004540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004541 ThrowMogrifyException(OptionError,"MissingArgument",option);
4542 if (IsGeometry(argv[i]) == MagickFalse)
4543 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4544 break;
4545 }
4546 if (LocaleCompare("extract",option+1) == 0)
4547 {
4548 if (*option == '+')
4549 break;
4550 i++;
cristybb503372010-05-27 20:51:26 +00004551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004552 ThrowMogrifyException(OptionError,"MissingArgument",option);
4553 if (IsGeometry(argv[i]) == MagickFalse)
4554 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4555 break;
4556 }
4557 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4558 }
4559 case 'f':
4560 {
4561 if (LocaleCompare("family",option+1) == 0)
4562 {
4563 if (*option == '+')
4564 break;
4565 i++;
cristybb503372010-05-27 20:51:26 +00004566 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004567 ThrowMogrifyException(OptionError,"MissingArgument",option);
4568 break;
4569 }
4570 if (LocaleCompare("fill",option+1) == 0)
4571 {
4572 if (*option == '+')
4573 break;
4574 i++;
cristybb503372010-05-27 20:51:26 +00004575 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004576 ThrowMogrifyException(OptionError,"MissingArgument",option);
4577 break;
4578 }
4579 if (LocaleCompare("filter",option+1) == 0)
4580 {
cristybb503372010-05-27 20:51:26 +00004581 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004582 filter;
4583
4584 if (*option == '+')
4585 break;
4586 i++;
cristybb503372010-05-27 20:51:26 +00004587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004588 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004589 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004590 if (filter < 0)
4591 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4592 argv[i]);
4593 break;
4594 }
4595 if (LocaleCompare("flatten",option+1) == 0)
4596 break;
4597 if (LocaleCompare("flip",option+1) == 0)
4598 break;
4599 if (LocaleCompare("flop",option+1) == 0)
4600 break;
4601 if (LocaleCompare("floodfill",option+1) == 0)
4602 {
4603 if (*option == '+')
4604 break;
4605 i++;
cristybb503372010-05-27 20:51:26 +00004606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004607 ThrowMogrifyException(OptionError,"MissingArgument",option);
4608 if (IsGeometry(argv[i]) == MagickFalse)
4609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4610 i++;
cristybb503372010-05-27 20:51:26 +00004611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004612 ThrowMogrifyException(OptionError,"MissingArgument",option);
4613 break;
4614 }
4615 if (LocaleCompare("font",option+1) == 0)
4616 {
4617 if (*option == '+')
4618 break;
4619 i++;
cristybb503372010-05-27 20:51:26 +00004620 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 break;
4623 }
4624 if (LocaleCompare("format",option+1) == 0)
4625 {
4626 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4627 (void) CloneString(&format,(char *) NULL);
4628 if (*option == '+')
4629 break;
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 (void) CloneString(&format,argv[i]);
4634 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4635 (void) ConcatenateMagickString(image_info->filename,":",
4636 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004637 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004638 if (*image_info->magick == '\0')
4639 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4640 format);
4641 break;
4642 }
4643 if (LocaleCompare("frame",option+1) == 0)
4644 {
4645 if (*option == '+')
4646 break;
4647 i++;
cristybb503372010-05-27 20:51:26 +00004648 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004649 ThrowMogrifyException(OptionError,"MissingArgument",option);
4650 if (IsGeometry(argv[i]) == MagickFalse)
4651 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4652 break;
4653 }
4654 if (LocaleCompare("function",option+1) == 0)
4655 {
cristybb503372010-05-27 20:51:26 +00004656 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004657 op;
4658
4659 if (*option == '+')
4660 break;
4661 i++;
cristybb503372010-05-27 20:51:26 +00004662 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004663 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004664 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004665 if (op < 0)
4666 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4667 i++;
cristybb503372010-05-27 20:51:26 +00004668 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004669 ThrowMogrifyException(OptionError,"MissingArgument",option);
4670 break;
4671 }
4672 if (LocaleCompare("fuzz",option+1) == 0)
4673 {
4674 if (*option == '+')
4675 break;
4676 i++;
cristybb503372010-05-27 20:51:26 +00004677 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004678 ThrowMogrifyException(OptionError,"MissingArgument",option);
4679 if (IsGeometry(argv[i]) == MagickFalse)
4680 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4681 break;
4682 }
4683 if (LocaleCompare("fx",option+1) == 0)
4684 {
4685 if (*option == '+')
4686 break;
4687 i++;
cristybb503372010-05-27 20:51:26 +00004688 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004689 ThrowMogrifyException(OptionError,"MissingArgument",option);
4690 break;
4691 }
4692 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4693 }
4694 case 'g':
4695 {
4696 if (LocaleCompare("gamma",option+1) == 0)
4697 {
4698 i++;
cristybb503372010-05-27 20:51:26 +00004699 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004700 ThrowMogrifyException(OptionError,"MissingArgument",option);
4701 if (IsGeometry(argv[i]) == MagickFalse)
4702 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4703 break;
4704 }
4705 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4706 (LocaleCompare("gaussian",option+1) == 0))
4707 {
4708 i++;
cristybb503372010-05-27 20:51:26 +00004709 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004710 ThrowMogrifyException(OptionError,"MissingArgument",option);
4711 if (IsGeometry(argv[i]) == MagickFalse)
4712 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4713 break;
4714 }
4715 if (LocaleCompare("geometry",option+1) == 0)
4716 {
4717 if (*option == '+')
4718 break;
4719 i++;
cristybb503372010-05-27 20:51:26 +00004720 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004721 ThrowMogrifyException(OptionError,"MissingArgument",option);
4722 if (IsGeometry(argv[i]) == MagickFalse)
4723 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4724 break;
4725 }
4726 if (LocaleCompare("gravity",option+1) == 0)
4727 {
cristybb503372010-05-27 20:51:26 +00004728 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004729 gravity;
4730
4731 if (*option == '+')
4732 break;
4733 i++;
cristybb503372010-05-27 20:51:26 +00004734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004735 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004736 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004737 if (gravity < 0)
4738 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4739 argv[i]);
4740 break;
4741 }
4742 if (LocaleCompare("green-primary",option+1) == 0)
4743 {
4744 if (*option == '+')
4745 break;
4746 i++;
cristybb503372010-05-27 20:51:26 +00004747 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004748 ThrowMogrifyException(OptionError,"MissingArgument",option);
4749 if (IsGeometry(argv[i]) == MagickFalse)
4750 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4751 break;
4752 }
4753 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4754 }
4755 case 'h':
4756 {
4757 if (LocaleCompare("hald-clut",option+1) == 0)
4758 break;
4759 if ((LocaleCompare("help",option+1) == 0) ||
4760 (LocaleCompare("-help",option+1) == 0))
4761 return(MogrifyUsage());
4762 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4763 }
4764 case 'i':
4765 {
4766 if (LocaleCompare("identify",option+1) == 0)
4767 break;
4768 if (LocaleCompare("idft",option+1) == 0)
4769 break;
4770 if (LocaleCompare("implode",option+1) == 0)
4771 {
4772 if (*option == '+')
4773 break;
4774 i++;
cristybb503372010-05-27 20:51:26 +00004775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004776 ThrowMogrifyException(OptionError,"MissingArgument",option);
4777 if (IsGeometry(argv[i]) == MagickFalse)
4778 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4779 break;
4780 }
4781 if (LocaleCompare("intent",option+1) == 0)
4782 {
cristybb503372010-05-27 20:51:26 +00004783 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004784 intent;
4785
4786 if (*option == '+')
4787 break;
4788 i++;
cristybb503372010-05-27 20:51:26 +00004789 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004790 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004791 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004792 if (intent < 0)
4793 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4794 argv[i]);
4795 break;
4796 }
4797 if (LocaleCompare("interlace",option+1) == 0)
4798 {
cristybb503372010-05-27 20:51:26 +00004799 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004800 interlace;
4801
4802 if (*option == '+')
4803 break;
4804 i++;
cristybb503372010-05-27 20:51:26 +00004805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004806 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004807 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004808 argv[i]);
4809 if (interlace < 0)
4810 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4811 argv[i]);
4812 break;
4813 }
cristyb32b90a2009-09-07 21:45:48 +00004814 if (LocaleCompare("interline-spacing",option+1) == 0)
4815 {
4816 if (*option == '+')
4817 break;
4818 i++;
cristybb503372010-05-27 20:51:26 +00004819 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004820 ThrowMogrifyException(OptionError,"MissingArgument",option);
4821 if (IsGeometry(argv[i]) == MagickFalse)
4822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4823 break;
4824 }
cristy3ed852e2009-09-05 21:47:34 +00004825 if (LocaleCompare("interpolate",option+1) == 0)
4826 {
cristybb503372010-05-27 20:51:26 +00004827 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004828 interpolate;
4829
4830 if (*option == '+')
4831 break;
4832 i++;
cristybb503372010-05-27 20:51:26 +00004833 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004834 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004835 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004836 argv[i]);
4837 if (interpolate < 0)
4838 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4839 argv[i]);
4840 break;
4841 }
4842 if (LocaleCompare("interword-spacing",option+1) == 0)
4843 {
4844 if (*option == '+')
4845 break;
4846 i++;
cristybb503372010-05-27 20:51:26 +00004847 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004848 ThrowMogrifyException(OptionError,"MissingArgument",option);
4849 if (IsGeometry(argv[i]) == MagickFalse)
4850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4851 break;
4852 }
4853 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4854 }
4855 case 'k':
4856 {
4857 if (LocaleCompare("kerning",option+1) == 0)
4858 {
4859 if (*option == '+')
4860 break;
4861 i++;
cristybb503372010-05-27 20:51:26 +00004862 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004863 ThrowMogrifyException(OptionError,"MissingArgument",option);
4864 if (IsGeometry(argv[i]) == MagickFalse)
4865 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4866 break;
4867 }
4868 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4869 }
4870 case 'l':
4871 {
4872 if (LocaleCompare("label",option+1) == 0)
4873 {
4874 if (*option == '+')
4875 break;
4876 i++;
cristybb503372010-05-27 20:51:26 +00004877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004878 ThrowMogrifyException(OptionError,"MissingArgument",option);
4879 break;
4880 }
4881 if (LocaleCompare("lat",option+1) == 0)
4882 {
4883 if (*option == '+')
4884 break;
4885 i++;
cristybb503372010-05-27 20:51:26 +00004886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004887 ThrowMogrifyException(OptionError,"MissingArgument",option);
4888 if (IsGeometry(argv[i]) == MagickFalse)
4889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4890 }
4891 if (LocaleCompare("layers",option+1) == 0)
4892 {
cristybb503372010-05-27 20:51:26 +00004893 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004894 type;
4895
4896 if (*option == '+')
4897 break;
4898 i++;
cristybb503372010-05-27 20:51:26 +00004899 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004900 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004901 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004902 if (type < 0)
4903 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4904 argv[i]);
4905 break;
4906 }
4907 if (LocaleCompare("level",option+1) == 0)
4908 {
4909 i++;
cristybb503372010-05-27 20:51:26 +00004910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004911 ThrowMogrifyException(OptionError,"MissingArgument",option);
4912 if (IsGeometry(argv[i]) == MagickFalse)
4913 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4914 break;
4915 }
4916 if (LocaleCompare("level-colors",option+1) == 0)
4917 {
4918 i++;
cristybb503372010-05-27 20:51:26 +00004919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004920 ThrowMogrifyException(OptionError,"MissingArgument",option);
4921 break;
4922 }
4923 if (LocaleCompare("linewidth",option+1) == 0)
4924 {
4925 if (*option == '+')
4926 break;
4927 i++;
cristybb503372010-05-27 20:51:26 +00004928 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004929 ThrowMogrifyException(OptionError,"MissingArgument",option);
4930 if (IsGeometry(argv[i]) == MagickFalse)
4931 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4932 break;
4933 }
4934 if (LocaleCompare("limit",option+1) == 0)
4935 {
4936 char
4937 *p;
4938
4939 double
4940 value;
4941
cristybb503372010-05-27 20:51:26 +00004942 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004943 resource;
4944
4945 if (*option == '+')
4946 break;
4947 i++;
cristybb503372010-05-27 20:51:26 +00004948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004949 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004950 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004951 argv[i]);
4952 if (resource < 0)
4953 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4954 argv[i]);
4955 i++;
cristybb503372010-05-27 20:51:26 +00004956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004957 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004958 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004959 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004960 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4961 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4962 break;
4963 }
4964 if (LocaleCompare("liquid-rescale",option+1) == 0)
4965 {
4966 i++;
cristybb503372010-05-27 20:51:26 +00004967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004968 ThrowMogrifyException(OptionError,"MissingArgument",option);
4969 if (IsGeometry(argv[i]) == MagickFalse)
4970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4971 break;
4972 }
4973 if (LocaleCompare("list",option+1) == 0)
4974 {
cristybb503372010-05-27 20:51:26 +00004975 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004976 list;
4977
4978 if (*option == '+')
4979 break;
4980 i++;
cristybb503372010-05-27 20:51:26 +00004981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004982 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004983 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004984 if (list < 0)
4985 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004986 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004987 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004988 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004989 }
4990 if (LocaleCompare("log",option+1) == 0)
4991 {
4992 if (*option == '+')
4993 break;
4994 i++;
cristybb503372010-05-27 20:51:26 +00004995 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004996 (strchr(argv[i],'%') == (char *) NULL))
4997 ThrowMogrifyException(OptionError,"MissingArgument",option);
4998 break;
4999 }
5000 if (LocaleCompare("loop",option+1) == 0)
5001 {
5002 if (*option == '+')
5003 break;
5004 i++;
cristybb503372010-05-27 20:51:26 +00005005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005006 ThrowMogrifyException(OptionError,"MissingArgument",option);
5007 if (IsGeometry(argv[i]) == MagickFalse)
5008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5009 break;
5010 }
5011 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5012 }
5013 case 'm':
5014 {
5015 if (LocaleCompare("map",option+1) == 0)
5016 {
5017 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5018 if (*option == '+')
5019 break;
5020 i++;
cristybb503372010-05-27 20:51:26 +00005021 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005022 ThrowMogrifyException(OptionError,"MissingArgument",option);
5023 break;
5024 }
5025 if (LocaleCompare("mask",option+1) == 0)
5026 {
5027 if (*option == '+')
5028 break;
5029 i++;
cristybb503372010-05-27 20:51:26 +00005030 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005031 ThrowMogrifyException(OptionError,"MissingArgument",option);
5032 break;
5033 }
5034 if (LocaleCompare("matte",option+1) == 0)
5035 break;
5036 if (LocaleCompare("mattecolor",option+1) == 0)
5037 {
5038 if (*option == '+')
5039 break;
5040 i++;
cristybb503372010-05-27 20:51:26 +00005041 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005042 ThrowMogrifyException(OptionError,"MissingArgument",option);
5043 break;
5044 }
cristyf40785b2010-03-06 02:27:27 +00005045 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005046 break;
cristyf40785b2010-03-06 02:27:27 +00005047 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005048 break;
cristy3ed852e2009-09-05 21:47:34 +00005049 if (LocaleCompare("modulate",option+1) == 0)
5050 {
5051 if (*option == '+')
5052 break;
5053 i++;
cristybb503372010-05-27 20:51:26 +00005054 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005055 ThrowMogrifyException(OptionError,"MissingArgument",option);
5056 if (IsGeometry(argv[i]) == MagickFalse)
5057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5058 break;
5059 }
5060 if (LocaleCompare("median",option+1) == 0)
5061 {
5062 if (*option == '+')
5063 break;
5064 i++;
cristybb503372010-05-27 20:51:26 +00005065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005066 ThrowMogrifyException(OptionError,"MissingArgument",option);
5067 if (IsGeometry(argv[i]) == MagickFalse)
5068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5069 break;
5070 }
cristy69ec32d2011-02-27 23:57:09 +00005071 if (LocaleCompare("mode",option+1) == 0)
5072 {
5073 if (*option == '+')
5074 break;
5075 i++;
5076 if (i == (ssize_t) argc)
5077 ThrowMogrifyException(OptionError,"MissingArgument",option);
5078 if (IsGeometry(argv[i]) == MagickFalse)
5079 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5080 break;
5081 }
cristy3ed852e2009-09-05 21:47:34 +00005082 if (LocaleCompare("monitor",option+1) == 0)
5083 break;
5084 if (LocaleCompare("monochrome",option+1) == 0)
5085 break;
5086 if (LocaleCompare("morph",option+1) == 0)
5087 {
5088 if (*option == '+')
5089 break;
5090 i++;
cristybb503372010-05-27 20:51:26 +00005091 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005092 ThrowMogrifyException(OptionError,"MissingArgument",option);
5093 if (IsGeometry(argv[i]) == MagickFalse)
5094 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5095 break;
5096 }
anthony29188a82010-01-22 10:12:34 +00005097 if (LocaleCompare("morphology",option+1) == 0)
5098 {
anthony29188a82010-01-22 10:12:34 +00005099 char
5100 token[MaxTextExtent];
5101
cristyb6bd4ad2010-08-08 01:12:27 +00005102 KernelInfo
5103 *kernel_info;
5104
5105 ssize_t
5106 op;
5107
anthony29188a82010-01-22 10:12:34 +00005108 i++;
cristybb503372010-05-27 20:51:26 +00005109 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005110 ThrowMogrifyException(OptionError,"MissingArgument",option);
5111 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005112 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005113 if (op < 0)
5114 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005115 token);
anthony29188a82010-01-22 10:12:34 +00005116 i++;
cristybb503372010-05-27 20:51:26 +00005117 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005118 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005119 kernel_info=AcquireKernelInfo(argv[i]);
5120 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005121 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005122 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005123 break;
5124 }
cristy3ed852e2009-09-05 21:47:34 +00005125 if (LocaleCompare("mosaic",option+1) == 0)
5126 break;
5127 if (LocaleCompare("motion-blur",option+1) == 0)
5128 {
5129 if (*option == '+')
5130 break;
5131 i++;
cristybb503372010-05-27 20:51:26 +00005132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005133 ThrowMogrifyException(OptionError,"MissingArgument",option);
5134 if (IsGeometry(argv[i]) == MagickFalse)
5135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5136 break;
5137 }
5138 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5139 }
5140 case 'n':
5141 {
5142 if (LocaleCompare("negate",option+1) == 0)
5143 break;
5144 if (LocaleCompare("noise",option+1) == 0)
5145 {
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 if (*option == '+')
5150 {
cristybb503372010-05-27 20:51:26 +00005151 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005152 noise;
5153
cristy042ee782011-04-22 18:48:30 +00005154 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005155 if (noise < 0)
5156 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5157 argv[i]);
5158 break;
5159 }
5160 if (IsGeometry(argv[i]) == MagickFalse)
5161 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5162 break;
5163 }
5164 if (LocaleCompare("noop",option+1) == 0)
5165 break;
5166 if (LocaleCompare("normalize",option+1) == 0)
5167 break;
5168 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5169 }
5170 case 'o':
5171 {
5172 if (LocaleCompare("opaque",option+1) == 0)
5173 {
cristy3ed852e2009-09-05 21:47:34 +00005174 i++;
cristybb503372010-05-27 20:51:26 +00005175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005176 ThrowMogrifyException(OptionError,"MissingArgument",option);
5177 break;
5178 }
5179 if (LocaleCompare("ordered-dither",option+1) == 0)
5180 {
5181 if (*option == '+')
5182 break;
5183 i++;
cristybb503372010-05-27 20:51:26 +00005184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005185 ThrowMogrifyException(OptionError,"MissingArgument",option);
5186 break;
5187 }
5188 if (LocaleCompare("orient",option+1) == 0)
5189 {
cristybb503372010-05-27 20:51:26 +00005190 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005191 orientation;
5192
5193 orientation=UndefinedOrientation;
5194 if (*option == '+')
5195 break;
5196 i++;
cristybb503372010-05-27 20:51:26 +00005197 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005198 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005199 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005200 argv[i]);
5201 if (orientation < 0)
5202 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5203 argv[i]);
5204 break;
5205 }
5206 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5207 }
5208 case 'p':
5209 {
5210 if (LocaleCompare("page",option+1) == 0)
5211 {
5212 if (*option == '+')
5213 break;
5214 i++;
cristybb503372010-05-27 20:51:26 +00005215 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005216 ThrowMogrifyException(OptionError,"MissingArgument",option);
5217 break;
5218 }
5219 if (LocaleCompare("paint",option+1) == 0)
5220 {
5221 if (*option == '+')
5222 break;
5223 i++;
cristybb503372010-05-27 20:51:26 +00005224 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005225 ThrowMogrifyException(OptionError,"MissingArgument",option);
5226 if (IsGeometry(argv[i]) == MagickFalse)
5227 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5228 break;
5229 }
5230 if (LocaleCompare("path",option+1) == 0)
5231 {
5232 (void) CloneString(&path,(char *) NULL);
5233 if (*option == '+')
5234 break;
5235 i++;
cristybb503372010-05-27 20:51:26 +00005236 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005237 ThrowMogrifyException(OptionError,"MissingArgument",option);
5238 (void) CloneString(&path,argv[i]);
5239 break;
5240 }
5241 if (LocaleCompare("pointsize",option+1) == 0)
5242 {
5243 if (*option == '+')
5244 break;
5245 i++;
cristybb503372010-05-27 20:51:26 +00005246 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005247 ThrowMogrifyException(OptionError,"MissingArgument",option);
5248 if (IsGeometry(argv[i]) == MagickFalse)
5249 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5250 break;
5251 }
5252 if (LocaleCompare("polaroid",option+1) == 0)
5253 {
5254 if (*option == '+')
5255 break;
5256 i++;
cristybb503372010-05-27 20:51:26 +00005257 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005258 ThrowMogrifyException(OptionError,"MissingArgument",option);
5259 if (IsGeometry(argv[i]) == MagickFalse)
5260 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5261 break;
5262 }
5263 if (LocaleCompare("posterize",option+1) == 0)
5264 {
5265 if (*option == '+')
5266 break;
5267 i++;
cristybb503372010-05-27 20:51:26 +00005268 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005269 ThrowMogrifyException(OptionError,"MissingArgument",option);
5270 if (IsGeometry(argv[i]) == MagickFalse)
5271 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5272 break;
5273 }
cristye7f51092010-01-17 00:39:37 +00005274 if (LocaleCompare("precision",option+1) == 0)
5275 {
5276 if (*option == '+')
5277 break;
5278 i++;
cristybb503372010-05-27 20:51:26 +00005279 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005280 ThrowMogrifyException(OptionError,"MissingArgument",option);
5281 if (IsGeometry(argv[i]) == MagickFalse)
5282 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5283 break;
5284 }
cristy3ed852e2009-09-05 21:47:34 +00005285 if (LocaleCompare("print",option+1) == 0)
5286 {
5287 if (*option == '+')
5288 break;
5289 i++;
cristybb503372010-05-27 20:51:26 +00005290 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005291 ThrowMogrifyException(OptionError,"MissingArgument",option);
5292 break;
5293 }
5294 if (LocaleCompare("process",option+1) == 0)
5295 {
5296 if (*option == '+')
5297 break;
5298 i++;
cristybb503372010-05-27 20:51:26 +00005299 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005300 ThrowMogrifyException(OptionError,"MissingArgument",option);
5301 break;
5302 }
5303 if (LocaleCompare("profile",option+1) == 0)
5304 {
5305 i++;
cristybb503372010-05-27 20:51:26 +00005306 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005307 ThrowMogrifyException(OptionError,"MissingArgument",option);
5308 break;
5309 }
5310 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5311 }
5312 case 'q':
5313 {
5314 if (LocaleCompare("quality",option+1) == 0)
5315 {
5316 if (*option == '+')
5317 break;
5318 i++;
cristybb503372010-05-27 20:51:26 +00005319 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005320 ThrowMogrifyException(OptionError,"MissingArgument",option);
5321 if (IsGeometry(argv[i]) == MagickFalse)
5322 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5323 break;
5324 }
5325 if (LocaleCompare("quantize",option+1) == 0)
5326 {
cristybb503372010-05-27 20:51:26 +00005327 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005328 colorspace;
5329
5330 if (*option == '+')
5331 break;
5332 i++;
cristybb503372010-05-27 20:51:26 +00005333 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005334 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005335 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005336 argv[i]);
5337 if (colorspace < 0)
5338 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5339 argv[i]);
5340 break;
5341 }
5342 if (LocaleCompare("quiet",option+1) == 0)
5343 break;
5344 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5345 }
5346 case 'r':
5347 {
5348 if (LocaleCompare("radial-blur",option+1) == 0)
5349 {
5350 i++;
cristybb503372010-05-27 20:51:26 +00005351 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005352 ThrowMogrifyException(OptionError,"MissingArgument",option);
5353 if (IsGeometry(argv[i]) == MagickFalse)
5354 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5355 break;
5356 }
5357 if (LocaleCompare("raise",option+1) == 0)
5358 {
5359 i++;
cristybb503372010-05-27 20:51:26 +00005360 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005361 ThrowMogrifyException(OptionError,"MissingArgument",option);
5362 if (IsGeometry(argv[i]) == MagickFalse)
5363 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5364 break;
5365 }
5366 if (LocaleCompare("random-threshold",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
cristybb503372010-05-27 20:51:26 +00005371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 break;
5376 }
cristye6365592010-04-02 17:31:23 +00005377 if (LocaleCompare("recolor",option+1) == 0)
5378 {
5379 if (*option == '+')
5380 break;
5381 i++;
cristybb503372010-05-27 20:51:26 +00005382 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005383 ThrowMogrifyException(OptionError,"MissingArgument",option);
5384 if (IsGeometry(argv[i]) == MagickFalse)
5385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5386 break;
5387 }
cristy3ed852e2009-09-05 21:47:34 +00005388 if (LocaleCompare("red-primary",option+1) == 0)
5389 {
5390 if (*option == '+')
5391 break;
5392 i++;
cristybb503372010-05-27 20:51:26 +00005393 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005394 ThrowMogrifyException(OptionError,"MissingArgument",option);
5395 if (IsGeometry(argv[i]) == MagickFalse)
5396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5397 }
cristy9f2083a2010-04-22 19:48:05 +00005398 if (LocaleCompare("regard-warnings",option+1) == 0)
5399 break;
cristy3ed852e2009-09-05 21:47:34 +00005400 if (LocaleCompare("region",option+1) == 0)
5401 {
5402 if (*option == '+')
5403 break;
5404 i++;
cristybb503372010-05-27 20:51:26 +00005405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 if (IsGeometry(argv[i]) == MagickFalse)
5408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5409 break;
5410 }
cristyf0c78232010-03-15 12:53:40 +00005411 if (LocaleCompare("remap",option+1) == 0)
5412 {
5413 if (*option == '+')
5414 break;
5415 i++;
cristybb503372010-05-27 20:51:26 +00005416 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005417 ThrowMogrifyException(OptionError,"MissingArgument",option);
5418 break;
5419 }
cristy3ed852e2009-09-05 21:47:34 +00005420 if (LocaleCompare("render",option+1) == 0)
5421 break;
5422 if (LocaleCompare("repage",option+1) == 0)
5423 {
5424 if (*option == '+')
5425 break;
5426 i++;
cristybb503372010-05-27 20:51:26 +00005427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005428 ThrowMogrifyException(OptionError,"MissingArgument",option);
5429 if (IsGeometry(argv[i]) == MagickFalse)
5430 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5431 break;
5432 }
5433 if (LocaleCompare("resample",option+1) == 0)
5434 {
5435 if (*option == '+')
5436 break;
5437 i++;
cristybb503372010-05-27 20:51:26 +00005438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005439 ThrowMogrifyException(OptionError,"MissingArgument",option);
5440 if (IsGeometry(argv[i]) == MagickFalse)
5441 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5442 break;
5443 }
5444 if (LocaleCompare("resize",option+1) == 0)
5445 {
5446 if (*option == '+')
5447 break;
5448 i++;
cristybb503372010-05-27 20:51:26 +00005449 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005450 ThrowMogrifyException(OptionError,"MissingArgument",option);
5451 if (IsGeometry(argv[i]) == MagickFalse)
5452 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5453 break;
5454 }
cristyebbcfea2011-02-25 02:43:54 +00005455 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5456 {
5457 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5458 break;
5459 }
cristy3ed852e2009-09-05 21:47:34 +00005460 if (LocaleCompare("reverse",option+1) == 0)
5461 break;
5462 if (LocaleCompare("roll",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("rotate",option+1) == 0)
5474 {
5475 i++;
cristybb503372010-05-27 20:51:26 +00005476 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005477 ThrowMogrifyException(OptionError,"MissingArgument",option);
5478 if (IsGeometry(argv[i]) == MagickFalse)
5479 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5480 break;
5481 }
5482 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5483 }
5484 case 's':
5485 {
5486 if (LocaleCompare("sample",option+1) == 0)
5487 {
5488 if (*option == '+')
5489 break;
5490 i++;
cristybb503372010-05-27 20:51:26 +00005491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005492 ThrowMogrifyException(OptionError,"MissingArgument",option);
5493 if (IsGeometry(argv[i]) == MagickFalse)
5494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5495 break;
5496 }
5497 if (LocaleCompare("sampling-factor",option+1) == 0)
5498 {
5499 if (*option == '+')
5500 break;
5501 i++;
cristybb503372010-05-27 20:51:26 +00005502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005503 ThrowMogrifyException(OptionError,"MissingArgument",option);
5504 if (IsGeometry(argv[i]) == MagickFalse)
5505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5506 break;
5507 }
5508 if (LocaleCompare("scale",option+1) == 0)
5509 {
5510 if (*option == '+')
5511 break;
5512 i++;
cristybb503372010-05-27 20:51:26 +00005513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005514 ThrowMogrifyException(OptionError,"MissingArgument",option);
5515 if (IsGeometry(argv[i]) == MagickFalse)
5516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5517 break;
5518 }
5519 if (LocaleCompare("scene",option+1) == 0)
5520 {
5521 if (*option == '+')
5522 break;
5523 i++;
cristybb503372010-05-27 20:51:26 +00005524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005525 ThrowMogrifyException(OptionError,"MissingArgument",option);
5526 if (IsGeometry(argv[i]) == MagickFalse)
5527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5528 break;
5529 }
5530 if (LocaleCompare("seed",option+1) == 0)
5531 {
5532 if (*option == '+')
5533 break;
5534 i++;
cristybb503372010-05-27 20:51:26 +00005535 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005536 ThrowMogrifyException(OptionError,"MissingArgument",option);
5537 if (IsGeometry(argv[i]) == MagickFalse)
5538 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5539 break;
5540 }
5541 if (LocaleCompare("segment",option+1) == 0)
5542 {
5543 if (*option == '+')
5544 break;
5545 i++;
cristybb503372010-05-27 20:51:26 +00005546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005547 ThrowMogrifyException(OptionError,"MissingArgument",option);
5548 if (IsGeometry(argv[i]) == MagickFalse)
5549 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550 break;
5551 }
5552 if (LocaleCompare("selective-blur",option+1) == 0)
5553 {
5554 i++;
cristybb503372010-05-27 20:51:26 +00005555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005556 ThrowMogrifyException(OptionError,"MissingArgument",option);
5557 if (IsGeometry(argv[i]) == MagickFalse)
5558 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5559 break;
5560 }
5561 if (LocaleCompare("separate",option+1) == 0)
5562 break;
5563 if (LocaleCompare("sepia-tone",option+1) == 0)
5564 {
5565 if (*option == '+')
5566 break;
5567 i++;
cristybb503372010-05-27 20:51:26 +00005568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005569 ThrowMogrifyException(OptionError,"MissingArgument",option);
5570 if (IsGeometry(argv[i]) == MagickFalse)
5571 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5572 break;
5573 }
5574 if (LocaleCompare("set",option+1) == 0)
5575 {
5576 i++;
cristybb503372010-05-27 20:51:26 +00005577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005578 ThrowMogrifyException(OptionError,"MissingArgument",option);
5579 if (*option == '+')
5580 break;
5581 i++;
cristybb503372010-05-27 20:51:26 +00005582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005583 ThrowMogrifyException(OptionError,"MissingArgument",option);
5584 break;
5585 }
5586 if (LocaleCompare("shade",option+1) == 0)
5587 {
5588 i++;
cristybb503372010-05-27 20:51:26 +00005589 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005590 ThrowMogrifyException(OptionError,"MissingArgument",option);
5591 if (IsGeometry(argv[i]) == MagickFalse)
5592 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5593 break;
5594 }
5595 if (LocaleCompare("shadow",option+1) == 0)
5596 {
5597 if (*option == '+')
5598 break;
5599 i++;
cristybb503372010-05-27 20:51:26 +00005600 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005601 ThrowMogrifyException(OptionError,"MissingArgument",option);
5602 if (IsGeometry(argv[i]) == MagickFalse)
5603 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5604 break;
5605 }
5606 if (LocaleCompare("sharpen",option+1) == 0)
5607 {
5608 i++;
cristybb503372010-05-27 20:51:26 +00005609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005610 ThrowMogrifyException(OptionError,"MissingArgument",option);
5611 if (IsGeometry(argv[i]) == MagickFalse)
5612 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5613 break;
5614 }
5615 if (LocaleCompare("shave",option+1) == 0)
5616 {
5617 if (*option == '+')
5618 break;
5619 i++;
cristybb503372010-05-27 20:51:26 +00005620 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005621 ThrowMogrifyException(OptionError,"MissingArgument",option);
5622 if (IsGeometry(argv[i]) == MagickFalse)
5623 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5624 break;
5625 }
5626 if (LocaleCompare("shear",option+1) == 0)
5627 {
5628 i++;
cristybb503372010-05-27 20:51:26 +00005629 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005630 ThrowMogrifyException(OptionError,"MissingArgument",option);
5631 if (IsGeometry(argv[i]) == MagickFalse)
5632 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5633 break;
5634 }
5635 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5636 {
5637 i++;
cristybb503372010-05-27 20:51:26 +00005638 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 if (IsGeometry(argv[i]) == MagickFalse)
5641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5642 break;
5643 }
5644 if (LocaleCompare("size",option+1) == 0)
5645 {
5646 if (*option == '+')
5647 break;
5648 i++;
cristybb503372010-05-27 20:51:26 +00005649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005650 ThrowMogrifyException(OptionError,"MissingArgument",option);
5651 if (IsGeometry(argv[i]) == MagickFalse)
5652 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5653 break;
5654 }
5655 if (LocaleCompare("sketch",option+1) == 0)
5656 {
5657 if (*option == '+')
5658 break;
5659 i++;
cristybb503372010-05-27 20:51:26 +00005660 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005661 ThrowMogrifyException(OptionError,"MissingArgument",option);
5662 if (IsGeometry(argv[i]) == MagickFalse)
5663 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5664 break;
5665 }
cristy4285d782011-02-09 20:12:28 +00005666 if (LocaleCompare("smush",option+1) == 0)
5667 {
cristy4285d782011-02-09 20:12:28 +00005668 i++;
5669 if (i == (ssize_t) argc)
5670 ThrowMogrifyException(OptionError,"MissingArgument",option);
5671 if (IsGeometry(argv[i]) == MagickFalse)
5672 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005673 i++;
5674 break;
5675 }
cristy3ed852e2009-09-05 21:47:34 +00005676 if (LocaleCompare("solarize",option+1) == 0)
5677 {
5678 if (*option == '+')
5679 break;
5680 i++;
cristybb503372010-05-27 20:51:26 +00005681 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005682 ThrowMogrifyException(OptionError,"MissingArgument",option);
5683 if (IsGeometry(argv[i]) == MagickFalse)
5684 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5685 break;
5686 }
5687 if (LocaleCompare("sparse-color",option+1) == 0)
5688 {
cristybb503372010-05-27 20:51:26 +00005689 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005690 op;
5691
5692 i++;
cristybb503372010-05-27 20:51:26 +00005693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005694 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005695 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005696 if (op < 0)
5697 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5698 argv[i]);
5699 i++;
cristybb503372010-05-27 20:51:26 +00005700 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 break;
5703 }
5704 if (LocaleCompare("spread",option+1) == 0)
5705 {
5706 if (*option == '+')
5707 break;
5708 i++;
cristybb503372010-05-27 20:51:26 +00005709 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005710 ThrowMogrifyException(OptionError,"MissingArgument",option);
5711 if (IsGeometry(argv[i]) == MagickFalse)
5712 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5713 break;
5714 }
cristy0834d642011-03-18 18:26:08 +00005715 if (LocaleCompare("statistic",option+1) == 0)
5716 {
5717 ssize_t
5718 op;
5719
5720 if (*option == '+')
5721 break;
5722 i++;
5723 if (i == (ssize_t) argc)
5724 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005725 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005726 if (op < 0)
5727 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5728 argv[i]);
5729 i++;
5730 if (i == (ssize_t) (argc-1))
5731 ThrowMogrifyException(OptionError,"MissingArgument",option);
5732 if (IsGeometry(argv[i]) == MagickFalse)
5733 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5734 break;
5735 }
cristy3ed852e2009-09-05 21:47:34 +00005736 if (LocaleCompare("stretch",option+1) == 0)
5737 {
cristybb503372010-05-27 20:51:26 +00005738 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005739 stretch;
5740
5741 if (*option == '+')
5742 break;
5743 i++;
cristybb503372010-05-27 20:51:26 +00005744 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005745 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005746 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005747 if (stretch < 0)
5748 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5749 argv[i]);
5750 break;
5751 }
5752 if (LocaleCompare("strip",option+1) == 0)
5753 break;
5754 if (LocaleCompare("stroke",option+1) == 0)
5755 {
5756 if (*option == '+')
5757 break;
5758 i++;
cristybb503372010-05-27 20:51:26 +00005759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005760 ThrowMogrifyException(OptionError,"MissingArgument",option);
5761 break;
5762 }
5763 if (LocaleCompare("strokewidth",option+1) == 0)
5764 {
5765 if (*option == '+')
5766 break;
5767 i++;
cristybb503372010-05-27 20:51:26 +00005768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005769 ThrowMogrifyException(OptionError,"MissingArgument",option);
5770 if (IsGeometry(argv[i]) == MagickFalse)
5771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5772 break;
5773 }
5774 if (LocaleCompare("style",option+1) == 0)
5775 {
cristybb503372010-05-27 20:51:26 +00005776 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005777 style;
5778
5779 if (*option == '+')
5780 break;
5781 i++;
cristybb503372010-05-27 20:51:26 +00005782 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005783 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005784 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005785 if (style < 0)
5786 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5787 argv[i]);
5788 break;
5789 }
cristyecb10ff2011-03-22 13:14:03 +00005790 if (LocaleCompare("swap",option+1) == 0)
5791 {
5792 if (*option == '+')
5793 break;
5794 i++;
5795 if (i == (ssize_t) (argc-1))
5796 ThrowMogrifyException(OptionError,"MissingArgument",option);
5797 if (IsGeometry(argv[i]) == MagickFalse)
5798 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5799 break;
5800 }
cristy3ed852e2009-09-05 21:47:34 +00005801 if (LocaleCompare("swirl",option+1) == 0)
5802 {
5803 if (*option == '+')
5804 break;
5805 i++;
cristybb503372010-05-27 20:51:26 +00005806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005807 ThrowMogrifyException(OptionError,"MissingArgument",option);
5808 if (IsGeometry(argv[i]) == MagickFalse)
5809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5810 break;
5811 }
cristyd9a29192010-10-16 16:49:53 +00005812 if (LocaleCompare("synchronize",option+1) == 0)
5813 break;
cristy3ed852e2009-09-05 21:47:34 +00005814 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5815 }
5816 case 't':
5817 {
5818 if (LocaleCompare("taint",option+1) == 0)
5819 break;
5820 if (LocaleCompare("texture",option+1) == 0)
5821 {
5822 if (*option == '+')
5823 break;
5824 i++;
cristybb503372010-05-27 20:51:26 +00005825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005826 ThrowMogrifyException(OptionError,"MissingArgument",option);
5827 break;
5828 }
5829 if (LocaleCompare("tile",option+1) == 0)
5830 {
5831 if (*option == '+')
5832 break;
5833 i++;
cristybb503372010-05-27 20:51:26 +00005834 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005835 ThrowMogrifyException(OptionError,"MissingArgument",option);
5836 break;
5837 }
5838 if (LocaleCompare("tile-offset",option+1) == 0)
5839 {
5840 if (*option == '+')
5841 break;
5842 i++;
cristybb503372010-05-27 20:51:26 +00005843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005844 ThrowMogrifyException(OptionError,"MissingArgument",option);
5845 if (IsGeometry(argv[i]) == MagickFalse)
5846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5847 break;
5848 }
5849 if (LocaleCompare("tint",option+1) == 0)
5850 {
5851 if (*option == '+')
5852 break;
5853 i++;
cristybb503372010-05-27 20:51:26 +00005854 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005855 ThrowMogrifyException(OptionError,"MissingArgument",option);
5856 if (IsGeometry(argv[i]) == MagickFalse)
5857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5858 break;
5859 }
5860 if (LocaleCompare("transform",option+1) == 0)
5861 break;
5862 if (LocaleCompare("transpose",option+1) == 0)
5863 break;
5864 if (LocaleCompare("transverse",option+1) == 0)
5865 break;
5866 if (LocaleCompare("threshold",option+1) == 0)
5867 {
5868 if (*option == '+')
5869 break;
5870 i++;
cristybb503372010-05-27 20:51:26 +00005871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005872 ThrowMogrifyException(OptionError,"MissingArgument",option);
5873 if (IsGeometry(argv[i]) == MagickFalse)
5874 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5875 break;
5876 }
5877 if (LocaleCompare("thumbnail",option+1) == 0)
5878 {
5879 if (*option == '+')
5880 break;
5881 i++;
cristybb503372010-05-27 20:51:26 +00005882 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005883 ThrowMogrifyException(OptionError,"MissingArgument",option);
5884 if (IsGeometry(argv[i]) == MagickFalse)
5885 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5886 break;
5887 }
5888 if (LocaleCompare("transparent",option+1) == 0)
5889 {
5890 i++;
cristybb503372010-05-27 20:51:26 +00005891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005892 ThrowMogrifyException(OptionError,"MissingArgument",option);
5893 break;
5894 }
5895 if (LocaleCompare("transparent-color",option+1) == 0)
5896 {
5897 if (*option == '+')
5898 break;
5899 i++;
cristybb503372010-05-27 20:51:26 +00005900 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005901 ThrowMogrifyException(OptionError,"MissingArgument",option);
5902 break;
5903 }
5904 if (LocaleCompare("treedepth",option+1) == 0)
5905 {
5906 if (*option == '+')
5907 break;
5908 i++;
cristybb503372010-05-27 20:51:26 +00005909 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005910 ThrowMogrifyException(OptionError,"MissingArgument",option);
5911 if (IsGeometry(argv[i]) == MagickFalse)
5912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5913 break;
5914 }
5915 if (LocaleCompare("trim",option+1) == 0)
5916 break;
5917 if (LocaleCompare("type",option+1) == 0)
5918 {
cristybb503372010-05-27 20:51:26 +00005919 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005920 type;
5921
5922 if (*option == '+')
5923 break;
5924 i++;
cristybb503372010-05-27 20:51:26 +00005925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005926 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005927 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005928 if (type < 0)
5929 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5930 argv[i]);
5931 break;
5932 }
5933 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5934 }
5935 case 'u':
5936 {
5937 if (LocaleCompare("undercolor",option+1) == 0)
5938 {
5939 if (*option == '+')
5940 break;
5941 i++;
cristybb503372010-05-27 20:51:26 +00005942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005943 ThrowMogrifyException(OptionError,"MissingArgument",option);
5944 break;
5945 }
5946 if (LocaleCompare("unique-colors",option+1) == 0)
5947 break;
5948 if (LocaleCompare("units",option+1) == 0)
5949 {
cristybb503372010-05-27 20:51:26 +00005950 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005951 units;
5952
5953 if (*option == '+')
5954 break;
5955 i++;
cristybb503372010-05-27 20:51:26 +00005956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005957 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005958 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005959 argv[i]);
5960 if (units < 0)
5961 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5962 argv[i]);
5963 break;
5964 }
5965 if (LocaleCompare("unsharp",option+1) == 0)
5966 {
5967 i++;
cristybb503372010-05-27 20:51:26 +00005968 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005969 ThrowMogrifyException(OptionError,"MissingArgument",option);
5970 if (IsGeometry(argv[i]) == MagickFalse)
5971 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5972 break;
5973 }
5974 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5975 }
5976 case 'v':
5977 {
5978 if (LocaleCompare("verbose",option+1) == 0)
5979 {
5980 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5981 break;
5982 }
5983 if ((LocaleCompare("version",option+1) == 0) ||
5984 (LocaleCompare("-version",option+1) == 0))
5985 {
cristyb51dff52011-05-19 16:55:47 +00005986 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005987 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005988 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5989 GetMagickCopyright());
5990 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5991 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005992 break;
5993 }
5994 if (LocaleCompare("view",option+1) == 0)
5995 {
5996 if (*option == '+')
5997 break;
5998 i++;
cristybb503372010-05-27 20:51:26 +00005999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006000 ThrowMogrifyException(OptionError,"MissingArgument",option);
6001 break;
6002 }
6003 if (LocaleCompare("vignette",option+1) == 0)
6004 {
6005 if (*option == '+')
6006 break;
6007 i++;
cristybb503372010-05-27 20:51:26 +00006008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006009 ThrowMogrifyException(OptionError,"MissingArgument",option);
6010 if (IsGeometry(argv[i]) == MagickFalse)
6011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6012 break;
6013 }
6014 if (LocaleCompare("virtual-pixel",option+1) == 0)
6015 {
cristybb503372010-05-27 20:51:26 +00006016 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006017 method;
6018
6019 if (*option == '+')
6020 break;
6021 i++;
cristybb503372010-05-27 20:51:26 +00006022 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006023 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006024 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006025 argv[i]);
6026 if (method < 0)
6027 ThrowMogrifyException(OptionError,
6028 "UnrecognizedVirtualPixelMethod",argv[i]);
6029 break;
6030 }
6031 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6032 }
6033 case 'w':
6034 {
6035 if (LocaleCompare("wave",option+1) == 0)
6036 {
6037 i++;
cristybb503372010-05-27 20:51:26 +00006038 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006039 ThrowMogrifyException(OptionError,"MissingArgument",option);
6040 if (IsGeometry(argv[i]) == MagickFalse)
6041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6042 break;
6043 }
6044 if (LocaleCompare("weight",option+1) == 0)
6045 {
6046 if (*option == '+')
6047 break;
6048 i++;
cristybb503372010-05-27 20:51:26 +00006049 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006050 ThrowMogrifyException(OptionError,"MissingArgument",option);
6051 break;
6052 }
6053 if (LocaleCompare("white-point",option+1) == 0)
6054 {
6055 if (*option == '+')
6056 break;
6057 i++;
cristybb503372010-05-27 20:51:26 +00006058 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006059 ThrowMogrifyException(OptionError,"MissingArgument",option);
6060 if (IsGeometry(argv[i]) == MagickFalse)
6061 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6062 break;
6063 }
6064 if (LocaleCompare("white-threshold",option+1) == 0)
6065 {
6066 if (*option == '+')
6067 break;
6068 i++;
cristybb503372010-05-27 20:51:26 +00006069 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006070 ThrowMogrifyException(OptionError,"MissingArgument",option);
6071 if (IsGeometry(argv[i]) == MagickFalse)
6072 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6073 break;
6074 }
6075 if (LocaleCompare("write",option+1) == 0)
6076 {
6077 i++;
cristybb503372010-05-27 20:51:26 +00006078 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006079 ThrowMogrifyException(OptionError,"MissingArgument",option);
6080 break;
6081 }
6082 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6083 }
6084 case '?':
6085 break;
6086 default:
6087 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6088 }
cristy042ee782011-04-22 18:48:30 +00006089 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6090 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006091 if (fire != MagickFalse)
6092 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6093 }
6094 if (k != 0)
6095 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006096 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006097 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6098 DestroyMogrify();
6099 return(status != 0 ? MagickTrue : MagickFalse);
6100}
6101
6102/*
6103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6104% %
6105% %
6106% %
6107+ M o g r i f y I m a g e I n f o %
6108% %
6109% %
6110% %
6111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6112%
6113% MogrifyImageInfo() applies image processing settings to the image as
6114% prescribed by command line options.
6115%
6116% The format of the MogrifyImageInfo method is:
6117%
6118% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6119% const char **argv,ExceptionInfo *exception)
6120%
6121% A description of each parameter follows:
6122%
6123% o image_info: the image info..
6124%
6125% o argc: Specifies a pointer to an integer describing the number of
6126% elements in the argument vector.
6127%
6128% o argv: Specifies a pointer to a text array containing the command line
6129% arguments.
6130%
6131% o exception: return any errors or warnings in this structure.
6132%
6133*/
6134WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6135 const int argc,const char **argv,ExceptionInfo *exception)
6136{
6137 const char
6138 *option;
6139
6140 GeometryInfo
6141 geometry_info;
6142
cristybb503372010-05-27 20:51:26 +00006143 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006144 count;
6145
cristybb503372010-05-27 20:51:26 +00006146 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006147 i;
6148
6149 /*
6150 Initialize method variables.
6151 */
6152 assert(image_info != (ImageInfo *) NULL);
6153 assert(image_info->signature == MagickSignature);
6154 if (image_info->debug != MagickFalse)
6155 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6156 image_info->filename);
6157 if (argc < 0)
6158 return(MagickTrue);
6159 /*
6160 Set the image settings.
6161 */
cristybb503372010-05-27 20:51:26 +00006162 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006163 {
6164 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006165 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006166 continue;
cristy042ee782011-04-22 18:48:30 +00006167 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006168 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006169 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006170 break;
6171 switch (*(option+1))
6172 {
6173 case 'a':
6174 {
6175 if (LocaleCompare("adjoin",option+1) == 0)
6176 {
6177 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6178 break;
6179 }
6180 if (LocaleCompare("antialias",option+1) == 0)
6181 {
6182 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6183 break;
6184 }
cristy3ed852e2009-09-05 21:47:34 +00006185 if (LocaleCompare("authenticate",option+1) == 0)
6186 {
6187 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006188 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006189 else
anthony1afdc7a2011-10-05 11:54:28 +00006190 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006191 break;
6192 }
6193 break;
6194 }
6195 case 'b':
6196 {
6197 if (LocaleCompare("background",option+1) == 0)
6198 {
6199 if (*option == '+')
6200 {
6201 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006202 (void) QueryColorCompliance(MogrifyBackgroundColor,
6203 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006204 break;
6205 }
6206 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006207 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6208 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006209 break;
6210 }
6211 if (LocaleCompare("bias",option+1) == 0)
6212 {
6213 if (*option == '+')
6214 {
6215 (void) SetImageOption(image_info,option+1,"0.0");
6216 break;
6217 }
6218 (void) SetImageOption(image_info,option+1,argv[i+1]);
6219 break;
6220 }
6221 if (LocaleCompare("black-point-compensation",option+1) == 0)
6222 {
6223 if (*option == '+')
6224 {
6225 (void) SetImageOption(image_info,option+1,"false");
6226 break;
6227 }
6228 (void) SetImageOption(image_info,option+1,"true");
6229 break;
6230 }
6231 if (LocaleCompare("blue-primary",option+1) == 0)
6232 {
6233 if (*option == '+')
6234 {
6235 (void) SetImageOption(image_info,option+1,"0.0");
6236 break;
6237 }
6238 (void) SetImageOption(image_info,option+1,argv[i+1]);
6239 break;
6240 }
6241 if (LocaleCompare("bordercolor",option+1) == 0)
6242 {
6243 if (*option == '+')
6244 {
6245 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006246 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006247 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006248 break;
6249 }
cristy9950d572011-10-01 18:22:35 +00006250 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6251 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006252 (void) SetImageOption(image_info,option+1,argv[i+1]);
6253 break;
6254 }
6255 if (LocaleCompare("box",option+1) == 0)
6256 {
6257 if (*option == '+')
6258 {
6259 (void) SetImageOption(image_info,"undercolor","none");
6260 break;
6261 }
6262 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6263 break;
6264 }
6265 break;
6266 }
6267 case 'c':
6268 {
6269 if (LocaleCompare("cache",option+1) == 0)
6270 {
6271 MagickSizeType
6272 limit;
6273
6274 limit=MagickResourceInfinity;
6275 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006276 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6277 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006278 (void) SetMagickResourceLimit(MemoryResource,limit);
6279 (void) SetMagickResourceLimit(MapResource,2*limit);
6280 break;
6281 }
6282 if (LocaleCompare("caption",option+1) == 0)
6283 {
6284 if (*option == '+')
6285 {
6286 (void) DeleteImageOption(image_info,option+1);
6287 break;
6288 }
6289 (void) SetImageOption(image_info,option+1,argv[i+1]);
6290 break;
6291 }
6292 if (LocaleCompare("channel",option+1) == 0)
6293 {
6294 if (*option == '+')
6295 {
6296 image_info->channel=DefaultChannels;
6297 break;
6298 }
6299 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6300 break;
6301 }
cristy3ed852e2009-09-05 21:47:34 +00006302 if (LocaleCompare("colorspace",option+1) == 0)
6303 {
6304 if (*option == '+')
6305 {
6306 image_info->colorspace=UndefinedColorspace;
6307 (void) SetImageOption(image_info,option+1,"undefined");
6308 break;
6309 }
cristy042ee782011-04-22 18:48:30 +00006310 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006311 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6312 (void) SetImageOption(image_info,option+1,argv[i+1]);
6313 break;
6314 }
cristy3ed852e2009-09-05 21:47:34 +00006315 if (LocaleCompare("comment",option+1) == 0)
6316 {
6317 if (*option == '+')
6318 {
6319 (void) DeleteImageOption(image_info,option+1);
6320 break;
6321 }
6322 (void) SetImageOption(image_info,option+1,argv[i+1]);
6323 break;
6324 }
6325 if (LocaleCompare("compose",option+1) == 0)
6326 {
6327 if (*option == '+')
6328 {
6329 (void) SetImageOption(image_info,option+1,"undefined");
6330 break;
6331 }
6332 (void) SetImageOption(image_info,option+1,argv[i+1]);
6333 break;
6334 }
6335 if (LocaleCompare("compress",option+1) == 0)
6336 {
6337 if (*option == '+')
6338 {
6339 image_info->compression=UndefinedCompression;
6340 (void) SetImageOption(image_info,option+1,"undefined");
6341 break;
6342 }
cristy042ee782011-04-22 18:48:30 +00006343 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006344 MagickCompressOptions,MagickFalse,argv[i+1]);
6345 (void) SetImageOption(image_info,option+1,argv[i+1]);
6346 break;
6347 }
6348 break;
6349 }
6350 case 'd':
6351 {
6352 if (LocaleCompare("debug",option+1) == 0)
6353 {
6354 if (*option == '+')
6355 (void) SetLogEventMask("none");
6356 else
6357 (void) SetLogEventMask(argv[i+1]);
6358 image_info->debug=IsEventLogging();
6359 break;
6360 }
6361 if (LocaleCompare("define",option+1) == 0)
6362 {
6363 if (*option == '+')
6364 {
6365 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6366 (void) DeleteImageRegistry(argv[i+1]+9);
6367 else
6368 (void) DeleteImageOption(image_info,argv[i+1]);
6369 break;
6370 }
6371 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6372 {
6373 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6374 exception);
6375 break;
6376 }
6377 (void) DefineImageOption(image_info,argv[i+1]);
6378 break;
6379 }
6380 if (LocaleCompare("delay",option+1) == 0)
6381 {
6382 if (*option == '+')
6383 {
6384 (void) SetImageOption(image_info,option+1,"0");
6385 break;
6386 }
6387 (void) SetImageOption(image_info,option+1,argv[i+1]);
6388 break;
6389 }
6390 if (LocaleCompare("density",option+1) == 0)
6391 {
6392 /*
6393 Set image density.
6394 */
6395 if (*option == '+')
6396 {
6397 if (image_info->density != (char *) NULL)
6398 image_info->density=DestroyString(image_info->density);
6399 (void) SetImageOption(image_info,option+1,"72");
6400 break;
6401 }
6402 (void) CloneString(&image_info->density,argv[i+1]);
6403 (void) SetImageOption(image_info,option+1,argv[i+1]);
6404 break;
6405 }
6406 if (LocaleCompare("depth",option+1) == 0)
6407 {
6408 if (*option == '+')
6409 {
6410 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6411 break;
6412 }
cristye27293e2009-12-18 02:53:20 +00006413 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006414 break;
6415 }
cristyc9b12952010-03-28 01:12:28 +00006416 if (LocaleCompare("direction",option+1) == 0)
6417 {
6418 if (*option == '+')
6419 {
6420 (void) SetImageOption(image_info,option+1,"undefined");
6421 break;
6422 }
6423 (void) SetImageOption(image_info,option+1,argv[i+1]);
6424 break;
6425 }
cristy3ed852e2009-09-05 21:47:34 +00006426 if (LocaleCompare("display",option+1) == 0)
6427 {
6428 if (*option == '+')
6429 {
6430 if (image_info->server_name != (char *) NULL)
6431 image_info->server_name=DestroyString(
6432 image_info->server_name);
6433 break;
6434 }
6435 (void) CloneString(&image_info->server_name,argv[i+1]);
6436 break;
6437 }
6438 if (LocaleCompare("dispose",option+1) == 0)
6439 {
6440 if (*option == '+')
6441 {
6442 (void) SetImageOption(image_info,option+1,"undefined");
6443 break;
6444 }
6445 (void) SetImageOption(image_info,option+1,argv[i+1]);
6446 break;
6447 }
6448 if (LocaleCompare("dither",option+1) == 0)
6449 {
6450 if (*option == '+')
6451 {
6452 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006453 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006454 break;
6455 }
6456 (void) SetImageOption(image_info,option+1,argv[i+1]);
6457 image_info->dither=MagickTrue;
6458 break;
6459 }
6460 break;
6461 }
6462 case 'e':
6463 {
6464 if (LocaleCompare("encoding",option+1) == 0)
6465 {
6466 if (*option == '+')
6467 {
6468 (void) SetImageOption(image_info,option+1,"undefined");
6469 break;
6470 }
6471 (void) SetImageOption(image_info,option+1,argv[i+1]);
6472 break;
6473 }
6474 if (LocaleCompare("endian",option+1) == 0)
6475 {
6476 if (*option == '+')
6477 {
6478 image_info->endian=UndefinedEndian;
6479 (void) SetImageOption(image_info,option+1,"undefined");
6480 break;
6481 }
cristy042ee782011-04-22 18:48:30 +00006482 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006483 MagickEndianOptions,MagickFalse,argv[i+1]);
6484 (void) SetImageOption(image_info,option+1,argv[i+1]);
6485 break;
6486 }
6487 if (LocaleCompare("extract",option+1) == 0)
6488 {
6489 /*
6490 Set image extract geometry.
6491 */
6492 if (*option == '+')
6493 {
6494 if (image_info->extract != (char *) NULL)
6495 image_info->extract=DestroyString(image_info->extract);
6496 break;
6497 }
6498 (void) CloneString(&image_info->extract,argv[i+1]);
6499 break;
6500 }
6501 break;
6502 }
6503 case 'f':
6504 {
6505 if (LocaleCompare("fill",option+1) == 0)
6506 {
6507 if (*option == '+')
6508 {
6509 (void) SetImageOption(image_info,option+1,"none");
6510 break;
6511 }
6512 (void) SetImageOption(image_info,option+1,argv[i+1]);
6513 break;
6514 }
6515 if (LocaleCompare("filter",option+1) == 0)
6516 {
6517 if (*option == '+')
6518 {
6519 (void) SetImageOption(image_info,option+1,"undefined");
6520 break;
6521 }
6522 (void) SetImageOption(image_info,option+1,argv[i+1]);
6523 break;
6524 }
6525 if (LocaleCompare("font",option+1) == 0)
6526 {
6527 if (*option == '+')
6528 {
6529 if (image_info->font != (char *) NULL)
6530 image_info->font=DestroyString(image_info->font);
6531 break;
6532 }
6533 (void) CloneString(&image_info->font,argv[i+1]);
6534 break;
6535 }
6536 if (LocaleCompare("format",option+1) == 0)
6537 {
6538 register const char
6539 *q;
6540
6541 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006542 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006543 image_info->ping=MagickFalse;
6544 (void) SetImageOption(image_info,option+1,argv[i+1]);
6545 break;
6546 }
6547 if (LocaleCompare("fuzz",option+1) == 0)
6548 {
6549 if (*option == '+')
6550 {
6551 image_info->fuzz=0.0;
6552 (void) SetImageOption(image_info,option+1,"0");
6553 break;
6554 }
cristydbdd0e32011-11-04 23:29:40 +00006555 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6556 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006557 (void) SetImageOption(image_info,option+1,argv[i+1]);
6558 break;
6559 }
6560 break;
6561 }
6562 case 'g':
6563 {
6564 if (LocaleCompare("gravity",option+1) == 0)
6565 {
6566 if (*option == '+')
6567 {
6568 (void) SetImageOption(image_info,option+1,"undefined");
6569 break;
6570 }
6571 (void) SetImageOption(image_info,option+1,argv[i+1]);
6572 break;
6573 }
6574 if (LocaleCompare("green-primary",option+1) == 0)
6575 {
6576 if (*option == '+')
6577 {
6578 (void) SetImageOption(image_info,option+1,"0.0");
6579 break;
6580 }
6581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
6584 break;
6585 }
6586 case 'i':
6587 {
6588 if (LocaleCompare("intent",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 (void) SetImageOption(image_info,option+1,"undefined");
6593 break;
6594 }
6595 (void) SetImageOption(image_info,option+1,argv[i+1]);
6596 break;
6597 }
6598 if (LocaleCompare("interlace",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 image_info->interlace=UndefinedInterlace;
6603 (void) SetImageOption(image_info,option+1,"undefined");
6604 break;
6605 }
cristy042ee782011-04-22 18:48:30 +00006606 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006607 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6608 (void) SetImageOption(image_info,option+1,argv[i+1]);
6609 break;
6610 }
cristyb32b90a2009-09-07 21:45:48 +00006611 if (LocaleCompare("interline-spacing",option+1) == 0)
6612 {
6613 if (*option == '+')
6614 {
6615 (void) SetImageOption(image_info,option+1,"undefined");
6616 break;
6617 }
6618 (void) SetImageOption(image_info,option+1,argv[i+1]);
6619 break;
6620 }
cristy3ed852e2009-09-05 21:47:34 +00006621 if (LocaleCompare("interpolate",option+1) == 0)
6622 {
6623 if (*option == '+')
6624 {
6625 (void) SetImageOption(image_info,option+1,"undefined");
6626 break;
6627 }
6628 (void) SetImageOption(image_info,option+1,argv[i+1]);
6629 break;
6630 }
6631 if (LocaleCompare("interword-spacing",option+1) == 0)
6632 {
6633 if (*option == '+')
6634 {
6635 (void) SetImageOption(image_info,option+1,"undefined");
6636 break;
6637 }
6638 (void) SetImageOption(image_info,option+1,argv[i+1]);
6639 break;
6640 }
6641 break;
6642 }
6643 case 'k':
6644 {
6645 if (LocaleCompare("kerning",option+1) == 0)
6646 {
6647 if (*option == '+')
6648 {
6649 (void) SetImageOption(image_info,option+1,"undefined");
6650 break;
6651 }
6652 (void) SetImageOption(image_info,option+1,argv[i+1]);
6653 break;
6654 }
6655 break;
6656 }
6657 case 'l':
6658 {
6659 if (LocaleCompare("label",option+1) == 0)
6660 {
6661 if (*option == '+')
6662 {
6663 (void) DeleteImageOption(image_info,option+1);
6664 break;
6665 }
6666 (void) SetImageOption(image_info,option+1,argv[i+1]);
6667 break;
6668 }
6669 if (LocaleCompare("limit",option+1) == 0)
6670 {
6671 MagickSizeType
6672 limit;
6673
6674 ResourceType
6675 type;
6676
6677 if (*option == '+')
6678 break;
cristy042ee782011-04-22 18:48:30 +00006679 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006680 MagickFalse,argv[i+1]);
6681 limit=MagickResourceInfinity;
6682 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006683 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006684 (void) SetMagickResourceLimit(type,limit);
6685 break;
6686 }
6687 if (LocaleCompare("list",option+1) == 0)
6688 {
cristybb503372010-05-27 20:51:26 +00006689 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006690 list;
6691
6692 /*
6693 Display configuration list.
6694 */
cristy042ee782011-04-22 18:48:30 +00006695 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006696 switch (list)
6697 {
6698 case MagickCoderOptions:
6699 {
6700 (void) ListCoderInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickColorOptions:
6704 {
6705 (void) ListColorInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickConfigureOptions:
6709 {
6710 (void) ListConfigureInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickDelegateOptions:
6714 {
6715 (void) ListDelegateInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickFontOptions:
6719 {
6720 (void) ListTypeInfo((FILE *) NULL,exception);
6721 break;
6722 }
6723 case MagickFormatOptions:
6724 {
6725 (void) ListMagickInfo((FILE *) NULL,exception);
6726 break;
6727 }
6728 case MagickLocaleOptions:
6729 {
6730 (void) ListLocaleInfo((FILE *) NULL,exception);
6731 break;
6732 }
6733 case MagickLogOptions:
6734 {
6735 (void) ListLogInfo((FILE *) NULL,exception);
6736 break;
6737 }
6738 case MagickMagicOptions:
6739 {
6740 (void) ListMagicInfo((FILE *) NULL,exception);
6741 break;
6742 }
6743 case MagickMimeOptions:
6744 {
6745 (void) ListMimeInfo((FILE *) NULL,exception);
6746 break;
6747 }
6748 case MagickModuleOptions:
6749 {
6750 (void) ListModuleInfo((FILE *) NULL,exception);
6751 break;
6752 }
6753 case MagickPolicyOptions:
6754 {
6755 (void) ListPolicyInfo((FILE *) NULL,exception);
6756 break;
6757 }
6758 case MagickResourceOptions:
6759 {
6760 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6761 break;
6762 }
6763 case MagickThresholdOptions:
6764 {
6765 (void) ListThresholdMaps((FILE *) NULL,exception);
6766 break;
6767 }
6768 default:
6769 {
cristy042ee782011-04-22 18:48:30 +00006770 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006771 exception);
6772 break;
6773 }
6774 }
cristyaeb2cbc2010-05-07 13:28:58 +00006775 break;
cristy3ed852e2009-09-05 21:47:34 +00006776 }
6777 if (LocaleCompare("log",option+1) == 0)
6778 {
6779 if (*option == '+')
6780 break;
6781 (void) SetLogFormat(argv[i+1]);
6782 break;
6783 }
6784 if (LocaleCompare("loop",option+1) == 0)
6785 {
6786 if (*option == '+')
6787 {
6788 (void) SetImageOption(image_info,option+1,"0");
6789 break;
6790 }
6791 (void) SetImageOption(image_info,option+1,argv[i+1]);
6792 break;
6793 }
6794 break;
6795 }
6796 case 'm':
6797 {
6798 if (LocaleCompare("matte",option+1) == 0)
6799 {
6800 if (*option == '+')
6801 {
6802 (void) SetImageOption(image_info,option+1,"false");
6803 break;
6804 }
6805 (void) SetImageOption(image_info,option+1,"true");
6806 break;
6807 }
6808 if (LocaleCompare("mattecolor",option+1) == 0)
6809 {
6810 if (*option == '+')
6811 {
6812 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006813 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006814 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006815 break;
6816 }
6817 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006818 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6819 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006820 break;
6821 }
6822 if (LocaleCompare("monitor",option+1) == 0)
6823 {
6824 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6825 (void *) NULL);
6826 break;
6827 }
6828 if (LocaleCompare("monochrome",option+1) == 0)
6829 {
6830 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6831 break;
6832 }
6833 break;
6834 }
6835 case 'o':
6836 {
6837 if (LocaleCompare("orient",option+1) == 0)
6838 {
6839 if (*option == '+')
6840 {
6841 image_info->orientation=UndefinedOrientation;
6842 (void) SetImageOption(image_info,option+1,"undefined");
6843 break;
6844 }
cristy042ee782011-04-22 18:48:30 +00006845 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006846 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006847 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006848 break;
6849 }
6850 }
6851 case 'p':
6852 {
6853 if (LocaleCompare("page",option+1) == 0)
6854 {
6855 char
6856 *canonical_page,
6857 page[MaxTextExtent];
6858
6859 const char
6860 *image_option;
6861
6862 MagickStatusType
6863 flags;
6864
6865 RectangleInfo
6866 geometry;
6867
6868 if (*option == '+')
6869 {
6870 (void) DeleteImageOption(image_info,option+1);
6871 (void) CloneString(&image_info->page,(char *) NULL);
6872 break;
6873 }
6874 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6875 image_option=GetImageOption(image_info,"page");
6876 if (image_option != (const char *) NULL)
6877 flags=ParseAbsoluteGeometry(image_option,&geometry);
6878 canonical_page=GetPageGeometry(argv[i+1]);
6879 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6880 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006881 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006882 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006883 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006884 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006885 (unsigned long) geometry.width,(unsigned long) geometry.height,
6886 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006887 (void) SetImageOption(image_info,option+1,page);
6888 (void) CloneString(&image_info->page,page);
6889 break;
6890 }
6891 if (LocaleCompare("pen",option+1) == 0)
6892 {
6893 if (*option == '+')
6894 {
6895 (void) SetImageOption(image_info,option+1,"none");
6896 break;
6897 }
6898 (void) SetImageOption(image_info,option+1,argv[i+1]);
6899 break;
6900 }
6901 if (LocaleCompare("ping",option+1) == 0)
6902 {
6903 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6904 break;
6905 }
6906 if (LocaleCompare("pointsize",option+1) == 0)
6907 {
6908 if (*option == '+')
6909 geometry_info.rho=0.0;
6910 else
6911 (void) ParseGeometry(argv[i+1],&geometry_info);
6912 image_info->pointsize=geometry_info.rho;
6913 break;
6914 }
cristye7f51092010-01-17 00:39:37 +00006915 if (LocaleCompare("precision",option+1) == 0)
6916 {
cristybf2766a2010-01-17 03:33:23 +00006917 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006918 break;
6919 }
cristy3ed852e2009-09-05 21:47:34 +00006920 if (LocaleCompare("preview",option+1) == 0)
6921 {
6922 /*
6923 Preview image.
6924 */
6925 if (*option == '+')
6926 {
6927 image_info->preview_type=UndefinedPreview;
6928 break;
6929 }
cristy042ee782011-04-22 18:48:30 +00006930 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006931 MagickPreviewOptions,MagickFalse,argv[i+1]);
6932 break;
6933 }
6934 break;
6935 }
6936 case 'q':
6937 {
6938 if (LocaleCompare("quality",option+1) == 0)
6939 {
6940 /*
6941 Set image compression quality.
6942 */
6943 if (*option == '+')
6944 {
6945 image_info->quality=UndefinedCompressionQuality;
6946 (void) SetImageOption(image_info,option+1,"0");
6947 break;
6948 }
cristye27293e2009-12-18 02:53:20 +00006949 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006950 (void) SetImageOption(image_info,option+1,argv[i+1]);
6951 break;
6952 }
6953 if (LocaleCompare("quiet",option+1) == 0)
6954 {
6955 static WarningHandler
6956 warning_handler = (WarningHandler) NULL;
6957
6958 if (*option == '+')
6959 {
6960 /*
6961 Restore error or warning messages.
6962 */
6963 warning_handler=SetWarningHandler(warning_handler);
6964 break;
6965 }
6966 /*
6967 Suppress error or warning messages.
6968 */
6969 warning_handler=SetWarningHandler((WarningHandler) NULL);
6970 break;
6971 }
6972 break;
6973 }
6974 case 'r':
6975 {
6976 if (LocaleCompare("red-primary",option+1) == 0)
6977 {
6978 if (*option == '+')
6979 {
6980 (void) SetImageOption(image_info,option+1,"0.0");
6981 break;
6982 }
6983 (void) SetImageOption(image_info,option+1,argv[i+1]);
6984 break;
6985 }
6986 break;
6987 }
6988 case 's':
6989 {
6990 if (LocaleCompare("sampling-factor",option+1) == 0)
6991 {
6992 /*
6993 Set image sampling factor.
6994 */
6995 if (*option == '+')
6996 {
6997 if (image_info->sampling_factor != (char *) NULL)
6998 image_info->sampling_factor=DestroyString(
6999 image_info->sampling_factor);
7000 break;
7001 }
7002 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7003 break;
7004 }
7005 if (LocaleCompare("scene",option+1) == 0)
7006 {
7007 /*
7008 Set image scene.
7009 */
7010 if (*option == '+')
7011 {
7012 image_info->scene=0;
7013 (void) SetImageOption(image_info,option+1,"0");
7014 break;
7015 }
cristye27293e2009-12-18 02:53:20 +00007016 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007017 (void) SetImageOption(image_info,option+1,argv[i+1]);
7018 break;
7019 }
7020 if (LocaleCompare("seed",option+1) == 0)
7021 {
cristybb503372010-05-27 20:51:26 +00007022 size_t
cristy3ed852e2009-09-05 21:47:34 +00007023 seed;
7024
7025 if (*option == '+')
7026 {
cristybb503372010-05-27 20:51:26 +00007027 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007028 SeedPseudoRandomGenerator(seed);
7029 break;
7030 }
cristye27293e2009-12-18 02:53:20 +00007031 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007032 SeedPseudoRandomGenerator(seed);
7033 break;
7034 }
7035 if (LocaleCompare("size",option+1) == 0)
7036 {
7037 if (*option == '+')
7038 {
7039 if (image_info->size != (char *) NULL)
7040 image_info->size=DestroyString(image_info->size);
7041 break;
7042 }
7043 (void) CloneString(&image_info->size,argv[i+1]);
7044 break;
7045 }
7046 if (LocaleCompare("stroke",option+1) == 0)
7047 {
7048 if (*option == '+')
7049 {
7050 (void) SetImageOption(image_info,option+1,"none");
7051 break;
7052 }
7053 (void) SetImageOption(image_info,option+1,argv[i+1]);
7054 break;
7055 }
7056 if (LocaleCompare("strokewidth",option+1) == 0)
7057 {
7058 if (*option == '+')
7059 {
7060 (void) SetImageOption(image_info,option+1,"0");
7061 break;
7062 }
7063 (void) SetImageOption(image_info,option+1,argv[i+1]);
7064 break;
7065 }
cristyd9a29192010-10-16 16:49:53 +00007066 if (LocaleCompare("synchronize",option+1) == 0)
7067 {
7068 if (*option == '+')
7069 {
7070 image_info->synchronize=MagickFalse;
7071 break;
7072 }
7073 image_info->synchronize=MagickTrue;
7074 break;
7075 }
cristy3ed852e2009-09-05 21:47:34 +00007076 break;
7077 }
7078 case 't':
7079 {
7080 if (LocaleCompare("taint",option+1) == 0)
7081 {
7082 if (*option == '+')
7083 {
7084 (void) SetImageOption(image_info,option+1,"false");
7085 break;
7086 }
7087 (void) SetImageOption(image_info,option+1,"true");
7088 break;
7089 }
7090 if (LocaleCompare("texture",option+1) == 0)
7091 {
7092 if (*option == '+')
7093 {
7094 if (image_info->texture != (char *) NULL)
7095 image_info->texture=DestroyString(image_info->texture);
7096 break;
7097 }
7098 (void) CloneString(&image_info->texture,argv[i+1]);
7099 break;
7100 }
7101 if (LocaleCompare("tile-offset",option+1) == 0)
7102 {
7103 if (*option == '+')
7104 {
7105 (void) SetImageOption(image_info,option+1,"0");
7106 break;
7107 }
7108 (void) SetImageOption(image_info,option+1,argv[i+1]);
7109 break;
7110 }
7111 if (LocaleCompare("transparent-color",option+1) == 0)
7112 {
7113 if (*option == '+')
7114 {
cristy9950d572011-10-01 18:22:35 +00007115 (void) QueryColorCompliance("none",AllCompliance,
7116 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007117 (void) SetImageOption(image_info,option+1,"none");
7118 break;
7119 }
cristy9950d572011-10-01 18:22:35 +00007120 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7121 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007122 (void) SetImageOption(image_info,option+1,argv[i+1]);
7123 break;
7124 }
7125 if (LocaleCompare("type",option+1) == 0)
7126 {
7127 if (*option == '+')
7128 {
cristy5f1c1ff2010-12-23 21:38:06 +00007129 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007130 (void) SetImageOption(image_info,option+1,"undefined");
7131 break;
7132 }
cristy042ee782011-04-22 18:48:30 +00007133 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007134 MagickFalse,argv[i+1]);
7135 (void) SetImageOption(image_info,option+1,argv[i+1]);
7136 break;
7137 }
7138 break;
7139 }
7140 case 'u':
7141 {
7142 if (LocaleCompare("undercolor",option+1) == 0)
7143 {
7144 if (*option == '+')
7145 {
7146 (void) DeleteImageOption(image_info,option+1);
7147 break;
7148 }
7149 (void) SetImageOption(image_info,option+1,argv[i+1]);
7150 break;
7151 }
7152 if (LocaleCompare("units",option+1) == 0)
7153 {
7154 if (*option == '+')
7155 {
7156 image_info->units=UndefinedResolution;
7157 (void) SetImageOption(image_info,option+1,"undefined");
7158 break;
7159 }
cristy042ee782011-04-22 18:48:30 +00007160 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007161 MagickResolutionOptions,MagickFalse,argv[i+1]);
7162 (void) SetImageOption(image_info,option+1,argv[i+1]);
7163 break;
7164 }
7165 break;
7166 }
7167 case 'v':
7168 {
7169 if (LocaleCompare("verbose",option+1) == 0)
7170 {
7171 if (*option == '+')
7172 {
7173 image_info->verbose=MagickFalse;
7174 break;
7175 }
7176 image_info->verbose=MagickTrue;
7177 image_info->ping=MagickFalse;
7178 break;
7179 }
7180 if (LocaleCompare("view",option+1) == 0)
7181 {
7182 if (*option == '+')
7183 {
7184 if (image_info->view != (char *) NULL)
7185 image_info->view=DestroyString(image_info->view);
7186 break;
7187 }
7188 (void) CloneString(&image_info->view,argv[i+1]);
7189 break;
7190 }
7191 if (LocaleCompare("virtual-pixel",option+1) == 0)
7192 {
7193 if (*option == '+')
7194 {
7195 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7196 (void) SetImageOption(image_info,option+1,"undefined");
7197 break;
7198 }
7199 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007200 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007201 argv[i+1]);
7202 (void) SetImageOption(image_info,option+1,argv[i+1]);
7203 break;
7204 }
7205 break;
7206 }
7207 case 'w':
7208 {
7209 if (LocaleCompare("white-point",option+1) == 0)
7210 {
7211 if (*option == '+')
7212 {
7213 (void) SetImageOption(image_info,option+1,"0.0");
7214 break;
7215 }
7216 (void) SetImageOption(image_info,option+1,argv[i+1]);
7217 break;
7218 }
7219 break;
7220 }
7221 default:
7222 break;
7223 }
7224 i+=count;
7225 }
7226 return(MagickTrue);
7227}
7228
7229/*
7230%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7231% %
7232% %
7233% %
7234+ M o g r i f y I m a g e L i s t %
7235% %
7236% %
7237% %
7238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7239%
7240% MogrifyImageList() applies any command line options that might affect the
7241% entire image list (e.g. -append, -coalesce, etc.).
7242%
7243% The format of the MogrifyImage method is:
7244%
7245% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7246% const char **argv,Image **images,ExceptionInfo *exception)
7247%
7248% A description of each parameter follows:
7249%
7250% o image_info: the image info..
7251%
7252% o argc: Specifies a pointer to an integer describing the number of
7253% elements in the argument vector.
7254%
7255% o argv: Specifies a pointer to a text array containing the command line
7256% arguments.
7257%
anthonye9c27192011-03-27 08:07:06 +00007258% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007259%
7260% o exception: return any errors or warnings in this structure.
7261%
7262*/
7263WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7264 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7265{
cristy3ed852e2009-09-05 21:47:34 +00007266 const char
7267 *option;
7268
cristy6b3da3a2010-06-20 02:21:46 +00007269 ImageInfo
7270 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007271
7272 MagickStatusType
7273 status;
7274
cristy28474bf2011-09-11 23:32:52 +00007275 PixelInterpolateMethod
7276 interpolate_method;
7277
cristy3ed852e2009-09-05 21:47:34 +00007278 QuantizeInfo
7279 *quantize_info;
7280
cristybb503372010-05-27 20:51:26 +00007281 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007282 i;
7283
cristy6b3da3a2010-06-20 02:21:46 +00007284 ssize_t
7285 count,
7286 index;
7287
cristy3ed852e2009-09-05 21:47:34 +00007288 /*
7289 Apply options to the image list.
7290 */
7291 assert(image_info != (ImageInfo *) NULL);
7292 assert(image_info->signature == MagickSignature);
7293 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007294 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007295 assert((*images)->signature == MagickSignature);
7296 if ((*images)->debug != MagickFalse)
7297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7298 (*images)->filename);
7299 if ((argc <= 0) || (*argv == (char *) NULL))
7300 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007301 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007302 mogrify_info=CloneImageInfo(image_info);
7303 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007304 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007305 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007306 {
cristy74fe8f12009-10-03 19:09:01 +00007307 if (*images == (Image *) NULL)
7308 break;
cristy3ed852e2009-09-05 21:47:34 +00007309 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007310 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007311 continue;
cristy042ee782011-04-22 18:48:30 +00007312 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007313 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007314 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007315 break;
cristy6b3da3a2010-06-20 02:21:46 +00007316 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007317 switch (*(option+1))
7318 {
7319 case 'a':
7320 {
7321 if (LocaleCompare("affinity",option+1) == 0)
7322 {
cristy6fccee12011-10-20 18:43:18 +00007323 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007324 if (*option == '+')
7325 {
cristy018f07f2011-09-04 21:15:19 +00007326 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7327 exception);
cristy3ed852e2009-09-05 21:47:34 +00007328 break;
7329 }
7330 i++;
7331 break;
7332 }
7333 if (LocaleCompare("append",option+1) == 0)
7334 {
7335 Image
7336 *append_image;
7337
cristy6fccee12011-10-20 18:43:18 +00007338 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007339 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7340 MagickFalse,exception);
7341 if (append_image == (Image *) NULL)
7342 {
7343 status=MagickFalse;
7344 break;
7345 }
7346 *images=DestroyImageList(*images);
7347 *images=append_image;
7348 break;
7349 }
7350 if (LocaleCompare("average",option+1) == 0)
7351 {
7352 Image
7353 *average_image;
7354
cristyd18ae7c2010-03-07 17:39:52 +00007355 /*
7356 Average an image sequence (deprecated).
7357 */
cristy6fccee12011-10-20 18:43:18 +00007358 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007359 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7360 exception);
cristy3ed852e2009-09-05 21:47:34 +00007361 if (average_image == (Image *) NULL)
7362 {
7363 status=MagickFalse;
7364 break;
7365 }
7366 *images=DestroyImageList(*images);
7367 *images=average_image;
7368 break;
7369 }
7370 break;
7371 }
7372 case 'c':
7373 {
7374 if (LocaleCompare("channel",option+1) == 0)
7375 {
cristyf4ad9df2011-07-08 16:49:03 +00007376 ChannelType
7377 channel;
7378
cristy3ed852e2009-09-05 21:47:34 +00007379 if (*option == '+')
7380 {
7381 channel=DefaultChannels;
7382 break;
7383 }
7384 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00007385 SetPixelChannelMapMask(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007386 break;
7387 }
7388 if (LocaleCompare("clut",option+1) == 0)
7389 {
7390 Image
7391 *clut_image,
7392 *image;
7393
cristy6fccee12011-10-20 18:43:18 +00007394 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007395 image=RemoveFirstImageFromList(images);
7396 clut_image=RemoveFirstImageFromList(images);
7397 if (clut_image == (Image *) NULL)
7398 {
7399 status=MagickFalse;
7400 break;
7401 }
cristy28474bf2011-09-11 23:32:52 +00007402 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007403 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007404 *images=DestroyImageList(*images);
7405 *images=image;
7406 break;
7407 }
7408 if (LocaleCompare("coalesce",option+1) == 0)
7409 {
7410 Image
7411 *coalesce_image;
7412
cristy6fccee12011-10-20 18:43:18 +00007413 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007414 coalesce_image=CoalesceImages(*images,exception);
7415 if (coalesce_image == (Image *) NULL)
7416 {
7417 status=MagickFalse;
7418 break;
7419 }
7420 *images=DestroyImageList(*images);
7421 *images=coalesce_image;
7422 break;
7423 }
7424 if (LocaleCompare("combine",option+1) == 0)
7425 {
7426 Image
7427 *combine_image;
7428
cristy6fccee12011-10-20 18:43:18 +00007429 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007430 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007431 if (combine_image == (Image *) NULL)
7432 {
7433 status=MagickFalse;
7434 break;
7435 }
7436 *images=DestroyImageList(*images);
7437 *images=combine_image;
7438 break;
7439 }
7440 if (LocaleCompare("composite",option+1) == 0)
7441 {
7442 Image
7443 *mask_image,
7444 *composite_image,
7445 *image;
7446
7447 RectangleInfo
7448 geometry;
7449
cristy6fccee12011-10-20 18:43:18 +00007450 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007451 image=RemoveFirstImageFromList(images);
7452 composite_image=RemoveFirstImageFromList(images);
7453 if (composite_image == (Image *) NULL)
7454 {
7455 status=MagickFalse;
7456 break;
7457 }
7458 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007459 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007460 SetGeometry(composite_image,&geometry);
7461 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7462 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7463 &geometry);
7464 mask_image=RemoveFirstImageFromList(images);
7465 if (mask_image != (Image *) NULL)
7466 {
7467 if ((image->compose == DisplaceCompositeOp) ||
7468 (image->compose == DistortCompositeOp))
7469 {
7470 /*
7471 Merge Y displacement into X displacement image.
7472 */
7473 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007474 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007475 mask_image=DestroyImage(mask_image);
7476 }
7477 else
7478 {
7479 /*
7480 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007481 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007482 */
7483 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007484 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007485 }
7486 }
cristyf4ad9df2011-07-08 16:49:03 +00007487 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007488 geometry.x,geometry.y,exception);
anthonya129f702011-04-14 01:08:48 +00007489 if (mask_image != (Image *) NULL)
7490 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007491 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007492 *images=DestroyImageList(*images);
7493 *images=image;
7494 break;
7495 }
cristy3ed852e2009-09-05 21:47:34 +00007496 break;
7497 }
7498 case 'd':
7499 {
7500 if (LocaleCompare("deconstruct",option+1) == 0)
7501 {
7502 Image
7503 *deconstruct_image;
7504
cristy6fccee12011-10-20 18:43:18 +00007505 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007506 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007507 exception);
cristy3ed852e2009-09-05 21:47:34 +00007508 if (deconstruct_image == (Image *) NULL)
7509 {
7510 status=MagickFalse;
7511 break;
7512 }
7513 *images=DestroyImageList(*images);
7514 *images=deconstruct_image;
7515 break;
7516 }
7517 if (LocaleCompare("delete",option+1) == 0)
7518 {
7519 if (*option == '+')
7520 DeleteImages(images,"-1",exception);
7521 else
7522 DeleteImages(images,argv[i+1],exception);
7523 break;
7524 }
7525 if (LocaleCompare("dither",option+1) == 0)
7526 {
7527 if (*option == '+')
7528 {
7529 quantize_info->dither=MagickFalse;
7530 break;
7531 }
7532 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007533 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007534 MagickDitherOptions,MagickFalse,argv[i+1]);
7535 break;
7536 }
cristyecb10ff2011-03-22 13:14:03 +00007537 if (LocaleCompare("duplicate",option+1) == 0)
7538 {
cristy72988482011-03-29 16:34:38 +00007539 Image
7540 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007541
anthony2b6bcae2011-03-23 13:05:34 +00007542 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007543 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7544 else
7545 {
7546 const char
7547 *p;
7548
anthony2b6bcae2011-03-23 13:05:34 +00007549 size_t
7550 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007551
anthony2b6bcae2011-03-23 13:05:34 +00007552 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007553 p=strchr(argv[i+1],',');
7554 if (p == (const char *) NULL)
7555 duplicate_images=DuplicateImages(*images,number_duplicates,
7556 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007557 else
cristy72988482011-03-29 16:34:38 +00007558 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7559 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007560 }
7561 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007562 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007563 break;
7564 }
cristy3ed852e2009-09-05 21:47:34 +00007565 break;
7566 }
cristyd18ae7c2010-03-07 17:39:52 +00007567 case 'e':
7568 {
7569 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7570 {
7571 Image
7572 *evaluate_image;
7573
7574 MagickEvaluateOperator
7575 op;
7576
cristy6fccee12011-10-20 18:43:18 +00007577 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007578 op=(MagickEvaluateOperator) ParseCommandOption(
7579 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007580 evaluate_image=EvaluateImages(*images,op,exception);
7581 if (evaluate_image == (Image *) NULL)
7582 {
7583 status=MagickFalse;
7584 break;
7585 }
7586 *images=DestroyImageList(*images);
7587 *images=evaluate_image;
7588 break;
7589 }
7590 break;
7591 }
cristy3ed852e2009-09-05 21:47:34 +00007592 case 'f':
7593 {
cristyf0a247f2009-10-04 00:20:03 +00007594 if (LocaleCompare("fft",option+1) == 0)
7595 {
7596 Image
7597 *fourier_image;
7598
7599 /*
7600 Implements the discrete Fourier transform (DFT).
7601 */
cristy6fccee12011-10-20 18:43:18 +00007602 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007603 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7604 MagickTrue : MagickFalse,exception);
7605 if (fourier_image == (Image *) NULL)
7606 break;
7607 *images=DestroyImage(*images);
7608 *images=fourier_image;
7609 break;
7610 }
cristy3ed852e2009-09-05 21:47:34 +00007611 if (LocaleCompare("flatten",option+1) == 0)
7612 {
7613 Image
7614 *flatten_image;
7615
cristy6fccee12011-10-20 18:43:18 +00007616 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007617 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7618 if (flatten_image == (Image *) NULL)
7619 break;
7620 *images=DestroyImageList(*images);
7621 *images=flatten_image;
7622 break;
7623 }
7624 if (LocaleCompare("fx",option+1) == 0)
7625 {
7626 Image
7627 *fx_image;
7628
cristy6fccee12011-10-20 18:43:18 +00007629 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007630 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007631 if (fx_image == (Image *) NULL)
7632 {
7633 status=MagickFalse;
7634 break;
7635 }
7636 *images=DestroyImageList(*images);
7637 *images=fx_image;
7638 break;
7639 }
7640 break;
7641 }
7642 case 'h':
7643 {
7644 if (LocaleCompare("hald-clut",option+1) == 0)
7645 {
7646 Image
7647 *hald_image,
7648 *image;
7649
cristy6fccee12011-10-20 18:43:18 +00007650 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007651 image=RemoveFirstImageFromList(images);
7652 hald_image=RemoveFirstImageFromList(images);
7653 if (hald_image == (Image *) NULL)
7654 {
7655 status=MagickFalse;
7656 break;
7657 }
cristy7c0a0a42011-08-23 17:57:25 +00007658 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007659 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007660 if (*images != (Image *) NULL)
7661 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007662 *images=image;
7663 break;
7664 }
7665 break;
7666 }
7667 case 'i':
7668 {
7669 if (LocaleCompare("ift",option+1) == 0)
7670 {
7671 Image
cristy8587f882009-11-13 20:28:49 +00007672 *fourier_image,
7673 *magnitude_image,
7674 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007675
7676 /*
7677 Implements the inverse fourier discrete Fourier transform (DFT).
7678 */
cristy6fccee12011-10-20 18:43:18 +00007679 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007680 magnitude_image=RemoveFirstImageFromList(images);
7681 phase_image=RemoveFirstImageFromList(images);
7682 if (phase_image == (Image *) NULL)
7683 {
7684 status=MagickFalse;
7685 break;
7686 }
7687 fourier_image=InverseFourierTransformImage(magnitude_image,
7688 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007689 if (fourier_image == (Image *) NULL)
7690 break;
cristy0aff6ea2009-11-14 01:40:53 +00007691 if (*images != (Image *) NULL)
7692 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007693 *images=fourier_image;
7694 break;
7695 }
7696 if (LocaleCompare("insert",option+1) == 0)
7697 {
7698 Image
7699 *p,
7700 *q;
7701
7702 index=0;
7703 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007704 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007705 p=RemoveLastImageFromList(images);
7706 if (p == (Image *) NULL)
7707 {
7708 (void) ThrowMagickException(exception,GetMagickModule(),
7709 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7710 status=MagickFalse;
7711 break;
7712 }
7713 q=p;
7714 if (index == 0)
7715 PrependImageToList(images,q);
7716 else
cristybb503372010-05-27 20:51:26 +00007717 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007718 AppendImageToList(images,q);
7719 else
7720 {
7721 q=GetImageFromList(*images,index-1);
7722 if (q == (Image *) NULL)
7723 {
7724 (void) ThrowMagickException(exception,GetMagickModule(),
7725 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7726 status=MagickFalse;
7727 break;
7728 }
7729 InsertImageInList(&q,p);
7730 }
7731 *images=GetFirstImageInList(q);
7732 break;
7733 }
cristy28474bf2011-09-11 23:32:52 +00007734 if (LocaleCompare("interpolate",option+1) == 0)
7735 {
7736 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7737 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7738 break;
7739 }
cristy3ed852e2009-09-05 21:47:34 +00007740 break;
7741 }
7742 case 'l':
7743 {
7744 if (LocaleCompare("layers",option+1) == 0)
7745 {
7746 Image
7747 *layers;
7748
7749 ImageLayerMethod
7750 method;
7751
cristy6fccee12011-10-20 18:43:18 +00007752 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007753 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007754 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007755 MagickFalse,argv[i+1]);
7756 switch (method)
7757 {
7758 case CoalesceLayer:
7759 {
7760 layers=CoalesceImages(*images,exception);
7761 break;
7762 }
7763 case CompareAnyLayer:
7764 case CompareClearLayer:
7765 case CompareOverlayLayer:
7766 default:
7767 {
cristy8a9106f2011-07-05 14:39:26 +00007768 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007769 break;
7770 }
7771 case MergeLayer:
7772 case FlattenLayer:
7773 case MosaicLayer:
7774 case TrimBoundsLayer:
7775 {
7776 layers=MergeImageLayers(*images,method,exception);
7777 break;
7778 }
7779 case DisposeLayer:
7780 {
7781 layers=DisposeImages(*images,exception);
7782 break;
7783 }
7784 case OptimizeImageLayer:
7785 {
7786 layers=OptimizeImageLayers(*images,exception);
7787 break;
7788 }
7789 case OptimizePlusLayer:
7790 {
7791 layers=OptimizePlusImageLayers(*images,exception);
7792 break;
7793 }
7794 case OptimizeTransLayer:
7795 {
7796 OptimizeImageTransparency(*images,exception);
7797 break;
7798 }
7799 case RemoveDupsLayer:
7800 {
7801 RemoveDuplicateLayers(images,exception);
7802 break;
7803 }
7804 case RemoveZeroLayer:
7805 {
7806 RemoveZeroDelayLayers(images,exception);
7807 break;
7808 }
7809 case OptimizeLayer:
7810 {
7811 /*
7812 General Purpose, GIF Animation Optimizer.
7813 */
7814 layers=CoalesceImages(*images,exception);
7815 if (layers == (Image *) NULL)
7816 {
7817 status=MagickFalse;
7818 break;
7819 }
cristy3ed852e2009-09-05 21:47:34 +00007820 *images=DestroyImageList(*images);
7821 *images=layers;
7822 layers=OptimizeImageLayers(*images,exception);
7823 if (layers == (Image *) NULL)
7824 {
7825 status=MagickFalse;
7826 break;
7827 }
cristy3ed852e2009-09-05 21:47:34 +00007828 *images=DestroyImageList(*images);
7829 *images=layers;
7830 layers=(Image *) NULL;
7831 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007832 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7833 exception);
cristy3ed852e2009-09-05 21:47:34 +00007834 break;
7835 }
7836 case CompositeLayer:
7837 {
7838 CompositeOperator
7839 compose;
7840
7841 Image
7842 *source;
7843
7844 RectangleInfo
7845 geometry;
7846
7847 /*
7848 Split image sequence at the first 'NULL:' image.
7849 */
7850 source=(*images);
7851 while (source != (Image *) NULL)
7852 {
7853 source=GetNextImageInList(source);
7854 if ((source != (Image *) NULL) &&
7855 (LocaleCompare(source->magick,"NULL") == 0))
7856 break;
7857 }
7858 if (source != (Image *) NULL)
7859 {
7860 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7861 (GetNextImageInList(source) == (Image *) NULL))
7862 source=(Image *) NULL;
7863 else
7864 {
7865 /*
7866 Separate the two lists, junk the null: image.
7867 */
7868 source=SplitImageList(source->previous);
7869 DeleteImageFromList(&source);
7870 }
7871 }
7872 if (source == (Image *) NULL)
7873 {
7874 (void) ThrowMagickException(exception,GetMagickModule(),
7875 OptionError,"MissingNullSeparator","layers Composite");
7876 status=MagickFalse;
7877 break;
7878 }
7879 /*
7880 Adjust offset with gravity and virtual canvas.
7881 */
7882 SetGeometry(*images,&geometry);
7883 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7884 geometry.width=source->page.width != 0 ?
7885 source->page.width : source->columns;
7886 geometry.height=source->page.height != 0 ?
7887 source->page.height : source->rows;
7888 GravityAdjustGeometry((*images)->page.width != 0 ?
7889 (*images)->page.width : (*images)->columns,
7890 (*images)->page.height != 0 ? (*images)->page.height :
7891 (*images)->rows,(*images)->gravity,&geometry);
7892 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007893 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007894 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007895 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007896 MagickComposeOptions,MagickFalse,option);
7897 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7898 exception);
7899 source=DestroyImageList(source);
7900 break;
7901 }
7902 }
7903 if (layers == (Image *) NULL)
7904 break;
cristy3ed852e2009-09-05 21:47:34 +00007905 *images=DestroyImageList(*images);
7906 *images=layers;
7907 break;
7908 }
7909 break;
7910 }
7911 case 'm':
7912 {
7913 if (LocaleCompare("map",option+1) == 0)
7914 {
cristy6fccee12011-10-20 18:43:18 +00007915 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007916 if (*option == '+')
7917 {
cristy018f07f2011-09-04 21:15:19 +00007918 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7919 exception);
cristy3ed852e2009-09-05 21:47:34 +00007920 break;
7921 }
7922 i++;
7923 break;
7924 }
cristyf40785b2010-03-06 02:27:27 +00007925 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007926 {
7927 Image
cristyf40785b2010-03-06 02:27:27 +00007928 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007929
cristyd18ae7c2010-03-07 17:39:52 +00007930 /*
7931 Maximum image sequence (deprecated).
7932 */
cristy6fccee12011-10-20 18:43:18 +00007933 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007934 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007935 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007936 {
7937 status=MagickFalse;
7938 break;
7939 }
7940 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007941 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007942 break;
7943 }
cristyf40785b2010-03-06 02:27:27 +00007944 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007945 {
7946 Image
cristyf40785b2010-03-06 02:27:27 +00007947 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007948
cristyd18ae7c2010-03-07 17:39:52 +00007949 /*
7950 Minimum image sequence (deprecated).
7951 */
cristy6fccee12011-10-20 18:43:18 +00007952 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007953 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007954 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007955 {
7956 status=MagickFalse;
7957 break;
7958 }
7959 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007960 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007961 break;
7962 }
cristy3ed852e2009-09-05 21:47:34 +00007963 if (LocaleCompare("morph",option+1) == 0)
7964 {
7965 Image
7966 *morph_image;
7967
cristy6fccee12011-10-20 18:43:18 +00007968 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007969 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007970 exception);
7971 if (morph_image == (Image *) NULL)
7972 {
7973 status=MagickFalse;
7974 break;
7975 }
7976 *images=DestroyImageList(*images);
7977 *images=morph_image;
7978 break;
7979 }
7980 if (LocaleCompare("mosaic",option+1) == 0)
7981 {
7982 Image
7983 *mosaic_image;
7984
cristy6fccee12011-10-20 18:43:18 +00007985 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007986 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7987 if (mosaic_image == (Image *) NULL)
7988 {
7989 status=MagickFalse;
7990 break;
7991 }
7992 *images=DestroyImageList(*images);
7993 *images=mosaic_image;
7994 break;
7995 }
7996 break;
7997 }
7998 case 'p':
7999 {
8000 if (LocaleCompare("print",option+1) == 0)
8001 {
8002 char
8003 *string;
8004
cristy6fccee12011-10-20 18:43:18 +00008005 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00008006 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8007 exception);
cristy3ed852e2009-09-05 21:47:34 +00008008 if (string == (char *) NULL)
8009 break;
cristyb51dff52011-05-19 16:55:47 +00008010 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008011 string=DestroyString(string);
8012 }
8013 if (LocaleCompare("process",option+1) == 0)
8014 {
8015 char
8016 **arguments;
8017
8018 int
8019 j,
8020 number_arguments;
8021
cristy6fccee12011-10-20 18:43:18 +00008022 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008023 arguments=StringToArgv(argv[i+1],&number_arguments);
8024 if (arguments == (char **) NULL)
8025 break;
8026 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8027 {
8028 char
8029 breaker,
8030 quote,
8031 *token;
8032
8033 const char
8034 *arguments;
8035
8036 int
8037 next,
8038 status;
8039
8040 size_t
8041 length;
8042
8043 TokenInfo
8044 *token_info;
8045
8046 /*
8047 Support old style syntax, filter="-option arg".
8048 */
8049 length=strlen(argv[i+1]);
8050 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008051 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008052 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8053 sizeof(*token));
8054 if (token == (char *) NULL)
8055 break;
8056 next=0;
8057 arguments=argv[i+1];
8058 token_info=AcquireTokenInfo();
8059 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8060 "\"",'\0',&breaker,&next,&quote);
8061 token_info=DestroyTokenInfo(token_info);
8062 if (status == 0)
8063 {
8064 const char
8065 *argv;
8066
8067 argv=(&(arguments[next]));
8068 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8069 exception);
8070 }
8071 token=DestroyString(token);
8072 break;
8073 }
cristy91c0da22010-05-02 01:44:07 +00008074 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008075 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8076 number_arguments-2,(const char **) arguments+2,exception);
8077 for (j=0; j < number_arguments; j++)
8078 arguments[j]=DestroyString(arguments[j]);
8079 arguments=(char **) RelinquishMagickMemory(arguments);
8080 break;
8081 }
8082 break;
8083 }
8084 case 'r':
8085 {
8086 if (LocaleCompare("reverse",option+1) == 0)
8087 {
8088 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008089 break;
8090 }
8091 break;
8092 }
8093 case 's':
8094 {
cristy4285d782011-02-09 20:12:28 +00008095 if (LocaleCompare("smush",option+1) == 0)
8096 {
8097 Image
8098 *smush_image;
8099
8100 ssize_t
8101 offset;
8102
cristy6fccee12011-10-20 18:43:18 +00008103 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008104 offset=(ssize_t) StringToLong(argv[i+1]);
8105 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8106 MagickFalse,offset,exception);
8107 if (smush_image == (Image *) NULL)
8108 {
8109 status=MagickFalse;
8110 break;
8111 }
8112 *images=DestroyImageList(*images);
8113 *images=smush_image;
8114 break;
8115 }
cristy3ed852e2009-09-05 21:47:34 +00008116 if (LocaleCompare("swap",option+1) == 0)
8117 {
8118 Image
8119 *p,
8120 *q,
8121 *swap;
8122
cristybb503372010-05-27 20:51:26 +00008123 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008124 swap_index;
8125
8126 index=(-1);
8127 swap_index=(-2);
8128 if (*option != '+')
8129 {
8130 GeometryInfo
8131 geometry_info;
8132
8133 MagickStatusType
8134 flags;
8135
8136 swap_index=(-1);
8137 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008138 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008139 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008140 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008141 }
8142 p=GetImageFromList(*images,index);
8143 q=GetImageFromList(*images,swap_index);
8144 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8145 {
8146 (void) ThrowMagickException(exception,GetMagickModule(),
8147 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8148 status=MagickFalse;
8149 break;
8150 }
8151 if (p == q)
8152 break;
8153 swap=CloneImage(p,0,0,MagickTrue,exception);
8154 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8155 ReplaceImageInList(&q,swap);
8156 *images=GetFirstImageInList(q);
8157 break;
8158 }
8159 break;
8160 }
8161 case 'w':
8162 {
8163 if (LocaleCompare("write",option+1) == 0)
8164 {
cristy071dd7b2010-04-09 13:04:54 +00008165 char
cristy06609ee2010-03-17 20:21:27 +00008166 key[MaxTextExtent];
8167
cristy3ed852e2009-09-05 21:47:34 +00008168 Image
8169 *write_images;
8170
8171 ImageInfo
8172 *write_info;
8173
cristy6fccee12011-10-20 18:43:18 +00008174 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008175 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008176 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008177 write_images=(*images);
8178 if (*option == '+')
8179 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008180 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008181 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8182 write_info=DestroyImageInfo(write_info);
8183 if (*option == '+')
8184 write_images=DestroyImageList(write_images);
8185 break;
8186 }
8187 break;
8188 }
8189 default:
8190 break;
8191 }
8192 i+=count;
8193 }
8194 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008195 mogrify_info=DestroyImageInfo(mogrify_info);
8196 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008197 return(status != 0 ? MagickTrue : MagickFalse);
8198}
8199
8200/*
8201%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8202% %
8203% %
8204% %
8205+ M o g r i f y I m a g e s %
8206% %
8207% %
8208% %
8209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8210%
8211% MogrifyImages() applies image processing options to a sequence of images as
8212% prescribed by command line options.
8213%
8214% The format of the MogrifyImage method is:
8215%
8216% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8217% const MagickBooleanType post,const int argc,const char **argv,
8218% Image **images,Exceptioninfo *exception)
8219%
8220% A description of each parameter follows:
8221%
8222% o image_info: the image info..
8223%
8224% o post: If true, post process image list operators otherwise pre-process.
8225%
8226% o argc: Specifies a pointer to an integer describing the number of
8227% elements in the argument vector.
8228%
8229% o argv: Specifies a pointer to a text array containing the command line
8230% arguments.
8231%
anthonye9c27192011-03-27 08:07:06 +00008232% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008233%
8234% o exception: return any errors or warnings in this structure.
8235%
8236*/
8237WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8238 const MagickBooleanType post,const int argc,const char **argv,
8239 Image **images,ExceptionInfo *exception)
8240{
8241#define MogrifyImageTag "Mogrify/Image"
8242
anthonye9c27192011-03-27 08:07:06 +00008243 MagickStatusType
8244 status;
cristy3ed852e2009-09-05 21:47:34 +00008245
cristy0e9f9c12010-02-11 03:00:47 +00008246 MagickBooleanType
8247 proceed;
8248
anthonye9c27192011-03-27 08:07:06 +00008249 size_t
8250 n;
cristy3ed852e2009-09-05 21:47:34 +00008251
cristybb503372010-05-27 20:51:26 +00008252 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008253 i;
8254
cristy3ed852e2009-09-05 21:47:34 +00008255 assert(image_info != (ImageInfo *) NULL);
8256 assert(image_info->signature == MagickSignature);
8257 if (images == (Image **) NULL)
8258 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008259 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008260 assert((*images)->signature == MagickSignature);
8261 if ((*images)->debug != MagickFalse)
8262 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8263 (*images)->filename);
8264 if ((argc <= 0) || (*argv == (char *) NULL))
8265 return(MagickTrue);
8266 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8267 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008268 status=0;
anthonye9c27192011-03-27 08:07:06 +00008269
anthonyce2716b2011-04-22 09:51:34 +00008270#if 0
cristy1e604812011-05-19 18:07:50 +00008271 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8272 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008273#endif
8274
anthonye9c27192011-03-27 08:07:06 +00008275 /*
8276 Pre-process multi-image sequence operators
8277 */
cristy3ed852e2009-09-05 21:47:34 +00008278 if (post == MagickFalse)
8279 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008280 /*
8281 For each image, process simple single image operators
8282 */
8283 i=0;
8284 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008285 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008286 {
anthonyce2716b2011-04-22 09:51:34 +00008287#if 0
cristy1e604812011-05-19 18:07:50 +00008288 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8289 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008290#endif
anthonye9c27192011-03-27 08:07:06 +00008291 status&=MogrifyImage(image_info,argc,argv,images,exception);
8292 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008293 if (proceed == MagickFalse)
8294 break;
anthonye9c27192011-03-27 08:07:06 +00008295 if ( (*images)->next == (Image *) NULL )
8296 break;
8297 *images=(*images)->next;
8298 i++;
cristy3ed852e2009-09-05 21:47:34 +00008299 }
anthonye9c27192011-03-27 08:07:06 +00008300 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008301#if 0
cristy1e604812011-05-19 18:07:50 +00008302 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8303 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008304#endif
anthonye9c27192011-03-27 08:07:06 +00008305
8306 /*
8307 Post-process, multi-image sequence operators
8308 */
8309 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008310 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008311 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008312 return(status != 0 ? MagickTrue : MagickFalse);
8313}