blob: 47f19edeb975eb92d24b010b03d08230975b6680 [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*/
47#include "wand/studio.h"
48#include "wand/MagickWand.h"
49#include "wand/mogrify-private.h"
cristy0e9f9c12010-02-11 03:00:47 +000050#include "magick/monitor-private.h"
cristy3980b0d2009-10-25 14:37:13 +000051#include "magick/thread-private.h"
cristyf2f27272009-12-17 14:48:46 +000052#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define UndefinedCompressionQuality 0UL
58
59/*
60 Constant declaration.
61*/
62static const char
cristy7138c592009-09-08 13:58:52 +000063 BackgroundColor[] = "#fff", /* white */
64 BorderColor[] = "#dfdfdf", /* gray */
65 MatteColor[] = "#bdbdbd"; /* gray */
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
cristy5063d812010-10-19 16:28:10 +000072% 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 +000073% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78% MagickCommandGenesis() applies image processing options to an image as
79% prescribed by command line options.
80%
81% The format of the MagickCommandGenesis method is:
82%
83% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000084% MagickCommand command,int argc,char **argv,char **metadata,
85% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000086%
87% A description of each parameter follows:
88%
89% o image_info: the image info.
90%
cristy5063d812010-10-19 16:28:10 +000091% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
92% MogrifyImageCommand, CompositeImageCommand, CompareImageCommand,
93% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
94% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000095%
96% o argc: Specifies a pointer to an integer describing the number of
97% elements in the argument vector.
98%
99% o argv: Specifies a pointer to a text array containing the command line
100% arguments.
101%
cristy5063d812010-10-19 16:28:10 +0000102% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000103%
104% o exception: return any errors or warnings in this structure.
105%
106*/
107WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
108 MagickCommand command,int argc,char **argv,char **metadata,
109 ExceptionInfo *exception)
110{
111 char
112 *option;
113
114 double
115 duration,
116 elapsed_time,
117 user_time;
118
cristy3980b0d2009-10-25 14:37:13 +0000119 MagickBooleanType
120 concurrent,
121 regard_warnings,
122 status;
123
cristybb503372010-05-27 20:51:26 +0000124 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000125 i;
126
127 TimerInfo
128 *timer;
129
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristy3980b0d2009-10-25 14:37:13 +0000131 iterations;
132
cristyd0a94fa2010-03-12 14:18:11 +0000133 (void) setlocale(LC_ALL,"");
134 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000135 concurrent=MagickFalse;
136 duration=(-1.0);
137 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000138 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000139 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000140 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000141 {
142 option=argv[i];
143 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
144 continue;
145 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000146 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000147 if (LocaleCompare("concurrent",option+1) == 0)
148 concurrent=MagickTrue;
149 if (LocaleCompare("debug",option+1) == 0)
150 (void) SetLogEventMask(argv[++i]);
151 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000152 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000153 if (LocaleCompare("regard-warnings",option+1) == 0)
154 regard_warnings=MagickTrue;
155 }
156 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000157 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000158 {
cristybb503372010-05-27 20:51:26 +0000159 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000160 {
cristy33557d72009-11-06 00:54:33 +0000161 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000162 continue;
163 if (duration > 0)
164 {
165 if (GetElapsedTime(timer) > duration)
166 continue;
167 (void) ContinueTimer(timer);
168 }
169 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000170 if (exception->severity != UndefinedException)
171 {
172 if ((exception->severity > ErrorException) ||
173 (regard_warnings != MagickFalse))
174 status=MagickTrue;
175 CatchException(exception);
176 }
cristy3d1a5512009-10-25 21:23:27 +0000177 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000178 {
179 (void) fputs(*metadata,stdout);
180 (void) fputc('\n',stdout);
181 *metadata=DestroyString(*metadata);
182 }
183 }
184 }
cristyceae09d2009-10-28 17:18:47 +0000185 else
186 {
187 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000188#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000189 # pragma omp parallel for shared(status)
190#endif
cristybb503372010-05-27 20:51:26 +0000191 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000192 {
cristy33557d72009-11-06 00:54:33 +0000193 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000194 continue;
195 if (duration > 0)
196 {
197 if (GetElapsedTime(timer) > duration)
198 continue;
199 (void) ContinueTimer(timer);
200 }
201 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000202#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000203 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000204#endif
205 {
206 if (exception->severity != UndefinedException)
207 {
208 if ((exception->severity > ErrorException) ||
209 (regard_warnings != MagickFalse))
210 status=MagickTrue;
211 CatchException(exception);
212 }
213 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
214 {
215 (void) fputs(*metadata,stdout);
216 (void) fputc('\n',stdout);
217 *metadata=DestroyString(*metadata);
218 }
219 }
220 }
221 }
cristy3980b0d2009-10-25 14:37:13 +0000222 if (iterations > 1)
223 {
224 elapsed_time=GetElapsedTime(timer);
225 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000226 (void) fprintf(stderr,
cristye8c25f92010-06-03 00:53:06 +0000227 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
228 iterations,1.0*iterations/elapsed_time,user_time,(double)
229 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
230 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000231 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000232 }
233 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000234 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000235}
236
237/*
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239% %
240% %
241% %
cristy3ed852e2009-09-05 21:47:34 +0000242+ M o g r i f y I m a g e %
243% %
244% %
245% %
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247%
anthonye9c27192011-03-27 08:07:06 +0000248% MogrifyImage() applies simple single image processing options to a single
249% image. That image however may be part of a longer list of images.
250%
251% The image in the list may be modified in three different ways...
252%
253% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
254% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
255% * replace by a list of images (only the -separate option!)
256%
257% In each case the result is returned into the list, and a pointer to the
258% modified image (last image added if replaced by a list of images) is
259% returned.
260%
261% ASIDE: The -crop is present but restricted to non-tile single image crops
262%
263% This means if all the images are being processed (such as by
264% MogrifyImages(), next image to be processed will be as per the pointer
265% (*image)->next. Also the image list may grow as a result of some specific
266% operations but as images are never merged or deleted, it will never shrink
267% in length. Typically the list will remain the same length.
268%
269% WARNING: As the image pointed to may be replaced, the first image in the
270% list may also change. GetFirstImageInList() should be used by caller if
271% they wish return the Image pointer to the first image in list.
272%
cristy3ed852e2009-09-05 21:47:34 +0000273%
274% The format of the MogrifyImage method is:
275%
276% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
277% const char **argv,Image **image)
278%
279% A description of each parameter follows:
280%
281% o image_info: the image info..
282%
283% o argc: Specifies a pointer to an integer describing the number of
284% elements in the argument vector.
285%
286% o argv: Specifies a pointer to a text array containing the command line
287% arguments.
288%
289% o image: the image.
290%
291% o exception: return any errors or warnings in this structure.
292%
293*/
294
anthonye9c27192011-03-27 08:07:06 +0000295/*
296** GetImageCache() will read an image into a image cache if not already
297** present then return the image that is in the cache under that filename.
298*/
cristy3ed852e2009-09-05 21:47:34 +0000299static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
300 ExceptionInfo *exception)
301{
302 char
303 key[MaxTextExtent];
304
305 ExceptionInfo
306 *sans_exception;
307
308 Image
309 *image;
310
311 ImageInfo
312 *read_info;
313
314 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
315 sans_exception=AcquireExceptionInfo();
316 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
317 sans_exception=DestroyExceptionInfo(sans_exception);
318 if (image != (Image *) NULL)
319 return(image);
320 read_info=CloneImageInfo(image_info);
321 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
322 image=ReadImage(read_info,exception);
323 read_info=DestroyImageInfo(read_info);
324 if (image != (Image *) NULL)
325 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
326 return(image);
327}
328
cristy3ed852e2009-09-05 21:47:34 +0000329static MagickBooleanType IsPathWritable(const char *path)
330{
331 if (IsPathAccessible(path) == MagickFalse)
332 return(MagickFalse);
333 if (access(path,W_OK) != 0)
334 return(MagickFalse);
335 return(MagickTrue);
336}
337
cristybb503372010-05-27 20:51:26 +0000338static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000339{
340 if (x > y)
341 return(x);
342 return(y);
343}
344
345static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000346 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000347 void *wand_unused(client_data))
348{
349 char
350 message[MaxTextExtent],
351 tag[MaxTextExtent];
352
353 const char
354 *locale_message;
355
356 register char
357 *p;
358
cristyb32b90a2009-09-07 21:45:48 +0000359 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000360 return(MagickTrue);
361 (void) CopyMagickMemory(tag,text,MaxTextExtent);
362 p=strrchr(tag,'/');
363 if (p != (char *) NULL)
364 *p='\0';
365 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
366 locale_message=GetLocaleMessage(message);
367 if (locale_message == message)
368 locale_message=tag;
369 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000370 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
cristyf2faecf2010-05-28 19:19:36 +0000371 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000372 else
cristyb32b90a2009-09-07 21:45:48 +0000373 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
cristyf2faecf2010-05-28 19:19:36 +0000374 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
cristyb32b90a2009-09-07 21:45:48 +0000375 (100L*offset/(extent-1)));
376 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000377 (void) fprintf(stderr,"\n");
378 (void) fflush(stderr);
379 return(MagickTrue);
380}
381
anthonye9c27192011-03-27 08:07:06 +0000382/*
383** SparseColorOption() parse the complex -sparse-color argument into an
384** an array of floating point values than call SparseColorImage().
385** Argument is a complex mix of floating-point pixel coodinates, and color
386** specifications (or direct floating point numbers). The number of floats
387** needed to represent a color varies depending on teh current channel
388** setting.
389*/
cristy3ed852e2009-09-05 21:47:34 +0000390static Image *SparseColorOption(const Image *image,const ChannelType channel,
391 const SparseColorMethod method,const char *arguments,
392 const MagickBooleanType color_from_image,ExceptionInfo *exception)
393{
394 ChannelType
395 channels;
396
397 char
398 token[MaxTextExtent];
399
400 const char
401 *p;
402
403 double
404 *sparse_arguments;
405
cristybb503372010-05-27 20:51:26 +0000406 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000407 x;
408
cristybb503372010-05-27 20:51:26 +0000409 size_t
cristy3ed852e2009-09-05 21:47:34 +0000410 number_arguments;
411
cristybb503372010-05-27 20:51:26 +0000412 size_t
cristy3ed852e2009-09-05 21:47:34 +0000413 number_colors;
414
415 Image
416 *sparse_image;
417
418 MagickPixelPacket
419 color;
420
421 MagickBooleanType
422 error;
423
424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
433 channels=channel;
434 if (image->colorspace != CMYKColorspace)
435 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
436 if (image->matte == MagickFalse)
437 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
438 number_colors=0;
439 if ((channels & RedChannel) != 0)
440 number_colors++;
441 if ((channels & GreenChannel) != 0)
442 number_colors++;
443 if ((channels & BlueChannel) != 0)
444 number_colors++;
445 if ((channels & IndexChannel) != 0)
446 number_colors++;
447 if ((channels & OpacityChannel) != 0)
448 number_colors++;
anthony1e4df872011-03-19 14:10:59 +0000449
cristy3ed852e2009-09-05 21:47:34 +0000450 /*
451 Read string, to determine number of arguments needed,
452 */
453 p=arguments;
454 x=0;
455 while( *p != '\0' )
456 {
457 GetMagickToken(p,&p,token);
458 if ( token[0] == ',' ) continue;
459 if ( isalpha((int) token[0]) || token[0] == '#' ) {
460 if ( color_from_image ) {
461 (void) ThrowMagickException(exception,GetMagickModule(),
462 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
463 "Color arg given, when colors are coming from image");
464 return( (Image *)NULL);
465 }
466 x += number_colors; /* color argument */
467 }
468 else {
469 x++; /* floating point argument */
470 }
471 }
472 error=MagickTrue;
473 if ( color_from_image ) {
474 /* just the control points are being given */
475 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
476 number_arguments=(x/2)*(2+number_colors);
477 }
478 else {
479 /* control points and color values */
480 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
481 number_arguments=x;
482 }
483 if ( error ) {
484 (void) ThrowMagickException(exception,GetMagickModule(),
485 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
486 "Invalid number of Arguments");
487 return( (Image *)NULL);
488 }
489
490 /* Allocate and fill in the floating point arguments */
491 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
492 sizeof(*sparse_arguments));
493 if (sparse_arguments == (double *) NULL) {
494 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
495 "MemoryAllocationFailed","%s","SparseColorOption");
496 return( (Image *)NULL);
497 }
498 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
499 sizeof(*sparse_arguments));
500 p=arguments;
501 x=0;
502 while( *p != '\0' && x < number_arguments ) {
503 /* X coordinate */
504 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
505 if ( token[0] == '\0' ) break;
506 if ( isalpha((int) token[0]) || token[0] == '#' ) {
507 (void) ThrowMagickException(exception,GetMagickModule(),
508 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
509 "Color found, instead of X-coord");
510 error = MagickTrue;
511 break;
512 }
cristyf2f27272009-12-17 14:48:46 +0000513 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000514 /* Y coordinate */
515 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
516 if ( token[0] == '\0' ) break;
517 if ( isalpha((int) token[0]) || token[0] == '#' ) {
518 (void) ThrowMagickException(exception,GetMagickModule(),
519 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
520 "Color found, instead of Y-coord");
521 error = MagickTrue;
522 break;
523 }
cristyf2f27272009-12-17 14:48:46 +0000524 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000525 /* color values for this control point */
526#if 0
527 if ( (color_from_image ) {
528 /* get color from image */
529 /* HOW??? */
530 }
531 else
532#endif
533 {
534 /* color name or function given in string argument */
535 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
536 if ( token[0] == '\0' ) break;
537 if ( isalpha((int) token[0]) || token[0] == '#' ) {
538 /* Color string given */
539 (void) QueryMagickColor(token,&color,exception);
540 if ( channels & RedChannel )
541 sparse_arguments[x++] = QuantumScale*color.red;
542 if ( channels & GreenChannel )
543 sparse_arguments[x++] = QuantumScale*color.green;
544 if ( channels & BlueChannel )
545 sparse_arguments[x++] = QuantumScale*color.blue;
546 if ( channels & IndexChannel )
547 sparse_arguments[x++] = QuantumScale*color.index;
548 if ( channels & OpacityChannel )
549 sparse_arguments[x++] = QuantumScale*color.opacity;
550 }
551 else {
cristy3ed852e2009-09-05 21:47:34 +0000552 /* Colors given as a set of floating point values - experimental */
553 /* NB: token contains the first floating point value to use! */
554 if ( channels & RedChannel ) {
555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristy0f19e682009-12-17 14:55:51 +0000558 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000559 token[0] = ','; /* used this token - get another */
560 }
561 if ( channels & GreenChannel ) {
562 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
563 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
564 break;
cristy0f19e682009-12-17 14:55:51 +0000565 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000566 token[0] = ','; /* used this token - get another */
567 }
568 if ( channels & BlueChannel ) {
569 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
570 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
571 break;
cristy0f19e682009-12-17 14:55:51 +0000572 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000573 token[0] = ','; /* used this token - get another */
574 }
575 if ( channels & IndexChannel ) {
576 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
577 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
578 break;
cristy0f19e682009-12-17 14:55:51 +0000579 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000580 token[0] = ','; /* used this token - get another */
581 }
582 if ( channels & OpacityChannel ) {
583 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
584 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
585 break;
cristy0f19e682009-12-17 14:55:51 +0000586 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000587 token[0] = ','; /* used this token - get another */
588 }
cristy3ed852e2009-09-05 21:47:34 +0000589 }
590 }
591 }
592 if ( number_arguments != x && !error ) {
593 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
594 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
595 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
596 return( (Image *)NULL);
597 }
598 if ( error )
599 return( (Image *)NULL);
600
601 /* Call the Interpolation function with the parsed arguments */
602 sparse_image=SparseColorImage(image,channels,method,number_arguments,
603 sparse_arguments,exception);
604 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
605 return( sparse_image );
606}
607
608WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
609 const char **argv,Image **image,ExceptionInfo *exception)
610{
611 ChannelType
612 channel;
613
614 const char
615 *format,
616 *option;
617
618 DrawInfo
619 *draw_info;
620
621 GeometryInfo
622 geometry_info;
623
624 Image
625 *region_image;
626
cristy6b3da3a2010-06-20 02:21:46 +0000627 ImageInfo
628 *mogrify_info;
629
cristyebbcfea2011-02-25 02:43:54 +0000630 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000631 status;
632
633 MagickPixelPacket
634 fill;
635
636 MagickStatusType
637 flags;
638
639 QuantizeInfo
640 *quantize_info;
641
642 RectangleInfo
643 geometry,
644 region_geometry;
645
cristybb503372010-05-27 20:51:26 +0000646 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000647 i;
648
649 /*
650 Initialize method variables.
651 */
652 assert(image_info != (const ImageInfo *) NULL);
653 assert(image_info->signature == MagickSignature);
654 assert(image != (Image **) NULL);
655 assert((*image)->signature == MagickSignature);
656 if ((*image)->debug != MagickFalse)
657 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
658 if (argc < 0)
659 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000660 mogrify_info=CloneImageInfo(image_info);
661 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
662 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +0000663 SetGeometryInfo(&geometry_info);
664 GetMagickPixelPacket(*image,&fill);
665 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
666 &fill);
cristy6b3da3a2010-06-20 02:21:46 +0000667 channel=mogrify_info->channel;
668 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000669 SetGeometry(*image,&region_geometry);
670 region_image=NewImageList();
671 /*
672 Transmogrify the image.
673 */
cristybb503372010-05-27 20:51:26 +0000674 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000675 {
anthonye9c27192011-03-27 08:07:06 +0000676 Image
cristyd241f442011-03-29 13:50:49 +0000677 *mogrify_image;
anthonye9c27192011-03-27 08:07:06 +0000678
679 ssize_t
680 count;
681
cristy3ed852e2009-09-05 21:47:34 +0000682 option=argv[i];
cristy042ee782011-04-22 18:48:30 +0000683 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000684 continue;
cristy042ee782011-04-22 18:48:30 +0000685 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +0000686 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +0000687 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000688 break;
cristy6b3da3a2010-06-20 02:21:46 +0000689 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristyd241f442011-03-29 13:50:49 +0000690 mogrify_image=(Image *)NULL;
cristy3ed852e2009-09-05 21:47:34 +0000691 switch (*(option+1))
692 {
693 case 'a':
694 {
695 if (LocaleCompare("adaptive-blur",option+1) == 0)
696 {
cristy3ed852e2009-09-05 21:47:34 +0000697 /*
698 Adaptive blur image.
699 */
cristy6b3da3a2010-06-20 02:21:46 +0000700 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000701 flags=ParseGeometry(argv[i+1],&geometry_info);
702 if ((flags & SigmaValue) == 0)
703 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000704 mogrify_image=AdaptiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +0000705 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000706 break;
707 }
708 if (LocaleCompare("adaptive-resize",option+1) == 0)
709 {
cristy3ed852e2009-09-05 21:47:34 +0000710 /*
711 Adaptive resize image.
712 */
cristy6b3da3a2010-06-20 02:21:46 +0000713 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000714 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +0000715 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +0000716 geometry.height,exception);
cristy3ed852e2009-09-05 21:47:34 +0000717 break;
718 }
719 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
720 {
cristy3ed852e2009-09-05 21:47:34 +0000721 /*
722 Adaptive sharpen image.
723 */
cristy6b3da3a2010-06-20 02:21:46 +0000724 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000725 flags=ParseGeometry(argv[i+1],&geometry_info);
726 if ((flags & SigmaValue) == 0)
727 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000728 mogrify_image=AdaptiveSharpenImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +0000729 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000730 break;
731 }
732 if (LocaleCompare("affine",option+1) == 0)
733 {
734 /*
735 Affine matrix.
736 */
737 if (*option == '+')
738 {
739 GetAffineMatrix(&draw_info->affine);
740 break;
741 }
742 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
743 break;
744 }
745 if (LocaleCompare("alpha",option+1) == 0)
746 {
747 AlphaChannelType
748 alpha_type;
749
cristy6b3da3a2010-06-20 02:21:46 +0000750 (void) SyncImageSettings(mogrify_info,*image);
cristy042ee782011-04-22 18:48:30 +0000751 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
cristy3ed852e2009-09-05 21:47:34 +0000752 MagickFalse,argv[i+1]);
753 (void) SetImageAlphaChannel(*image,alpha_type);
754 InheritException(exception,&(*image)->exception);
755 break;
756 }
757 if (LocaleCompare("annotate",option+1) == 0)
758 {
759 char
760 *text,
761 geometry[MaxTextExtent];
762
763 /*
764 Annotate image.
765 */
cristy6b3da3a2010-06-20 02:21:46 +0000766 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000767 SetGeometryInfo(&geometry_info);
768 flags=ParseGeometry(argv[i+1],&geometry_info);
769 if ((flags & SigmaValue) == 0)
770 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000771 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000772 InheritException(exception,&(*image)->exception);
773 if (text == (char *) NULL)
774 break;
775 (void) CloneString(&draw_info->text,text);
776 text=DestroyString(text);
777 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
778 geometry_info.xi,geometry_info.psi);
779 (void) CloneString(&draw_info->geometry,geometry);
780 draw_info->affine.sx=cos(DegreesToRadians(
781 fmod(geometry_info.rho,360.0)));
782 draw_info->affine.rx=sin(DegreesToRadians(
783 fmod(geometry_info.rho,360.0)));
784 draw_info->affine.ry=(-sin(DegreesToRadians(
785 fmod(geometry_info.sigma,360.0))));
786 draw_info->affine.sy=cos(DegreesToRadians(
787 fmod(geometry_info.sigma,360.0)));
788 (void) AnnotateImage(*image,draw_info);
789 InheritException(exception,&(*image)->exception);
790 break;
791 }
792 if (LocaleCompare("antialias",option+1) == 0)
793 {
794 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
795 MagickFalse;
796 draw_info->text_antialias=(*option == '-') ? MagickTrue :
797 MagickFalse;
798 break;
799 }
800 if (LocaleCompare("auto-gamma",option+1) == 0)
801 {
802 /*
803 Auto Adjust Gamma of image based on its mean
804 */
cristy6b3da3a2010-06-20 02:21:46 +0000805 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000806 (void) AutoGammaImageChannel(*image,channel);
807 break;
808 }
809 if (LocaleCompare("auto-level",option+1) == 0)
810 {
811 /*
812 Perfectly Normalize (max/min stretch) the image
813 */
cristy6b3da3a2010-06-20 02:21:46 +0000814 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000815 (void) AutoLevelImageChannel(*image,channel);
816 break;
817 }
818 if (LocaleCompare("auto-orient",option+1) == 0)
819 {
cristy6b3da3a2010-06-20 02:21:46 +0000820 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000821 switch ((*image)->orientation)
822 {
823 case TopRightOrientation:
824 {
cristyd241f442011-03-29 13:50:49 +0000825 mogrify_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000826 break;
827 }
828 case BottomRightOrientation:
829 {
cristyd241f442011-03-29 13:50:49 +0000830 mogrify_image=RotateImage(*image,180.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000831 break;
832 }
833 case BottomLeftOrientation:
834 {
cristyd241f442011-03-29 13:50:49 +0000835 mogrify_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000836 break;
837 }
838 case LeftTopOrientation:
839 {
cristyd241f442011-03-29 13:50:49 +0000840 mogrify_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000841 break;
842 }
843 case RightTopOrientation:
844 {
cristyd241f442011-03-29 13:50:49 +0000845 mogrify_image=RotateImage(*image,90.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000846 break;
847 }
848 case RightBottomOrientation:
849 {
cristyd241f442011-03-29 13:50:49 +0000850 mogrify_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000851 break;
852 }
853 case LeftBottomOrientation:
854 {
cristyd241f442011-03-29 13:50:49 +0000855 mogrify_image=RotateImage(*image,270.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000856 break;
857 }
858 default:
859 break;
860 }
cristyd241f442011-03-29 13:50:49 +0000861 if (mogrify_image != (Image *) NULL)
862 mogrify_image->orientation=TopLeftOrientation;
cristy3ed852e2009-09-05 21:47:34 +0000863 break;
864 }
865 break;
866 }
867 case 'b':
868 {
869 if (LocaleCompare("black-threshold",option+1) == 0)
870 {
871 /*
872 Black threshold image.
873 */
cristy6b3da3a2010-06-20 02:21:46 +0000874 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000875 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
876 exception);
877 InheritException(exception,&(*image)->exception);
878 break;
879 }
880 if (LocaleCompare("blue-shift",option+1) == 0)
881 {
cristy3ed852e2009-09-05 21:47:34 +0000882 /*
883 Blue shift image.
884 */
cristy6b3da3a2010-06-20 02:21:46 +0000885 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000886 geometry_info.rho=1.5;
887 if (*option == '-')
888 flags=ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +0000889 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +0000890 break;
891 }
892 if (LocaleCompare("blur",option+1) == 0)
893 {
cristy3ed852e2009-09-05 21:47:34 +0000894 /*
895 Gaussian blur image.
896 */
cristy6b3da3a2010-06-20 02:21:46 +0000897 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000898 flags=ParseGeometry(argv[i+1],&geometry_info);
899 if ((flags & SigmaValue) == 0)
900 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000901 mogrify_image=BlurImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +0000902 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000903 break;
904 }
905 if (LocaleCompare("border",option+1) == 0)
906 {
cristy3ed852e2009-09-05 21:47:34 +0000907 /*
908 Surround image with a border of solid color.
909 */
cristy6b3da3a2010-06-20 02:21:46 +0000910 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000911 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
912 if ((flags & SigmaValue) == 0)
913 geometry.height=geometry.width;
cristyd241f442011-03-29 13:50:49 +0000914 mogrify_image=BorderImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +0000915 break;
916 }
917 if (LocaleCompare("bordercolor",option+1) == 0)
918 {
919 if (*option == '+')
920 {
921 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
922 exception);
923 break;
924 }
925 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
926 exception);
927 break;
928 }
929 if (LocaleCompare("box",option+1) == 0)
930 {
931 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
932 exception);
933 break;
934 }
cristya28d6b82010-01-11 20:03:47 +0000935 if (LocaleCompare("brightness-contrast",option+1) == 0)
936 {
937 double
938 brightness,
939 contrast;
940
941 GeometryInfo
942 geometry_info;
943
944 MagickStatusType
945 flags;
946
947 /*
948 Brightness / contrast image.
949 */
cristy6b3da3a2010-06-20 02:21:46 +0000950 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000951 flags=ParseGeometry(argv[i+1],&geometry_info);
952 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000953 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000954 if ((flags & SigmaValue) != 0)
955 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000956 (void) BrightnessContrastImageChannel(*image,channel,brightness,
957 contrast);
cristya28d6b82010-01-11 20:03:47 +0000958 InheritException(exception,&(*image)->exception);
959 break;
960 }
cristy3ed852e2009-09-05 21:47:34 +0000961 break;
962 }
963 case 'c':
964 {
965 if (LocaleCompare("cdl",option+1) == 0)
966 {
967 char
968 *color_correction_collection;
969
970 /*
971 Color correct with a color decision list.
972 */
cristy6b3da3a2010-06-20 02:21:46 +0000973 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000974 color_correction_collection=FileToString(argv[i+1],~0,exception);
975 if (color_correction_collection == (char *) NULL)
976 break;
977 (void) ColorDecisionListImage(*image,color_correction_collection);
978 InheritException(exception,&(*image)->exception);
979 break;
980 }
981 if (LocaleCompare("channel",option+1) == 0)
982 {
983 if (*option == '+')
cristy3ed852e2009-09-05 21:47:34 +0000984 channel=DefaultChannels;
anthonye9c27192011-03-27 08:07:06 +0000985 else
986 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +0000987 break;
988 }
989 if (LocaleCompare("charcoal",option+1) == 0)
990 {
cristy3ed852e2009-09-05 21:47:34 +0000991 /*
992 Charcoal image.
993 */
cristy6b3da3a2010-06-20 02:21:46 +0000994 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000995 flags=ParseGeometry(argv[i+1],&geometry_info);
996 if ((flags & SigmaValue) == 0)
997 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000998 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +0000999 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001000 break;
1001 }
1002 if (LocaleCompare("chop",option+1) == 0)
1003 {
cristy3ed852e2009-09-05 21:47:34 +00001004 /*
1005 Chop the image.
1006 */
cristy6b3da3a2010-06-20 02:21:46 +00001007 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001008 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00001009 mogrify_image=ChopImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00001010 break;
1011 }
cristy1eb45dd2009-09-25 16:38:06 +00001012 if (LocaleCompare("clamp",option+1) == 0)
1013 {
1014 /*
1015 Clamp image.
1016 */
cristy6b3da3a2010-06-20 02:21:46 +00001017 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001018 (void) ClampImageChannel(*image,channel);
1019 InheritException(exception,&(*image)->exception);
1020 break;
1021 }
cristy3ed852e2009-09-05 21:47:34 +00001022 if (LocaleCompare("clip",option+1) == 0)
1023 {
cristy6b3da3a2010-06-20 02:21:46 +00001024 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001025 if (*option == '+')
1026 {
1027 (void) SetImageClipMask(*image,(Image *) NULL);
1028 InheritException(exception,&(*image)->exception);
1029 break;
1030 }
1031 (void) ClipImage(*image);
1032 InheritException(exception,&(*image)->exception);
1033 break;
1034 }
1035 if (LocaleCompare("clip-mask",option+1) == 0)
1036 {
cristyb0d3bb92010-09-22 14:37:58 +00001037 CacheView
1038 *mask_view;
cristya01cbea2010-11-03 16:33:33 +00001039
cristy3ed852e2009-09-05 21:47:34 +00001040 Image
cristyb0d3bb92010-09-22 14:37:58 +00001041 *mask_image;
cristy3ed852e2009-09-05 21:47:34 +00001042
cristy9d314ff2011-03-09 01:30:28 +00001043 register PixelPacket
1044 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001045
cristybb503372010-05-27 20:51:26 +00001046 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001047 x;
1048
cristy9d314ff2011-03-09 01:30:28 +00001049 ssize_t
1050 y;
cristy3ed852e2009-09-05 21:47:34 +00001051
cristy6b3da3a2010-06-20 02:21:46 +00001052 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001053 if (*option == '+')
1054 {
1055 /*
1056 Remove a mask.
1057 */
1058 (void) SetImageMask(*image,(Image *) NULL);
1059 InheritException(exception,&(*image)->exception);
1060 break;
1061 }
1062 /*
1063 Set the image mask.
anthony77cc4a42011-04-14 02:59:06 +00001064 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
cristy3ed852e2009-09-05 21:47:34 +00001065 */
cristyb0d3bb92010-09-22 14:37:58 +00001066 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1067 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001068 break;
cristyb0d3bb92010-09-22 14:37:58 +00001069 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1070 return(MagickFalse);
1071 mask_view=AcquireCacheView(mask_image);
1072 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001073 {
cristyb0d3bb92010-09-22 14:37:58 +00001074 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1075 exception);
cristy3ed852e2009-09-05 21:47:34 +00001076 if (q == (PixelPacket *) NULL)
1077 break;
cristyb0d3bb92010-09-22 14:37:58 +00001078 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001079 {
cristyb0d3bb92010-09-22 14:37:58 +00001080 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001081 q->opacity=PixelIntensityToQuantum(q);
1082 q->red=q->opacity;
1083 q->green=q->opacity;
1084 q->blue=q->opacity;
1085 q++;
1086 }
cristyb0d3bb92010-09-22 14:37:58 +00001087 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001088 break;
1089 }
cristyb0d3bb92010-09-22 14:37:58 +00001090 mask_view=DestroyCacheView(mask_view);
1091 mask_image->matte=MagickTrue;
1092 (void) SetImageClipMask(*image,mask_image);
1093 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001094 InheritException(exception,&(*image)->exception);
1095 break;
1096 }
1097 if (LocaleCompare("clip-path",option+1) == 0)
1098 {
cristy6b3da3a2010-06-20 02:21:46 +00001099 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001100 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1101 MagickFalse);
1102 InheritException(exception,&(*image)->exception);
1103 break;
1104 }
1105 if (LocaleCompare("colorize",option+1) == 0)
1106 {
cristy3ed852e2009-09-05 21:47:34 +00001107 /*
1108 Colorize the image.
1109 */
cristy6b3da3a2010-06-20 02:21:46 +00001110 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001111 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
cristy3ed852e2009-09-05 21:47:34 +00001112 exception);
cristy3ed852e2009-09-05 21:47:34 +00001113 break;
1114 }
cristye6365592010-04-02 17:31:23 +00001115 if (LocaleCompare("color-matrix",option+1) == 0)
1116 {
cristye6365592010-04-02 17:31:23 +00001117 KernelInfo
1118 *kernel;
1119
cristy6b3da3a2010-06-20 02:21:46 +00001120 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001121 kernel=AcquireKernelInfo(argv[i+1]);
1122 if (kernel == (KernelInfo *) NULL)
1123 break;
cristyd241f442011-03-29 13:50:49 +00001124 mogrify_image=ColorMatrixImage(*image,kernel,exception);
cristye6365592010-04-02 17:31:23 +00001125 kernel=DestroyKernelInfo(kernel);
cristye6365592010-04-02 17:31:23 +00001126 break;
1127 }
cristy3ed852e2009-09-05 21:47:34 +00001128 if (LocaleCompare("colors",option+1) == 0)
1129 {
1130 /*
1131 Reduce the number of colors in the image.
1132 */
cristy6b3da3a2010-06-20 02:21:46 +00001133 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001134 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001135 if (quantize_info->number_colors == 0)
1136 break;
1137 if (((*image)->storage_class == DirectClass) ||
1138 (*image)->colors > quantize_info->number_colors)
1139 (void) QuantizeImage(quantize_info,*image);
1140 else
1141 (void) CompressImageColormap(*image);
1142 InheritException(exception,&(*image)->exception);
1143 break;
1144 }
1145 if (LocaleCompare("colorspace",option+1) == 0)
1146 {
1147 ColorspaceType
1148 colorspace;
1149
cristy6b3da3a2010-06-20 02:21:46 +00001150 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001151 if (*option == '+')
1152 {
1153 (void) TransformImageColorspace(*image,RGBColorspace);
1154 InheritException(exception,&(*image)->exception);
1155 break;
1156 }
cristy042ee782011-04-22 18:48:30 +00001157 colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00001158 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1159 (void) TransformImageColorspace(*image,colorspace);
1160 InheritException(exception,&(*image)->exception);
1161 break;
1162 }
1163 if (LocaleCompare("contrast",option+1) == 0)
1164 {
cristy6b3da3a2010-06-20 02:21:46 +00001165 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001166 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1167 MagickFalse);
1168 InheritException(exception,&(*image)->exception);
1169 break;
1170 }
1171 if (LocaleCompare("contrast-stretch",option+1) == 0)
1172 {
1173 double
1174 black_point,
1175 white_point;
1176
cristy3ed852e2009-09-05 21:47:34 +00001177 MagickStatusType
1178 flags;
1179
1180 /*
1181 Contrast stretch image.
1182 */
cristy6b3da3a2010-06-20 02:21:46 +00001183 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001184 flags=ParseGeometry(argv[i+1],&geometry_info);
1185 black_point=geometry_info.rho;
1186 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1187 black_point;
1188 if ((flags & PercentValue) != 0)
1189 {
1190 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1191 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1192 }
1193 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1194 white_point;
1195 (void) ContrastStretchImageChannel(*image,channel,black_point,
1196 white_point);
1197 InheritException(exception,&(*image)->exception);
1198 break;
1199 }
1200 if (LocaleCompare("convolve",option+1) == 0)
1201 {
cristy36826ab2010-03-06 01:29:30 +00001202 double
1203 gamma;
1204
cristy2be15382010-01-21 02:38:03 +00001205 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001206 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001207
cristybb503372010-05-27 20:51:26 +00001208 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001209 j;
1210
cristy6b3da3a2010-06-20 02:21:46 +00001211 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001212 kernel=AcquireKernelInfo(argv[i+1]);
1213 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001214 break;
cristy36826ab2010-03-06 01:29:30 +00001215 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001216 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001217 gamma+=kernel->values[j];
1218 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001219 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001220 kernel->values[j]*=gamma;
cristyd241f442011-03-29 13:50:49 +00001221 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001222 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001223 break;
1224 }
1225 if (LocaleCompare("crop",option+1) == 0)
1226 {
anthonye9c27192011-03-27 08:07:06 +00001227 /*
1228 Crop a image to a smaller size
anthonye9c27192011-03-27 08:07:06 +00001229 */
cristy6b3da3a2010-06-20 02:21:46 +00001230 (void) SyncImageSettings(mogrify_info,*image);
anthony9f4f0342011-03-28 11:47:22 +00001231#if 0
cristy3ed852e2009-09-05 21:47:34 +00001232 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1233 if (((geometry.width != 0) || (geometry.height != 0)) &&
1234 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1235 break;
anthony9f4f0342011-03-28 11:47:22 +00001236#endif
1237#if 0
cristyd241f442011-03-29 13:50:49 +00001238 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1239 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1240 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1241 InheritException(exception,&mogrify_image->exception);
anthony9f4f0342011-03-28 11:47:22 +00001242#else
cristyd241f442011-03-29 13:50:49 +00001243 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthony9f4f0342011-03-28 11:47:22 +00001244#endif
cristy3ed852e2009-09-05 21:47:34 +00001245 break;
1246 }
1247 if (LocaleCompare("cycle",option+1) == 0)
1248 {
1249 /*
1250 Cycle an image colormap.
1251 */
cristy6b3da3a2010-06-20 02:21:46 +00001252 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001253 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001254 InheritException(exception,&(*image)->exception);
1255 break;
1256 }
1257 break;
1258 }
1259 case 'd':
1260 {
1261 if (LocaleCompare("decipher",option+1) == 0)
1262 {
1263 StringInfo
1264 *passkey;
1265
1266 /*
1267 Decipher pixels.
1268 */
cristy6b3da3a2010-06-20 02:21:46 +00001269 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001270 passkey=FileToStringInfo(argv[i+1],~0,exception);
1271 if (passkey != (StringInfo *) NULL)
1272 {
1273 (void) PasskeyDecipherImage(*image,passkey,exception);
1274 passkey=DestroyStringInfo(passkey);
1275 }
1276 break;
1277 }
1278 if (LocaleCompare("density",option+1) == 0)
1279 {
1280 /*
1281 Set image density.
1282 */
1283 (void) CloneString(&draw_info->density,argv[i+1]);
1284 break;
1285 }
1286 if (LocaleCompare("depth",option+1) == 0)
1287 {
cristy6b3da3a2010-06-20 02:21:46 +00001288 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001289 if (*option == '+')
1290 {
1291 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1292 break;
1293 }
cristye27293e2009-12-18 02:53:20 +00001294 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001295 break;
1296 }
1297 if (LocaleCompare("deskew",option+1) == 0)
1298 {
1299 double
1300 threshold;
1301
cristy3ed852e2009-09-05 21:47:34 +00001302 /*
1303 Straighten the image.
1304 */
cristy6b3da3a2010-06-20 02:21:46 +00001305 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001306 if (*option == '+')
1307 threshold=40.0*QuantumRange/100.0;
1308 else
cristyf2f27272009-12-17 14:48:46 +00001309 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00001310 mogrify_image=DeskewImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00001311 break;
1312 }
1313 if (LocaleCompare("despeckle",option+1) == 0)
1314 {
cristy3ed852e2009-09-05 21:47:34 +00001315 /*
1316 Reduce the speckles within an image.
1317 */
cristy6b3da3a2010-06-20 02:21:46 +00001318 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001319 mogrify_image=DespeckleImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001320 break;
1321 }
1322 if (LocaleCompare("display",option+1) == 0)
1323 {
1324 (void) CloneString(&draw_info->server_name,argv[i+1]);
1325 break;
1326 }
cristy3ed852e2009-09-05 21:47:34 +00001327 if (LocaleCompare("distort",option+1) == 0)
1328 {
1329 char
1330 *args,
1331 token[MaxTextExtent];
1332
1333 const char
1334 *p;
1335
1336 DistortImageMethod
1337 method;
1338
1339 double
1340 *arguments;
1341
cristybb503372010-05-27 20:51:26 +00001342 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001343 x;
1344
cristybb503372010-05-27 20:51:26 +00001345 size_t
cristy3ed852e2009-09-05 21:47:34 +00001346 number_arguments;
1347
1348 /*
1349 Distort image.
1350 */
cristy6b3da3a2010-06-20 02:21:46 +00001351 (void) SyncImageSettings(mogrify_info,*image);
cristy042ee782011-04-22 18:48:30 +00001352 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
cristy3ed852e2009-09-05 21:47:34 +00001353 MagickFalse,argv[i+1]);
anthony2029ddc2011-03-30 12:13:27 +00001354 if ( method == ResizeDistortion )
1355 {
1356 /* Special Case - Argument is actually a resize geometry!
1357 ** Convert that to an appropriate distortion argument array.
1358 */
1359 double
1360 resize_args[2];
1361 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1362 exception);
1363 resize_args[0]=(double)geometry.width;
1364 resize_args[1]=(double)geometry.height;
1365 mogrify_image=DistortImage(*image,method,(size_t)2,
1366 resize_args,MagickTrue,exception);
1367 break;
1368 }
cristy6b3da3a2010-06-20 02:21:46 +00001369 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001370 InheritException(exception,&(*image)->exception);
1371 if (args == (char *) NULL)
1372 break;
1373 p=(char *) args;
1374 for (x=0; *p != '\0'; x++)
1375 {
1376 GetMagickToken(p,&p,token);
1377 if (*token == ',')
1378 GetMagickToken(p,&p,token);
1379 }
cristybb503372010-05-27 20:51:26 +00001380 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001381 arguments=(double *) AcquireQuantumMemory(number_arguments,
1382 sizeof(*arguments));
1383 if (arguments == (double *) NULL)
1384 ThrowWandFatalException(ResourceLimitFatalError,
1385 "MemoryAllocationFailed",(*image)->filename);
1386 (void) ResetMagickMemory(arguments,0,number_arguments*
1387 sizeof(*arguments));
1388 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001389 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001390 {
1391 GetMagickToken(p,&p,token);
1392 if (*token == ',')
1393 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001394 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001395 }
1396 args=DestroyString(args);
cristyd241f442011-03-29 13:50:49 +00001397 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
cristy3ed852e2009-09-05 21:47:34 +00001398 (*option == '+') ? MagickTrue : MagickFalse,exception);
1399 arguments=(double *) RelinquishMagickMemory(arguments);
cristy3ed852e2009-09-05 21:47:34 +00001400 break;
1401 }
1402 if (LocaleCompare("dither",option+1) == 0)
1403 {
1404 if (*option == '+')
1405 {
1406 quantize_info->dither=MagickFalse;
1407 break;
1408 }
1409 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00001410 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00001411 MagickDitherOptions,MagickFalse,argv[i+1]);
1412 if (quantize_info->dither_method == NoDitherMethod)
1413 quantize_info->dither=MagickFalse;
1414 break;
1415 }
1416 if (LocaleCompare("draw",option+1) == 0)
1417 {
1418 /*
1419 Draw image.
1420 */
cristy6b3da3a2010-06-20 02:21:46 +00001421 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001422 (void) CloneString(&draw_info->primitive,argv[i+1]);
1423 (void) DrawImage(*image,draw_info);
1424 InheritException(exception,&(*image)->exception);
1425 break;
1426 }
1427 break;
1428 }
1429 case 'e':
1430 {
1431 if (LocaleCompare("edge",option+1) == 0)
1432 {
cristy3ed852e2009-09-05 21:47:34 +00001433 /*
1434 Enhance edges in the image.
1435 */
cristy6b3da3a2010-06-20 02:21:46 +00001436 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001437 flags=ParseGeometry(argv[i+1],&geometry_info);
1438 if ((flags & SigmaValue) == 0)
1439 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001440 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001441 break;
1442 }
1443 if (LocaleCompare("emboss",option+1) == 0)
1444 {
cristy3ed852e2009-09-05 21:47:34 +00001445 /*
1446 Gaussian embossen image.
1447 */
cristy6b3da3a2010-06-20 02:21:46 +00001448 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001449 flags=ParseGeometry(argv[i+1],&geometry_info);
1450 if ((flags & SigmaValue) == 0)
1451 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001452 mogrify_image=EmbossImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00001453 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001454 break;
1455 }
1456 if (LocaleCompare("encipher",option+1) == 0)
1457 {
1458 StringInfo
1459 *passkey;
1460
1461 /*
1462 Encipher pixels.
1463 */
cristy6b3da3a2010-06-20 02:21:46 +00001464 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001465 passkey=FileToStringInfo(argv[i+1],~0,exception);
1466 if (passkey != (StringInfo *) NULL)
1467 {
1468 (void) PasskeyEncipherImage(*image,passkey,exception);
1469 passkey=DestroyStringInfo(passkey);
1470 }
1471 break;
1472 }
1473 if (LocaleCompare("encoding",option+1) == 0)
1474 {
1475 (void) CloneString(&draw_info->encoding,argv[i+1]);
1476 break;
1477 }
1478 if (LocaleCompare("enhance",option+1) == 0)
1479 {
cristy3ed852e2009-09-05 21:47:34 +00001480 /*
1481 Enhance image.
1482 */
cristy6b3da3a2010-06-20 02:21:46 +00001483 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001484 mogrify_image=EnhanceImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001485 break;
1486 }
1487 if (LocaleCompare("equalize",option+1) == 0)
1488 {
1489 /*
1490 Equalize image.
1491 */
cristy6b3da3a2010-06-20 02:21:46 +00001492 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001493 (void) EqualizeImageChannel(*image,channel);
1494 InheritException(exception,&(*image)->exception);
1495 break;
1496 }
1497 if (LocaleCompare("evaluate",option+1) == 0)
1498 {
1499 double
1500 constant;
1501
1502 MagickEvaluateOperator
1503 op;
1504
cristy6b3da3a2010-06-20 02:21:46 +00001505 (void) SyncImageSettings(mogrify_info,*image);
cristy042ee782011-04-22 18:48:30 +00001506 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristy3ed852e2009-09-05 21:47:34 +00001507 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001508 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001509 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1510 break;
1511 }
1512 if (LocaleCompare("extent",option+1) == 0)
1513 {
cristy3ed852e2009-09-05 21:47:34 +00001514 /*
1515 Set the image extent.
1516 */
cristy6b3da3a2010-06-20 02:21:46 +00001517 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001518 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001519 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001520 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001521 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001522 geometry.height=(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00001523 mogrify_image=ExtentImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00001524 break;
1525 }
1526 break;
1527 }
1528 case 'f':
1529 {
1530 if (LocaleCompare("family",option+1) == 0)
1531 {
1532 if (*option == '+')
1533 {
1534 if (draw_info->family != (char *) NULL)
1535 draw_info->family=DestroyString(draw_info->family);
1536 break;
1537 }
1538 (void) CloneString(&draw_info->family,argv[i+1]);
1539 break;
1540 }
cristy0fe961c2010-01-30 03:09:54 +00001541 if (LocaleCompare("features",option+1) == 0)
1542 {
1543 if (*option == '+')
1544 {
1545 (void) DeleteImageArtifact(*image,"identify:features");
1546 break;
1547 }
1548 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1549 break;
1550 }
cristy3ed852e2009-09-05 21:47:34 +00001551 if (LocaleCompare("fill",option+1) == 0)
1552 {
1553 ExceptionInfo
1554 *sans;
1555
1556 GetMagickPixelPacket(*image,&fill);
1557 if (*option == '+')
1558 {
1559 (void) QueryMagickColor("none",&fill,exception);
1560 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1561 if (draw_info->fill_pattern != (Image *) NULL)
1562 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1563 break;
1564 }
1565 sans=AcquireExceptionInfo();
1566 (void) QueryMagickColor(argv[i+1],&fill,sans);
1567 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1568 sans=DestroyExceptionInfo(sans);
1569 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001570 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001571 exception);
1572 break;
1573 }
1574 if (LocaleCompare("flip",option+1) == 0)
1575 {
cristy3ed852e2009-09-05 21:47:34 +00001576 /*
1577 Flip image scanlines.
1578 */
cristy6b3da3a2010-06-20 02:21:46 +00001579 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001580 mogrify_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001581 break;
1582 }
1583 if (LocaleCompare("flop",option+1) == 0)
1584 {
cristy3ed852e2009-09-05 21:47:34 +00001585 /*
1586 Flop image scanlines.
1587 */
cristy6b3da3a2010-06-20 02:21:46 +00001588 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001589 mogrify_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001590 break;
1591 }
1592 if (LocaleCompare("floodfill",option+1) == 0)
1593 {
1594 MagickPixelPacket
1595 target;
1596
1597 /*
1598 Floodfill image.
1599 */
cristy6b3da3a2010-06-20 02:21:46 +00001600 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001601 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1602 (void) QueryMagickColor(argv[i+2],&target,exception);
1603 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1604 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1605 InheritException(exception,&(*image)->exception);
1606 break;
1607 }
1608 if (LocaleCompare("font",option+1) == 0)
1609 {
1610 if (*option == '+')
1611 {
1612 if (draw_info->font != (char *) NULL)
1613 draw_info->font=DestroyString(draw_info->font);
1614 break;
1615 }
1616 (void) CloneString(&draw_info->font,argv[i+1]);
1617 break;
1618 }
1619 if (LocaleCompare("format",option+1) == 0)
1620 {
1621 format=argv[i+1];
1622 break;
1623 }
1624 if (LocaleCompare("frame",option+1) == 0)
1625 {
1626 FrameInfo
1627 frame_info;
1628
cristy3ed852e2009-09-05 21:47:34 +00001629 /*
1630 Surround image with an ornamental border.
1631 */
cristy6b3da3a2010-06-20 02:21:46 +00001632 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001633 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1634 frame_info.width=geometry.width;
1635 frame_info.height=geometry.height;
1636 if ((flags & HeightValue) == 0)
1637 frame_info.height=geometry.width;
1638 frame_info.outer_bevel=geometry.x;
1639 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001640 frame_info.x=(ssize_t) frame_info.width;
1641 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001642 frame_info.width=(*image)->columns+2*frame_info.width;
1643 frame_info.height=(*image)->rows+2*frame_info.height;
cristyd241f442011-03-29 13:50:49 +00001644 mogrify_image=FrameImage(*image,&frame_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00001645 break;
1646 }
1647 if (LocaleCompare("function",option+1) == 0)
1648 {
1649 char
1650 *arguments,
1651 token[MaxTextExtent];
1652
1653 const char
1654 *p;
1655
1656 double
1657 *parameters;
1658
1659 MagickFunction
1660 function;
1661
cristybb503372010-05-27 20:51:26 +00001662 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001663 x;
1664
cristybb503372010-05-27 20:51:26 +00001665 size_t
cristy3ed852e2009-09-05 21:47:34 +00001666 number_parameters;
1667
1668 /*
1669 Function Modify Image Values
1670 */
cristy6b3da3a2010-06-20 02:21:46 +00001671 (void) SyncImageSettings(mogrify_info,*image);
cristy042ee782011-04-22 18:48:30 +00001672 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
cristy3ed852e2009-09-05 21:47:34 +00001673 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001674 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001675 InheritException(exception,&(*image)->exception);
1676 if (arguments == (char *) NULL)
1677 break;
1678 p=(char *) arguments;
1679 for (x=0; *p != '\0'; x++)
1680 {
1681 GetMagickToken(p,&p,token);
1682 if (*token == ',')
1683 GetMagickToken(p,&p,token);
1684 }
cristybb503372010-05-27 20:51:26 +00001685 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001686 parameters=(double *) AcquireQuantumMemory(number_parameters,
1687 sizeof(*parameters));
1688 if (parameters == (double *) NULL)
1689 ThrowWandFatalException(ResourceLimitFatalError,
1690 "MemoryAllocationFailed",(*image)->filename);
1691 (void) ResetMagickMemory(parameters,0,number_parameters*
1692 sizeof(*parameters));
1693 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001694 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001695 {
1696 GetMagickToken(p,&p,token);
1697 if (*token == ',')
1698 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001699 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001700 }
1701 arguments=DestroyString(arguments);
1702 (void) FunctionImageChannel(*image,channel,function,
1703 number_parameters,parameters,exception);
1704 parameters=(double *) RelinquishMagickMemory(parameters);
1705 break;
1706 }
1707 break;
1708 }
1709 case 'g':
1710 {
1711 if (LocaleCompare("gamma",option+1) == 0)
1712 {
1713 /*
1714 Gamma image.
1715 */
cristy6b3da3a2010-06-20 02:21:46 +00001716 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001717 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001718 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001719 else
1720 {
1721 if (strchr(argv[i+1],',') != (char *) NULL)
1722 (void) GammaImage(*image,argv[i+1]);
1723 else
cristya5447be2010-01-11 00:20:51 +00001724 (void) GammaImageChannel(*image,channel,
1725 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001726 InheritException(exception,&(*image)->exception);
1727 }
1728 break;
1729 }
1730 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1731 (LocaleCompare("gaussian",option+1) == 0))
1732 {
cristy3ed852e2009-09-05 21:47:34 +00001733 /*
1734 Gaussian blur image.
1735 */
cristy6b3da3a2010-06-20 02:21:46 +00001736 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001737 flags=ParseGeometry(argv[i+1],&geometry_info);
1738 if ((flags & SigmaValue) == 0)
1739 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001740 mogrify_image=GaussianBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00001741 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001742 break;
1743 }
1744 if (LocaleCompare("geometry",option+1) == 0)
1745 {
anthonye9c27192011-03-27 08:07:06 +00001746 /*
1747 Record Image offset, Resize last image.
1748 */
cristy6b3da3a2010-06-20 02:21:46 +00001749 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001750 if (*option == '+')
1751 {
1752 if ((*image)->geometry != (char *) NULL)
1753 (*image)->geometry=DestroyString((*image)->geometry);
1754 break;
1755 }
1756 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1757 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1758 (void) CloneString(&(*image)->geometry,argv[i+1]);
1759 else
cristyd241f442011-03-29 13:50:49 +00001760 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
anthonye9c27192011-03-27 08:07:06 +00001761 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00001762 break;
1763 }
1764 if (LocaleCompare("gravity",option+1) == 0)
1765 {
1766 if (*option == '+')
1767 {
1768 draw_info->gravity=UndefinedGravity;
1769 break;
1770 }
cristy042ee782011-04-22 18:48:30 +00001771 draw_info->gravity=(GravityType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00001772 MagickGravityOptions,MagickFalse,argv[i+1]);
1773 break;
1774 }
1775 break;
1776 }
1777 case 'h':
1778 {
1779 if (LocaleCompare("highlight-color",option+1) == 0)
1780 {
1781 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1782 break;
1783 }
1784 break;
1785 }
1786 case 'i':
1787 {
1788 if (LocaleCompare("identify",option+1) == 0)
1789 {
1790 char
1791 *text;
1792
cristy6b3da3a2010-06-20 02:21:46 +00001793 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001794 if (format == (char *) NULL)
1795 {
cristy6b3da3a2010-06-20 02:21:46 +00001796 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001797 InheritException(exception,&(*image)->exception);
1798 break;
1799 }
cristy6b3da3a2010-06-20 02:21:46 +00001800 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001801 InheritException(exception,&(*image)->exception);
1802 if (text == (char *) NULL)
1803 break;
1804 (void) fputs(text,stdout);
1805 (void) fputc('\n',stdout);
1806 text=DestroyString(text);
1807 break;
1808 }
1809 if (LocaleCompare("implode",option+1) == 0)
1810 {
cristy3ed852e2009-09-05 21:47:34 +00001811 /*
1812 Implode image.
1813 */
cristy6b3da3a2010-06-20 02:21:46 +00001814 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001815 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00001816 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001817 break;
1818 }
cristyb32b90a2009-09-07 21:45:48 +00001819 if (LocaleCompare("interline-spacing",option+1) == 0)
1820 {
1821 if (*option == '+')
1822 (void) ParseGeometry("0",&geometry_info);
1823 else
1824 (void) ParseGeometry(argv[i+1],&geometry_info);
1825 draw_info->interline_spacing=geometry_info.rho;
1826 break;
1827 }
cristy3ed852e2009-09-05 21:47:34 +00001828 if (LocaleCompare("interword-spacing",option+1) == 0)
1829 {
1830 if (*option == '+')
1831 (void) ParseGeometry("0",&geometry_info);
1832 else
1833 (void) ParseGeometry(argv[i+1],&geometry_info);
1834 draw_info->interword_spacing=geometry_info.rho;
1835 break;
1836 }
1837 break;
1838 }
1839 case 'k':
1840 {
1841 if (LocaleCompare("kerning",option+1) == 0)
1842 {
1843 if (*option == '+')
1844 (void) ParseGeometry("0",&geometry_info);
1845 else
1846 (void) ParseGeometry(argv[i+1],&geometry_info);
1847 draw_info->kerning=geometry_info.rho;
1848 break;
1849 }
1850 break;
1851 }
1852 case 'l':
1853 {
1854 if (LocaleCompare("lat",option+1) == 0)
1855 {
cristy3ed852e2009-09-05 21:47:34 +00001856 /*
1857 Local adaptive threshold image.
1858 */
cristy6b3da3a2010-06-20 02:21:46 +00001859 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001860 flags=ParseGeometry(argv[i+1],&geometry_info);
1861 if ((flags & PercentValue) != 0)
1862 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00001863 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1864 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1865 geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001866 break;
1867 }
1868 if (LocaleCompare("level",option+1) == 0)
1869 {
cristy3ed852e2009-09-05 21:47:34 +00001870 MagickRealType
1871 black_point,
1872 gamma,
1873 white_point;
1874
1875 MagickStatusType
1876 flags;
1877
1878 /*
1879 Parse levels.
1880 */
cristy6b3da3a2010-06-20 02:21:46 +00001881 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001882 flags=ParseGeometry(argv[i+1],&geometry_info);
1883 black_point=geometry_info.rho;
1884 white_point=(MagickRealType) QuantumRange;
1885 if ((flags & SigmaValue) != 0)
1886 white_point=geometry_info.sigma;
1887 gamma=1.0;
1888 if ((flags & XiValue) != 0)
1889 gamma=geometry_info.xi;
1890 if ((flags & PercentValue) != 0)
1891 {
1892 black_point*=(MagickRealType) (QuantumRange/100.0);
1893 white_point*=(MagickRealType) (QuantumRange/100.0);
1894 }
1895 if ((flags & SigmaValue) == 0)
1896 white_point=(MagickRealType) QuantumRange-black_point;
1897 if ((*option == '+') || ((flags & AspectValue) != 0))
1898 (void) LevelizeImageChannel(*image,channel,black_point,
1899 white_point,gamma);
1900 else
1901 (void) LevelImageChannel(*image,channel,black_point,white_point,
1902 gamma);
1903 InheritException(exception,&(*image)->exception);
1904 break;
1905 }
1906 if (LocaleCompare("level-colors",option+1) == 0)
1907 {
1908 char
1909 token[MaxTextExtent];
1910
1911 const char
1912 *p;
1913
1914 MagickPixelPacket
1915 black_point,
1916 white_point;
1917
1918 p=(const char *) argv[i+1];
1919 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00001920 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001921 (void) QueryMagickColor(token,&black_point,exception);
1922 else
cristyee0f8d72009-09-19 00:58:29 +00001923 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001924 if (isalpha((int) token[0]) || (token[0] == '#'))
1925 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00001926 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00001927 white_point=black_point; /* set everything to that color */
1928 else
1929 {
cristyee0f8d72009-09-19 00:58:29 +00001930 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
anthonye9c27192011-03-27 08:07:06 +00001931 GetMagickToken(p,&p,token); /* Get white point color. */
cristyee0f8d72009-09-19 00:58:29 +00001932 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001933 (void) QueryMagickColor(token,&white_point,exception);
1934 else
cristyee0f8d72009-09-19 00:58:29 +00001935 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001936 }
cristy74fe8f12009-10-03 19:09:01 +00001937 (void) LevelColorsImageChannel(*image,channel,&black_point,
1938 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001939 break;
1940 }
1941 if (LocaleCompare("linear-stretch",option+1) == 0)
1942 {
1943 double
1944 black_point,
1945 white_point;
1946
cristy3ed852e2009-09-05 21:47:34 +00001947 MagickStatusType
1948 flags;
1949
cristy6b3da3a2010-06-20 02:21:46 +00001950 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001951 flags=ParseGeometry(argv[i+1],&geometry_info);
1952 black_point=geometry_info.rho;
1953 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1954 if ((flags & SigmaValue) != 0)
1955 white_point=geometry_info.sigma;
1956 if ((flags & PercentValue) != 0)
1957 {
1958 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1959 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1960 }
1961 if ((flags & SigmaValue) == 0)
1962 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1963 black_point;
1964 (void) LinearStretchImage(*image,black_point,white_point);
1965 InheritException(exception,&(*image)->exception);
1966 break;
1967 }
1968 if (LocaleCompare("linewidth",option+1) == 0)
1969 {
cristyf2f27272009-12-17 14:48:46 +00001970 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001971 break;
1972 }
1973 if (LocaleCompare("liquid-rescale",option+1) == 0)
1974 {
cristy3ed852e2009-09-05 21:47:34 +00001975 /*
1976 Liquid rescale image.
1977 */
cristy6b3da3a2010-06-20 02:21:46 +00001978 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001979 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1980 if ((flags & XValue) == 0)
1981 geometry.x=1;
1982 if ((flags & YValue) == 0)
1983 geometry.y=0;
cristyd241f442011-03-29 13:50:49 +00001984 mogrify_image=LiquidRescaleImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +00001985 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00001986 break;
1987 }
1988 if (LocaleCompare("lowlight-color",option+1) == 0)
1989 {
1990 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1991 break;
1992 }
1993 break;
1994 }
1995 case 'm':
1996 {
1997 if (LocaleCompare("map",option+1) == 0)
1998 {
1999 Image
2000 *remap_image;
2001
2002 /*
2003 Transform image colors to match this set of colors.
2004 */
cristy6b3da3a2010-06-20 02:21:46 +00002005 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002006 if (*option == '+')
2007 break;
cristy6b3da3a2010-06-20 02:21:46 +00002008 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002009 if (remap_image == (Image *) NULL)
2010 break;
2011 (void) RemapImage(quantize_info,*image,remap_image);
2012 InheritException(exception,&(*image)->exception);
2013 remap_image=DestroyImage(remap_image);
2014 break;
2015 }
2016 if (LocaleCompare("mask",option+1) == 0)
2017 {
2018 Image
2019 *mask;
2020
cristy6b3da3a2010-06-20 02:21:46 +00002021 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002022 if (*option == '+')
2023 {
2024 /*
2025 Remove a mask.
2026 */
2027 (void) SetImageMask(*image,(Image *) NULL);
2028 InheritException(exception,&(*image)->exception);
2029 break;
2030 }
2031 /*
2032 Set the image mask.
2033 */
cristy6b3da3a2010-06-20 02:21:46 +00002034 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002035 if (mask == (Image *) NULL)
2036 break;
2037 (void) SetImageMask(*image,mask);
2038 mask=DestroyImage(mask);
2039 InheritException(exception,&(*image)->exception);
2040 break;
2041 }
2042 if (LocaleCompare("matte",option+1) == 0)
2043 {
2044 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2045 SetAlphaChannel : DeactivateAlphaChannel );
2046 InheritException(exception,&(*image)->exception);
2047 break;
2048 }
2049 if (LocaleCompare("median",option+1) == 0)
2050 {
cristy3ed852e2009-09-05 21:47:34 +00002051 /*
2052 Median filter image.
2053 */
cristy6b3da3a2010-06-20 02:21:46 +00002054 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002055 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002056 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
cristy95c38342011-03-18 22:39:51 +00002057 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002058 break;
2059 }
cristy69ec32d2011-02-27 23:57:09 +00002060 if (LocaleCompare("mode",option+1) == 0)
2061 {
cristy69ec32d2011-02-27 23:57:09 +00002062 /*
2063 Mode image.
2064 */
2065 (void) SyncImageSettings(mogrify_info,*image);
2066 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002067 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
cristy95c38342011-03-18 22:39:51 +00002068 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy69ec32d2011-02-27 23:57:09 +00002069 break;
2070 }
cristy3ed852e2009-09-05 21:47:34 +00002071 if (LocaleCompare("modulate",option+1) == 0)
2072 {
cristy6b3da3a2010-06-20 02:21:46 +00002073 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002074 (void) ModulateImage(*image,argv[i+1]);
2075 InheritException(exception,&(*image)->exception);
2076 break;
2077 }
2078 if (LocaleCompare("monitor",option+1) == 0)
2079 {
cristy7d34ef22010-03-25 01:11:22 +00002080 if (*option == '+')
2081 {
2082 (void) SetImageProgressMonitor(*image,
2083 (MagickProgressMonitor) NULL,(void *) NULL);
2084 break;
2085 }
cristy3ed852e2009-09-05 21:47:34 +00002086 (void) SetImageProgressMonitor(*image,MonitorProgress,
2087 (void *) NULL);
2088 break;
2089 }
2090 if (LocaleCompare("monochrome",option+1) == 0)
2091 {
cristy6b3da3a2010-06-20 02:21:46 +00002092 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002093 (void) SetImageType(*image,BilevelType);
2094 InheritException(exception,&(*image)->exception);
2095 break;
2096 }
anthony29188a82010-01-22 10:12:34 +00002097 if (LocaleCompare("morphology",option+1) == 0)
2098 {
anthony29188a82010-01-22 10:12:34 +00002099 char
2100 token[MaxTextExtent];
2101
2102 const char
2103 *p;
2104
cristye96405a2010-05-19 02:24:31 +00002105 KernelInfo
2106 *kernel;
2107
cristye96405a2010-05-19 02:24:31 +00002108 MorphologyMethod
2109 method;
2110
cristy9d314ff2011-03-09 01:30:28 +00002111 ssize_t
2112 iterations;
2113
anthony29188a82010-01-22 10:12:34 +00002114 /*
2115 Morphological Image Operation
2116 */
cristy6b3da3a2010-06-20 02:21:46 +00002117 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002118 p=argv[i+1];
2119 GetMagickToken(p,&p,token);
cristy042ee782011-04-22 18:48:30 +00002120 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002121 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002122 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002123 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002124 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002125 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002126 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002127 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002128 kernel=AcquireKernelInfo(argv[i+2]);
2129 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002130 {
2131 (void) ThrowMagickException(exception,GetMagickModule(),
2132 OptionError,"UnabletoParseKernel","morphology");
2133 status=MagickFalse;
2134 break;
2135 }
cristyd241f442011-03-29 13:50:49 +00002136 mogrify_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002137 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002138 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002139 break;
2140 }
cristy3ed852e2009-09-05 21:47:34 +00002141 if (LocaleCompare("motion-blur",option+1) == 0)
2142 {
cristy3ed852e2009-09-05 21:47:34 +00002143 /*
2144 Motion blur image.
2145 */
cristy6b3da3a2010-06-20 02:21:46 +00002146 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002147 flags=ParseGeometry(argv[i+1],&geometry_info);
2148 if ((flags & SigmaValue) == 0)
2149 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002150 mogrify_image=MotionBlurImageChannel(*image,channel,
2151 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002152 break;
2153 }
2154 break;
2155 }
2156 case 'n':
2157 {
2158 if (LocaleCompare("negate",option+1) == 0)
2159 {
cristy6b3da3a2010-06-20 02:21:46 +00002160 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002161 (void) NegateImageChannel(*image,channel,*option == '+' ?
2162 MagickTrue : MagickFalse);
2163 InheritException(exception,&(*image)->exception);
2164 break;
2165 }
2166 if (LocaleCompare("noise",option+1) == 0)
2167 {
cristy6b3da3a2010-06-20 02:21:46 +00002168 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002169 if (*option == '-')
2170 {
2171 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002172 mogrify_image=StatisticImageChannel(*image,channel,
cristy95c38342011-03-18 22:39:51 +00002173 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2174 geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002175 }
2176 else
2177 {
2178 NoiseType
2179 noise;
2180
cristy042ee782011-04-22 18:48:30 +00002181 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
cristy3ed852e2009-09-05 21:47:34 +00002182 MagickFalse,argv[i+1]);
cristyd241f442011-03-29 13:50:49 +00002183 mogrify_image=AddNoiseImageChannel(*image,channel,noise,
cristy3ed852e2009-09-05 21:47:34 +00002184 exception);
2185 }
cristy3ed852e2009-09-05 21:47:34 +00002186 break;
2187 }
2188 if (LocaleCompare("normalize",option+1) == 0)
2189 {
cristy6b3da3a2010-06-20 02:21:46 +00002190 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002191 (void) NormalizeImageChannel(*image,channel);
2192 InheritException(exception,&(*image)->exception);
2193 break;
2194 }
2195 break;
2196 }
2197 case 'o':
2198 {
2199 if (LocaleCompare("opaque",option+1) == 0)
2200 {
2201 MagickPixelPacket
2202 target;
2203
cristy6b3da3a2010-06-20 02:21:46 +00002204 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002205 (void) QueryMagickColor(argv[i+1],&target,exception);
2206 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2207 *option == '-' ? MagickFalse : MagickTrue);
2208 break;
2209 }
2210 if (LocaleCompare("ordered-dither",option+1) == 0)
2211 {
cristy6b3da3a2010-06-20 02:21:46 +00002212 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002213 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2214 exception);
2215 break;
2216 }
2217 break;
2218 }
2219 case 'p':
2220 {
2221 if (LocaleCompare("paint",option+1) == 0)
2222 {
2223 Image
2224 *paint_image;
2225
2226 /*
2227 Oil paint image.
2228 */
cristy6b3da3a2010-06-20 02:21:46 +00002229 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002230 (void) ParseGeometry(argv[i+1],&geometry_info);
2231 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2232 if (paint_image == (Image *) NULL)
2233 break;
2234 *image=DestroyImage(*image);
2235 *image=paint_image;
2236 break;
2237 }
2238 if (LocaleCompare("pen",option+1) == 0)
2239 {
2240 if (*option == '+')
2241 {
2242 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2243 break;
2244 }
2245 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2246 break;
2247 }
2248 if (LocaleCompare("pointsize",option+1) == 0)
2249 {
2250 if (*option == '+')
2251 (void) ParseGeometry("12",&geometry_info);
2252 else
2253 (void) ParseGeometry(argv[i+1],&geometry_info);
2254 draw_info->pointsize=geometry_info.rho;
2255 break;
2256 }
2257 if (LocaleCompare("polaroid",option+1) == 0)
2258 {
2259 double
2260 angle;
2261
cristy3ed852e2009-09-05 21:47:34 +00002262 RandomInfo
2263 *random_info;
2264
2265 /*
2266 Simulate a Polaroid picture.
2267 */
cristy6b3da3a2010-06-20 02:21:46 +00002268 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002269 random_info=AcquireRandomInfo();
2270 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2271 random_info=DestroyRandomInfo(random_info);
2272 if (*option == '-')
2273 {
2274 SetGeometryInfo(&geometry_info);
2275 flags=ParseGeometry(argv[i+1],&geometry_info);
2276 angle=geometry_info.rho;
2277 }
cristyd241f442011-03-29 13:50:49 +00002278 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
cristy3ed852e2009-09-05 21:47:34 +00002279 break;
2280 }
2281 if (LocaleCompare("posterize",option+1) == 0)
2282 {
2283 /*
2284 Posterize image.
2285 */
cristy6b3da3a2010-06-20 02:21:46 +00002286 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002287 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002288 quantize_info->dither);
2289 InheritException(exception,&(*image)->exception);
2290 break;
2291 }
2292 if (LocaleCompare("preview",option+1) == 0)
2293 {
cristy3ed852e2009-09-05 21:47:34 +00002294 PreviewType
2295 preview_type;
2296
2297 /*
2298 Preview image.
2299 */
cristy6b3da3a2010-06-20 02:21:46 +00002300 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002301 if (*option == '+')
2302 preview_type=UndefinedPreview;
2303 else
cristy042ee782011-04-22 18:48:30 +00002304 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
cristy3ed852e2009-09-05 21:47:34 +00002305 MagickFalse,argv[i+1]);
cristyd241f442011-03-29 13:50:49 +00002306 mogrify_image=PreviewImage(*image,preview_type,exception);
cristy3ed852e2009-09-05 21:47:34 +00002307 break;
2308 }
2309 if (LocaleCompare("profile",option+1) == 0)
2310 {
2311 const char
2312 *name;
2313
2314 const StringInfo
2315 *profile;
2316
2317 Image
2318 *profile_image;
2319
2320 ImageInfo
2321 *profile_info;
2322
cristy6b3da3a2010-06-20 02:21:46 +00002323 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002324 if (*option == '+')
2325 {
2326 /*
2327 Remove a profile from the image.
2328 */
2329 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2330 NULL,0,MagickTrue);
2331 InheritException(exception,&(*image)->exception);
2332 break;
2333 }
2334 /*
2335 Associate a profile with the image.
2336 */
cristy6b3da3a2010-06-20 02:21:46 +00002337 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002338 profile=GetImageProfile(*image,"iptc");
2339 if (profile != (StringInfo *) NULL)
2340 profile_info->profile=(void *) CloneStringInfo(profile);
2341 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2342 profile_info=DestroyImageInfo(profile_info);
2343 if (profile_image == (Image *) NULL)
2344 {
cristy3ed852e2009-09-05 21:47:34 +00002345 StringInfo
2346 *profile;
2347
cristy6b3da3a2010-06-20 02:21:46 +00002348 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002349 (void) CopyMagickString(profile_info->filename,argv[i+1],
2350 MaxTextExtent);
2351 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002352 if (profile != (StringInfo *) NULL)
2353 {
cristy071dd7b2010-04-09 13:04:54 +00002354 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002355 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002356 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002357 profile=DestroyStringInfo(profile);
2358 }
cristy071dd7b2010-04-09 13:04:54 +00002359 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002360 break;
2361 }
2362 ResetImageProfileIterator(profile_image);
2363 name=GetNextImageProfile(profile_image);
2364 while (name != (const char *) NULL)
2365 {
2366 profile=GetImageProfile(profile_image,name);
2367 if (profile != (StringInfo *) NULL)
2368 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002369 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002370 name=GetNextImageProfile(profile_image);
2371 }
2372 profile_image=DestroyImage(profile_image);
2373 break;
2374 }
2375 break;
2376 }
2377 case 'q':
2378 {
2379 if (LocaleCompare("quantize",option+1) == 0)
2380 {
2381 if (*option == '+')
2382 {
2383 quantize_info->colorspace=UndefinedColorspace;
2384 break;
2385 }
cristy042ee782011-04-22 18:48:30 +00002386 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00002387 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2388 break;
2389 }
2390 break;
2391 }
2392 case 'r':
2393 {
2394 if (LocaleCompare("radial-blur",option+1) == 0)
2395 {
cristy3ed852e2009-09-05 21:47:34 +00002396 /*
2397 Radial blur image.
2398 */
cristy6b3da3a2010-06-20 02:21:46 +00002399 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002400 mogrify_image=RadialBlurImageChannel(*image,channel,
cristya5447be2010-01-11 00:20:51 +00002401 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002402 break;
2403 }
2404 if (LocaleCompare("raise",option+1) == 0)
2405 {
2406 /*
2407 Surround image with a raise of solid color.
2408 */
2409 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2410 if ((flags & SigmaValue) == 0)
2411 geometry.height=geometry.width;
2412 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2413 MagickFalse);
2414 InheritException(exception,&(*image)->exception);
2415 break;
2416 }
2417 if (LocaleCompare("random-threshold",option+1) == 0)
2418 {
2419 /*
2420 Threshold image.
2421 */
cristy6b3da3a2010-06-20 02:21:46 +00002422 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002423 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2424 exception);
2425 break;
2426 }
2427 if (LocaleCompare("recolor",option+1) == 0)
2428 {
cristyf055ae42010-04-02 23:01:38 +00002429 KernelInfo
2430 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002431
cristy6b3da3a2010-06-20 02:21:46 +00002432 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002433 kernel=AcquireKernelInfo(argv[i+1]);
2434 if (kernel == (KernelInfo *) NULL)
2435 break;
cristyd241f442011-03-29 13:50:49 +00002436 mogrify_image=ColorMatrixImage(*image,kernel,exception);
cristyf055ae42010-04-02 23:01:38 +00002437 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00002438 break;
2439 }
2440 if (LocaleCompare("region",option+1) == 0)
2441 {
cristy6b3da3a2010-06-20 02:21:46 +00002442 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002443 if (region_image != (Image *) NULL)
2444 {
2445 /*
2446 Composite region.
2447 */
anthonya129f702011-04-14 01:08:48 +00002448 (void) CompositeImage(region_image,region_image->matte !=
2449 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2450 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00002451 InheritException(exception,&region_image->exception);
2452 *image=DestroyImage(*image);
2453 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00002454 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002455 }
2456 if (*option == '+')
anthonye9c27192011-03-27 08:07:06 +00002457 break;
cristy3ed852e2009-09-05 21:47:34 +00002458 /*
2459 Apply transformations to a selected region of the image.
2460 */
2461 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2462 exception);
cristyd241f442011-03-29 13:50:49 +00002463 mogrify_image=CropImage(*image,&region_geometry,exception);
2464 if (mogrify_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002465 break;
2466 region_image=(*image);
cristyd241f442011-03-29 13:50:49 +00002467 *image=mogrify_image;
2468 mogrify_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002469 break;
2470 }
2471 if (LocaleCompare("render",option+1) == 0)
2472 {
cristy6b3da3a2010-06-20 02:21:46 +00002473 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002474 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2475 break;
2476 }
2477 if (LocaleCompare("remap",option+1) == 0)
2478 {
2479 Image
2480 *remap_image;
2481
2482 /*
2483 Transform image colors to match this set of colors.
2484 */
cristy6b3da3a2010-06-20 02:21:46 +00002485 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002486 if (*option == '+')
2487 break;
cristy6b3da3a2010-06-20 02:21:46 +00002488 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002489 if (remap_image == (Image *) NULL)
2490 break;
2491 (void) RemapImage(quantize_info,*image,remap_image);
2492 InheritException(exception,&(*image)->exception);
2493 remap_image=DestroyImage(remap_image);
2494 break;
2495 }
2496 if (LocaleCompare("repage",option+1) == 0)
2497 {
2498 if (*option == '+')
2499 {
2500 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2501 break;
2502 }
2503 (void) ResetImagePage(*image,argv[i+1]);
2504 InheritException(exception,&(*image)->exception);
2505 break;
2506 }
2507 if (LocaleCompare("resample",option+1) == 0)
2508 {
cristy3ed852e2009-09-05 21:47:34 +00002509 /*
2510 Resample image.
2511 */
cristy6b3da3a2010-06-20 02:21:46 +00002512 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002513 flags=ParseGeometry(argv[i+1],&geometry_info);
2514 if ((flags & SigmaValue) == 0)
2515 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002516 mogrify_image=ResampleImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002517 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002518 break;
2519 }
2520 if (LocaleCompare("resize",option+1) == 0)
2521 {
cristy3ed852e2009-09-05 21:47:34 +00002522 /*
2523 Resize image.
2524 */
cristy6b3da3a2010-06-20 02:21:46 +00002525 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002526 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002527 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002528 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002529 break;
2530 }
cristy3ed852e2009-09-05 21:47:34 +00002531 if (LocaleCompare("roll",option+1) == 0)
2532 {
cristy3ed852e2009-09-05 21:47:34 +00002533 /*
2534 Roll image.
2535 */
cristy6b3da3a2010-06-20 02:21:46 +00002536 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002537 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002538 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00002539 break;
2540 }
2541 if (LocaleCompare("rotate",option+1) == 0)
2542 {
2543 char
2544 *geometry;
2545
cristy3ed852e2009-09-05 21:47:34 +00002546 /*
2547 Check for conditional image rotation.
2548 */
cristy6b3da3a2010-06-20 02:21:46 +00002549 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002550 if (strchr(argv[i+1],'>') != (char *) NULL)
2551 if ((*image)->columns <= (*image)->rows)
2552 break;
2553 if (strchr(argv[i+1],'<') != (char *) NULL)
2554 if ((*image)->columns >= (*image)->rows)
2555 break;
2556 /*
2557 Rotate image.
2558 */
2559 geometry=ConstantString(argv[i+1]);
2560 (void) SubstituteString(&geometry,">","");
2561 (void) SubstituteString(&geometry,"<","");
2562 (void) ParseGeometry(geometry,&geometry_info);
2563 geometry=DestroyString(geometry);
cristyd241f442011-03-29 13:50:49 +00002564 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002565 break;
2566 }
2567 break;
2568 }
2569 case 's':
2570 {
2571 if (LocaleCompare("sample",option+1) == 0)
2572 {
cristy3ed852e2009-09-05 21:47:34 +00002573 /*
2574 Sample image with pixel replication.
2575 */
cristy6b3da3a2010-06-20 02:21:46 +00002576 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002577 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002578 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002579 exception);
cristy3ed852e2009-09-05 21:47:34 +00002580 break;
2581 }
2582 if (LocaleCompare("scale",option+1) == 0)
2583 {
cristy3ed852e2009-09-05 21:47:34 +00002584 /*
2585 Resize image.
2586 */
cristy6b3da3a2010-06-20 02:21:46 +00002587 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002588 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002589 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002590 exception);
cristy3ed852e2009-09-05 21:47:34 +00002591 break;
2592 }
2593 if (LocaleCompare("selective-blur",option+1) == 0)
2594 {
cristy3ed852e2009-09-05 21:47:34 +00002595 /*
2596 Selectively blur pixels within a contrast threshold.
2597 */
cristy6b3da3a2010-06-20 02:21:46 +00002598 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002599 flags=ParseGeometry(argv[i+1],&geometry_info);
2600 if ((flags & PercentValue) != 0)
2601 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00002602 mogrify_image=SelectiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00002603 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002604 break;
2605 }
2606 if (LocaleCompare("separate",option+1) == 0)
2607 {
cristy3ed852e2009-09-05 21:47:34 +00002608 /*
2609 Break channels into separate images.
anthonye9c27192011-03-27 08:07:06 +00002610 WARNING: This can generate multiple images!
cristy3ed852e2009-09-05 21:47:34 +00002611 */
cristy6b3da3a2010-06-20 02:21:46 +00002612 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002613 mogrify_image=SeparateImages(*image,channel,exception);
cristy3ed852e2009-09-05 21:47:34 +00002614 break;
2615 }
2616 if (LocaleCompare("sepia-tone",option+1) == 0)
2617 {
2618 double
2619 threshold;
2620
cristy3ed852e2009-09-05 21:47:34 +00002621 /*
2622 Sepia-tone image.
2623 */
cristy6b3da3a2010-06-20 02:21:46 +00002624 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002625 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00002626 mogrify_image=SepiaToneImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00002627 break;
2628 }
2629 if (LocaleCompare("segment",option+1) == 0)
2630 {
2631 /*
2632 Segment image.
2633 */
cristy6b3da3a2010-06-20 02:21:46 +00002634 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002635 flags=ParseGeometry(argv[i+1],&geometry_info);
2636 if ((flags & SigmaValue) == 0)
2637 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002638 (void) SegmentImage(*image,(*image)->colorspace,
2639 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002640 InheritException(exception,&(*image)->exception);
2641 break;
2642 }
2643 if (LocaleCompare("set",option+1) == 0)
2644 {
cristy6d9a1292010-05-31 14:17:06 +00002645 char
2646 *value;
2647
cristy3ed852e2009-09-05 21:47:34 +00002648 /*
2649 Set image option.
2650 */
cristy6d9a1292010-05-31 14:17:06 +00002651 if (*option == '+')
2652 {
2653 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2654 (void) DeleteImageRegistry(argv[i+1]+9);
2655 else
2656 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002657 {
cristy6b3da3a2010-06-20 02:21:46 +00002658 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002659 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2660 }
cristy6d9a1292010-05-31 14:17:06 +00002661 else
2662 (void) DeleteImageProperty(*image,argv[i+1]);
2663 break;
2664 }
cristy6b3da3a2010-06-20 02:21:46 +00002665 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002666 if (value == (char *) NULL)
2667 break;
cristy3ed852e2009-09-05 21:47:34 +00002668 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002669 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2670 exception);
cristy3ed852e2009-09-05 21:47:34 +00002671 else
2672 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002673 {
cristy7f02ba12010-09-21 12:39:28 +00002674 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002675 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002676 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2677 }
cristy3ed852e2009-09-05 21:47:34 +00002678 else
cristy6d9a1292010-05-31 14:17:06 +00002679 (void) SetImageProperty(*image,argv[i+1],value);
2680 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002681 break;
2682 }
2683 if (LocaleCompare("shade",option+1) == 0)
2684 {
cristy3ed852e2009-09-05 21:47:34 +00002685 /*
2686 Shade image.
2687 */
cristy6b3da3a2010-06-20 02:21:46 +00002688 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002689 flags=ParseGeometry(argv[i+1],&geometry_info);
2690 if ((flags & SigmaValue) == 0)
2691 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002692 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
cristy3ed852e2009-09-05 21:47:34 +00002693 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002694 break;
2695 }
2696 if (LocaleCompare("shadow",option+1) == 0)
2697 {
cristy3ed852e2009-09-05 21:47:34 +00002698 /*
2699 Shadow image.
2700 */
cristy6b3da3a2010-06-20 02:21:46 +00002701 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002702 flags=ParseGeometry(argv[i+1],&geometry_info);
2703 if ((flags & SigmaValue) == 0)
2704 geometry_info.sigma=1.0;
2705 if ((flags & XiValue) == 0)
2706 geometry_info.xi=4.0;
2707 if ((flags & PsiValue) == 0)
2708 geometry_info.psi=4.0;
cristyd241f442011-03-29 13:50:49 +00002709 mogrify_image=ShadowImage(*image,geometry_info.rho,
2710 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2711 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002712 break;
2713 }
2714 if (LocaleCompare("sharpen",option+1) == 0)
2715 {
cristy3ed852e2009-09-05 21:47:34 +00002716 /*
2717 Sharpen image.
2718 */
cristy6b3da3a2010-06-20 02:21:46 +00002719 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002720 flags=ParseGeometry(argv[i+1],&geometry_info);
2721 if ((flags & SigmaValue) == 0)
2722 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002723 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002724 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002725 break;
2726 }
2727 if (LocaleCompare("shave",option+1) == 0)
2728 {
cristy3ed852e2009-09-05 21:47:34 +00002729 /*
2730 Shave the image edges.
2731 */
cristy6b3da3a2010-06-20 02:21:46 +00002732 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002733 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002734 mogrify_image=ShaveImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002735 break;
2736 }
2737 if (LocaleCompare("shear",option+1) == 0)
2738 {
cristy3ed852e2009-09-05 21:47:34 +00002739 /*
2740 Shear image.
2741 */
cristy6b3da3a2010-06-20 02:21:46 +00002742 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002743 flags=ParseGeometry(argv[i+1],&geometry_info);
2744 if ((flags & SigmaValue) == 0)
2745 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002746 mogrify_image=ShearImage(*image,geometry_info.rho,
2747 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002748 break;
2749 }
2750 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2751 {
2752 /*
2753 Sigmoidal non-linearity contrast control.
2754 */
cristy6b3da3a2010-06-20 02:21:46 +00002755 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002756 flags=ParseGeometry(argv[i+1],&geometry_info);
2757 if ((flags & SigmaValue) == 0)
2758 geometry_info.sigma=(double) QuantumRange/2.0;
2759 if ((flags & PercentValue) != 0)
2760 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2761 100.0;
2762 (void) SigmoidalContrastImageChannel(*image,channel,
2763 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2764 geometry_info.sigma);
2765 InheritException(exception,&(*image)->exception);
2766 break;
2767 }
2768 if (LocaleCompare("sketch",option+1) == 0)
2769 {
cristy3ed852e2009-09-05 21:47:34 +00002770 /*
2771 Sketch image.
2772 */
cristy6b3da3a2010-06-20 02:21:46 +00002773 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002774 flags=ParseGeometry(argv[i+1],&geometry_info);
2775 if ((flags & SigmaValue) == 0)
2776 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002777 mogrify_image=SketchImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002778 geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002779 break;
2780 }
2781 if (LocaleCompare("solarize",option+1) == 0)
2782 {
2783 double
2784 threshold;
2785
cristy6b3da3a2010-06-20 02:21:46 +00002786 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002787 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002788 (void) SolarizeImage(*image,threshold);
2789 InheritException(exception,&(*image)->exception);
2790 break;
2791 }
2792 if (LocaleCompare("sparse-color",option+1) == 0)
2793 {
cristy3ed852e2009-09-05 21:47:34 +00002794 SparseColorMethod
2795 method;
2796
2797 char
2798 *arguments;
2799
2800 /*
2801 Sparse Color Interpolated Gradient
2802 */
cristy6b3da3a2010-06-20 02:21:46 +00002803 (void) SyncImageSettings(mogrify_info,*image);
cristy042ee782011-04-22 18:48:30 +00002804 method=(SparseColorMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00002805 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00002806 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00002807 InheritException(exception,&(*image)->exception);
2808 if (arguments == (char *) NULL)
2809 break;
cristyd241f442011-03-29 13:50:49 +00002810 mogrify_image=SparseColorOption(*image,channel,method,arguments,
cristy3ed852e2009-09-05 21:47:34 +00002811 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2812 arguments=DestroyString(arguments);
cristy3ed852e2009-09-05 21:47:34 +00002813 break;
2814 }
2815 if (LocaleCompare("splice",option+1) == 0)
2816 {
cristy3ed852e2009-09-05 21:47:34 +00002817 /*
2818 Splice a solid color into the image.
2819 */
cristy6b3da3a2010-06-20 02:21:46 +00002820 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002821 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002822 mogrify_image=SpliceImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002823 break;
2824 }
2825 if (LocaleCompare("spread",option+1) == 0)
2826 {
cristy3ed852e2009-09-05 21:47:34 +00002827 /*
2828 Spread an image.
2829 */
cristy6b3da3a2010-06-20 02:21:46 +00002830 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002831 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002832 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002833 break;
2834 }
cristy0834d642011-03-18 18:26:08 +00002835 if (LocaleCompare("statistic",option+1) == 0)
2836 {
cristy0834d642011-03-18 18:26:08 +00002837 StatisticType
2838 type;
2839
2840 (void) SyncImageSettings(mogrify_info,*image);
cristy042ee782011-04-22 18:48:30 +00002841 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
cristy0834d642011-03-18 18:26:08 +00002842 MagickFalse,argv[i+1]);
2843 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002844 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2845 geometry_info.rho,(size_t) geometry_info.sigma,exception);
cristy0834d642011-03-18 18:26:08 +00002846 break;
2847 }
cristy3ed852e2009-09-05 21:47:34 +00002848 if (LocaleCompare("stretch",option+1) == 0)
2849 {
2850 if (*option == '+')
2851 {
2852 draw_info->stretch=UndefinedStretch;
2853 break;
2854 }
cristy042ee782011-04-22 18:48:30 +00002855 draw_info->stretch=(StretchType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00002856 MagickStretchOptions,MagickFalse,argv[i+1]);
2857 break;
2858 }
2859 if (LocaleCompare("strip",option+1) == 0)
2860 {
2861 /*
2862 Strip image of profiles and comments.
2863 */
cristy6b3da3a2010-06-20 02:21:46 +00002864 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00002865 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00002866 InheritException(exception,&(*image)->exception);
2867 break;
2868 }
2869 if (LocaleCompare("stroke",option+1) == 0)
2870 {
2871 ExceptionInfo
2872 *sans;
2873
2874 if (*option == '+')
2875 {
2876 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2877 if (draw_info->stroke_pattern != (Image *) NULL)
2878 draw_info->stroke_pattern=DestroyImage(
2879 draw_info->stroke_pattern);
2880 break;
2881 }
2882 sans=AcquireExceptionInfo();
2883 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2884 sans=DestroyExceptionInfo(sans);
2885 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00002886 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002887 exception);
2888 break;
2889 }
2890 if (LocaleCompare("strokewidth",option+1) == 0)
2891 {
cristyf2f27272009-12-17 14:48:46 +00002892 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002893 break;
2894 }
2895 if (LocaleCompare("style",option+1) == 0)
2896 {
2897 if (*option == '+')
2898 {
2899 draw_info->style=UndefinedStyle;
2900 break;
2901 }
cristy042ee782011-04-22 18:48:30 +00002902 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
cristy3ed852e2009-09-05 21:47:34 +00002903 MagickFalse,argv[i+1]);
2904 break;
2905 }
2906 if (LocaleCompare("swirl",option+1) == 0)
2907 {
cristy3ed852e2009-09-05 21:47:34 +00002908 /*
2909 Swirl image.
2910 */
cristy6b3da3a2010-06-20 02:21:46 +00002911 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002912 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002913 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002914 break;
2915 }
2916 break;
2917 }
2918 case 't':
2919 {
2920 if (LocaleCompare("threshold",option+1) == 0)
2921 {
2922 double
2923 threshold;
2924
2925 /*
2926 Threshold image.
2927 */
cristy6b3da3a2010-06-20 02:21:46 +00002928 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002929 if (*option == '+')
2930 threshold=(double) QuantumRange/2.5;
2931 else
cristyf2f27272009-12-17 14:48:46 +00002932 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002933 (void) BilevelImageChannel(*image,channel,threshold);
2934 InheritException(exception,&(*image)->exception);
2935 break;
2936 }
2937 if (LocaleCompare("thumbnail",option+1) == 0)
2938 {
cristy3ed852e2009-09-05 21:47:34 +00002939 /*
2940 Thumbnail image.
2941 */
cristy6b3da3a2010-06-20 02:21:46 +00002942 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002943 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002944 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2945 exception);
cristy3ed852e2009-09-05 21:47:34 +00002946 break;
2947 }
2948 if (LocaleCompare("tile",option+1) == 0)
2949 {
2950 if (*option == '+')
2951 {
2952 if (draw_info->fill_pattern != (Image *) NULL)
2953 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2954 break;
2955 }
cristy6b3da3a2010-06-20 02:21:46 +00002956 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002957 exception);
2958 break;
2959 }
2960 if (LocaleCompare("tint",option+1) == 0)
2961 {
cristy3ed852e2009-09-05 21:47:34 +00002962 /*
2963 Tint the image.
2964 */
cristy6b3da3a2010-06-20 02:21:46 +00002965 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002966 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
cristy3ed852e2009-09-05 21:47:34 +00002967 break;
2968 }
2969 if (LocaleCompare("transform",option+1) == 0)
2970 {
cristy3ed852e2009-09-05 21:47:34 +00002971 /*
2972 Affine transform image.
2973 */
cristy6b3da3a2010-06-20 02:21:46 +00002974 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002975 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
cristy3ed852e2009-09-05 21:47:34 +00002976 exception);
cristy3ed852e2009-09-05 21:47:34 +00002977 break;
2978 }
2979 if (LocaleCompare("transparent",option+1) == 0)
2980 {
2981 MagickPixelPacket
2982 target;
2983
cristy6b3da3a2010-06-20 02:21:46 +00002984 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002985 (void) QueryMagickColor(argv[i+1],&target,exception);
2986 (void) TransparentPaintImage(*image,&target,(Quantum)
2987 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
2988 InheritException(exception,&(*image)->exception);
2989 break;
2990 }
2991 if (LocaleCompare("transpose",option+1) == 0)
2992 {
cristy3ed852e2009-09-05 21:47:34 +00002993 /*
2994 Transpose image scanlines.
2995 */
cristy6b3da3a2010-06-20 02:21:46 +00002996 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002997 mogrify_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002998 break;
2999 }
3000 if (LocaleCompare("transverse",option+1) == 0)
3001 {
cristy3ed852e2009-09-05 21:47:34 +00003002 /*
3003 Transverse image scanlines.
3004 */
cristy6b3da3a2010-06-20 02:21:46 +00003005 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003006 mogrify_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003007 break;
3008 }
3009 if (LocaleCompare("treedepth",option+1) == 0)
3010 {
cristye27293e2009-12-18 02:53:20 +00003011 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003012 break;
3013 }
3014 if (LocaleCompare("trim",option+1) == 0)
3015 {
cristy3ed852e2009-09-05 21:47:34 +00003016 /*
3017 Trim image.
3018 */
cristy6b3da3a2010-06-20 02:21:46 +00003019 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003020 mogrify_image=TrimImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003021 break;
3022 }
3023 if (LocaleCompare("type",option+1) == 0)
3024 {
3025 ImageType
3026 type;
3027
cristy6b3da3a2010-06-20 02:21:46 +00003028 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003029 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003030 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003031 else
cristy042ee782011-04-22 18:48:30 +00003032 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00003033 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003034 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003035 (void) SetImageType(*image,type);
3036 InheritException(exception,&(*image)->exception);
3037 break;
3038 }
3039 break;
3040 }
3041 case 'u':
3042 {
3043 if (LocaleCompare("undercolor",option+1) == 0)
3044 {
3045 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3046 exception);
3047 break;
3048 }
cristy045bd902010-01-30 18:56:24 +00003049 if (LocaleCompare("unique",option+1) == 0)
3050 {
3051 if (*option == '+')
3052 {
cristy83fae872010-04-22 15:04:16 +00003053 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003054 break;
3055 }
cristy83fae872010-04-22 15:04:16 +00003056 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003057 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003058 break;
3059 }
cristy3ed852e2009-09-05 21:47:34 +00003060 if (LocaleCompare("unique-colors",option+1) == 0)
3061 {
cristy3ed852e2009-09-05 21:47:34 +00003062 /*
3063 Unique image colors.
3064 */
cristy6b3da3a2010-06-20 02:21:46 +00003065 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003066 mogrify_image=UniqueImageColors(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003067 break;
3068 }
3069 if (LocaleCompare("unsharp",option+1) == 0)
3070 {
cristy3ed852e2009-09-05 21:47:34 +00003071 /*
3072 Unsharp mask image.
3073 */
cristy6b3da3a2010-06-20 02:21:46 +00003074 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003075 flags=ParseGeometry(argv[i+1],&geometry_info);
3076 if ((flags & SigmaValue) == 0)
3077 geometry_info.sigma=1.0;
3078 if ((flags & XiValue) == 0)
3079 geometry_info.xi=1.0;
3080 if ((flags & PsiValue) == 0)
3081 geometry_info.psi=0.05;
cristyd241f442011-03-29 13:50:49 +00003082 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3083 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3084 geometry_info.psi,exception);
cristy3ed852e2009-09-05 21:47:34 +00003085 break;
3086 }
3087 break;
3088 }
3089 case 'v':
3090 {
3091 if (LocaleCompare("verbose",option+1) == 0)
3092 {
3093 (void) SetImageArtifact(*image,option+1,
3094 *option == '+' ? "false" : "true");
3095 break;
3096 }
3097 if (LocaleCompare("vignette",option+1) == 0)
3098 {
cristy3ed852e2009-09-05 21:47:34 +00003099 /*
3100 Vignette image.
3101 */
cristy6b3da3a2010-06-20 02:21:46 +00003102 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003103 flags=ParseGeometry(argv[i+1],&geometry_info);
3104 if ((flags & SigmaValue) == 0)
3105 geometry_info.sigma=1.0;
3106 if ((flags & XiValue) == 0)
3107 geometry_info.xi=0.1*(*image)->columns;
3108 if ((flags & PsiValue) == 0)
3109 geometry_info.psi=0.1*(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00003110 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003111 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003112 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003113 break;
3114 }
3115 if (LocaleCompare("virtual-pixel",option+1) == 0)
3116 {
3117 if (*option == '+')
3118 {
3119 (void) SetImageVirtualPixelMethod(*image,
3120 UndefinedVirtualPixelMethod);
3121 break;
3122 }
3123 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00003124 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00003125 argv[i+1]));
3126 break;
3127 }
3128 break;
3129 }
3130 case 'w':
3131 {
3132 if (LocaleCompare("wave",option+1) == 0)
3133 {
cristy3ed852e2009-09-05 21:47:34 +00003134 /*
3135 Wave image.
3136 */
cristy6b3da3a2010-06-20 02:21:46 +00003137 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003138 flags=ParseGeometry(argv[i+1],&geometry_info);
3139 if ((flags & SigmaValue) == 0)
3140 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00003141 mogrify_image=WaveImage(*image,geometry_info.rho,
3142 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00003143 break;
3144 }
3145 if (LocaleCompare("weight",option+1) == 0)
3146 {
cristye27293e2009-12-18 02:53:20 +00003147 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003148 if (LocaleCompare(argv[i+1],"all") == 0)
3149 draw_info->weight=0;
3150 if (LocaleCompare(argv[i+1],"bold") == 0)
3151 draw_info->weight=700;
3152 if (LocaleCompare(argv[i+1],"bolder") == 0)
3153 if (draw_info->weight <= 800)
3154 draw_info->weight+=100;
3155 if (LocaleCompare(argv[i+1],"lighter") == 0)
3156 if (draw_info->weight >= 100)
3157 draw_info->weight-=100;
3158 if (LocaleCompare(argv[i+1],"normal") == 0)
3159 draw_info->weight=400;
3160 break;
3161 }
3162 if (LocaleCompare("white-threshold",option+1) == 0)
3163 {
3164 /*
3165 White threshold image.
3166 */
cristy6b3da3a2010-06-20 02:21:46 +00003167 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003168 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3169 exception);
3170 InheritException(exception,&(*image)->exception);
3171 break;
3172 }
3173 break;
3174 }
3175 default:
3176 break;
3177 }
anthonye9c27192011-03-27 08:07:06 +00003178 /*
3179 Replace current image with any image that was generated
3180 */
cristyd241f442011-03-29 13:50:49 +00003181 if (mogrify_image != (Image *) NULL)
3182 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003183 i+=count;
3184 }
3185 if (region_image != (Image *) NULL)
3186 {
3187 /*
3188 Composite transformed region onto image.
3189 */
cristy6b3da3a2010-06-20 02:21:46 +00003190 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003191 (void) CompositeImage(region_image,region_image->matte !=
3192 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
anthonye9c27192011-03-27 08:07:06 +00003193 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003194 InheritException(exception,&region_image->exception);
3195 *image=DestroyImage(*image);
3196 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003197 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003198 }
3199 /*
3200 Free resources.
3201 */
3202 quantize_info=DestroyQuantizeInfo(quantize_info);
3203 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003204 mogrify_info=DestroyImageInfo(mogrify_info);
cristy72988482011-03-29 16:34:38 +00003205 status=(*image)->exception.severity == UndefinedException ? 1 : 0;
3206 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003207}
3208
3209/*
3210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3211% %
3212% %
3213% %
cristy5063d812010-10-19 16:28:10 +00003214+ 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 +00003215% %
3216% %
3217% %
3218%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3219%
3220% MogrifyImageCommand() transforms an image or a sequence of images. These
3221% transforms include image scaling, image rotation, color reduction, and
3222% others. The transmogrified image overwrites the original image.
3223%
3224% The format of the MogrifyImageCommand method is:
3225%
3226% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3227% const char **argv,char **metadata,ExceptionInfo *exception)
3228%
3229% A description of each parameter follows:
3230%
3231% o image_info: the image info.
3232%
3233% o argc: the number of elements in the argument vector.
3234%
3235% o argv: A text array containing the command line arguments.
3236%
3237% o metadata: any metadata is returned here.
3238%
3239% o exception: return any errors or warnings in this structure.
3240%
3241*/
3242
3243static MagickBooleanType MogrifyUsage(void)
3244{
3245 static const char
3246 *miscellaneous[]=
3247 {
3248 "-debug events display copious debugging information",
3249 "-help print program options",
3250 "-list type print a list of supported option arguments",
3251 "-log format format of debugging information",
3252 "-version print version information",
3253 (char *) NULL
3254 },
3255 *operators[]=
3256 {
3257 "-adaptive-blur geometry",
3258 " adaptively blur pixels; decrease effect near edges",
3259 "-adaptive-resize geometry",
3260 " adaptively resize image using 'mesh' interpolation",
3261 "-adaptive-sharpen geometry",
3262 " adaptively sharpen pixels; increase effect near edges",
3263 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3264 " transparent, extract, background, or shape",
3265 "-annotate geometry text",
3266 " annotate the image with text",
3267 "-auto-gamma automagically adjust gamma level of image",
3268 "-auto-level automagically adjust color levels of image",
3269 "-auto-orient automagically orient (rotate) image",
3270 "-bench iterations measure performance",
3271 "-black-threshold value",
3272 " force all pixels below the threshold into black",
3273 "-blue-shift simulate a scene at nighttime in the moonlight",
3274 "-blur geometry reduce image noise and reduce detail levels",
3275 "-border geometry surround image with a border of color",
3276 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003277 "-brightness-contrast geometry",
3278 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003279 "-cdl filename color correct with a color decision list",
3280 "-charcoal radius simulate a charcoal drawing",
3281 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003282 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003283 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003284 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003285 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003286 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003287 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003288 "-contrast enhance or reduce the image contrast",
3289 "-contrast-stretch geometry",
3290 " improve contrast by `stretching' the intensity range",
3291 "-convolve coefficients",
3292 " apply a convolution kernel to the image",
3293 "-cycle amount cycle the image colormap",
3294 "-decipher filename convert cipher pixels to plain pixels",
3295 "-deskew threshold straighten an image",
3296 "-despeckle reduce the speckles within an image",
3297 "-distort method args",
3298 " distort images according to given method ad args",
3299 "-draw string annotate the image with a graphic primitive",
3300 "-edge radius apply a filter to detect edges in the image",
3301 "-encipher filename convert plain pixels to cipher pixels",
3302 "-emboss radius emboss an image",
3303 "-enhance apply a digital filter to enhance a noisy image",
3304 "-equalize perform histogram equalization to an image",
3305 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003306 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003307 "-extent geometry set the image size",
3308 "-extract geometry extract area from image",
3309 "-fft implements the discrete Fourier transform (DFT)",
3310 "-flip flip image vertically",
3311 "-floodfill geometry color",
3312 " floodfill the image with color",
3313 "-flop flop image horizontally",
3314 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003315 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003316 " apply function over image values",
3317 "-gamma value level of gamma correction",
3318 "-gaussian-blur geometry",
3319 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003320 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003321 "-identify identify the format and characteristics of the image",
3322 "-ift implements the inverse discrete Fourier transform (DFT)",
3323 "-implode amount implode image pixels about the center",
3324 "-lat geometry local adaptive thresholding",
3325 "-layers method optimize, merge, or compare image layers",
3326 "-level value adjust the level of image contrast",
3327 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003328 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003329 "-linear-stretch geometry",
3330 " improve contrast by `stretching with saturation'",
3331 "-liquid-rescale geometry",
3332 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003333 "-median geometry apply a median filter to the image",
3334 "-mode geometry make each pixel the 'predominate color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003335 "-modulate value vary the brightness, saturation, and hue",
3336 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003337 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003338 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003339 "-motion-blur geometry",
3340 " simulate motion blur",
3341 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003342 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-normalize transform image to span the full range of colors",
3344 "-opaque color change this color to the fill color",
3345 "-ordered-dither NxN",
3346 " add a noise pattern to the image with specific",
3347 " amplitudes",
3348 "-paint radius simulate an oil painting",
3349 "-polaroid angle simulate a Polaroid picture",
3350 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003351 "-profile filename add, delete, or apply an image profile",
3352 "-quantize colorspace reduce colors in this colorspace",
3353 "-radial-blur angle radial blur the image",
3354 "-raise value lighten/darken image edges to create a 3-D effect",
3355 "-random-threshold low,high",
3356 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-region geometry apply options to a portion of the image",
3358 "-render render vector graphics",
3359 "-repage geometry size and location of an image canvas",
3360 "-resample geometry change the resolution of an image",
3361 "-resize geometry resize the image",
3362 "-roll geometry roll an image vertically or horizontally",
3363 "-rotate degrees apply Paeth rotation to the image",
3364 "-sample geometry scale image with pixel sampling",
3365 "-scale geometry scale the image",
3366 "-segment values segment an image",
3367 "-selective-blur geometry",
3368 " selectively blur pixels within a contrast threshold",
3369 "-sepia-tone threshold",
3370 " simulate a sepia-toned photo",
3371 "-set property value set an image property",
3372 "-shade degrees shade the image using a distant light source",
3373 "-shadow geometry simulate an image shadow",
3374 "-sharpen geometry sharpen the image",
3375 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003376 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-sigmoidal-contrast geometry",
3378 " increase the contrast without saturating highlights or shadows",
3379 "-sketch geometry simulate a pencil sketch",
3380 "-solarize threshold negate all pixels above the threshold level",
3381 "-sparse-color method args",
3382 " fill in a image based on a few color points",
3383 "-splice geometry splice the background color into the image",
3384 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003385 "-statistic type radius",
3386 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003387 "-strip strip image of all profiles and comments",
3388 "-swirl degrees swirl image pixels about the center",
3389 "-threshold value threshold the image",
3390 "-thumbnail geometry create a thumbnail of the image",
3391 "-tile filename tile image when filling a graphic primitive",
3392 "-tint value tint the image with the fill color",
3393 "-transform affine transform image",
3394 "-transparent color make this color transparent within the image",
3395 "-transpose flip image vertically and rotate 90 degrees",
3396 "-transverse flop image horizontally and rotate 270 degrees",
3397 "-trim trim image edges",
3398 "-type type image type",
3399 "-unique-colors discard all but one of any pixel color",
3400 "-unsharp geometry sharpen the image",
3401 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003402 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003403 "-white-threshold value",
3404 " force all pixels above the threshold into white",
3405 (char *) NULL
3406 },
3407 *sequence_operators[]=
3408 {
cristy4285d782011-02-09 20:12:28 +00003409 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003410 "-clut apply a color lookup table to the image",
3411 "-coalesce merge a sequence of images",
3412 "-combine combine a sequence of images",
3413 "-composite composite image",
3414 "-crop geometry cut out a rectangular region of the image",
3415 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003416 "-evaluate-sequence operator",
3417 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003418 "-flatten flatten a sequence of images",
3419 "-fx expression apply mathematical expression to an image channel(s)",
3420 "-hald-clut apply a Hald color lookup table to the image",
3421 "-morph value morph an image sequence",
3422 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003423 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003424 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003425 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003426 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003427 "-write filename write images to this file",
3428 (char *) NULL
3429 },
3430 *settings[]=
3431 {
3432 "-adjoin join images into a single multi-image file",
3433 "-affine matrix affine transform matrix",
3434 "-alpha option activate, deactivate, reset, or set the alpha channel",
3435 "-antialias remove pixel-aliasing",
3436 "-authenticate password",
3437 " decipher image with this password",
3438 "-attenuate value lessen (or intensify) when adding noise to an image",
3439 "-background color background color",
3440 "-bias value add bias when convolving an image",
3441 "-black-point-compensation",
3442 " use black point compensation",
3443 "-blue-primary point chromaticity blue primary point",
3444 "-bordercolor color border color",
3445 "-caption string assign a caption to an image",
3446 "-channel type apply option to select image channels",
3447 "-colors value preferred number of colors in the image",
3448 "-colorspace type alternate image colorspace",
3449 "-comment string annotate image with comment",
3450 "-compose operator set image composite operator",
3451 "-compress type type of pixel compression when writing the image",
3452 "-define format:option",
3453 " define one or more image format options",
3454 "-delay value display the next image after pausing",
3455 "-density geometry horizontal and vertical density of the image",
3456 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003457 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003458 "-display server get image or font from this X server",
3459 "-dispose method layer disposal method",
3460 "-dither method apply error diffusion to image",
3461 "-encoding type text encoding type",
3462 "-endian type endianness (MSB or LSB) of the image",
3463 "-family name render text with this font family",
3464 "-fill color color to use when filling a graphic primitive",
3465 "-filter type use this filter when resizing an image",
3466 "-font name render text with this font",
3467 "-format \"string\" output formatted image characteristics",
3468 "-fuzz distance colors within this distance are considered equal",
3469 "-gravity type horizontal and vertical text placement",
3470 "-green-primary point chromaticity green primary point",
3471 "-intent type type of rendering intent when managing the image color",
3472 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003473 "-interline-spacing value",
3474 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003475 "-interpolate method pixel color interpolation method",
3476 "-interword-spacing value",
3477 " set the space between two words",
3478 "-kerning value set the space between two letters",
3479 "-label string assign a label to an image",
3480 "-limit type value pixel cache resource limit",
3481 "-loop iterations add Netscape loop extension to your GIF animation",
3482 "-mask filename associate a mask with the image",
3483 "-mattecolor color frame color",
3484 "-monitor monitor progress",
3485 "-orient type image orientation",
3486 "-page geometry size and location of an image canvas (setting)",
3487 "-ping efficiently determine image attributes",
3488 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003489 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003490 "-preview type image preview type",
3491 "-quality value JPEG/MIFF/PNG compression level",
3492 "-quiet suppress all warning messages",
3493 "-red-primary point chromaticity red primary point",
3494 "-regard-warnings pay attention to warning messages",
3495 "-remap filename transform image colors to match this set of colors",
3496 "-respect-parentheses settings remain in effect until parenthesis boundary",
3497 "-sampling-factor geometry",
3498 " horizontal and vertical sampling factor",
3499 "-scene value image scene number",
3500 "-seed value seed a new sequence of pseudo-random numbers",
3501 "-size geometry width and height of image",
3502 "-stretch type render text with this font stretch",
3503 "-stroke color graphic primitive stroke color",
3504 "-strokewidth value graphic primitive stroke width",
3505 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003506 "-synchronize synchronize image to storage device",
3507 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003508 "-texture filename name of texture to tile onto the image background",
3509 "-tile-offset geometry",
3510 " tile offset",
3511 "-treedepth value color tree depth",
3512 "-transparent-color color",
3513 " transparent color",
3514 "-undercolor color annotation bounding box color",
3515 "-units type the units of image resolution",
3516 "-verbose print detailed information about the image",
3517 "-view FlashPix viewing transforms",
3518 "-virtual-pixel method",
3519 " virtual pixel access method",
3520 "-weight type render text with this font weight",
3521 "-white-point point chromaticity white point",
3522 (char *) NULL
3523 },
3524 *stack_operators[]=
3525 {
anthonyb69c4b32011-03-23 04:37:44 +00003526 "-delete indexes delete the image from the image sequence",
3527 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003528 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003529 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003530 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003531 "-swap indexes swap two images in the image sequence",
3532 (char *) NULL
3533 };
3534
3535 const char
3536 **p;
3537
cristybb503372010-05-27 20:51:26 +00003538 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003539 (void) printf("Copyright: %s\n",GetMagickCopyright());
3540 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003541 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3542 GetClientName());
3543 (void) printf("\nImage Settings:\n");
3544 for (p=settings; *p != (char *) NULL; p++)
3545 (void) printf(" %s\n",*p);
3546 (void) printf("\nImage Operators:\n");
3547 for (p=operators; *p != (char *) NULL; p++)
3548 (void) printf(" %s\n",*p);
3549 (void) printf("\nImage Sequence Operators:\n");
3550 for (p=sequence_operators; *p != (char *) NULL; p++)
3551 (void) printf(" %s\n",*p);
3552 (void) printf("\nImage Stack Operators:\n");
3553 for (p=stack_operators; *p != (char *) NULL; p++)
3554 (void) printf(" %s\n",*p);
3555 (void) printf("\nMiscellaneous Options:\n");
3556 for (p=miscellaneous; *p != (char *) NULL; p++)
3557 (void) printf(" %s\n",*p);
3558 (void) printf(
3559 "\nBy default, the image format of `file' is determined by its magic\n");
3560 (void) printf(
3561 "number. To specify a particular image format, precede the filename\n");
3562 (void) printf(
3563 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3564 (void) printf(
3565 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3566 (void) printf("'-' for standard input or output.\n");
3567 return(MagickFalse);
3568}
3569
3570WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3571 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3572{
3573#define DestroyMogrify() \
3574{ \
3575 if (format != (char *) NULL) \
3576 format=DestroyString(format); \
3577 if (path != (char *) NULL) \
3578 path=DestroyString(path); \
3579 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003580 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003581 argv[i]=DestroyString(argv[i]); \
3582 argv=(char **) RelinquishMagickMemory(argv); \
3583}
3584#define ThrowMogrifyException(asperity,tag,option) \
3585{ \
3586 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3587 option); \
3588 DestroyMogrify(); \
3589 return(MagickFalse); \
3590}
3591#define ThrowMogrifyInvalidArgumentException(option,argument) \
3592{ \
3593 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3594 "InvalidArgument","`%s': %s",argument,option); \
3595 DestroyMogrify(); \
3596 return(MagickFalse); \
3597}
3598
3599 char
3600 *format,
3601 *option,
3602 *path;
3603
3604 Image
3605 *image;
3606
3607 ImageStack
3608 image_stack[MaxImageStackDepth+1];
3609
cristy3ed852e2009-09-05 21:47:34 +00003610 MagickBooleanType
3611 global_colormap;
3612
3613 MagickBooleanType
3614 fire,
cristyebbcfea2011-02-25 02:43:54 +00003615 pend,
3616 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003617
3618 MagickStatusType
3619 status;
3620
cristyebbcfea2011-02-25 02:43:54 +00003621 register ssize_t
3622 i;
3623
3624 ssize_t
3625 j,
3626 k;
3627
cristy3ed852e2009-09-05 21:47:34 +00003628 /*
3629 Set defaults.
3630 */
3631 assert(image_info != (ImageInfo *) NULL);
3632 assert(image_info->signature == MagickSignature);
3633 if (image_info->debug != MagickFalse)
3634 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3635 assert(exception != (ExceptionInfo *) NULL);
3636 if (argc == 2)
3637 {
3638 option=argv[1];
3639 if ((LocaleCompare("version",option+1) == 0) ||
3640 (LocaleCompare("-version",option+1) == 0))
3641 {
3642 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003643 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003644 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
3645 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003646 return(MagickFalse);
3647 }
3648 }
3649 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003650 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003651 format=(char *) NULL;
3652 path=(char *) NULL;
3653 global_colormap=MagickFalse;
3654 k=0;
3655 j=1;
3656 NewImageStack();
3657 option=(char *) NULL;
3658 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003659 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003660 status=MagickTrue;
3661 /*
3662 Parse command line.
3663 */
3664 ReadCommandlLine(argc,&argv);
3665 status=ExpandFilenames(&argc,&argv);
3666 if (status == MagickFalse)
3667 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3668 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003669 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003670 {
3671 option=argv[i];
3672 if (LocaleCompare(option,"(") == 0)
3673 {
3674 FireImageStack(MagickFalse,MagickTrue,pend);
3675 if (k == MaxImageStackDepth)
3676 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3677 option);
3678 PushImageStack();
3679 continue;
3680 }
3681 if (LocaleCompare(option,")") == 0)
3682 {
3683 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3684 if (k == 0)
3685 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3686 PopImageStack();
3687 continue;
3688 }
cristy042ee782011-04-22 18:48:30 +00003689 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003690 {
3691 char
3692 backup_filename[MaxTextExtent],
3693 *filename;
3694
3695 Image
3696 *images;
3697
3698 /*
3699 Option is a file name: begin by reading image from specified file.
3700 */
3701 FireImageStack(MagickFalse,MagickFalse,pend);
3702 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003703 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003704 filename=argv[++i];
3705 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3706 images=ReadImages(image_info,exception);
3707 status&=(images != (Image *) NULL) &&
3708 (exception->severity < ErrorException);
3709 if (images == (Image *) NULL)
3710 continue;
cristydaa76602010-06-30 13:05:11 +00003711 if (format != (char *) NULL)
3712 (void) CopyMagickString(images->filename,images->magick_filename,
3713 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003714 if (path != (char *) NULL)
3715 {
3716 GetPathComponent(option,TailPath,filename);
3717 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
3718 path,*DirectorySeparator,filename);
3719 }
3720 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003721 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003722 AppendImageStack(images);
3723 FinalizeImageSettings(image_info,image,MagickFalse);
3724 if (global_colormap != MagickFalse)
3725 {
3726 QuantizeInfo
3727 *quantize_info;
3728
3729 quantize_info=AcquireQuantizeInfo(image_info);
3730 (void) RemapImages(quantize_info,images,(Image *) NULL);
3731 quantize_info=DestroyQuantizeInfo(quantize_info);
3732 }
3733 *backup_filename='\0';
3734 if ((LocaleCompare(image->filename,"-") != 0) &&
3735 (IsPathWritable(image->filename) != MagickFalse))
3736 {
cristybb503372010-05-27 20:51:26 +00003737 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003738 i;
3739
3740 /*
3741 Rename image file as backup.
3742 */
3743 (void) CopyMagickString(backup_filename,image->filename,
3744 MaxTextExtent);
3745 for (i=0; i < 6; i++)
3746 {
3747 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3748 if (IsPathAccessible(backup_filename) == MagickFalse)
3749 break;
3750 }
3751 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3752 (rename(image->filename,backup_filename) != 0))
3753 *backup_filename='\0';
3754 }
3755 /*
3756 Write transmogrified image to disk.
3757 */
3758 image_info->synchronize=MagickTrue;
3759 status&=WriteImages(image_info,image,image->filename,exception);
3760 if ((status == MagickFalse) && (*backup_filename != '\0'))
3761 (void) remove(backup_filename);
3762 RemoveAllImageStack();
3763 continue;
3764 }
3765 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3766 switch (*(option+1))
3767 {
3768 case 'a':
3769 {
3770 if (LocaleCompare("adaptive-blur",option+1) == 0)
3771 {
3772 i++;
cristybb503372010-05-27 20:51:26 +00003773 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003774 ThrowMogrifyException(OptionError,"MissingArgument",option);
3775 if (IsGeometry(argv[i]) == MagickFalse)
3776 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3777 break;
3778 }
3779 if (LocaleCompare("adaptive-resize",option+1) == 0)
3780 {
3781 i++;
cristybb503372010-05-27 20:51:26 +00003782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003783 ThrowMogrifyException(OptionError,"MissingArgument",option);
3784 if (IsGeometry(argv[i]) == MagickFalse)
3785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3786 break;
3787 }
3788 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3789 {
3790 i++;
cristybb503372010-05-27 20:51:26 +00003791 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003792 ThrowMogrifyException(OptionError,"MissingArgument",option);
3793 if (IsGeometry(argv[i]) == MagickFalse)
3794 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3795 break;
3796 }
3797 if (LocaleCompare("affine",option+1) == 0)
3798 {
3799 if (*option == '+')
3800 break;
3801 i++;
cristybb503372010-05-27 20:51:26 +00003802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003803 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003804 break;
3805 }
3806 if (LocaleCompare("alpha",option+1) == 0)
3807 {
cristybb503372010-05-27 20:51:26 +00003808 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003809 type;
3810
3811 if (*option == '+')
3812 break;
3813 i++;
cristybb503372010-05-27 20:51:26 +00003814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003815 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003816 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003817 if (type < 0)
3818 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3819 argv[i]);
3820 break;
3821 }
3822 if (LocaleCompare("annotate",option+1) == 0)
3823 {
3824 if (*option == '+')
3825 break;
3826 i++;
cristybb503372010-05-27 20:51:26 +00003827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003828 ThrowMogrifyException(OptionError,"MissingArgument",option);
3829 if (IsGeometry(argv[i]) == MagickFalse)
3830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003831 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003832 ThrowMogrifyException(OptionError,"MissingArgument",option);
3833 i++;
3834 break;
3835 }
3836 if (LocaleCompare("antialias",option+1) == 0)
3837 break;
3838 if (LocaleCompare("append",option+1) == 0)
3839 break;
3840 if (LocaleCompare("attenuate",option+1) == 0)
3841 {
3842 if (*option == '+')
3843 break;
3844 i++;
cristybb503372010-05-27 20:51:26 +00003845 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003846 ThrowMogrifyException(OptionError,"MissingArgument",option);
3847 if (IsGeometry(argv[i]) == MagickFalse)
3848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3849 break;
3850 }
3851 if (LocaleCompare("authenticate",option+1) == 0)
3852 {
3853 if (*option == '+')
3854 break;
3855 i++;
cristybb503372010-05-27 20:51:26 +00003856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003857 ThrowMogrifyException(OptionError,"MissingArgument",option);
3858 break;
3859 }
3860 if (LocaleCompare("auto-gamma",option+1) == 0)
3861 break;
3862 if (LocaleCompare("auto-level",option+1) == 0)
3863 break;
3864 if (LocaleCompare("auto-orient",option+1) == 0)
3865 break;
3866 if (LocaleCompare("average",option+1) == 0)
3867 break;
3868 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3869 }
3870 case 'b':
3871 {
3872 if (LocaleCompare("background",option+1) == 0)
3873 {
3874 if (*option == '+')
3875 break;
3876 i++;
cristybb503372010-05-27 20:51:26 +00003877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003878 ThrowMogrifyException(OptionError,"MissingArgument",option);
3879 break;
3880 }
3881 if (LocaleCompare("bias",option+1) == 0)
3882 {
3883 if (*option == '+')
3884 break;
3885 i++;
cristybb503372010-05-27 20:51:26 +00003886 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003887 ThrowMogrifyException(OptionError,"MissingArgument",option);
3888 if (IsGeometry(argv[i]) == MagickFalse)
3889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3890 break;
3891 }
3892 if (LocaleCompare("black-point-compensation",option+1) == 0)
3893 break;
3894 if (LocaleCompare("black-threshold",option+1) == 0)
3895 {
3896 if (*option == '+')
3897 break;
3898 i++;
cristybb503372010-05-27 20:51:26 +00003899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003900 ThrowMogrifyException(OptionError,"MissingArgument",option);
3901 if (IsGeometry(argv[i]) == MagickFalse)
3902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3903 break;
3904 }
3905 if (LocaleCompare("blue-primary",option+1) == 0)
3906 {
3907 if (*option == '+')
3908 break;
3909 i++;
cristybb503372010-05-27 20:51:26 +00003910 if (i == (ssize_t) argc)
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("blue-shift",option+1) == 0)
3917 {
3918 i++;
cristybb503372010-05-27 20:51:26 +00003919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003920 ThrowMogrifyException(OptionError,"MissingArgument",option);
3921 if (IsGeometry(argv[i]) == MagickFalse)
3922 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3923 break;
3924 }
3925 if (LocaleCompare("blur",option+1) == 0)
3926 {
3927 i++;
cristybb503372010-05-27 20:51:26 +00003928 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003929 ThrowMogrifyException(OptionError,"MissingArgument",option);
3930 if (IsGeometry(argv[i]) == MagickFalse)
3931 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3932 break;
3933 }
3934 if (LocaleCompare("border",option+1) == 0)
3935 {
3936 if (*option == '+')
3937 break;
3938 i++;
cristybb503372010-05-27 20:51:26 +00003939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003940 ThrowMogrifyException(OptionError,"MissingArgument",option);
3941 if (IsGeometry(argv[i]) == MagickFalse)
3942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3943 break;
3944 }
3945 if (LocaleCompare("bordercolor",option+1) == 0)
3946 {
3947 if (*option == '+')
3948 break;
3949 i++;
cristybb503372010-05-27 20:51:26 +00003950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003951 ThrowMogrifyException(OptionError,"MissingArgument",option);
3952 break;
3953 }
3954 if (LocaleCompare("box",option+1) == 0)
3955 {
3956 if (*option == '+')
3957 break;
3958 i++;
cristybb503372010-05-27 20:51:26 +00003959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003960 ThrowMogrifyException(OptionError,"MissingArgument",option);
3961 break;
3962 }
cristya28d6b82010-01-11 20:03:47 +00003963 if (LocaleCompare("brightness-contrast",option+1) == 0)
3964 {
3965 i++;
cristybb503372010-05-27 20:51:26 +00003966 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003967 ThrowMogrifyException(OptionError,"MissingArgument",option);
3968 if (IsGeometry(argv[i]) == MagickFalse)
3969 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3970 break;
3971 }
cristy3ed852e2009-09-05 21:47:34 +00003972 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3973 }
3974 case 'c':
3975 {
3976 if (LocaleCompare("cache",option+1) == 0)
3977 {
3978 if (*option == '+')
3979 break;
3980 i++;
cristybb503372010-05-27 20:51:26 +00003981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003982 ThrowMogrifyException(OptionError,"MissingArgument",option);
3983 if (IsGeometry(argv[i]) == MagickFalse)
3984 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3985 break;
3986 }
3987 if (LocaleCompare("caption",option+1) == 0)
3988 {
3989 if (*option == '+')
3990 break;
3991 i++;
cristybb503372010-05-27 20:51:26 +00003992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003993 ThrowMogrifyException(OptionError,"MissingArgument",option);
3994 break;
3995 }
3996 if (LocaleCompare("channel",option+1) == 0)
3997 {
cristybb503372010-05-27 20:51:26 +00003998 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003999 channel;
4000
4001 if (*option == '+')
4002 break;
4003 i++;
cristybb503372010-05-27 20:51:26 +00004004 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004005 ThrowMogrifyException(OptionError,"MissingArgument",option);
4006 channel=ParseChannelOption(argv[i]);
4007 if (channel < 0)
4008 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4009 argv[i]);
4010 break;
4011 }
4012 if (LocaleCompare("cdl",option+1) == 0)
4013 {
4014 if (*option == '+')
4015 break;
4016 i++;
cristybb503372010-05-27 20:51:26 +00004017 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004018 ThrowMogrifyException(OptionError,"MissingArgument",option);
4019 break;
4020 }
4021 if (LocaleCompare("charcoal",option+1) == 0)
4022 {
4023 if (*option == '+')
4024 break;
4025 i++;
cristybb503372010-05-27 20:51:26 +00004026 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004027 ThrowMogrifyException(OptionError,"MissingArgument",option);
4028 if (IsGeometry(argv[i]) == MagickFalse)
4029 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4030 break;
4031 }
4032 if (LocaleCompare("chop",option+1) == 0)
4033 {
4034 if (*option == '+')
4035 break;
4036 i++;
cristybb503372010-05-27 20:51:26 +00004037 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004038 ThrowMogrifyException(OptionError,"MissingArgument",option);
4039 if (IsGeometry(argv[i]) == MagickFalse)
4040 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4041 break;
4042 }
cristy1eb45dd2009-09-25 16:38:06 +00004043 if (LocaleCompare("clamp",option+1) == 0)
4044 break;
4045 if (LocaleCompare("clip",option+1) == 0)
4046 break;
cristy3ed852e2009-09-05 21:47:34 +00004047 if (LocaleCompare("clip-mask",option+1) == 0)
4048 {
4049 if (*option == '+')
4050 break;
4051 i++;
cristybb503372010-05-27 20:51:26 +00004052 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004053 ThrowMogrifyException(OptionError,"MissingArgument",option);
4054 break;
4055 }
4056 if (LocaleCompare("clut",option+1) == 0)
4057 break;
4058 if (LocaleCompare("coalesce",option+1) == 0)
4059 break;
4060 if (LocaleCompare("colorize",option+1) == 0)
4061 {
4062 if (*option == '+')
4063 break;
4064 i++;
cristybb503372010-05-27 20:51:26 +00004065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004066 ThrowMogrifyException(OptionError,"MissingArgument",option);
4067 if (IsGeometry(argv[i]) == MagickFalse)
4068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4069 break;
4070 }
cristye6365592010-04-02 17:31:23 +00004071 if (LocaleCompare("color-matrix",option+1) == 0)
4072 {
cristyb6bd4ad2010-08-08 01:12:27 +00004073 KernelInfo
4074 *kernel_info;
4075
cristye6365592010-04-02 17:31:23 +00004076 if (*option == '+')
4077 break;
4078 i++;
cristybb503372010-05-27 20:51:26 +00004079 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004080 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004081 kernel_info=AcquireKernelInfo(argv[i]);
4082 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004083 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004084 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004085 break;
4086 }
cristy3ed852e2009-09-05 21:47:34 +00004087 if (LocaleCompare("colors",option+1) == 0)
4088 {
4089 if (*option == '+')
4090 break;
4091 i++;
cristybb503372010-05-27 20:51:26 +00004092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004093 ThrowMogrifyException(OptionError,"MissingArgument",option);
4094 if (IsGeometry(argv[i]) == MagickFalse)
4095 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4096 break;
4097 }
4098 if (LocaleCompare("colorspace",option+1) == 0)
4099 {
cristybb503372010-05-27 20:51:26 +00004100 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004101 colorspace;
4102
4103 if (*option == '+')
4104 break;
4105 i++;
cristybb503372010-05-27 20:51:26 +00004106 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004107 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004108 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004109 argv[i]);
4110 if (colorspace < 0)
4111 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4112 argv[i]);
4113 break;
4114 }
4115 if (LocaleCompare("combine",option+1) == 0)
4116 break;
4117 if (LocaleCompare("comment",option+1) == 0)
4118 {
4119 if (*option == '+')
4120 break;
4121 i++;
cristybb503372010-05-27 20:51:26 +00004122 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004123 ThrowMogrifyException(OptionError,"MissingArgument",option);
4124 break;
4125 }
4126 if (LocaleCompare("composite",option+1) == 0)
4127 break;
4128 if (LocaleCompare("compress",option+1) == 0)
4129 {
cristybb503372010-05-27 20:51:26 +00004130 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004131 compress;
4132
4133 if (*option == '+')
4134 break;
4135 i++;
cristybb503372010-05-27 20:51:26 +00004136 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004137 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004138 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004139 argv[i]);
4140 if (compress < 0)
4141 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4142 argv[i]);
4143 break;
4144 }
cristy22879752009-10-25 23:55:40 +00004145 if (LocaleCompare("concurrent",option+1) == 0)
4146 break;
cristy3ed852e2009-09-05 21:47:34 +00004147 if (LocaleCompare("contrast",option+1) == 0)
4148 break;
4149 if (LocaleCompare("contrast-stretch",option+1) == 0)
4150 {
4151 i++;
cristybb503372010-05-27 20:51:26 +00004152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004153 ThrowMogrifyException(OptionError,"MissingArgument",option);
4154 if (IsGeometry(argv[i]) == MagickFalse)
4155 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4156 break;
4157 }
4158 if (LocaleCompare("convolve",option+1) == 0)
4159 {
cristyb6bd4ad2010-08-08 01:12:27 +00004160 KernelInfo
4161 *kernel_info;
4162
cristy3ed852e2009-09-05 21:47:34 +00004163 if (*option == '+')
4164 break;
4165 i++;
cristybb503372010-05-27 20:51:26 +00004166 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004167 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004168 kernel_info=AcquireKernelInfo(argv[i]);
4169 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004170 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004171 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004172 break;
4173 }
4174 if (LocaleCompare("crop",option+1) == 0)
4175 {
4176 if (*option == '+')
4177 break;
4178 i++;
cristybb503372010-05-27 20:51:26 +00004179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004180 ThrowMogrifyException(OptionError,"MissingArgument",option);
4181 if (IsGeometry(argv[i]) == MagickFalse)
4182 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4183 break;
4184 }
4185 if (LocaleCompare("cycle",option+1) == 0)
4186 {
4187 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);
4192 if (IsGeometry(argv[i]) == MagickFalse)
4193 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4194 break;
4195 }
4196 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4197 }
4198 case 'd':
4199 {
4200 if (LocaleCompare("decipher",option+1) == 0)
4201 {
4202 if (*option == '+')
4203 break;
4204 i++;
cristybb503372010-05-27 20:51:26 +00004205 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004206 ThrowMogrifyException(OptionError,"MissingArgument",option);
4207 break;
4208 }
4209 if (LocaleCompare("deconstruct",option+1) == 0)
4210 break;
4211 if (LocaleCompare("debug",option+1) == 0)
4212 {
cristybb503372010-05-27 20:51:26 +00004213 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004214 event;
4215
4216 if (*option == '+')
4217 break;
4218 i++;
cristybb503372010-05-27 20:51:26 +00004219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004220 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004221 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004222 if (event < 0)
4223 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4224 argv[i]);
4225 (void) SetLogEventMask(argv[i]);
4226 break;
4227 }
4228 if (LocaleCompare("define",option+1) == 0)
4229 {
4230 i++;
cristybb503372010-05-27 20:51:26 +00004231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004232 ThrowMogrifyException(OptionError,"MissingArgument",option);
4233 if (*option == '+')
4234 {
4235 const char
4236 *define;
4237
4238 define=GetImageOption(image_info,argv[i]);
4239 if (define == (const char *) NULL)
4240 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4241 break;
4242 }
4243 break;
4244 }
4245 if (LocaleCompare("delay",option+1) == 0)
4246 {
4247 if (*option == '+')
4248 break;
4249 i++;
cristybb503372010-05-27 20:51:26 +00004250 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004251 ThrowMogrifyException(OptionError,"MissingArgument",option);
4252 if (IsGeometry(argv[i]) == MagickFalse)
4253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4254 break;
4255 }
cristyecb10ff2011-03-22 13:14:03 +00004256 if (LocaleCompare("delete",option+1) == 0)
4257 {
4258 if (*option == '+')
4259 break;
4260 i++;
4261 if (i == (ssize_t) (argc-1))
4262 ThrowMogrifyException(OptionError,"MissingArgument",option);
4263 if (IsGeometry(argv[i]) == MagickFalse)
4264 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4265 break;
4266 }
cristy3ed852e2009-09-05 21:47:34 +00004267 if (LocaleCompare("density",option+1) == 0)
4268 {
4269 if (*option == '+')
4270 break;
4271 i++;
cristybb503372010-05-27 20:51:26 +00004272 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004273 ThrowMogrifyException(OptionError,"MissingArgument",option);
4274 if (IsGeometry(argv[i]) == MagickFalse)
4275 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4276 break;
4277 }
4278 if (LocaleCompare("depth",option+1) == 0)
4279 {
4280 if (*option == '+')
4281 break;
4282 i++;
cristybb503372010-05-27 20:51:26 +00004283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004284 ThrowMogrifyException(OptionError,"MissingArgument",option);
4285 if (IsGeometry(argv[i]) == MagickFalse)
4286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4287 break;
4288 }
4289 if (LocaleCompare("deskew",option+1) == 0)
4290 {
4291 if (*option == '+')
4292 break;
4293 i++;
cristybb503372010-05-27 20:51:26 +00004294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004295 ThrowMogrifyException(OptionError,"MissingArgument",option);
4296 if (IsGeometry(argv[i]) == MagickFalse)
4297 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4298 break;
4299 }
4300 if (LocaleCompare("despeckle",option+1) == 0)
4301 break;
4302 if (LocaleCompare("dft",option+1) == 0)
4303 break;
cristyc9b12952010-03-28 01:12:28 +00004304 if (LocaleCompare("direction",option+1) == 0)
4305 {
cristybb503372010-05-27 20:51:26 +00004306 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004307 direction;
4308
4309 if (*option == '+')
4310 break;
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004314 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004315 argv[i]);
4316 if (direction < 0)
4317 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4318 argv[i]);
4319 break;
4320 }
cristy3ed852e2009-09-05 21:47:34 +00004321 if (LocaleCompare("display",option+1) == 0)
4322 {
4323 if (*option == '+')
4324 break;
4325 i++;
cristybb503372010-05-27 20:51:26 +00004326 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004327 ThrowMogrifyException(OptionError,"MissingArgument",option);
4328 break;
4329 }
4330 if (LocaleCompare("dispose",option+1) == 0)
4331 {
cristybb503372010-05-27 20:51:26 +00004332 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004333 dispose;
4334
4335 if (*option == '+')
4336 break;
4337 i++;
cristybb503372010-05-27 20:51:26 +00004338 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004339 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004340 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004341 if (dispose < 0)
4342 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4343 argv[i]);
4344 break;
4345 }
4346 if (LocaleCompare("distort",option+1) == 0)
4347 {
cristybb503372010-05-27 20:51:26 +00004348 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004349 op;
4350
4351 i++;
cristybb503372010-05-27 20:51:26 +00004352 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004353 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004354 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004355 if (op < 0)
4356 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4357 argv[i]);
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 break;
4362 }
4363 if (LocaleCompare("dither",option+1) == 0)
4364 {
cristybb503372010-05-27 20:51:26 +00004365 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004366 method;
4367
4368 if (*option == '+')
4369 break;
4370 i++;
cristybb503372010-05-27 20:51:26 +00004371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004372 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004373 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004374 if (method < 0)
4375 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4376 argv[i]);
4377 break;
4378 }
4379 if (LocaleCompare("draw",option+1) == 0)
4380 {
4381 if (*option == '+')
4382 break;
4383 i++;
cristybb503372010-05-27 20:51:26 +00004384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004385 ThrowMogrifyException(OptionError,"MissingArgument",option);
4386 break;
4387 }
cristyecb10ff2011-03-22 13:14:03 +00004388 if (LocaleCompare("duplicate",option+1) == 0)
4389 {
4390 if (*option == '+')
4391 break;
4392 i++;
4393 if (i == (ssize_t) (argc-1))
4394 ThrowMogrifyException(OptionError,"MissingArgument",option);
4395 if (IsGeometry(argv[i]) == MagickFalse)
4396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4397 break;
4398 }
cristy22879752009-10-25 23:55:40 +00004399 if (LocaleCompare("duration",option+1) == 0)
4400 {
4401 if (*option == '+')
4402 break;
4403 i++;
cristybb503372010-05-27 20:51:26 +00004404 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004405 ThrowMogrifyException(OptionError,"MissingArgument",option);
4406 if (IsGeometry(argv[i]) == MagickFalse)
4407 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4408 break;
4409 }
cristy3ed852e2009-09-05 21:47:34 +00004410 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4411 }
4412 case 'e':
4413 {
4414 if (LocaleCompare("edge",option+1) == 0)
4415 {
4416 if (*option == '+')
4417 break;
4418 i++;
cristybb503372010-05-27 20:51:26 +00004419 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004420 ThrowMogrifyException(OptionError,"MissingArgument",option);
4421 if (IsGeometry(argv[i]) == MagickFalse)
4422 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4423 break;
4424 }
4425 if (LocaleCompare("emboss",option+1) == 0)
4426 {
4427 if (*option == '+')
4428 break;
4429 i++;
cristybb503372010-05-27 20:51:26 +00004430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004431 ThrowMogrifyException(OptionError,"MissingArgument",option);
4432 if (IsGeometry(argv[i]) == MagickFalse)
4433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4434 break;
4435 }
4436 if (LocaleCompare("encipher",option+1) == 0)
4437 {
4438 if (*option == '+')
4439 break;
4440 i++;
cristybb503372010-05-27 20:51:26 +00004441 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004442 ThrowMogrifyException(OptionError,"MissingArgument",option);
4443 break;
4444 }
4445 if (LocaleCompare("encoding",option+1) == 0)
4446 {
4447 if (*option == '+')
4448 break;
4449 i++;
cristybb503372010-05-27 20:51:26 +00004450 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004451 ThrowMogrifyException(OptionError,"MissingArgument",option);
4452 break;
4453 }
4454 if (LocaleCompare("endian",option+1) == 0)
4455 {
cristybb503372010-05-27 20:51:26 +00004456 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004457 endian;
4458
4459 if (*option == '+')
4460 break;
4461 i++;
cristybb503372010-05-27 20:51:26 +00004462 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004463 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004464 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004465 if (endian < 0)
4466 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4467 argv[i]);
4468 break;
4469 }
4470 if (LocaleCompare("enhance",option+1) == 0)
4471 break;
4472 if (LocaleCompare("equalize",option+1) == 0)
4473 break;
4474 if (LocaleCompare("evaluate",option+1) == 0)
4475 {
cristybb503372010-05-27 20:51:26 +00004476 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004477 op;
4478
4479 if (*option == '+')
4480 break;
4481 i++;
cristybb503372010-05-27 20:51:26 +00004482 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004483 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004484 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004485 if (op < 0)
4486 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4487 argv[i]);
4488 i++;
cristybb503372010-05-27 20:51:26 +00004489 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004490 ThrowMogrifyException(OptionError,"MissingArgument",option);
4491 if (IsGeometry(argv[i]) == MagickFalse)
4492 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4493 break;
4494 }
cristyd18ae7c2010-03-07 17:39:52 +00004495 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4496 {
cristybb503372010-05-27 20:51:26 +00004497 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004498 op;
4499
4500 if (*option == '+')
4501 break;
4502 i++;
cristybb503372010-05-27 20:51:26 +00004503 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004504 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004505 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004506 if (op < 0)
4507 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4508 argv[i]);
4509 break;
4510 }
cristy3ed852e2009-09-05 21:47:34 +00004511 if (LocaleCompare("extent",option+1) == 0)
4512 {
4513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
4518 if (IsGeometry(argv[i]) == MagickFalse)
4519 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4520 break;
4521 }
4522 if (LocaleCompare("extract",option+1) == 0)
4523 {
4524 if (*option == '+')
4525 break;
4526 i++;
cristybb503372010-05-27 20:51:26 +00004527 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004528 ThrowMogrifyException(OptionError,"MissingArgument",option);
4529 if (IsGeometry(argv[i]) == MagickFalse)
4530 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4531 break;
4532 }
4533 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4534 }
4535 case 'f':
4536 {
4537 if (LocaleCompare("family",option+1) == 0)
4538 {
4539 if (*option == '+')
4540 break;
4541 i++;
cristybb503372010-05-27 20:51:26 +00004542 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004543 ThrowMogrifyException(OptionError,"MissingArgument",option);
4544 break;
4545 }
4546 if (LocaleCompare("fill",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 break;
4554 }
4555 if (LocaleCompare("filter",option+1) == 0)
4556 {
cristybb503372010-05-27 20:51:26 +00004557 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004558 filter;
4559
4560 if (*option == '+')
4561 break;
4562 i++;
cristybb503372010-05-27 20:51:26 +00004563 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004564 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004565 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004566 if (filter < 0)
4567 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4568 argv[i]);
4569 break;
4570 }
4571 if (LocaleCompare("flatten",option+1) == 0)
4572 break;
4573 if (LocaleCompare("flip",option+1) == 0)
4574 break;
4575 if (LocaleCompare("flop",option+1) == 0)
4576 break;
4577 if (LocaleCompare("floodfill",option+1) == 0)
4578 {
4579 if (*option == '+')
4580 break;
4581 i++;
cristybb503372010-05-27 20:51:26 +00004582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004583 ThrowMogrifyException(OptionError,"MissingArgument",option);
4584 if (IsGeometry(argv[i]) == MagickFalse)
4585 ThrowMogrifyInvalidArgumentException(option,argv[i]);
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);
4589 break;
4590 }
4591 if (LocaleCompare("font",option+1) == 0)
4592 {
4593 if (*option == '+')
4594 break;
4595 i++;
cristybb503372010-05-27 20:51:26 +00004596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004597 ThrowMogrifyException(OptionError,"MissingArgument",option);
4598 break;
4599 }
4600 if (LocaleCompare("format",option+1) == 0)
4601 {
4602 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4603 (void) CloneString(&format,(char *) NULL);
4604 if (*option == '+')
4605 break;
4606 i++;
cristybb503372010-05-27 20:51:26 +00004607 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004608 ThrowMogrifyException(OptionError,"MissingArgument",option);
4609 (void) CloneString(&format,argv[i]);
4610 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4611 (void) ConcatenateMagickString(image_info->filename,":",
4612 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004613 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004614 if (*image_info->magick == '\0')
4615 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4616 format);
4617 break;
4618 }
4619 if (LocaleCompare("frame",option+1) == 0)
4620 {
4621 if (*option == '+')
4622 break;
4623 i++;
cristybb503372010-05-27 20:51:26 +00004624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004625 ThrowMogrifyException(OptionError,"MissingArgument",option);
4626 if (IsGeometry(argv[i]) == MagickFalse)
4627 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4628 break;
4629 }
4630 if (LocaleCompare("function",option+1) == 0)
4631 {
cristybb503372010-05-27 20:51:26 +00004632 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004633 op;
4634
4635 if (*option == '+')
4636 break;
4637 i++;
cristybb503372010-05-27 20:51:26 +00004638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004639 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004640 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004641 if (op < 0)
4642 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4643 i++;
cristybb503372010-05-27 20:51:26 +00004644 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004645 ThrowMogrifyException(OptionError,"MissingArgument",option);
4646 break;
4647 }
4648 if (LocaleCompare("fuzz",option+1) == 0)
4649 {
4650 if (*option == '+')
4651 break;
4652 i++;
cristybb503372010-05-27 20:51:26 +00004653 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004654 ThrowMogrifyException(OptionError,"MissingArgument",option);
4655 if (IsGeometry(argv[i]) == MagickFalse)
4656 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4657 break;
4658 }
4659 if (LocaleCompare("fx",option+1) == 0)
4660 {
4661 if (*option == '+')
4662 break;
4663 i++;
cristybb503372010-05-27 20:51:26 +00004664 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004665 ThrowMogrifyException(OptionError,"MissingArgument",option);
4666 break;
4667 }
4668 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4669 }
4670 case 'g':
4671 {
4672 if (LocaleCompare("gamma",option+1) == 0)
4673 {
4674 i++;
cristybb503372010-05-27 20:51:26 +00004675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004676 ThrowMogrifyException(OptionError,"MissingArgument",option);
4677 if (IsGeometry(argv[i]) == MagickFalse)
4678 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4679 break;
4680 }
4681 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4682 (LocaleCompare("gaussian",option+1) == 0))
4683 {
4684 i++;
cristybb503372010-05-27 20:51:26 +00004685 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004686 ThrowMogrifyException(OptionError,"MissingArgument",option);
4687 if (IsGeometry(argv[i]) == MagickFalse)
4688 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4689 break;
4690 }
4691 if (LocaleCompare("geometry",option+1) == 0)
4692 {
4693 if (*option == '+')
4694 break;
4695 i++;
cristybb503372010-05-27 20:51:26 +00004696 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004697 ThrowMogrifyException(OptionError,"MissingArgument",option);
4698 if (IsGeometry(argv[i]) == MagickFalse)
4699 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4700 break;
4701 }
4702 if (LocaleCompare("gravity",option+1) == 0)
4703 {
cristybb503372010-05-27 20:51:26 +00004704 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004705 gravity;
4706
4707 if (*option == '+')
4708 break;
4709 i++;
cristybb503372010-05-27 20:51:26 +00004710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004711 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004712 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004713 if (gravity < 0)
4714 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4715 argv[i]);
4716 break;
4717 }
4718 if (LocaleCompare("green-primary",option+1) == 0)
4719 {
4720 if (*option == '+')
4721 break;
4722 i++;
cristybb503372010-05-27 20:51:26 +00004723 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004724 ThrowMogrifyException(OptionError,"MissingArgument",option);
4725 if (IsGeometry(argv[i]) == MagickFalse)
4726 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4727 break;
4728 }
4729 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4730 }
4731 case 'h':
4732 {
4733 if (LocaleCompare("hald-clut",option+1) == 0)
4734 break;
4735 if ((LocaleCompare("help",option+1) == 0) ||
4736 (LocaleCompare("-help",option+1) == 0))
4737 return(MogrifyUsage());
4738 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4739 }
4740 case 'i':
4741 {
4742 if (LocaleCompare("identify",option+1) == 0)
4743 break;
4744 if (LocaleCompare("idft",option+1) == 0)
4745 break;
4746 if (LocaleCompare("implode",option+1) == 0)
4747 {
4748 if (*option == '+')
4749 break;
4750 i++;
cristybb503372010-05-27 20:51:26 +00004751 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004752 ThrowMogrifyException(OptionError,"MissingArgument",option);
4753 if (IsGeometry(argv[i]) == MagickFalse)
4754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4755 break;
4756 }
4757 if (LocaleCompare("intent",option+1) == 0)
4758 {
cristybb503372010-05-27 20:51:26 +00004759 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004760 intent;
4761
4762 if (*option == '+')
4763 break;
4764 i++;
cristybb503372010-05-27 20:51:26 +00004765 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004766 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004767 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004768 if (intent < 0)
4769 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4770 argv[i]);
4771 break;
4772 }
4773 if (LocaleCompare("interlace",option+1) == 0)
4774 {
cristybb503372010-05-27 20:51:26 +00004775 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004776 interlace;
4777
4778 if (*option == '+')
4779 break;
4780 i++;
cristybb503372010-05-27 20:51:26 +00004781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004782 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004783 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004784 argv[i]);
4785 if (interlace < 0)
4786 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4787 argv[i]);
4788 break;
4789 }
cristyb32b90a2009-09-07 21:45:48 +00004790 if (LocaleCompare("interline-spacing",option+1) == 0)
4791 {
4792 if (*option == '+')
4793 break;
4794 i++;
cristybb503372010-05-27 20:51:26 +00004795 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004796 ThrowMogrifyException(OptionError,"MissingArgument",option);
4797 if (IsGeometry(argv[i]) == MagickFalse)
4798 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4799 break;
4800 }
cristy3ed852e2009-09-05 21:47:34 +00004801 if (LocaleCompare("interpolate",option+1) == 0)
4802 {
cristybb503372010-05-27 20:51:26 +00004803 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004804 interpolate;
4805
4806 if (*option == '+')
4807 break;
4808 i++;
cristybb503372010-05-27 20:51:26 +00004809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004810 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004811 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004812 argv[i]);
4813 if (interpolate < 0)
4814 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4815 argv[i]);
4816 break;
4817 }
4818 if (LocaleCompare("interword-spacing",option+1) == 0)
4819 {
4820 if (*option == '+')
4821 break;
4822 i++;
cristybb503372010-05-27 20:51:26 +00004823 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004824 ThrowMogrifyException(OptionError,"MissingArgument",option);
4825 if (IsGeometry(argv[i]) == MagickFalse)
4826 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4827 break;
4828 }
4829 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4830 }
4831 case 'k':
4832 {
4833 if (LocaleCompare("kerning",option+1) == 0)
4834 {
4835 if (*option == '+')
4836 break;
4837 i++;
cristybb503372010-05-27 20:51:26 +00004838 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004839 ThrowMogrifyException(OptionError,"MissingArgument",option);
4840 if (IsGeometry(argv[i]) == MagickFalse)
4841 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4842 break;
4843 }
4844 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4845 }
4846 case 'l':
4847 {
4848 if (LocaleCompare("label",option+1) == 0)
4849 {
4850 if (*option == '+')
4851 break;
4852 i++;
cristybb503372010-05-27 20:51:26 +00004853 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004854 ThrowMogrifyException(OptionError,"MissingArgument",option);
4855 break;
4856 }
4857 if (LocaleCompare("lat",option+1) == 0)
4858 {
4859 if (*option == '+')
4860 break;
4861 i++;
cristybb503372010-05-27 20:51:26 +00004862 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004863 ThrowMogrifyException(OptionError,"MissingArgument",option);
4864 if (IsGeometry(argv[i]) == MagickFalse)
4865 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4866 }
4867 if (LocaleCompare("layers",option+1) == 0)
4868 {
cristybb503372010-05-27 20:51:26 +00004869 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004870 type;
4871
4872 if (*option == '+')
4873 break;
4874 i++;
cristybb503372010-05-27 20:51:26 +00004875 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004876 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004877 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004878 if (type < 0)
4879 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4880 argv[i]);
4881 break;
4882 }
4883 if (LocaleCompare("level",option+1) == 0)
4884 {
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 break;
4891 }
4892 if (LocaleCompare("level-colors",option+1) == 0)
4893 {
4894 i++;
cristybb503372010-05-27 20:51:26 +00004895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004896 ThrowMogrifyException(OptionError,"MissingArgument",option);
4897 break;
4898 }
4899 if (LocaleCompare("linewidth",option+1) == 0)
4900 {
4901 if (*option == '+')
4902 break;
4903 i++;
cristybb503372010-05-27 20:51:26 +00004904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004905 ThrowMogrifyException(OptionError,"MissingArgument",option);
4906 if (IsGeometry(argv[i]) == MagickFalse)
4907 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4908 break;
4909 }
4910 if (LocaleCompare("limit",option+1) == 0)
4911 {
4912 char
4913 *p;
4914
4915 double
4916 value;
4917
cristybb503372010-05-27 20:51:26 +00004918 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004919 resource;
4920
4921 if (*option == '+')
4922 break;
4923 i++;
cristybb503372010-05-27 20:51:26 +00004924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004925 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004926 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004927 argv[i]);
4928 if (resource < 0)
4929 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4930 argv[i]);
4931 i++;
cristybb503372010-05-27 20:51:26 +00004932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004933 ThrowMogrifyException(OptionError,"MissingArgument",option);
4934 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004935 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004936 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4938 break;
4939 }
4940 if (LocaleCompare("liquid-rescale",option+1) == 0)
4941 {
4942 i++;
cristybb503372010-05-27 20:51:26 +00004943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004944 ThrowMogrifyException(OptionError,"MissingArgument",option);
4945 if (IsGeometry(argv[i]) == MagickFalse)
4946 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4947 break;
4948 }
4949 if (LocaleCompare("list",option+1) == 0)
4950 {
cristybb503372010-05-27 20:51:26 +00004951 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004952 list;
4953
4954 if (*option == '+')
4955 break;
4956 i++;
cristybb503372010-05-27 20:51:26 +00004957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004958 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004959 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004960 if (list < 0)
4961 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004962 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004963 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004964 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004965 }
4966 if (LocaleCompare("log",option+1) == 0)
4967 {
4968 if (*option == '+')
4969 break;
4970 i++;
cristybb503372010-05-27 20:51:26 +00004971 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004972 (strchr(argv[i],'%') == (char *) NULL))
4973 ThrowMogrifyException(OptionError,"MissingArgument",option);
4974 break;
4975 }
4976 if (LocaleCompare("loop",option+1) == 0)
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);
4983 if (IsGeometry(argv[i]) == MagickFalse)
4984 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4985 break;
4986 }
4987 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4988 }
4989 case 'm':
4990 {
4991 if (LocaleCompare("map",option+1) == 0)
4992 {
4993 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4994 if (*option == '+')
4995 break;
4996 i++;
cristybb503372010-05-27 20:51:26 +00004997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004998 ThrowMogrifyException(OptionError,"MissingArgument",option);
4999 break;
5000 }
5001 if (LocaleCompare("mask",option+1) == 0)
5002 {
5003 if (*option == '+')
5004 break;
5005 i++;
cristybb503372010-05-27 20:51:26 +00005006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005007 ThrowMogrifyException(OptionError,"MissingArgument",option);
5008 break;
5009 }
5010 if (LocaleCompare("matte",option+1) == 0)
5011 break;
5012 if (LocaleCompare("mattecolor",option+1) == 0)
5013 {
5014 if (*option == '+')
5015 break;
5016 i++;
cristybb503372010-05-27 20:51:26 +00005017 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005018 ThrowMogrifyException(OptionError,"MissingArgument",option);
5019 break;
5020 }
cristyf40785b2010-03-06 02:27:27 +00005021 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005022 break;
cristyf40785b2010-03-06 02:27:27 +00005023 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005024 break;
cristy3ed852e2009-09-05 21:47:34 +00005025 if (LocaleCompare("modulate",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 if (IsGeometry(argv[i]) == MagickFalse)
5033 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5034 break;
5035 }
5036 if (LocaleCompare("median",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 if (IsGeometry(argv[i]) == MagickFalse)
5044 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5045 break;
5046 }
cristy69ec32d2011-02-27 23:57:09 +00005047 if (LocaleCompare("mode",option+1) == 0)
5048 {
5049 if (*option == '+')
5050 break;
5051 i++;
5052 if (i == (ssize_t) argc)
5053 ThrowMogrifyException(OptionError,"MissingArgument",option);
5054 if (IsGeometry(argv[i]) == MagickFalse)
5055 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5056 break;
5057 }
cristy3ed852e2009-09-05 21:47:34 +00005058 if (LocaleCompare("monitor",option+1) == 0)
5059 break;
5060 if (LocaleCompare("monochrome",option+1) == 0)
5061 break;
5062 if (LocaleCompare("morph",option+1) == 0)
5063 {
5064 if (*option == '+')
5065 break;
5066 i++;
cristybb503372010-05-27 20:51:26 +00005067 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005068 ThrowMogrifyException(OptionError,"MissingArgument",option);
5069 if (IsGeometry(argv[i]) == MagickFalse)
5070 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5071 break;
5072 }
anthony29188a82010-01-22 10:12:34 +00005073 if (LocaleCompare("morphology",option+1) == 0)
5074 {
anthony29188a82010-01-22 10:12:34 +00005075 char
5076 token[MaxTextExtent];
5077
cristyb6bd4ad2010-08-08 01:12:27 +00005078 KernelInfo
5079 *kernel_info;
5080
5081 ssize_t
5082 op;
5083
anthony29188a82010-01-22 10:12:34 +00005084 i++;
cristybb503372010-05-27 20:51:26 +00005085 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005086 ThrowMogrifyException(OptionError,"MissingArgument",option);
5087 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005088 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005089 if (op < 0)
5090 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005091 token);
anthony29188a82010-01-22 10:12:34 +00005092 i++;
cristybb503372010-05-27 20:51:26 +00005093 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005094 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005095 kernel_info=AcquireKernelInfo(argv[i]);
5096 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005097 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005098 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005099 break;
5100 }
cristy3ed852e2009-09-05 21:47:34 +00005101 if (LocaleCompare("mosaic",option+1) == 0)
5102 break;
5103 if (LocaleCompare("motion-blur",option+1) == 0)
5104 {
5105 if (*option == '+')
5106 break;
5107 i++;
cristybb503372010-05-27 20:51:26 +00005108 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005109 ThrowMogrifyException(OptionError,"MissingArgument",option);
5110 if (IsGeometry(argv[i]) == MagickFalse)
5111 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5112 break;
5113 }
5114 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5115 }
5116 case 'n':
5117 {
5118 if (LocaleCompare("negate",option+1) == 0)
5119 break;
5120 if (LocaleCompare("noise",option+1) == 0)
5121 {
5122 i++;
cristybb503372010-05-27 20:51:26 +00005123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005124 ThrowMogrifyException(OptionError,"MissingArgument",option);
5125 if (*option == '+')
5126 {
cristybb503372010-05-27 20:51:26 +00005127 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005128 noise;
5129
cristy042ee782011-04-22 18:48:30 +00005130 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005131 if (noise < 0)
5132 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5133 argv[i]);
5134 break;
5135 }
5136 if (IsGeometry(argv[i]) == MagickFalse)
5137 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5138 break;
5139 }
5140 if (LocaleCompare("noop",option+1) == 0)
5141 break;
5142 if (LocaleCompare("normalize",option+1) == 0)
5143 break;
5144 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5145 }
5146 case 'o':
5147 {
5148 if (LocaleCompare("opaque",option+1) == 0)
5149 {
cristy3ed852e2009-09-05 21:47:34 +00005150 i++;
cristybb503372010-05-27 20:51:26 +00005151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005152 ThrowMogrifyException(OptionError,"MissingArgument",option);
5153 break;
5154 }
5155 if (LocaleCompare("ordered-dither",option+1) == 0)
5156 {
5157 if (*option == '+')
5158 break;
5159 i++;
cristybb503372010-05-27 20:51:26 +00005160 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005161 ThrowMogrifyException(OptionError,"MissingArgument",option);
5162 break;
5163 }
5164 if (LocaleCompare("orient",option+1) == 0)
5165 {
cristybb503372010-05-27 20:51:26 +00005166 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005167 orientation;
5168
5169 orientation=UndefinedOrientation;
5170 if (*option == '+')
5171 break;
5172 i++;
cristybb503372010-05-27 20:51:26 +00005173 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005174 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005175 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005176 argv[i]);
5177 if (orientation < 0)
5178 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5179 argv[i]);
5180 break;
5181 }
5182 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5183 }
5184 case 'p':
5185 {
5186 if (LocaleCompare("page",option+1) == 0)
5187 {
5188 if (*option == '+')
5189 break;
5190 i++;
cristybb503372010-05-27 20:51:26 +00005191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005192 ThrowMogrifyException(OptionError,"MissingArgument",option);
5193 break;
5194 }
5195 if (LocaleCompare("paint",option+1) == 0)
5196 {
5197 if (*option == '+')
5198 break;
5199 i++;
cristybb503372010-05-27 20:51:26 +00005200 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005201 ThrowMogrifyException(OptionError,"MissingArgument",option);
5202 if (IsGeometry(argv[i]) == MagickFalse)
5203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5204 break;
5205 }
5206 if (LocaleCompare("path",option+1) == 0)
5207 {
5208 (void) CloneString(&path,(char *) NULL);
5209 if (*option == '+')
5210 break;
5211 i++;
cristybb503372010-05-27 20:51:26 +00005212 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005213 ThrowMogrifyException(OptionError,"MissingArgument",option);
5214 (void) CloneString(&path,argv[i]);
5215 break;
5216 }
5217 if (LocaleCompare("pointsize",option+1) == 0)
5218 {
5219 if (*option == '+')
5220 break;
5221 i++;
cristybb503372010-05-27 20:51:26 +00005222 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005223 ThrowMogrifyException(OptionError,"MissingArgument",option);
5224 if (IsGeometry(argv[i]) == MagickFalse)
5225 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5226 break;
5227 }
5228 if (LocaleCompare("polaroid",option+1) == 0)
5229 {
5230 if (*option == '+')
5231 break;
5232 i++;
cristybb503372010-05-27 20:51:26 +00005233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005234 ThrowMogrifyException(OptionError,"MissingArgument",option);
5235 if (IsGeometry(argv[i]) == MagickFalse)
5236 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5237 break;
5238 }
5239 if (LocaleCompare("posterize",option+1) == 0)
5240 {
5241 if (*option == '+')
5242 break;
5243 i++;
cristybb503372010-05-27 20:51:26 +00005244 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005245 ThrowMogrifyException(OptionError,"MissingArgument",option);
5246 if (IsGeometry(argv[i]) == MagickFalse)
5247 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5248 break;
5249 }
cristye7f51092010-01-17 00:39:37 +00005250 if (LocaleCompare("precision",option+1) == 0)
5251 {
5252 if (*option == '+')
5253 break;
5254 i++;
cristybb503372010-05-27 20:51:26 +00005255 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005256 ThrowMogrifyException(OptionError,"MissingArgument",option);
5257 if (IsGeometry(argv[i]) == MagickFalse)
5258 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5259 break;
5260 }
cristy3ed852e2009-09-05 21:47:34 +00005261 if (LocaleCompare("print",option+1) == 0)
5262 {
5263 if (*option == '+')
5264 break;
5265 i++;
cristybb503372010-05-27 20:51:26 +00005266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005267 ThrowMogrifyException(OptionError,"MissingArgument",option);
5268 break;
5269 }
5270 if (LocaleCompare("process",option+1) == 0)
5271 {
5272 if (*option == '+')
5273 break;
5274 i++;
cristybb503372010-05-27 20:51:26 +00005275 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005276 ThrowMogrifyException(OptionError,"MissingArgument",option);
5277 break;
5278 }
5279 if (LocaleCompare("profile",option+1) == 0)
5280 {
5281 i++;
cristybb503372010-05-27 20:51:26 +00005282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005283 ThrowMogrifyException(OptionError,"MissingArgument",option);
5284 break;
5285 }
5286 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5287 }
5288 case 'q':
5289 {
5290 if (LocaleCompare("quality",option+1) == 0)
5291 {
5292 if (*option == '+')
5293 break;
5294 i++;
cristybb503372010-05-27 20:51:26 +00005295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005296 ThrowMogrifyException(OptionError,"MissingArgument",option);
5297 if (IsGeometry(argv[i]) == MagickFalse)
5298 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5299 break;
5300 }
5301 if (LocaleCompare("quantize",option+1) == 0)
5302 {
cristybb503372010-05-27 20:51:26 +00005303 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005304 colorspace;
5305
5306 if (*option == '+')
5307 break;
5308 i++;
cristybb503372010-05-27 20:51:26 +00005309 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005310 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005311 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005312 argv[i]);
5313 if (colorspace < 0)
5314 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5315 argv[i]);
5316 break;
5317 }
5318 if (LocaleCompare("quiet",option+1) == 0)
5319 break;
5320 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5321 }
5322 case 'r':
5323 {
5324 if (LocaleCompare("radial-blur",option+1) == 0)
5325 {
5326 i++;
cristybb503372010-05-27 20:51:26 +00005327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005328 ThrowMogrifyException(OptionError,"MissingArgument",option);
5329 if (IsGeometry(argv[i]) == MagickFalse)
5330 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5331 break;
5332 }
5333 if (LocaleCompare("raise",option+1) == 0)
5334 {
5335 i++;
cristybb503372010-05-27 20:51:26 +00005336 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005337 ThrowMogrifyException(OptionError,"MissingArgument",option);
5338 if (IsGeometry(argv[i]) == MagickFalse)
5339 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5340 break;
5341 }
5342 if (LocaleCompare("random-threshold",option+1) == 0)
5343 {
5344 if (*option == '+')
5345 break;
5346 i++;
cristybb503372010-05-27 20:51:26 +00005347 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005348 ThrowMogrifyException(OptionError,"MissingArgument",option);
5349 if (IsGeometry(argv[i]) == MagickFalse)
5350 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5351 break;
5352 }
cristye6365592010-04-02 17:31:23 +00005353 if (LocaleCompare("recolor",option+1) == 0)
5354 {
5355 if (*option == '+')
5356 break;
5357 i++;
cristybb503372010-05-27 20:51:26 +00005358 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005359 ThrowMogrifyException(OptionError,"MissingArgument",option);
5360 if (IsGeometry(argv[i]) == MagickFalse)
5361 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5362 break;
5363 }
cristy3ed852e2009-09-05 21:47:34 +00005364 if (LocaleCompare("red-primary",option+1) == 0)
5365 {
5366 if (*option == '+')
5367 break;
5368 i++;
cristybb503372010-05-27 20:51:26 +00005369 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005370 ThrowMogrifyException(OptionError,"MissingArgument",option);
5371 if (IsGeometry(argv[i]) == MagickFalse)
5372 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5373 }
cristy9f2083a2010-04-22 19:48:05 +00005374 if (LocaleCompare("regard-warnings",option+1) == 0)
5375 break;
cristy3ed852e2009-09-05 21:47:34 +00005376 if (LocaleCompare("region",option+1) == 0)
5377 {
5378 if (*option == '+')
5379 break;
5380 i++;
cristybb503372010-05-27 20:51:26 +00005381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005382 ThrowMogrifyException(OptionError,"MissingArgument",option);
5383 if (IsGeometry(argv[i]) == MagickFalse)
5384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5385 break;
5386 }
cristyf0c78232010-03-15 12:53:40 +00005387 if (LocaleCompare("remap",option+1) == 0)
5388 {
5389 if (*option == '+')
5390 break;
5391 i++;
cristybb503372010-05-27 20:51:26 +00005392 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005393 ThrowMogrifyException(OptionError,"MissingArgument",option);
5394 break;
5395 }
cristy3ed852e2009-09-05 21:47:34 +00005396 if (LocaleCompare("render",option+1) == 0)
5397 break;
5398 if (LocaleCompare("repage",option+1) == 0)
5399 {
5400 if (*option == '+')
5401 break;
5402 i++;
cristybb503372010-05-27 20:51:26 +00005403 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005404 ThrowMogrifyException(OptionError,"MissingArgument",option);
5405 if (IsGeometry(argv[i]) == MagickFalse)
5406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5407 break;
5408 }
5409 if (LocaleCompare("resample",option+1) == 0)
5410 {
5411 if (*option == '+')
5412 break;
5413 i++;
cristybb503372010-05-27 20:51:26 +00005414 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005415 ThrowMogrifyException(OptionError,"MissingArgument",option);
5416 if (IsGeometry(argv[i]) == MagickFalse)
5417 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5418 break;
5419 }
5420 if (LocaleCompare("resize",option+1) == 0)
5421 {
5422 if (*option == '+')
5423 break;
5424 i++;
cristybb503372010-05-27 20:51:26 +00005425 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005426 ThrowMogrifyException(OptionError,"MissingArgument",option);
5427 if (IsGeometry(argv[i]) == MagickFalse)
5428 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5429 break;
5430 }
cristyebbcfea2011-02-25 02:43:54 +00005431 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5432 {
5433 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5434 break;
5435 }
cristy3ed852e2009-09-05 21:47:34 +00005436 if (LocaleCompare("reverse",option+1) == 0)
5437 break;
5438 if (LocaleCompare("roll",option+1) == 0)
5439 {
5440 if (*option == '+')
5441 break;
5442 i++;
cristybb503372010-05-27 20:51:26 +00005443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005444 ThrowMogrifyException(OptionError,"MissingArgument",option);
5445 if (IsGeometry(argv[i]) == MagickFalse)
5446 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5447 break;
5448 }
5449 if (LocaleCompare("rotate",option+1) == 0)
5450 {
5451 i++;
cristybb503372010-05-27 20:51:26 +00005452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005453 ThrowMogrifyException(OptionError,"MissingArgument",option);
5454 if (IsGeometry(argv[i]) == MagickFalse)
5455 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5456 break;
5457 }
5458 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5459 }
5460 case 's':
5461 {
5462 if (LocaleCompare("sample",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("sampling-factor",option+1) == 0)
5474 {
5475 if (*option == '+')
5476 break;
5477 i++;
cristybb503372010-05-27 20:51:26 +00005478 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005479 ThrowMogrifyException(OptionError,"MissingArgument",option);
5480 if (IsGeometry(argv[i]) == MagickFalse)
5481 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5482 break;
5483 }
5484 if (LocaleCompare("scale",option+1) == 0)
5485 {
5486 if (*option == '+')
5487 break;
5488 i++;
cristybb503372010-05-27 20:51:26 +00005489 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005490 ThrowMogrifyException(OptionError,"MissingArgument",option);
5491 if (IsGeometry(argv[i]) == MagickFalse)
5492 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5493 break;
5494 }
5495 if (LocaleCompare("scene",option+1) == 0)
5496 {
5497 if (*option == '+')
5498 break;
5499 i++;
cristybb503372010-05-27 20:51:26 +00005500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005501 ThrowMogrifyException(OptionError,"MissingArgument",option);
5502 if (IsGeometry(argv[i]) == MagickFalse)
5503 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5504 break;
5505 }
5506 if (LocaleCompare("seed",option+1) == 0)
5507 {
5508 if (*option == '+')
5509 break;
5510 i++;
cristybb503372010-05-27 20:51:26 +00005511 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005512 ThrowMogrifyException(OptionError,"MissingArgument",option);
5513 if (IsGeometry(argv[i]) == MagickFalse)
5514 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5515 break;
5516 }
5517 if (LocaleCompare("segment",option+1) == 0)
5518 {
5519 if (*option == '+')
5520 break;
5521 i++;
cristybb503372010-05-27 20:51:26 +00005522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005523 ThrowMogrifyException(OptionError,"MissingArgument",option);
5524 if (IsGeometry(argv[i]) == MagickFalse)
5525 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5526 break;
5527 }
5528 if (LocaleCompare("selective-blur",option+1) == 0)
5529 {
5530 i++;
cristybb503372010-05-27 20:51:26 +00005531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005532 ThrowMogrifyException(OptionError,"MissingArgument",option);
5533 if (IsGeometry(argv[i]) == MagickFalse)
5534 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5535 break;
5536 }
5537 if (LocaleCompare("separate",option+1) == 0)
5538 break;
5539 if (LocaleCompare("sepia-tone",option+1) == 0)
5540 {
5541 if (*option == '+')
5542 break;
5543 i++;
cristybb503372010-05-27 20:51:26 +00005544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005545 ThrowMogrifyException(OptionError,"MissingArgument",option);
5546 if (IsGeometry(argv[i]) == MagickFalse)
5547 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5548 break;
5549 }
5550 if (LocaleCompare("set",option+1) == 0)
5551 {
5552 i++;
cristybb503372010-05-27 20:51:26 +00005553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005554 ThrowMogrifyException(OptionError,"MissingArgument",option);
5555 if (*option == '+')
5556 break;
5557 i++;
cristybb503372010-05-27 20:51:26 +00005558 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005559 ThrowMogrifyException(OptionError,"MissingArgument",option);
5560 break;
5561 }
5562 if (LocaleCompare("shade",option+1) == 0)
5563 {
5564 i++;
cristybb503372010-05-27 20:51:26 +00005565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005566 ThrowMogrifyException(OptionError,"MissingArgument",option);
5567 if (IsGeometry(argv[i]) == MagickFalse)
5568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5569 break;
5570 }
5571 if (LocaleCompare("shadow",option+1) == 0)
5572 {
5573 if (*option == '+')
5574 break;
5575 i++;
cristybb503372010-05-27 20:51:26 +00005576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005577 ThrowMogrifyException(OptionError,"MissingArgument",option);
5578 if (IsGeometry(argv[i]) == MagickFalse)
5579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5580 break;
5581 }
5582 if (LocaleCompare("sharpen",option+1) == 0)
5583 {
5584 i++;
cristybb503372010-05-27 20:51:26 +00005585 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 if (IsGeometry(argv[i]) == MagickFalse)
5588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5589 break;
5590 }
5591 if (LocaleCompare("shave",option+1) == 0)
5592 {
5593 if (*option == '+')
5594 break;
5595 i++;
cristybb503372010-05-27 20:51:26 +00005596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005597 ThrowMogrifyException(OptionError,"MissingArgument",option);
5598 if (IsGeometry(argv[i]) == MagickFalse)
5599 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5600 break;
5601 }
5602 if (LocaleCompare("shear",option+1) == 0)
5603 {
5604 i++;
cristybb503372010-05-27 20:51:26 +00005605 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005606 ThrowMogrifyException(OptionError,"MissingArgument",option);
5607 if (IsGeometry(argv[i]) == MagickFalse)
5608 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5609 break;
5610 }
5611 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5612 {
5613 i++;
cristybb503372010-05-27 20:51:26 +00005614 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005615 ThrowMogrifyException(OptionError,"MissingArgument",option);
5616 if (IsGeometry(argv[i]) == MagickFalse)
5617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5618 break;
5619 }
5620 if (LocaleCompare("size",option+1) == 0)
5621 {
5622 if (*option == '+')
5623 break;
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 if (IsGeometry(argv[i]) == MagickFalse)
5628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5629 break;
5630 }
5631 if (LocaleCompare("sketch",option+1) == 0)
5632 {
5633 if (*option == '+')
5634 break;
5635 i++;
cristybb503372010-05-27 20:51:26 +00005636 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005637 ThrowMogrifyException(OptionError,"MissingArgument",option);
5638 if (IsGeometry(argv[i]) == MagickFalse)
5639 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5640 break;
5641 }
cristy4285d782011-02-09 20:12:28 +00005642 if (LocaleCompare("smush",option+1) == 0)
5643 {
cristy4285d782011-02-09 20:12:28 +00005644 i++;
5645 if (i == (ssize_t) argc)
5646 ThrowMogrifyException(OptionError,"MissingArgument",option);
5647 if (IsGeometry(argv[i]) == MagickFalse)
5648 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005649 i++;
5650 break;
5651 }
cristy3ed852e2009-09-05 21:47:34 +00005652 if (LocaleCompare("solarize",option+1) == 0)
5653 {
5654 if (*option == '+')
5655 break;
5656 i++;
cristybb503372010-05-27 20:51:26 +00005657 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005658 ThrowMogrifyException(OptionError,"MissingArgument",option);
5659 if (IsGeometry(argv[i]) == MagickFalse)
5660 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5661 break;
5662 }
5663 if (LocaleCompare("sparse-color",option+1) == 0)
5664 {
cristybb503372010-05-27 20:51:26 +00005665 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005666 op;
5667
5668 i++;
cristybb503372010-05-27 20:51:26 +00005669 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005670 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005671 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005672 if (op < 0)
5673 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5674 argv[i]);
5675 i++;
cristybb503372010-05-27 20:51:26 +00005676 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005677 ThrowMogrifyException(OptionError,"MissingArgument",option);
5678 break;
5679 }
5680 if (LocaleCompare("spread",option+1) == 0)
5681 {
5682 if (*option == '+')
5683 break;
5684 i++;
cristybb503372010-05-27 20:51:26 +00005685 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005686 ThrowMogrifyException(OptionError,"MissingArgument",option);
5687 if (IsGeometry(argv[i]) == MagickFalse)
5688 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5689 break;
5690 }
cristy0834d642011-03-18 18:26:08 +00005691 if (LocaleCompare("statistic",option+1) == 0)
5692 {
5693 ssize_t
5694 op;
5695
5696 if (*option == '+')
5697 break;
5698 i++;
5699 if (i == (ssize_t) argc)
5700 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005701 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005702 if (op < 0)
5703 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5704 argv[i]);
5705 i++;
5706 if (i == (ssize_t) (argc-1))
5707 ThrowMogrifyException(OptionError,"MissingArgument",option);
5708 if (IsGeometry(argv[i]) == MagickFalse)
5709 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5710 break;
5711 }
cristy3ed852e2009-09-05 21:47:34 +00005712 if (LocaleCompare("stretch",option+1) == 0)
5713 {
cristybb503372010-05-27 20:51:26 +00005714 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005715 stretch;
5716
5717 if (*option == '+')
5718 break;
5719 i++;
cristybb503372010-05-27 20:51:26 +00005720 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005721 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005722 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005723 if (stretch < 0)
5724 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5725 argv[i]);
5726 break;
5727 }
5728 if (LocaleCompare("strip",option+1) == 0)
5729 break;
5730 if (LocaleCompare("stroke",option+1) == 0)
5731 {
5732 if (*option == '+')
5733 break;
5734 i++;
cristybb503372010-05-27 20:51:26 +00005735 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005736 ThrowMogrifyException(OptionError,"MissingArgument",option);
5737 break;
5738 }
5739 if (LocaleCompare("strokewidth",option+1) == 0)
5740 {
5741 if (*option == '+')
5742 break;
5743 i++;
cristybb503372010-05-27 20:51:26 +00005744 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005745 ThrowMogrifyException(OptionError,"MissingArgument",option);
5746 if (IsGeometry(argv[i]) == MagickFalse)
5747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5748 break;
5749 }
5750 if (LocaleCompare("style",option+1) == 0)
5751 {
cristybb503372010-05-27 20:51:26 +00005752 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005753 style;
5754
5755 if (*option == '+')
5756 break;
5757 i++;
cristybb503372010-05-27 20:51:26 +00005758 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005759 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005760 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005761 if (style < 0)
5762 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5763 argv[i]);
5764 break;
5765 }
cristyecb10ff2011-03-22 13:14:03 +00005766 if (LocaleCompare("swap",option+1) == 0)
5767 {
5768 if (*option == '+')
5769 break;
5770 i++;
5771 if (i == (ssize_t) (argc-1))
5772 ThrowMogrifyException(OptionError,"MissingArgument",option);
5773 if (IsGeometry(argv[i]) == MagickFalse)
5774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5775 break;
5776 }
cristy3ed852e2009-09-05 21:47:34 +00005777 if (LocaleCompare("swirl",option+1) == 0)
5778 {
5779 if (*option == '+')
5780 break;
5781 i++;
cristybb503372010-05-27 20:51:26 +00005782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005783 ThrowMogrifyException(OptionError,"MissingArgument",option);
5784 if (IsGeometry(argv[i]) == MagickFalse)
5785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5786 break;
5787 }
cristyd9a29192010-10-16 16:49:53 +00005788 if (LocaleCompare("synchronize",option+1) == 0)
5789 break;
cristy3ed852e2009-09-05 21:47:34 +00005790 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5791 }
5792 case 't':
5793 {
5794 if (LocaleCompare("taint",option+1) == 0)
5795 break;
5796 if (LocaleCompare("texture",option+1) == 0)
5797 {
5798 if (*option == '+')
5799 break;
5800 i++;
cristybb503372010-05-27 20:51:26 +00005801 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005802 ThrowMogrifyException(OptionError,"MissingArgument",option);
5803 break;
5804 }
5805 if (LocaleCompare("tile",option+1) == 0)
5806 {
5807 if (*option == '+')
5808 break;
5809 i++;
cristybb503372010-05-27 20:51:26 +00005810 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005811 ThrowMogrifyException(OptionError,"MissingArgument",option);
5812 break;
5813 }
5814 if (LocaleCompare("tile-offset",option+1) == 0)
5815 {
5816 if (*option == '+')
5817 break;
5818 i++;
cristybb503372010-05-27 20:51:26 +00005819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005820 ThrowMogrifyException(OptionError,"MissingArgument",option);
5821 if (IsGeometry(argv[i]) == MagickFalse)
5822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5823 break;
5824 }
5825 if (LocaleCompare("tint",option+1) == 0)
5826 {
5827 if (*option == '+')
5828 break;
5829 i++;
cristybb503372010-05-27 20:51:26 +00005830 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005831 ThrowMogrifyException(OptionError,"MissingArgument",option);
5832 if (IsGeometry(argv[i]) == MagickFalse)
5833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834 break;
5835 }
5836 if (LocaleCompare("transform",option+1) == 0)
5837 break;
5838 if (LocaleCompare("transpose",option+1) == 0)
5839 break;
5840 if (LocaleCompare("transverse",option+1) == 0)
5841 break;
5842 if (LocaleCompare("threshold",option+1) == 0)
5843 {
5844 if (*option == '+')
5845 break;
5846 i++;
cristybb503372010-05-27 20:51:26 +00005847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005848 ThrowMogrifyException(OptionError,"MissingArgument",option);
5849 if (IsGeometry(argv[i]) == MagickFalse)
5850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5851 break;
5852 }
5853 if (LocaleCompare("thumbnail",option+1) == 0)
5854 {
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 if (IsGeometry(argv[i]) == MagickFalse)
5861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5862 break;
5863 }
5864 if (LocaleCompare("transparent",option+1) == 0)
5865 {
5866 i++;
cristybb503372010-05-27 20:51:26 +00005867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005868 ThrowMogrifyException(OptionError,"MissingArgument",option);
5869 break;
5870 }
5871 if (LocaleCompare("transparent-color",option+1) == 0)
5872 {
5873 if (*option == '+')
5874 break;
5875 i++;
cristybb503372010-05-27 20:51:26 +00005876 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005877 ThrowMogrifyException(OptionError,"MissingArgument",option);
5878 break;
5879 }
5880 if (LocaleCompare("treedepth",option+1) == 0)
5881 {
5882 if (*option == '+')
5883 break;
5884 i++;
cristybb503372010-05-27 20:51:26 +00005885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005886 ThrowMogrifyException(OptionError,"MissingArgument",option);
5887 if (IsGeometry(argv[i]) == MagickFalse)
5888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5889 break;
5890 }
5891 if (LocaleCompare("trim",option+1) == 0)
5892 break;
5893 if (LocaleCompare("type",option+1) == 0)
5894 {
cristybb503372010-05-27 20:51:26 +00005895 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005896 type;
5897
5898 if (*option == '+')
5899 break;
5900 i++;
cristybb503372010-05-27 20:51:26 +00005901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005902 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005903 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005904 if (type < 0)
5905 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5906 argv[i]);
5907 break;
5908 }
5909 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5910 }
5911 case 'u':
5912 {
5913 if (LocaleCompare("undercolor",option+1) == 0)
5914 {
5915 if (*option == '+')
5916 break;
5917 i++;
cristybb503372010-05-27 20:51:26 +00005918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005919 ThrowMogrifyException(OptionError,"MissingArgument",option);
5920 break;
5921 }
5922 if (LocaleCompare("unique-colors",option+1) == 0)
5923 break;
5924 if (LocaleCompare("units",option+1) == 0)
5925 {
cristybb503372010-05-27 20:51:26 +00005926 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005927 units;
5928
5929 if (*option == '+')
5930 break;
5931 i++;
cristybb503372010-05-27 20:51:26 +00005932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005933 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005934 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005935 argv[i]);
5936 if (units < 0)
5937 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5938 argv[i]);
5939 break;
5940 }
5941 if (LocaleCompare("unsharp",option+1) == 0)
5942 {
5943 i++;
cristybb503372010-05-27 20:51:26 +00005944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005945 ThrowMogrifyException(OptionError,"MissingArgument",option);
5946 if (IsGeometry(argv[i]) == MagickFalse)
5947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5948 break;
5949 }
5950 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5951 }
5952 case 'v':
5953 {
5954 if (LocaleCompare("verbose",option+1) == 0)
5955 {
5956 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5957 break;
5958 }
5959 if ((LocaleCompare("version",option+1) == 0) ||
5960 (LocaleCompare("-version",option+1) == 0))
5961 {
5962 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005963 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00005964 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
5965 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005966 break;
5967 }
5968 if (LocaleCompare("view",option+1) == 0)
5969 {
5970 if (*option == '+')
5971 break;
5972 i++;
cristybb503372010-05-27 20:51:26 +00005973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005974 ThrowMogrifyException(OptionError,"MissingArgument",option);
5975 break;
5976 }
5977 if (LocaleCompare("vignette",option+1) == 0)
5978 {
5979 if (*option == '+')
5980 break;
5981 i++;
cristybb503372010-05-27 20:51:26 +00005982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005983 ThrowMogrifyException(OptionError,"MissingArgument",option);
5984 if (IsGeometry(argv[i]) == MagickFalse)
5985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5986 break;
5987 }
5988 if (LocaleCompare("virtual-pixel",option+1) == 0)
5989 {
cristybb503372010-05-27 20:51:26 +00005990 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005991 method;
5992
5993 if (*option == '+')
5994 break;
5995 i++;
cristybb503372010-05-27 20:51:26 +00005996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005997 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005998 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005999 argv[i]);
6000 if (method < 0)
6001 ThrowMogrifyException(OptionError,
6002 "UnrecognizedVirtualPixelMethod",argv[i]);
6003 break;
6004 }
6005 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6006 }
6007 case 'w':
6008 {
6009 if (LocaleCompare("wave",option+1) == 0)
6010 {
6011 i++;
cristybb503372010-05-27 20:51:26 +00006012 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006013 ThrowMogrifyException(OptionError,"MissingArgument",option);
6014 if (IsGeometry(argv[i]) == MagickFalse)
6015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6016 break;
6017 }
6018 if (LocaleCompare("weight",option+1) == 0)
6019 {
6020 if (*option == '+')
6021 break;
6022 i++;
cristybb503372010-05-27 20:51:26 +00006023 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006024 ThrowMogrifyException(OptionError,"MissingArgument",option);
6025 break;
6026 }
6027 if (LocaleCompare("white-point",option+1) == 0)
6028 {
6029 if (*option == '+')
6030 break;
6031 i++;
cristybb503372010-05-27 20:51:26 +00006032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006033 ThrowMogrifyException(OptionError,"MissingArgument",option);
6034 if (IsGeometry(argv[i]) == MagickFalse)
6035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036 break;
6037 }
6038 if (LocaleCompare("white-threshold",option+1) == 0)
6039 {
6040 if (*option == '+')
6041 break;
6042 i++;
cristybb503372010-05-27 20:51:26 +00006043 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006044 ThrowMogrifyException(OptionError,"MissingArgument",option);
6045 if (IsGeometry(argv[i]) == MagickFalse)
6046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6047 break;
6048 }
6049 if (LocaleCompare("write",option+1) == 0)
6050 {
6051 i++;
cristybb503372010-05-27 20:51:26 +00006052 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006053 ThrowMogrifyException(OptionError,"MissingArgument",option);
6054 break;
6055 }
6056 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6057 }
6058 case '?':
6059 break;
6060 default:
6061 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6062 }
cristy042ee782011-04-22 18:48:30 +00006063 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6064 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006065 if (fire != MagickFalse)
6066 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6067 }
6068 if (k != 0)
6069 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006070 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006071 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6072 DestroyMogrify();
6073 return(status != 0 ? MagickTrue : MagickFalse);
6074}
6075
6076/*
6077%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6078% %
6079% %
6080% %
6081+ M o g r i f y I m a g e I n f o %
6082% %
6083% %
6084% %
6085%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6086%
6087% MogrifyImageInfo() applies image processing settings to the image as
6088% prescribed by command line options.
6089%
6090% The format of the MogrifyImageInfo method is:
6091%
6092% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6093% const char **argv,ExceptionInfo *exception)
6094%
6095% A description of each parameter follows:
6096%
6097% o image_info: the image info..
6098%
6099% o argc: Specifies a pointer to an integer describing the number of
6100% elements in the argument vector.
6101%
6102% o argv: Specifies a pointer to a text array containing the command line
6103% arguments.
6104%
6105% o exception: return any errors or warnings in this structure.
6106%
6107*/
6108WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6109 const int argc,const char **argv,ExceptionInfo *exception)
6110{
6111 const char
6112 *option;
6113
6114 GeometryInfo
6115 geometry_info;
6116
cristybb503372010-05-27 20:51:26 +00006117 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006118 count;
6119
cristybb503372010-05-27 20:51:26 +00006120 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006121 i;
6122
6123 /*
6124 Initialize method variables.
6125 */
6126 assert(image_info != (ImageInfo *) NULL);
6127 assert(image_info->signature == MagickSignature);
6128 if (image_info->debug != MagickFalse)
6129 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6130 image_info->filename);
6131 if (argc < 0)
6132 return(MagickTrue);
6133 /*
6134 Set the image settings.
6135 */
cristybb503372010-05-27 20:51:26 +00006136 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006137 {
6138 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006139 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006140 continue;
cristy042ee782011-04-22 18:48:30 +00006141 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006142 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006143 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006144 break;
6145 switch (*(option+1))
6146 {
6147 case 'a':
6148 {
6149 if (LocaleCompare("adjoin",option+1) == 0)
6150 {
6151 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6152 break;
6153 }
6154 if (LocaleCompare("antialias",option+1) == 0)
6155 {
6156 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6157 break;
6158 }
6159 if (LocaleCompare("attenuate",option+1) == 0)
6160 {
6161 if (*option == '+')
6162 {
6163 (void) DeleteImageOption(image_info,option+1);
6164 break;
6165 }
6166 (void) SetImageOption(image_info,option+1,argv[i+1]);
6167 break;
6168 }
6169 if (LocaleCompare("authenticate",option+1) == 0)
6170 {
6171 if (*option == '+')
6172 (void) CloneString(&image_info->authenticate,(char *) NULL);
6173 else
6174 (void) CloneString(&image_info->authenticate,argv[i+1]);
6175 break;
6176 }
6177 break;
6178 }
6179 case 'b':
6180 {
6181 if (LocaleCompare("background",option+1) == 0)
6182 {
6183 if (*option == '+')
6184 {
6185 (void) DeleteImageOption(image_info,option+1);
6186 (void) QueryColorDatabase(BackgroundColor,
6187 &image_info->background_color,exception);
6188 break;
6189 }
6190 (void) SetImageOption(image_info,option+1,argv[i+1]);
6191 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6192 exception);
6193 break;
6194 }
6195 if (LocaleCompare("bias",option+1) == 0)
6196 {
6197 if (*option == '+')
6198 {
6199 (void) SetImageOption(image_info,option+1,"0.0");
6200 break;
6201 }
6202 (void) SetImageOption(image_info,option+1,argv[i+1]);
6203 break;
6204 }
6205 if (LocaleCompare("black-point-compensation",option+1) == 0)
6206 {
6207 if (*option == '+')
6208 {
6209 (void) SetImageOption(image_info,option+1,"false");
6210 break;
6211 }
6212 (void) SetImageOption(image_info,option+1,"true");
6213 break;
6214 }
6215 if (LocaleCompare("blue-primary",option+1) == 0)
6216 {
6217 if (*option == '+')
6218 {
6219 (void) SetImageOption(image_info,option+1,"0.0");
6220 break;
6221 }
6222 (void) SetImageOption(image_info,option+1,argv[i+1]);
6223 break;
6224 }
6225 if (LocaleCompare("bordercolor",option+1) == 0)
6226 {
6227 if (*option == '+')
6228 {
6229 (void) DeleteImageOption(image_info,option+1);
6230 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6231 exception);
6232 break;
6233 }
6234 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6235 exception);
6236 (void) SetImageOption(image_info,option+1,argv[i+1]);
6237 break;
6238 }
6239 if (LocaleCompare("box",option+1) == 0)
6240 {
6241 if (*option == '+')
6242 {
6243 (void) SetImageOption(image_info,"undercolor","none");
6244 break;
6245 }
6246 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6247 break;
6248 }
6249 break;
6250 }
6251 case 'c':
6252 {
6253 if (LocaleCompare("cache",option+1) == 0)
6254 {
6255 MagickSizeType
6256 limit;
6257
6258 limit=MagickResourceInfinity;
6259 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006260 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006261 (void) SetMagickResourceLimit(MemoryResource,limit);
6262 (void) SetMagickResourceLimit(MapResource,2*limit);
6263 break;
6264 }
6265 if (LocaleCompare("caption",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 {
6269 (void) DeleteImageOption(image_info,option+1);
6270 break;
6271 }
6272 (void) SetImageOption(image_info,option+1,argv[i+1]);
6273 break;
6274 }
6275 if (LocaleCompare("channel",option+1) == 0)
6276 {
6277 if (*option == '+')
6278 {
6279 image_info->channel=DefaultChannels;
6280 break;
6281 }
6282 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6283 break;
6284 }
6285 if (LocaleCompare("colors",option+1) == 0)
6286 {
cristye27293e2009-12-18 02:53:20 +00006287 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006288 break;
6289 }
6290 if (LocaleCompare("colorspace",option+1) == 0)
6291 {
6292 if (*option == '+')
6293 {
6294 image_info->colorspace=UndefinedColorspace;
6295 (void) SetImageOption(image_info,option+1,"undefined");
6296 break;
6297 }
cristy042ee782011-04-22 18:48:30 +00006298 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006299 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6300 (void) SetImageOption(image_info,option+1,argv[i+1]);
6301 break;
6302 }
6303 if (LocaleCompare("compress",option+1) == 0)
6304 {
6305 if (*option == '+')
6306 {
6307 image_info->compression=UndefinedCompression;
6308 (void) SetImageOption(image_info,option+1,"undefined");
6309 break;
6310 }
cristy042ee782011-04-22 18:48:30 +00006311 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006312 MagickCompressOptions,MagickFalse,argv[i+1]);
6313 (void) SetImageOption(image_info,option+1,argv[i+1]);
6314 break;
6315 }
6316 if (LocaleCompare("comment",option+1) == 0)
6317 {
6318 if (*option == '+')
6319 {
6320 (void) DeleteImageOption(image_info,option+1);
6321 break;
6322 }
6323 (void) SetImageOption(image_info,option+1,argv[i+1]);
6324 break;
6325 }
6326 if (LocaleCompare("compose",option+1) == 0)
6327 {
6328 if (*option == '+')
6329 {
6330 (void) SetImageOption(image_info,option+1,"undefined");
6331 break;
6332 }
6333 (void) SetImageOption(image_info,option+1,argv[i+1]);
6334 break;
6335 }
6336 if (LocaleCompare("compress",option+1) == 0)
6337 {
6338 if (*option == '+')
6339 {
6340 image_info->compression=UndefinedCompression;
6341 (void) SetImageOption(image_info,option+1,"undefined");
6342 break;
6343 }
cristy042ee782011-04-22 18:48:30 +00006344 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006345 MagickCompressOptions,MagickFalse,argv[i+1]);
6346 (void) SetImageOption(image_info,option+1,argv[i+1]);
6347 break;
6348 }
6349 break;
6350 }
6351 case 'd':
6352 {
6353 if (LocaleCompare("debug",option+1) == 0)
6354 {
6355 if (*option == '+')
6356 (void) SetLogEventMask("none");
6357 else
6358 (void) SetLogEventMask(argv[i+1]);
6359 image_info->debug=IsEventLogging();
6360 break;
6361 }
6362 if (LocaleCompare("define",option+1) == 0)
6363 {
6364 if (*option == '+')
6365 {
6366 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6367 (void) DeleteImageRegistry(argv[i+1]+9);
6368 else
6369 (void) DeleteImageOption(image_info,argv[i+1]);
6370 break;
6371 }
6372 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6373 {
6374 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6375 exception);
6376 break;
6377 }
6378 (void) DefineImageOption(image_info,argv[i+1]);
6379 break;
6380 }
6381 if (LocaleCompare("delay",option+1) == 0)
6382 {
6383 if (*option == '+')
6384 {
6385 (void) SetImageOption(image_info,option+1,"0");
6386 break;
6387 }
6388 (void) SetImageOption(image_info,option+1,argv[i+1]);
6389 break;
6390 }
6391 if (LocaleCompare("density",option+1) == 0)
6392 {
6393 /*
6394 Set image density.
6395 */
6396 if (*option == '+')
6397 {
6398 if (image_info->density != (char *) NULL)
6399 image_info->density=DestroyString(image_info->density);
6400 (void) SetImageOption(image_info,option+1,"72");
6401 break;
6402 }
6403 (void) CloneString(&image_info->density,argv[i+1]);
6404 (void) SetImageOption(image_info,option+1,argv[i+1]);
6405 break;
6406 }
6407 if (LocaleCompare("depth",option+1) == 0)
6408 {
6409 if (*option == '+')
6410 {
6411 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6412 break;
6413 }
cristye27293e2009-12-18 02:53:20 +00006414 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006415 break;
6416 }
cristyc9b12952010-03-28 01:12:28 +00006417 if (LocaleCompare("direction",option+1) == 0)
6418 {
6419 if (*option == '+')
6420 {
6421 (void) SetImageOption(image_info,option+1,"undefined");
6422 break;
6423 }
6424 (void) SetImageOption(image_info,option+1,argv[i+1]);
6425 break;
6426 }
cristy3ed852e2009-09-05 21:47:34 +00006427 if (LocaleCompare("display",option+1) == 0)
6428 {
6429 if (*option == '+')
6430 {
6431 if (image_info->server_name != (char *) NULL)
6432 image_info->server_name=DestroyString(
6433 image_info->server_name);
6434 break;
6435 }
6436 (void) CloneString(&image_info->server_name,argv[i+1]);
6437 break;
6438 }
6439 if (LocaleCompare("dispose",option+1) == 0)
6440 {
6441 if (*option == '+')
6442 {
6443 (void) SetImageOption(image_info,option+1,"undefined");
6444 break;
6445 }
6446 (void) SetImageOption(image_info,option+1,argv[i+1]);
6447 break;
6448 }
6449 if (LocaleCompare("dither",option+1) == 0)
6450 {
6451 if (*option == '+')
6452 {
6453 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006454 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006455 break;
6456 }
6457 (void) SetImageOption(image_info,option+1,argv[i+1]);
6458 image_info->dither=MagickTrue;
6459 break;
6460 }
6461 break;
6462 }
6463 case 'e':
6464 {
6465 if (LocaleCompare("encoding",option+1) == 0)
6466 {
6467 if (*option == '+')
6468 {
6469 (void) SetImageOption(image_info,option+1,"undefined");
6470 break;
6471 }
6472 (void) SetImageOption(image_info,option+1,argv[i+1]);
6473 break;
6474 }
6475 if (LocaleCompare("endian",option+1) == 0)
6476 {
6477 if (*option == '+')
6478 {
6479 image_info->endian=UndefinedEndian;
6480 (void) SetImageOption(image_info,option+1,"undefined");
6481 break;
6482 }
cristy042ee782011-04-22 18:48:30 +00006483 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006484 MagickEndianOptions,MagickFalse,argv[i+1]);
6485 (void) SetImageOption(image_info,option+1,argv[i+1]);
6486 break;
6487 }
6488 if (LocaleCompare("extract",option+1) == 0)
6489 {
6490 /*
6491 Set image extract geometry.
6492 */
6493 if (*option == '+')
6494 {
6495 if (image_info->extract != (char *) NULL)
6496 image_info->extract=DestroyString(image_info->extract);
6497 break;
6498 }
6499 (void) CloneString(&image_info->extract,argv[i+1]);
6500 break;
6501 }
6502 break;
6503 }
6504 case 'f':
6505 {
6506 if (LocaleCompare("fill",option+1) == 0)
6507 {
6508 if (*option == '+')
6509 {
6510 (void) SetImageOption(image_info,option+1,"none");
6511 break;
6512 }
6513 (void) SetImageOption(image_info,option+1,argv[i+1]);
6514 break;
6515 }
6516 if (LocaleCompare("filter",option+1) == 0)
6517 {
6518 if (*option == '+')
6519 {
6520 (void) SetImageOption(image_info,option+1,"undefined");
6521 break;
6522 }
6523 (void) SetImageOption(image_info,option+1,argv[i+1]);
6524 break;
6525 }
6526 if (LocaleCompare("font",option+1) == 0)
6527 {
6528 if (*option == '+')
6529 {
6530 if (image_info->font != (char *) NULL)
6531 image_info->font=DestroyString(image_info->font);
6532 break;
6533 }
6534 (void) CloneString(&image_info->font,argv[i+1]);
6535 break;
6536 }
6537 if (LocaleCompare("format",option+1) == 0)
6538 {
6539 register const char
6540 *q;
6541
6542 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006543 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006544 image_info->ping=MagickFalse;
6545 (void) SetImageOption(image_info,option+1,argv[i+1]);
6546 break;
6547 }
6548 if (LocaleCompare("fuzz",option+1) == 0)
6549 {
6550 if (*option == '+')
6551 {
6552 image_info->fuzz=0.0;
6553 (void) SetImageOption(image_info,option+1,"0");
6554 break;
6555 }
cristyf2f27272009-12-17 14:48:46 +00006556 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006557 1.0);
6558 (void) SetImageOption(image_info,option+1,argv[i+1]);
6559 break;
6560 }
6561 break;
6562 }
6563 case 'g':
6564 {
6565 if (LocaleCompare("gravity",option+1) == 0)
6566 {
6567 if (*option == '+')
6568 {
6569 (void) SetImageOption(image_info,option+1,"undefined");
6570 break;
6571 }
6572 (void) SetImageOption(image_info,option+1,argv[i+1]);
6573 break;
6574 }
6575 if (LocaleCompare("green-primary",option+1) == 0)
6576 {
6577 if (*option == '+')
6578 {
6579 (void) SetImageOption(image_info,option+1,"0.0");
6580 break;
6581 }
6582 (void) SetImageOption(image_info,option+1,argv[i+1]);
6583 break;
6584 }
6585 break;
6586 }
6587 case 'i':
6588 {
6589 if (LocaleCompare("intent",option+1) == 0)
6590 {
6591 if (*option == '+')
6592 {
6593 (void) SetImageOption(image_info,option+1,"undefined");
6594 break;
6595 }
6596 (void) SetImageOption(image_info,option+1,argv[i+1]);
6597 break;
6598 }
6599 if (LocaleCompare("interlace",option+1) == 0)
6600 {
6601 if (*option == '+')
6602 {
6603 image_info->interlace=UndefinedInterlace;
6604 (void) SetImageOption(image_info,option+1,"undefined");
6605 break;
6606 }
cristy042ee782011-04-22 18:48:30 +00006607 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006608 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6609 (void) SetImageOption(image_info,option+1,argv[i+1]);
6610 break;
6611 }
cristyb32b90a2009-09-07 21:45:48 +00006612 if (LocaleCompare("interline-spacing",option+1) == 0)
6613 {
6614 if (*option == '+')
6615 {
6616 (void) SetImageOption(image_info,option+1,"undefined");
6617 break;
6618 }
6619 (void) SetImageOption(image_info,option+1,argv[i+1]);
6620 break;
6621 }
cristy3ed852e2009-09-05 21:47:34 +00006622 if (LocaleCompare("interpolate",option+1) == 0)
6623 {
6624 if (*option == '+')
6625 {
6626 (void) SetImageOption(image_info,option+1,"undefined");
6627 break;
6628 }
6629 (void) SetImageOption(image_info,option+1,argv[i+1]);
6630 break;
6631 }
6632 if (LocaleCompare("interword-spacing",option+1) == 0)
6633 {
6634 if (*option == '+')
6635 {
6636 (void) SetImageOption(image_info,option+1,"undefined");
6637 break;
6638 }
6639 (void) SetImageOption(image_info,option+1,argv[i+1]);
6640 break;
6641 }
6642 break;
6643 }
6644 case 'k':
6645 {
6646 if (LocaleCompare("kerning",option+1) == 0)
6647 {
6648 if (*option == '+')
6649 {
6650 (void) SetImageOption(image_info,option+1,"undefined");
6651 break;
6652 }
6653 (void) SetImageOption(image_info,option+1,argv[i+1]);
6654 break;
6655 }
6656 break;
6657 }
6658 case 'l':
6659 {
6660 if (LocaleCompare("label",option+1) == 0)
6661 {
6662 if (*option == '+')
6663 {
6664 (void) DeleteImageOption(image_info,option+1);
6665 break;
6666 }
6667 (void) SetImageOption(image_info,option+1,argv[i+1]);
6668 break;
6669 }
6670 if (LocaleCompare("limit",option+1) == 0)
6671 {
6672 MagickSizeType
6673 limit;
6674
6675 ResourceType
6676 type;
6677
6678 if (*option == '+')
6679 break;
cristy042ee782011-04-22 18:48:30 +00006680 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006681 MagickFalse,argv[i+1]);
6682 limit=MagickResourceInfinity;
6683 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006684 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006685 (void) SetMagickResourceLimit(type,limit);
6686 break;
6687 }
6688 if (LocaleCompare("list",option+1) == 0)
6689 {
cristybb503372010-05-27 20:51:26 +00006690 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006691 list;
6692
6693 /*
6694 Display configuration list.
6695 */
cristy042ee782011-04-22 18:48:30 +00006696 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006697 switch (list)
6698 {
6699 case MagickCoderOptions:
6700 {
6701 (void) ListCoderInfo((FILE *) NULL,exception);
6702 break;
6703 }
6704 case MagickColorOptions:
6705 {
6706 (void) ListColorInfo((FILE *) NULL,exception);
6707 break;
6708 }
6709 case MagickConfigureOptions:
6710 {
6711 (void) ListConfigureInfo((FILE *) NULL,exception);
6712 break;
6713 }
6714 case MagickDelegateOptions:
6715 {
6716 (void) ListDelegateInfo((FILE *) NULL,exception);
6717 break;
6718 }
6719 case MagickFontOptions:
6720 {
6721 (void) ListTypeInfo((FILE *) NULL,exception);
6722 break;
6723 }
6724 case MagickFormatOptions:
6725 {
6726 (void) ListMagickInfo((FILE *) NULL,exception);
6727 break;
6728 }
6729 case MagickLocaleOptions:
6730 {
6731 (void) ListLocaleInfo((FILE *) NULL,exception);
6732 break;
6733 }
6734 case MagickLogOptions:
6735 {
6736 (void) ListLogInfo((FILE *) NULL,exception);
6737 break;
6738 }
6739 case MagickMagicOptions:
6740 {
6741 (void) ListMagicInfo((FILE *) NULL,exception);
6742 break;
6743 }
6744 case MagickMimeOptions:
6745 {
6746 (void) ListMimeInfo((FILE *) NULL,exception);
6747 break;
6748 }
6749 case MagickModuleOptions:
6750 {
6751 (void) ListModuleInfo((FILE *) NULL,exception);
6752 break;
6753 }
6754 case MagickPolicyOptions:
6755 {
6756 (void) ListPolicyInfo((FILE *) NULL,exception);
6757 break;
6758 }
6759 case MagickResourceOptions:
6760 {
6761 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6762 break;
6763 }
6764 case MagickThresholdOptions:
6765 {
6766 (void) ListThresholdMaps((FILE *) NULL,exception);
6767 break;
6768 }
6769 default:
6770 {
cristy042ee782011-04-22 18:48:30 +00006771 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006772 exception);
6773 break;
6774 }
6775 }
cristyaeb2cbc2010-05-07 13:28:58 +00006776 break;
cristy3ed852e2009-09-05 21:47:34 +00006777 }
6778 if (LocaleCompare("log",option+1) == 0)
6779 {
6780 if (*option == '+')
6781 break;
6782 (void) SetLogFormat(argv[i+1]);
6783 break;
6784 }
6785 if (LocaleCompare("loop",option+1) == 0)
6786 {
6787 if (*option == '+')
6788 {
6789 (void) SetImageOption(image_info,option+1,"0");
6790 break;
6791 }
6792 (void) SetImageOption(image_info,option+1,argv[i+1]);
6793 break;
6794 }
6795 break;
6796 }
6797 case 'm':
6798 {
6799 if (LocaleCompare("matte",option+1) == 0)
6800 {
6801 if (*option == '+')
6802 {
6803 (void) SetImageOption(image_info,option+1,"false");
6804 break;
6805 }
6806 (void) SetImageOption(image_info,option+1,"true");
6807 break;
6808 }
6809 if (LocaleCompare("mattecolor",option+1) == 0)
6810 {
6811 if (*option == '+')
6812 {
6813 (void) SetImageOption(image_info,option+1,argv[i+1]);
6814 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6815 exception);
6816 break;
6817 }
6818 (void) SetImageOption(image_info,option+1,argv[i+1]);
6819 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6820 exception);
6821 break;
6822 }
6823 if (LocaleCompare("monitor",option+1) == 0)
6824 {
6825 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6826 (void *) NULL);
6827 break;
6828 }
6829 if (LocaleCompare("monochrome",option+1) == 0)
6830 {
6831 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6832 break;
6833 }
6834 break;
6835 }
6836 case 'o':
6837 {
6838 if (LocaleCompare("orient",option+1) == 0)
6839 {
6840 if (*option == '+')
6841 {
6842 image_info->orientation=UndefinedOrientation;
6843 (void) SetImageOption(image_info,option+1,"undefined");
6844 break;
6845 }
cristy042ee782011-04-22 18:48:30 +00006846 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006847 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006848 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006849 break;
6850 }
6851 }
6852 case 'p':
6853 {
6854 if (LocaleCompare("page",option+1) == 0)
6855 {
6856 char
6857 *canonical_page,
6858 page[MaxTextExtent];
6859
6860 const char
6861 *image_option;
6862
6863 MagickStatusType
6864 flags;
6865
6866 RectangleInfo
6867 geometry;
6868
6869 if (*option == '+')
6870 {
6871 (void) DeleteImageOption(image_info,option+1);
6872 (void) CloneString(&image_info->page,(char *) NULL);
6873 break;
6874 }
6875 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6876 image_option=GetImageOption(image_info,"page");
6877 if (image_option != (const char *) NULL)
6878 flags=ParseAbsoluteGeometry(image_option,&geometry);
6879 canonical_page=GetPageGeometry(argv[i+1]);
6880 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6881 canonical_page=DestroyString(canonical_page);
6882 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006883 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006884 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6885 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006886 (unsigned long) geometry.width,(unsigned long) geometry.height,
6887 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006888 (void) SetImageOption(image_info,option+1,page);
6889 (void) CloneString(&image_info->page,page);
6890 break;
6891 }
6892 if (LocaleCompare("pen",option+1) == 0)
6893 {
6894 if (*option == '+')
6895 {
6896 (void) SetImageOption(image_info,option+1,"none");
6897 break;
6898 }
6899 (void) SetImageOption(image_info,option+1,argv[i+1]);
6900 break;
6901 }
6902 if (LocaleCompare("ping",option+1) == 0)
6903 {
6904 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6905 break;
6906 }
6907 if (LocaleCompare("pointsize",option+1) == 0)
6908 {
6909 if (*option == '+')
6910 geometry_info.rho=0.0;
6911 else
6912 (void) ParseGeometry(argv[i+1],&geometry_info);
6913 image_info->pointsize=geometry_info.rho;
6914 break;
6915 }
cristye7f51092010-01-17 00:39:37 +00006916 if (LocaleCompare("precision",option+1) == 0)
6917 {
cristybf2766a2010-01-17 03:33:23 +00006918 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006919 break;
6920 }
cristy3ed852e2009-09-05 21:47:34 +00006921 if (LocaleCompare("preview",option+1) == 0)
6922 {
6923 /*
6924 Preview image.
6925 */
6926 if (*option == '+')
6927 {
6928 image_info->preview_type=UndefinedPreview;
6929 break;
6930 }
cristy042ee782011-04-22 18:48:30 +00006931 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006932 MagickPreviewOptions,MagickFalse,argv[i+1]);
6933 break;
6934 }
6935 break;
6936 }
6937 case 'q':
6938 {
6939 if (LocaleCompare("quality",option+1) == 0)
6940 {
6941 /*
6942 Set image compression quality.
6943 */
6944 if (*option == '+')
6945 {
6946 image_info->quality=UndefinedCompressionQuality;
6947 (void) SetImageOption(image_info,option+1,"0");
6948 break;
6949 }
cristye27293e2009-12-18 02:53:20 +00006950 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006951 (void) SetImageOption(image_info,option+1,argv[i+1]);
6952 break;
6953 }
6954 if (LocaleCompare("quiet",option+1) == 0)
6955 {
6956 static WarningHandler
6957 warning_handler = (WarningHandler) NULL;
6958
6959 if (*option == '+')
6960 {
6961 /*
6962 Restore error or warning messages.
6963 */
6964 warning_handler=SetWarningHandler(warning_handler);
6965 break;
6966 }
6967 /*
6968 Suppress error or warning messages.
6969 */
6970 warning_handler=SetWarningHandler((WarningHandler) NULL);
6971 break;
6972 }
6973 break;
6974 }
6975 case 'r':
6976 {
6977 if (LocaleCompare("red-primary",option+1) == 0)
6978 {
6979 if (*option == '+')
6980 {
6981 (void) SetImageOption(image_info,option+1,"0.0");
6982 break;
6983 }
6984 (void) SetImageOption(image_info,option+1,argv[i+1]);
6985 break;
6986 }
6987 break;
6988 }
6989 case 's':
6990 {
6991 if (LocaleCompare("sampling-factor",option+1) == 0)
6992 {
6993 /*
6994 Set image sampling factor.
6995 */
6996 if (*option == '+')
6997 {
6998 if (image_info->sampling_factor != (char *) NULL)
6999 image_info->sampling_factor=DestroyString(
7000 image_info->sampling_factor);
7001 break;
7002 }
7003 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7004 break;
7005 }
7006 if (LocaleCompare("scene",option+1) == 0)
7007 {
7008 /*
7009 Set image scene.
7010 */
7011 if (*option == '+')
7012 {
7013 image_info->scene=0;
7014 (void) SetImageOption(image_info,option+1,"0");
7015 break;
7016 }
cristye27293e2009-12-18 02:53:20 +00007017 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007018 (void) SetImageOption(image_info,option+1,argv[i+1]);
7019 break;
7020 }
7021 if (LocaleCompare("seed",option+1) == 0)
7022 {
cristybb503372010-05-27 20:51:26 +00007023 size_t
cristy3ed852e2009-09-05 21:47:34 +00007024 seed;
7025
7026 if (*option == '+')
7027 {
cristybb503372010-05-27 20:51:26 +00007028 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007029 SeedPseudoRandomGenerator(seed);
7030 break;
7031 }
cristye27293e2009-12-18 02:53:20 +00007032 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007033 SeedPseudoRandomGenerator(seed);
7034 break;
7035 }
7036 if (LocaleCompare("size",option+1) == 0)
7037 {
7038 if (*option == '+')
7039 {
7040 if (image_info->size != (char *) NULL)
7041 image_info->size=DestroyString(image_info->size);
7042 break;
7043 }
7044 (void) CloneString(&image_info->size,argv[i+1]);
7045 break;
7046 }
7047 if (LocaleCompare("stroke",option+1) == 0)
7048 {
7049 if (*option == '+')
7050 {
7051 (void) SetImageOption(image_info,option+1,"none");
7052 break;
7053 }
7054 (void) SetImageOption(image_info,option+1,argv[i+1]);
7055 break;
7056 }
7057 if (LocaleCompare("strokewidth",option+1) == 0)
7058 {
7059 if (*option == '+')
7060 {
7061 (void) SetImageOption(image_info,option+1,"0");
7062 break;
7063 }
7064 (void) SetImageOption(image_info,option+1,argv[i+1]);
7065 break;
7066 }
cristyd9a29192010-10-16 16:49:53 +00007067 if (LocaleCompare("synchronize",option+1) == 0)
7068 {
7069 if (*option == '+')
7070 {
7071 image_info->synchronize=MagickFalse;
7072 break;
7073 }
7074 image_info->synchronize=MagickTrue;
7075 break;
7076 }
cristy3ed852e2009-09-05 21:47:34 +00007077 break;
7078 }
7079 case 't':
7080 {
7081 if (LocaleCompare("taint",option+1) == 0)
7082 {
7083 if (*option == '+')
7084 {
7085 (void) SetImageOption(image_info,option+1,"false");
7086 break;
7087 }
7088 (void) SetImageOption(image_info,option+1,"true");
7089 break;
7090 }
7091 if (LocaleCompare("texture",option+1) == 0)
7092 {
7093 if (*option == '+')
7094 {
7095 if (image_info->texture != (char *) NULL)
7096 image_info->texture=DestroyString(image_info->texture);
7097 break;
7098 }
7099 (void) CloneString(&image_info->texture,argv[i+1]);
7100 break;
7101 }
7102 if (LocaleCompare("tile-offset",option+1) == 0)
7103 {
7104 if (*option == '+')
7105 {
7106 (void) SetImageOption(image_info,option+1,"0");
7107 break;
7108 }
7109 (void) SetImageOption(image_info,option+1,argv[i+1]);
7110 break;
7111 }
7112 if (LocaleCompare("transparent-color",option+1) == 0)
7113 {
7114 if (*option == '+')
7115 {
7116 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7117 (void) SetImageOption(image_info,option+1,"none");
7118 break;
7119 }
7120 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7121 exception);
7122 (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{
7266 ChannelType
7267 channel;
7268
7269 const char
7270 *option;
7271
cristy6b3da3a2010-06-20 02:21:46 +00007272 ImageInfo
7273 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007274
7275 MagickStatusType
7276 status;
7277
7278 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);
cristy6b3da3a2010-06-20 02:21:46 +00007301 mogrify_info=CloneImageInfo(image_info);
7302 quantize_info=AcquireQuantizeInfo(mogrify_info);
7303 channel=mogrify_info->channel;
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 {
cristy6b3da3a2010-06-20 02:21:46 +00007323 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007324 if (*option == '+')
7325 {
7326 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7327 InheritException(exception,&(*images)->exception);
7328 break;
7329 }
7330 i++;
7331 break;
7332 }
7333 if (LocaleCompare("append",option+1) == 0)
7334 {
7335 Image
7336 *append_image;
7337
cristy6b3da3a2010-06-20 02:21:46 +00007338 (void) SyncImagesSettings(mogrify_info,*images);
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 */
cristy6b3da3a2010-06-20 02:21:46 +00007358 (void) SyncImagesSettings(mogrify_info,*images);
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 {
7376 if (*option == '+')
7377 {
7378 channel=DefaultChannels;
7379 break;
7380 }
7381 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7382 break;
7383 }
7384 if (LocaleCompare("clut",option+1) == 0)
7385 {
7386 Image
7387 *clut_image,
7388 *image;
7389
cristy6b3da3a2010-06-20 02:21:46 +00007390 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007391 image=RemoveFirstImageFromList(images);
7392 clut_image=RemoveFirstImageFromList(images);
7393 if (clut_image == (Image *) NULL)
7394 {
7395 status=MagickFalse;
7396 break;
7397 }
7398 (void) ClutImageChannel(image,channel,clut_image);
7399 clut_image=DestroyImage(clut_image);
7400 InheritException(exception,&image->exception);
7401 *images=DestroyImageList(*images);
7402 *images=image;
7403 break;
7404 }
7405 if (LocaleCompare("coalesce",option+1) == 0)
7406 {
7407 Image
7408 *coalesce_image;
7409
cristy6b3da3a2010-06-20 02:21:46 +00007410 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007411 coalesce_image=CoalesceImages(*images,exception);
7412 if (coalesce_image == (Image *) NULL)
7413 {
7414 status=MagickFalse;
7415 break;
7416 }
7417 *images=DestroyImageList(*images);
7418 *images=coalesce_image;
7419 break;
7420 }
7421 if (LocaleCompare("combine",option+1) == 0)
7422 {
7423 Image
7424 *combine_image;
7425
cristy6b3da3a2010-06-20 02:21:46 +00007426 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007427 combine_image=CombineImages(*images,channel,exception);
7428 if (combine_image == (Image *) NULL)
7429 {
7430 status=MagickFalse;
7431 break;
7432 }
7433 *images=DestroyImageList(*images);
7434 *images=combine_image;
7435 break;
7436 }
7437 if (LocaleCompare("composite",option+1) == 0)
7438 {
7439 Image
7440 *mask_image,
7441 *composite_image,
7442 *image;
7443
7444 RectangleInfo
7445 geometry;
7446
cristy6b3da3a2010-06-20 02:21:46 +00007447 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007448 image=RemoveFirstImageFromList(images);
7449 composite_image=RemoveFirstImageFromList(images);
7450 if (composite_image == (Image *) NULL)
7451 {
7452 status=MagickFalse;
7453 break;
7454 }
7455 (void) TransformImage(&composite_image,(char *) NULL,
7456 composite_image->geometry);
7457 SetGeometry(composite_image,&geometry);
7458 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7459 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7460 &geometry);
7461 mask_image=RemoveFirstImageFromList(images);
7462 if (mask_image != (Image *) NULL)
7463 {
7464 if ((image->compose == DisplaceCompositeOp) ||
7465 (image->compose == DistortCompositeOp))
7466 {
7467 /*
7468 Merge Y displacement into X displacement image.
7469 */
7470 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7471 mask_image,0,0);
7472 mask_image=DestroyImage(mask_image);
7473 }
7474 else
7475 {
7476 /*
7477 Set a blending mask for the composition.
7478 */
anthonya129f702011-04-14 01:08:48 +00007479 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007480 image->mask=mask_image;
7481 (void) NegateImage(image->mask,MagickFalse);
7482 }
7483 }
7484 (void) CompositeImageChannel(image,channel,image->compose,
7485 composite_image,geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007486 if (mask_image != (Image *) NULL)
7487 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007488 composite_image=DestroyImage(composite_image);
7489 InheritException(exception,&image->exception);
7490 *images=DestroyImageList(*images);
7491 *images=image;
7492 break;
7493 }
anthony9f4f0342011-03-28 11:47:22 +00007494#if 0
7495This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007496 if (LocaleCompare("crop",option+1) == 0)
7497 {
7498 MagickStatusType
7499 flags;
7500
7501 RectangleInfo
7502 geometry;
7503
anthonye9c27192011-03-27 08:07:06 +00007504 /*
anthony9f4f0342011-03-28 11:47:22 +00007505 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007506 */
cristy6b3da3a2010-06-20 02:21:46 +00007507 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007508 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7509 if (((geometry.width == 0) && (geometry.height == 0)) ||
7510 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7511 break;
7512 (void) TransformImages(images,argv[i+1],(char *) NULL);
7513 InheritException(exception,&(*images)->exception);
7514 break;
7515 }
anthony9f4f0342011-03-28 11:47:22 +00007516#endif
cristy3ed852e2009-09-05 21:47:34 +00007517 break;
7518 }
7519 case 'd':
7520 {
7521 if (LocaleCompare("deconstruct",option+1) == 0)
7522 {
7523 Image
7524 *deconstruct_image;
7525
cristy6b3da3a2010-06-20 02:21:46 +00007526 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007527 deconstruct_image=DeconstructImages(*images,exception);
7528 if (deconstruct_image == (Image *) NULL)
7529 {
7530 status=MagickFalse;
7531 break;
7532 }
7533 *images=DestroyImageList(*images);
7534 *images=deconstruct_image;
7535 break;
7536 }
7537 if (LocaleCompare("delete",option+1) == 0)
7538 {
7539 if (*option == '+')
7540 DeleteImages(images,"-1",exception);
7541 else
7542 DeleteImages(images,argv[i+1],exception);
7543 break;
7544 }
7545 if (LocaleCompare("dither",option+1) == 0)
7546 {
7547 if (*option == '+')
7548 {
7549 quantize_info->dither=MagickFalse;
7550 break;
7551 }
7552 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007553 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007554 MagickDitherOptions,MagickFalse,argv[i+1]);
7555 break;
7556 }
cristyecb10ff2011-03-22 13:14:03 +00007557 if (LocaleCompare("duplicate",option+1) == 0)
7558 {
cristy72988482011-03-29 16:34:38 +00007559 Image
7560 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007561
anthony2b6bcae2011-03-23 13:05:34 +00007562 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007563 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7564 else
7565 {
7566 const char
7567 *p;
7568
anthony2b6bcae2011-03-23 13:05:34 +00007569 size_t
7570 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007571
anthony2b6bcae2011-03-23 13:05:34 +00007572 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007573 p=strchr(argv[i+1],',');
7574 if (p == (const char *) NULL)
7575 duplicate_images=DuplicateImages(*images,number_duplicates,
7576 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007577 else
cristy72988482011-03-29 16:34:38 +00007578 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7579 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007580 }
7581 AppendImageToList(images, duplicate_images);
7582 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007583 break;
7584 }
cristy3ed852e2009-09-05 21:47:34 +00007585 break;
7586 }
cristyd18ae7c2010-03-07 17:39:52 +00007587 case 'e':
7588 {
7589 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7590 {
7591 Image
7592 *evaluate_image;
7593
7594 MagickEvaluateOperator
7595 op;
7596
cristy6b3da3a2010-06-20 02:21:46 +00007597 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007598 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007599 MagickFalse,argv[i+1]);
7600 evaluate_image=EvaluateImages(*images,op,exception);
7601 if (evaluate_image == (Image *) NULL)
7602 {
7603 status=MagickFalse;
7604 break;
7605 }
7606 *images=DestroyImageList(*images);
7607 *images=evaluate_image;
7608 break;
7609 }
7610 break;
7611 }
cristy3ed852e2009-09-05 21:47:34 +00007612 case 'f':
7613 {
cristyf0a247f2009-10-04 00:20:03 +00007614 if (LocaleCompare("fft",option+1) == 0)
7615 {
7616 Image
7617 *fourier_image;
7618
7619 /*
7620 Implements the discrete Fourier transform (DFT).
7621 */
cristy6b3da3a2010-06-20 02:21:46 +00007622 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007623 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7624 MagickTrue : MagickFalse,exception);
7625 if (fourier_image == (Image *) NULL)
7626 break;
7627 *images=DestroyImage(*images);
7628 *images=fourier_image;
7629 break;
7630 }
cristy3ed852e2009-09-05 21:47:34 +00007631 if (LocaleCompare("flatten",option+1) == 0)
7632 {
7633 Image
7634 *flatten_image;
7635
cristy6b3da3a2010-06-20 02:21:46 +00007636 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007637 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7638 if (flatten_image == (Image *) NULL)
7639 break;
7640 *images=DestroyImageList(*images);
7641 *images=flatten_image;
7642 break;
7643 }
7644 if (LocaleCompare("fx",option+1) == 0)
7645 {
7646 Image
7647 *fx_image;
7648
cristy6b3da3a2010-06-20 02:21:46 +00007649 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007650 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7651 if (fx_image == (Image *) NULL)
7652 {
7653 status=MagickFalse;
7654 break;
7655 }
7656 *images=DestroyImageList(*images);
7657 *images=fx_image;
7658 break;
7659 }
7660 break;
7661 }
7662 case 'h':
7663 {
7664 if (LocaleCompare("hald-clut",option+1) == 0)
7665 {
7666 Image
7667 *hald_image,
7668 *image;
7669
cristy6b3da3a2010-06-20 02:21:46 +00007670 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007671 image=RemoveFirstImageFromList(images);
7672 hald_image=RemoveFirstImageFromList(images);
7673 if (hald_image == (Image *) NULL)
7674 {
7675 status=MagickFalse;
7676 break;
7677 }
7678 (void) HaldClutImageChannel(image,channel,hald_image);
7679 hald_image=DestroyImage(hald_image);
7680 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007681 if (*images != (Image *) NULL)
7682 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007683 *images=image;
7684 break;
7685 }
7686 break;
7687 }
7688 case 'i':
7689 {
7690 if (LocaleCompare("ift",option+1) == 0)
7691 {
7692 Image
cristy8587f882009-11-13 20:28:49 +00007693 *fourier_image,
7694 *magnitude_image,
7695 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007696
7697 /*
7698 Implements the inverse fourier discrete Fourier transform (DFT).
7699 */
cristy6b3da3a2010-06-20 02:21:46 +00007700 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007701 magnitude_image=RemoveFirstImageFromList(images);
7702 phase_image=RemoveFirstImageFromList(images);
7703 if (phase_image == (Image *) NULL)
7704 {
7705 status=MagickFalse;
7706 break;
7707 }
7708 fourier_image=InverseFourierTransformImage(magnitude_image,
7709 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007710 if (fourier_image == (Image *) NULL)
7711 break;
cristy0aff6ea2009-11-14 01:40:53 +00007712 if (*images != (Image *) NULL)
7713 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007714 *images=fourier_image;
7715 break;
7716 }
7717 if (LocaleCompare("insert",option+1) == 0)
7718 {
7719 Image
7720 *p,
7721 *q;
7722
7723 index=0;
7724 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007725 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007726 p=RemoveLastImageFromList(images);
7727 if (p == (Image *) NULL)
7728 {
7729 (void) ThrowMagickException(exception,GetMagickModule(),
7730 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7731 status=MagickFalse;
7732 break;
7733 }
7734 q=p;
7735 if (index == 0)
7736 PrependImageToList(images,q);
7737 else
cristybb503372010-05-27 20:51:26 +00007738 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007739 AppendImageToList(images,q);
7740 else
7741 {
7742 q=GetImageFromList(*images,index-1);
7743 if (q == (Image *) NULL)
7744 {
7745 (void) ThrowMagickException(exception,GetMagickModule(),
7746 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7747 status=MagickFalse;
7748 break;
7749 }
7750 InsertImageInList(&q,p);
7751 }
7752 *images=GetFirstImageInList(q);
7753 break;
7754 }
7755 break;
7756 }
7757 case 'l':
7758 {
7759 if (LocaleCompare("layers",option+1) == 0)
7760 {
7761 Image
7762 *layers;
7763
7764 ImageLayerMethod
7765 method;
7766
cristy6b3da3a2010-06-20 02:21:46 +00007767 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007768 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007769 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007770 MagickFalse,argv[i+1]);
7771 switch (method)
7772 {
7773 case CoalesceLayer:
7774 {
7775 layers=CoalesceImages(*images,exception);
7776 break;
7777 }
7778 case CompareAnyLayer:
7779 case CompareClearLayer:
7780 case CompareOverlayLayer:
7781 default:
7782 {
7783 layers=CompareImageLayers(*images,method,exception);
7784 break;
7785 }
7786 case MergeLayer:
7787 case FlattenLayer:
7788 case MosaicLayer:
7789 case TrimBoundsLayer:
7790 {
7791 layers=MergeImageLayers(*images,method,exception);
7792 break;
7793 }
7794 case DisposeLayer:
7795 {
7796 layers=DisposeImages(*images,exception);
7797 break;
7798 }
7799 case OptimizeImageLayer:
7800 {
7801 layers=OptimizeImageLayers(*images,exception);
7802 break;
7803 }
7804 case OptimizePlusLayer:
7805 {
7806 layers=OptimizePlusImageLayers(*images,exception);
7807 break;
7808 }
7809 case OptimizeTransLayer:
7810 {
7811 OptimizeImageTransparency(*images,exception);
7812 break;
7813 }
7814 case RemoveDupsLayer:
7815 {
7816 RemoveDuplicateLayers(images,exception);
7817 break;
7818 }
7819 case RemoveZeroLayer:
7820 {
7821 RemoveZeroDelayLayers(images,exception);
7822 break;
7823 }
7824 case OptimizeLayer:
7825 {
7826 /*
7827 General Purpose, GIF Animation Optimizer.
7828 */
7829 layers=CoalesceImages(*images,exception);
7830 if (layers == (Image *) NULL)
7831 {
7832 status=MagickFalse;
7833 break;
7834 }
7835 InheritException(exception,&layers->exception);
7836 *images=DestroyImageList(*images);
7837 *images=layers;
7838 layers=OptimizeImageLayers(*images,exception);
7839 if (layers == (Image *) NULL)
7840 {
7841 status=MagickFalse;
7842 break;
7843 }
7844 InheritException(exception,&layers->exception);
7845 *images=DestroyImageList(*images);
7846 *images=layers;
7847 layers=(Image *) NULL;
7848 OptimizeImageTransparency(*images,exception);
7849 InheritException(exception,&(*images)->exception);
7850 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7851 break;
7852 }
7853 case CompositeLayer:
7854 {
7855 CompositeOperator
7856 compose;
7857
7858 Image
7859 *source;
7860
7861 RectangleInfo
7862 geometry;
7863
7864 /*
7865 Split image sequence at the first 'NULL:' image.
7866 */
7867 source=(*images);
7868 while (source != (Image *) NULL)
7869 {
7870 source=GetNextImageInList(source);
7871 if ((source != (Image *) NULL) &&
7872 (LocaleCompare(source->magick,"NULL") == 0))
7873 break;
7874 }
7875 if (source != (Image *) NULL)
7876 {
7877 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7878 (GetNextImageInList(source) == (Image *) NULL))
7879 source=(Image *) NULL;
7880 else
7881 {
7882 /*
7883 Separate the two lists, junk the null: image.
7884 */
7885 source=SplitImageList(source->previous);
7886 DeleteImageFromList(&source);
7887 }
7888 }
7889 if (source == (Image *) NULL)
7890 {
7891 (void) ThrowMagickException(exception,GetMagickModule(),
7892 OptionError,"MissingNullSeparator","layers Composite");
7893 status=MagickFalse;
7894 break;
7895 }
7896 /*
7897 Adjust offset with gravity and virtual canvas.
7898 */
7899 SetGeometry(*images,&geometry);
7900 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7901 geometry.width=source->page.width != 0 ?
7902 source->page.width : source->columns;
7903 geometry.height=source->page.height != 0 ?
7904 source->page.height : source->rows;
7905 GravityAdjustGeometry((*images)->page.width != 0 ?
7906 (*images)->page.width : (*images)->columns,
7907 (*images)->page.height != 0 ? (*images)->page.height :
7908 (*images)->rows,(*images)->gravity,&geometry);
7909 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007910 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007911 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007912 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007913 MagickComposeOptions,MagickFalse,option);
7914 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7915 exception);
7916 source=DestroyImageList(source);
7917 break;
7918 }
7919 }
7920 if (layers == (Image *) NULL)
7921 break;
7922 InheritException(exception,&layers->exception);
7923 *images=DestroyImageList(*images);
7924 *images=layers;
7925 break;
7926 }
7927 break;
7928 }
7929 case 'm':
7930 {
7931 if (LocaleCompare("map",option+1) == 0)
7932 {
cristy6b3da3a2010-06-20 02:21:46 +00007933 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007934 if (*option == '+')
7935 {
7936 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7937 InheritException(exception,&(*images)->exception);
7938 break;
7939 }
7940 i++;
7941 break;
7942 }
cristyf40785b2010-03-06 02:27:27 +00007943 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007944 {
7945 Image
cristyf40785b2010-03-06 02:27:27 +00007946 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007947
cristyd18ae7c2010-03-07 17:39:52 +00007948 /*
7949 Maximum image sequence (deprecated).
7950 */
cristy6b3da3a2010-06-20 02:21:46 +00007951 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007952 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007953 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007954 {
7955 status=MagickFalse;
7956 break;
7957 }
7958 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007959 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007960 break;
7961 }
cristyf40785b2010-03-06 02:27:27 +00007962 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007963 {
7964 Image
cristyf40785b2010-03-06 02:27:27 +00007965 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007966
cristyd18ae7c2010-03-07 17:39:52 +00007967 /*
7968 Minimum image sequence (deprecated).
7969 */
cristy6b3da3a2010-06-20 02:21:46 +00007970 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007971 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007972 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007973 {
7974 status=MagickFalse;
7975 break;
7976 }
7977 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007978 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007979 break;
7980 }
cristy3ed852e2009-09-05 21:47:34 +00007981 if (LocaleCompare("morph",option+1) == 0)
7982 {
7983 Image
7984 *morph_image;
7985
cristy6b3da3a2010-06-20 02:21:46 +00007986 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007987 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007988 exception);
7989 if (morph_image == (Image *) NULL)
7990 {
7991 status=MagickFalse;
7992 break;
7993 }
7994 *images=DestroyImageList(*images);
7995 *images=morph_image;
7996 break;
7997 }
7998 if (LocaleCompare("mosaic",option+1) == 0)
7999 {
8000 Image
8001 *mosaic_image;
8002
cristy6b3da3a2010-06-20 02:21:46 +00008003 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008004 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8005 if (mosaic_image == (Image *) NULL)
8006 {
8007 status=MagickFalse;
8008 break;
8009 }
8010 *images=DestroyImageList(*images);
8011 *images=mosaic_image;
8012 break;
8013 }
8014 break;
8015 }
8016 case 'p':
8017 {
8018 if (LocaleCompare("print",option+1) == 0)
8019 {
8020 char
8021 *string;
8022
cristy6b3da3a2010-06-20 02:21:46 +00008023 (void) SyncImagesSettings(mogrify_info,*images);
8024 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008025 if (string == (char *) NULL)
8026 break;
8027 InheritException(exception,&(*images)->exception);
8028 (void) fprintf(stdout,"%s",string);
8029 string=DestroyString(string);
8030 }
8031 if (LocaleCompare("process",option+1) == 0)
8032 {
8033 char
8034 **arguments;
8035
8036 int
8037 j,
8038 number_arguments;
8039
cristy6b3da3a2010-06-20 02:21:46 +00008040 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008041 arguments=StringToArgv(argv[i+1],&number_arguments);
8042 if (arguments == (char **) NULL)
8043 break;
8044 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8045 {
8046 char
8047 breaker,
8048 quote,
8049 *token;
8050
8051 const char
8052 *arguments;
8053
8054 int
8055 next,
8056 status;
8057
8058 size_t
8059 length;
8060
8061 TokenInfo
8062 *token_info;
8063
8064 /*
8065 Support old style syntax, filter="-option arg".
8066 */
8067 length=strlen(argv[i+1]);
8068 token=(char *) NULL;
8069 if (~length >= MaxTextExtent)
8070 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8071 sizeof(*token));
8072 if (token == (char *) NULL)
8073 break;
8074 next=0;
8075 arguments=argv[i+1];
8076 token_info=AcquireTokenInfo();
8077 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8078 "\"",'\0',&breaker,&next,&quote);
8079 token_info=DestroyTokenInfo(token_info);
8080 if (status == 0)
8081 {
8082 const char
8083 *argv;
8084
8085 argv=(&(arguments[next]));
8086 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8087 exception);
8088 }
8089 token=DestroyString(token);
8090 break;
8091 }
cristy91c0da22010-05-02 01:44:07 +00008092 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008093 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8094 number_arguments-2,(const char **) arguments+2,exception);
8095 for (j=0; j < number_arguments; j++)
8096 arguments[j]=DestroyString(arguments[j]);
8097 arguments=(char **) RelinquishMagickMemory(arguments);
8098 break;
8099 }
8100 break;
8101 }
8102 case 'r':
8103 {
8104 if (LocaleCompare("reverse",option+1) == 0)
8105 {
8106 ReverseImageList(images);
8107 InheritException(exception,&(*images)->exception);
8108 break;
8109 }
8110 break;
8111 }
8112 case 's':
8113 {
cristy4285d782011-02-09 20:12:28 +00008114 if (LocaleCompare("smush",option+1) == 0)
8115 {
8116 Image
8117 *smush_image;
8118
8119 ssize_t
8120 offset;
8121
8122 (void) SyncImagesSettings(mogrify_info,*images);
8123 offset=(ssize_t) StringToLong(argv[i+1]);
8124 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8125 MagickFalse,offset,exception);
8126 if (smush_image == (Image *) NULL)
8127 {
8128 status=MagickFalse;
8129 break;
8130 }
8131 *images=DestroyImageList(*images);
8132 *images=smush_image;
8133 break;
8134 }
cristy3ed852e2009-09-05 21:47:34 +00008135 if (LocaleCompare("swap",option+1) == 0)
8136 {
8137 Image
8138 *p,
8139 *q,
8140 *swap;
8141
cristybb503372010-05-27 20:51:26 +00008142 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008143 swap_index;
8144
8145 index=(-1);
8146 swap_index=(-2);
8147 if (*option != '+')
8148 {
8149 GeometryInfo
8150 geometry_info;
8151
8152 MagickStatusType
8153 flags;
8154
8155 swap_index=(-1);
8156 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008157 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008158 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008159 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008160 }
8161 p=GetImageFromList(*images,index);
8162 q=GetImageFromList(*images,swap_index);
8163 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8164 {
8165 (void) ThrowMagickException(exception,GetMagickModule(),
8166 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8167 status=MagickFalse;
8168 break;
8169 }
8170 if (p == q)
8171 break;
8172 swap=CloneImage(p,0,0,MagickTrue,exception);
8173 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8174 ReplaceImageInList(&q,swap);
8175 *images=GetFirstImageInList(q);
8176 break;
8177 }
8178 break;
8179 }
8180 case 'w':
8181 {
8182 if (LocaleCompare("write",option+1) == 0)
8183 {
cristy071dd7b2010-04-09 13:04:54 +00008184 char
cristy06609ee2010-03-17 20:21:27 +00008185 key[MaxTextExtent];
8186
cristy3ed852e2009-09-05 21:47:34 +00008187 Image
8188 *write_images;
8189
8190 ImageInfo
8191 *write_info;
8192
cristy6b3da3a2010-06-20 02:21:46 +00008193 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008194 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8195 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008196 write_images=(*images);
8197 if (*option == '+')
8198 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008199 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008200 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8201 write_info=DestroyImageInfo(write_info);
8202 if (*option == '+')
8203 write_images=DestroyImageList(write_images);
8204 break;
8205 }
8206 break;
8207 }
8208 default:
8209 break;
8210 }
8211 i+=count;
8212 }
8213 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008214 mogrify_info=DestroyImageInfo(mogrify_info);
8215 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008216 return(status != 0 ? MagickTrue : MagickFalse);
8217}
8218
8219/*
8220%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8221% %
8222% %
8223% %
8224+ M o g r i f y I m a g e s %
8225% %
8226% %
8227% %
8228%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8229%
8230% MogrifyImages() applies image processing options to a sequence of images as
8231% prescribed by command line options.
8232%
8233% The format of the MogrifyImage method is:
8234%
8235% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8236% const MagickBooleanType post,const int argc,const char **argv,
8237% Image **images,Exceptioninfo *exception)
8238%
8239% A description of each parameter follows:
8240%
8241% o image_info: the image info..
8242%
8243% o post: If true, post process image list operators otherwise pre-process.
8244%
8245% o argc: Specifies a pointer to an integer describing the number of
8246% elements in the argument vector.
8247%
8248% o argv: Specifies a pointer to a text array containing the command line
8249% arguments.
8250%
anthonye9c27192011-03-27 08:07:06 +00008251% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008252%
8253% o exception: return any errors or warnings in this structure.
8254%
8255*/
8256WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8257 const MagickBooleanType post,const int argc,const char **argv,
8258 Image **images,ExceptionInfo *exception)
8259{
8260#define MogrifyImageTag "Mogrify/Image"
8261
anthonye9c27192011-03-27 08:07:06 +00008262 MagickStatusType
8263 status;
cristy3ed852e2009-09-05 21:47:34 +00008264
cristy0e9f9c12010-02-11 03:00:47 +00008265 MagickBooleanType
8266 proceed;
8267
anthonye9c27192011-03-27 08:07:06 +00008268 size_t
8269 n;
cristy3ed852e2009-09-05 21:47:34 +00008270
cristybb503372010-05-27 20:51:26 +00008271 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008272 i;
8273
cristy3ed852e2009-09-05 21:47:34 +00008274 assert(image_info != (ImageInfo *) NULL);
8275 assert(image_info->signature == MagickSignature);
8276 if (images == (Image **) NULL)
8277 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008278 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008279 assert((*images)->signature == MagickSignature);
8280 if ((*images)->debug != MagickFalse)
8281 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8282 (*images)->filename);
8283 if ((argc <= 0) || (*argv == (char *) NULL))
8284 return(MagickTrue);
8285 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8286 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008287 status=0;
anthonye9c27192011-03-27 08:07:06 +00008288
anthonyce2716b2011-04-22 09:51:34 +00008289#if 0
8290fprintf(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,post?"post":"pre");
8291#endif
8292
anthonye9c27192011-03-27 08:07:06 +00008293 /*
8294 Pre-process multi-image sequence operators
8295 */
cristy3ed852e2009-09-05 21:47:34 +00008296 if (post == MagickFalse)
8297 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008298
8299 /*
8300 For each image, process simple single image operators
8301 */
8302 i=0;
8303 n=GetImageListLength(*images);
8304 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008305 {
anthonyce2716b2011-04-22 09:51:34 +00008306#if 0
8307fprintf(stderr, "mogrify %ld of %ld\n",
8308 (long)GetImageIndexInList(*images),(long)GetImageListLength(*images));
8309#endif
anthonye9c27192011-03-27 08:07:06 +00008310 status&=MogrifyImage(image_info,argc,argv,images,exception);
8311 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008312 if (proceed == MagickFalse)
8313 break;
anthonye9c27192011-03-27 08:07:06 +00008314 if ( (*images)->next == (Image *) NULL )
8315 break;
8316 *images=(*images)->next;
8317 i++;
cristy3ed852e2009-09-05 21:47:34 +00008318 }
anthonye9c27192011-03-27 08:07:06 +00008319 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008320#if 0
8321fprintf(stderr, "mogrify end %ld of %ld\n",
8322 (long)GetImageIndexInList(*images),(long)GetImageListLength(*images));
8323#endif
anthonye9c27192011-03-27 08:07:06 +00008324
8325 /*
8326 Post-process, multi-image sequence operators
8327 */
8328 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008329 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008330 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008331 return(status != 0 ? MagickTrue : MagickFalse);
8332}