blob: a0ddab3039f4385cd9893d1a358c82a086d77eb0 [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];
683 if (IsMagickOption(option) == MagickFalse)
684 continue;
685 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
686 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);
cristy3ed852e2009-09-05 21:47:34 +0000751 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
752 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.
1064 */
cristyb0d3bb92010-09-22 14:37:58 +00001065 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1066 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001067 break;
cristyb0d3bb92010-09-22 14:37:58 +00001068 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1069 return(MagickFalse);
1070 mask_view=AcquireCacheView(mask_image);
1071 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001072 {
cristyb0d3bb92010-09-22 14:37:58 +00001073 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1074 exception);
cristy3ed852e2009-09-05 21:47:34 +00001075 if (q == (PixelPacket *) NULL)
1076 break;
cristyb0d3bb92010-09-22 14:37:58 +00001077 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001078 {
cristyb0d3bb92010-09-22 14:37:58 +00001079 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001080 q->opacity=PixelIntensityToQuantum(q);
1081 q->red=q->opacity;
1082 q->green=q->opacity;
1083 q->blue=q->opacity;
1084 q++;
1085 }
cristyb0d3bb92010-09-22 14:37:58 +00001086 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001087 break;
1088 }
cristyb0d3bb92010-09-22 14:37:58 +00001089 mask_view=DestroyCacheView(mask_view);
1090 mask_image->matte=MagickTrue;
1091 (void) SetImageClipMask(*image,mask_image);
1092 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001093 InheritException(exception,&(*image)->exception);
1094 break;
1095 }
1096 if (LocaleCompare("clip-path",option+1) == 0)
1097 {
cristy6b3da3a2010-06-20 02:21:46 +00001098 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001099 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1100 MagickFalse);
1101 InheritException(exception,&(*image)->exception);
1102 break;
1103 }
1104 if (LocaleCompare("colorize",option+1) == 0)
1105 {
cristy3ed852e2009-09-05 21:47:34 +00001106 /*
1107 Colorize the image.
1108 */
cristy6b3da3a2010-06-20 02:21:46 +00001109 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001110 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
cristy3ed852e2009-09-05 21:47:34 +00001111 exception);
cristy3ed852e2009-09-05 21:47:34 +00001112 break;
1113 }
cristye6365592010-04-02 17:31:23 +00001114 if (LocaleCompare("color-matrix",option+1) == 0)
1115 {
cristye6365592010-04-02 17:31:23 +00001116 KernelInfo
1117 *kernel;
1118
cristy6b3da3a2010-06-20 02:21:46 +00001119 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001120 kernel=AcquireKernelInfo(argv[i+1]);
1121 if (kernel == (KernelInfo *) NULL)
1122 break;
cristyd241f442011-03-29 13:50:49 +00001123 mogrify_image=ColorMatrixImage(*image,kernel,exception);
cristye6365592010-04-02 17:31:23 +00001124 kernel=DestroyKernelInfo(kernel);
cristye6365592010-04-02 17:31:23 +00001125 break;
1126 }
cristy3ed852e2009-09-05 21:47:34 +00001127 if (LocaleCompare("colors",option+1) == 0)
1128 {
1129 /*
1130 Reduce the number of colors in the image.
1131 */
cristy6b3da3a2010-06-20 02:21:46 +00001132 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001133 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001134 if (quantize_info->number_colors == 0)
1135 break;
1136 if (((*image)->storage_class == DirectClass) ||
1137 (*image)->colors > quantize_info->number_colors)
1138 (void) QuantizeImage(quantize_info,*image);
1139 else
1140 (void) CompressImageColormap(*image);
1141 InheritException(exception,&(*image)->exception);
1142 break;
1143 }
1144 if (LocaleCompare("colorspace",option+1) == 0)
1145 {
1146 ColorspaceType
1147 colorspace;
1148
cristy6b3da3a2010-06-20 02:21:46 +00001149 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001150 if (*option == '+')
1151 {
1152 (void) TransformImageColorspace(*image,RGBColorspace);
1153 InheritException(exception,&(*image)->exception);
1154 break;
1155 }
1156 colorspace=(ColorspaceType) ParseMagickOption(
1157 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1158 (void) TransformImageColorspace(*image,colorspace);
1159 InheritException(exception,&(*image)->exception);
1160 break;
1161 }
1162 if (LocaleCompare("contrast",option+1) == 0)
1163 {
cristy6b3da3a2010-06-20 02:21:46 +00001164 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001165 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1166 MagickFalse);
1167 InheritException(exception,&(*image)->exception);
1168 break;
1169 }
1170 if (LocaleCompare("contrast-stretch",option+1) == 0)
1171 {
1172 double
1173 black_point,
1174 white_point;
1175
cristy3ed852e2009-09-05 21:47:34 +00001176 MagickStatusType
1177 flags;
1178
1179 /*
1180 Contrast stretch image.
1181 */
cristy6b3da3a2010-06-20 02:21:46 +00001182 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001183 flags=ParseGeometry(argv[i+1],&geometry_info);
1184 black_point=geometry_info.rho;
1185 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1186 black_point;
1187 if ((flags & PercentValue) != 0)
1188 {
1189 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1190 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1191 }
1192 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1193 white_point;
1194 (void) ContrastStretchImageChannel(*image,channel,black_point,
1195 white_point);
1196 InheritException(exception,&(*image)->exception);
1197 break;
1198 }
1199 if (LocaleCompare("convolve",option+1) == 0)
1200 {
cristy36826ab2010-03-06 01:29:30 +00001201 double
1202 gamma;
1203
cristy2be15382010-01-21 02:38:03 +00001204 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001205 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001206
cristybb503372010-05-27 20:51:26 +00001207 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001208 j;
1209
cristy6b3da3a2010-06-20 02:21:46 +00001210 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001211 kernel=AcquireKernelInfo(argv[i+1]);
1212 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001213 break;
cristy36826ab2010-03-06 01:29:30 +00001214 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001215 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001216 gamma+=kernel->values[j];
1217 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001218 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001219 kernel->values[j]*=gamma;
cristyd241f442011-03-29 13:50:49 +00001220 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001221 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001222 break;
1223 }
1224 if (LocaleCompare("crop",option+1) == 0)
1225 {
anthonye9c27192011-03-27 08:07:06 +00001226 /*
1227 Crop a image to a smaller size
anthonye9c27192011-03-27 08:07:06 +00001228 */
cristy6b3da3a2010-06-20 02:21:46 +00001229 (void) SyncImageSettings(mogrify_info,*image);
anthony9f4f0342011-03-28 11:47:22 +00001230#if 0
cristy3ed852e2009-09-05 21:47:34 +00001231 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1232 if (((geometry.width != 0) || (geometry.height != 0)) &&
1233 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1234 break;
anthony9f4f0342011-03-28 11:47:22 +00001235#endif
1236#if 0
cristyd241f442011-03-29 13:50:49 +00001237 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1238 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1239 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1240 InheritException(exception,&mogrify_image->exception);
anthony9f4f0342011-03-28 11:47:22 +00001241#else
cristyd241f442011-03-29 13:50:49 +00001242 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthony9f4f0342011-03-28 11:47:22 +00001243#endif
cristy3ed852e2009-09-05 21:47:34 +00001244 break;
1245 }
1246 if (LocaleCompare("cycle",option+1) == 0)
1247 {
1248 /*
1249 Cycle an image colormap.
1250 */
cristy6b3da3a2010-06-20 02:21:46 +00001251 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001252 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001253 InheritException(exception,&(*image)->exception);
1254 break;
1255 }
1256 break;
1257 }
1258 case 'd':
1259 {
1260 if (LocaleCompare("decipher",option+1) == 0)
1261 {
1262 StringInfo
1263 *passkey;
1264
1265 /*
1266 Decipher pixels.
1267 */
cristy6b3da3a2010-06-20 02:21:46 +00001268 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001269 passkey=FileToStringInfo(argv[i+1],~0,exception);
1270 if (passkey != (StringInfo *) NULL)
1271 {
1272 (void) PasskeyDecipherImage(*image,passkey,exception);
1273 passkey=DestroyStringInfo(passkey);
1274 }
1275 break;
1276 }
1277 if (LocaleCompare("density",option+1) == 0)
1278 {
1279 /*
1280 Set image density.
1281 */
1282 (void) CloneString(&draw_info->density,argv[i+1]);
1283 break;
1284 }
1285 if (LocaleCompare("depth",option+1) == 0)
1286 {
cristy6b3da3a2010-06-20 02:21:46 +00001287 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001288 if (*option == '+')
1289 {
1290 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1291 break;
1292 }
cristye27293e2009-12-18 02:53:20 +00001293 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001294 break;
1295 }
1296 if (LocaleCompare("deskew",option+1) == 0)
1297 {
1298 double
1299 threshold;
1300
cristy3ed852e2009-09-05 21:47:34 +00001301 /*
1302 Straighten the image.
1303 */
cristy6b3da3a2010-06-20 02:21:46 +00001304 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001305 if (*option == '+')
1306 threshold=40.0*QuantumRange/100.0;
1307 else
cristyf2f27272009-12-17 14:48:46 +00001308 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00001309 mogrify_image=DeskewImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00001310 break;
1311 }
1312 if (LocaleCompare("despeckle",option+1) == 0)
1313 {
cristy3ed852e2009-09-05 21:47:34 +00001314 /*
1315 Reduce the speckles within an image.
1316 */
cristy6b3da3a2010-06-20 02:21:46 +00001317 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001318 mogrify_image=DespeckleImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001319 break;
1320 }
1321 if (LocaleCompare("display",option+1) == 0)
1322 {
1323 (void) CloneString(&draw_info->server_name,argv[i+1]);
1324 break;
1325 }
cristy3ed852e2009-09-05 21:47:34 +00001326 if (LocaleCompare("distort",option+1) == 0)
1327 {
1328 char
1329 *args,
1330 token[MaxTextExtent];
1331
1332 const char
1333 *p;
1334
1335 DistortImageMethod
1336 method;
1337
1338 double
1339 *arguments;
1340
cristybb503372010-05-27 20:51:26 +00001341 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001342 x;
1343
cristybb503372010-05-27 20:51:26 +00001344 size_t
cristy3ed852e2009-09-05 21:47:34 +00001345 number_arguments;
1346
1347 /*
1348 Distort image.
1349 */
cristy6b3da3a2010-06-20 02:21:46 +00001350 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001351 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1352 MagickFalse,argv[i+1]);
anthony2029ddc2011-03-30 12:13:27 +00001353 if ( method == ResizeDistortion )
1354 {
1355 /* Special Case - Argument is actually a resize geometry!
1356 ** Convert that to an appropriate distortion argument array.
1357 */
1358 double
1359 resize_args[2];
1360 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1361 exception);
1362 resize_args[0]=(double)geometry.width;
1363 resize_args[1]=(double)geometry.height;
1364 mogrify_image=DistortImage(*image,method,(size_t)2,
1365 resize_args,MagickTrue,exception);
1366 break;
1367 }
cristy6b3da3a2010-06-20 02:21:46 +00001368 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001369 InheritException(exception,&(*image)->exception);
1370 if (args == (char *) NULL)
1371 break;
1372 p=(char *) args;
1373 for (x=0; *p != '\0'; x++)
1374 {
1375 GetMagickToken(p,&p,token);
1376 if (*token == ',')
1377 GetMagickToken(p,&p,token);
1378 }
cristybb503372010-05-27 20:51:26 +00001379 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001380 arguments=(double *) AcquireQuantumMemory(number_arguments,
1381 sizeof(*arguments));
1382 if (arguments == (double *) NULL)
1383 ThrowWandFatalException(ResourceLimitFatalError,
1384 "MemoryAllocationFailed",(*image)->filename);
1385 (void) ResetMagickMemory(arguments,0,number_arguments*
1386 sizeof(*arguments));
1387 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001388 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001389 {
1390 GetMagickToken(p,&p,token);
1391 if (*token == ',')
1392 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001393 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001394 }
1395 args=DestroyString(args);
cristyd241f442011-03-29 13:50:49 +00001396 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
cristy3ed852e2009-09-05 21:47:34 +00001397 (*option == '+') ? MagickTrue : MagickFalse,exception);
1398 arguments=(double *) RelinquishMagickMemory(arguments);
cristy3ed852e2009-09-05 21:47:34 +00001399 break;
1400 }
1401 if (LocaleCompare("dither",option+1) == 0)
1402 {
1403 if (*option == '+')
1404 {
1405 quantize_info->dither=MagickFalse;
1406 break;
1407 }
1408 quantize_info->dither=MagickTrue;
1409 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1410 MagickDitherOptions,MagickFalse,argv[i+1]);
1411 if (quantize_info->dither_method == NoDitherMethod)
1412 quantize_info->dither=MagickFalse;
1413 break;
1414 }
1415 if (LocaleCompare("draw",option+1) == 0)
1416 {
1417 /*
1418 Draw image.
1419 */
cristy6b3da3a2010-06-20 02:21:46 +00001420 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001421 (void) CloneString(&draw_info->primitive,argv[i+1]);
1422 (void) DrawImage(*image,draw_info);
1423 InheritException(exception,&(*image)->exception);
1424 break;
1425 }
1426 break;
1427 }
1428 case 'e':
1429 {
1430 if (LocaleCompare("edge",option+1) == 0)
1431 {
cristy3ed852e2009-09-05 21:47:34 +00001432 /*
1433 Enhance edges in the image.
1434 */
cristy6b3da3a2010-06-20 02:21:46 +00001435 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001436 flags=ParseGeometry(argv[i+1],&geometry_info);
1437 if ((flags & SigmaValue) == 0)
1438 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001439 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001440 break;
1441 }
1442 if (LocaleCompare("emboss",option+1) == 0)
1443 {
cristy3ed852e2009-09-05 21:47:34 +00001444 /*
1445 Gaussian embossen image.
1446 */
cristy6b3da3a2010-06-20 02:21:46 +00001447 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001448 flags=ParseGeometry(argv[i+1],&geometry_info);
1449 if ((flags & SigmaValue) == 0)
1450 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001451 mogrify_image=EmbossImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00001452 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001453 break;
1454 }
1455 if (LocaleCompare("encipher",option+1) == 0)
1456 {
1457 StringInfo
1458 *passkey;
1459
1460 /*
1461 Encipher pixels.
1462 */
cristy6b3da3a2010-06-20 02:21:46 +00001463 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001464 passkey=FileToStringInfo(argv[i+1],~0,exception);
1465 if (passkey != (StringInfo *) NULL)
1466 {
1467 (void) PasskeyEncipherImage(*image,passkey,exception);
1468 passkey=DestroyStringInfo(passkey);
1469 }
1470 break;
1471 }
1472 if (LocaleCompare("encoding",option+1) == 0)
1473 {
1474 (void) CloneString(&draw_info->encoding,argv[i+1]);
1475 break;
1476 }
1477 if (LocaleCompare("enhance",option+1) == 0)
1478 {
cristy3ed852e2009-09-05 21:47:34 +00001479 /*
1480 Enhance image.
1481 */
cristy6b3da3a2010-06-20 02:21:46 +00001482 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001483 mogrify_image=EnhanceImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001484 break;
1485 }
1486 if (LocaleCompare("equalize",option+1) == 0)
1487 {
1488 /*
1489 Equalize image.
1490 */
cristy6b3da3a2010-06-20 02:21:46 +00001491 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001492 (void) EqualizeImageChannel(*image,channel);
1493 InheritException(exception,&(*image)->exception);
1494 break;
1495 }
1496 if (LocaleCompare("evaluate",option+1) == 0)
1497 {
1498 double
1499 constant;
1500
1501 MagickEvaluateOperator
1502 op;
1503
cristy6b3da3a2010-06-20 02:21:46 +00001504 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001505 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1506 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001507 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001508 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1509 break;
1510 }
1511 if (LocaleCompare("extent",option+1) == 0)
1512 {
cristy3ed852e2009-09-05 21:47:34 +00001513 /*
1514 Set the image extent.
1515 */
cristy6b3da3a2010-06-20 02:21:46 +00001516 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001517 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001518 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001519 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001520 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001521 geometry.height=(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00001522 mogrify_image=ExtentImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00001523 break;
1524 }
1525 break;
1526 }
1527 case 'f':
1528 {
1529 if (LocaleCompare("family",option+1) == 0)
1530 {
1531 if (*option == '+')
1532 {
1533 if (draw_info->family != (char *) NULL)
1534 draw_info->family=DestroyString(draw_info->family);
1535 break;
1536 }
1537 (void) CloneString(&draw_info->family,argv[i+1]);
1538 break;
1539 }
cristy0fe961c2010-01-30 03:09:54 +00001540 if (LocaleCompare("features",option+1) == 0)
1541 {
1542 if (*option == '+')
1543 {
1544 (void) DeleteImageArtifact(*image,"identify:features");
1545 break;
1546 }
1547 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1548 break;
1549 }
cristy3ed852e2009-09-05 21:47:34 +00001550 if (LocaleCompare("fill",option+1) == 0)
1551 {
1552 ExceptionInfo
1553 *sans;
1554
1555 GetMagickPixelPacket(*image,&fill);
1556 if (*option == '+')
1557 {
1558 (void) QueryMagickColor("none",&fill,exception);
1559 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1560 if (draw_info->fill_pattern != (Image *) NULL)
1561 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1562 break;
1563 }
1564 sans=AcquireExceptionInfo();
1565 (void) QueryMagickColor(argv[i+1],&fill,sans);
1566 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1567 sans=DestroyExceptionInfo(sans);
1568 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001569 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001570 exception);
1571 break;
1572 }
1573 if (LocaleCompare("flip",option+1) == 0)
1574 {
cristy3ed852e2009-09-05 21:47:34 +00001575 /*
1576 Flip image scanlines.
1577 */
cristy6b3da3a2010-06-20 02:21:46 +00001578 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001579 mogrify_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001580 break;
1581 }
1582 if (LocaleCompare("flop",option+1) == 0)
1583 {
cristy3ed852e2009-09-05 21:47:34 +00001584 /*
1585 Flop image scanlines.
1586 */
cristy6b3da3a2010-06-20 02:21:46 +00001587 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001588 mogrify_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001589 break;
1590 }
1591 if (LocaleCompare("floodfill",option+1) == 0)
1592 {
1593 MagickPixelPacket
1594 target;
1595
1596 /*
1597 Floodfill image.
1598 */
cristy6b3da3a2010-06-20 02:21:46 +00001599 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001600 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1601 (void) QueryMagickColor(argv[i+2],&target,exception);
1602 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1603 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1604 InheritException(exception,&(*image)->exception);
1605 break;
1606 }
1607 if (LocaleCompare("font",option+1) == 0)
1608 {
1609 if (*option == '+')
1610 {
1611 if (draw_info->font != (char *) NULL)
1612 draw_info->font=DestroyString(draw_info->font);
1613 break;
1614 }
1615 (void) CloneString(&draw_info->font,argv[i+1]);
1616 break;
1617 }
1618 if (LocaleCompare("format",option+1) == 0)
1619 {
1620 format=argv[i+1];
1621 break;
1622 }
1623 if (LocaleCompare("frame",option+1) == 0)
1624 {
1625 FrameInfo
1626 frame_info;
1627
cristy3ed852e2009-09-05 21:47:34 +00001628 /*
1629 Surround image with an ornamental border.
1630 */
cristy6b3da3a2010-06-20 02:21:46 +00001631 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001632 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1633 frame_info.width=geometry.width;
1634 frame_info.height=geometry.height;
1635 if ((flags & HeightValue) == 0)
1636 frame_info.height=geometry.width;
1637 frame_info.outer_bevel=geometry.x;
1638 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001639 frame_info.x=(ssize_t) frame_info.width;
1640 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001641 frame_info.width=(*image)->columns+2*frame_info.width;
1642 frame_info.height=(*image)->rows+2*frame_info.height;
cristyd241f442011-03-29 13:50:49 +00001643 mogrify_image=FrameImage(*image,&frame_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00001644 break;
1645 }
1646 if (LocaleCompare("function",option+1) == 0)
1647 {
1648 char
1649 *arguments,
1650 token[MaxTextExtent];
1651
1652 const char
1653 *p;
1654
1655 double
1656 *parameters;
1657
1658 MagickFunction
1659 function;
1660
cristybb503372010-05-27 20:51:26 +00001661 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001662 x;
1663
cristybb503372010-05-27 20:51:26 +00001664 size_t
cristy3ed852e2009-09-05 21:47:34 +00001665 number_parameters;
1666
1667 /*
1668 Function Modify Image Values
1669 */
cristy6b3da3a2010-06-20 02:21:46 +00001670 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001671 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1672 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001673 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001674 InheritException(exception,&(*image)->exception);
1675 if (arguments == (char *) NULL)
1676 break;
1677 p=(char *) arguments;
1678 for (x=0; *p != '\0'; x++)
1679 {
1680 GetMagickToken(p,&p,token);
1681 if (*token == ',')
1682 GetMagickToken(p,&p,token);
1683 }
cristybb503372010-05-27 20:51:26 +00001684 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001685 parameters=(double *) AcquireQuantumMemory(number_parameters,
1686 sizeof(*parameters));
1687 if (parameters == (double *) NULL)
1688 ThrowWandFatalException(ResourceLimitFatalError,
1689 "MemoryAllocationFailed",(*image)->filename);
1690 (void) ResetMagickMemory(parameters,0,number_parameters*
1691 sizeof(*parameters));
1692 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001693 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001694 {
1695 GetMagickToken(p,&p,token);
1696 if (*token == ',')
1697 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001698 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001699 }
1700 arguments=DestroyString(arguments);
1701 (void) FunctionImageChannel(*image,channel,function,
1702 number_parameters,parameters,exception);
1703 parameters=(double *) RelinquishMagickMemory(parameters);
1704 break;
1705 }
1706 break;
1707 }
1708 case 'g':
1709 {
1710 if (LocaleCompare("gamma",option+1) == 0)
1711 {
1712 /*
1713 Gamma image.
1714 */
cristy6b3da3a2010-06-20 02:21:46 +00001715 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001716 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001717 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001718 else
1719 {
1720 if (strchr(argv[i+1],',') != (char *) NULL)
1721 (void) GammaImage(*image,argv[i+1]);
1722 else
cristya5447be2010-01-11 00:20:51 +00001723 (void) GammaImageChannel(*image,channel,
1724 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001725 InheritException(exception,&(*image)->exception);
1726 }
1727 break;
1728 }
1729 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1730 (LocaleCompare("gaussian",option+1) == 0))
1731 {
cristy3ed852e2009-09-05 21:47:34 +00001732 /*
1733 Gaussian blur image.
1734 */
cristy6b3da3a2010-06-20 02:21:46 +00001735 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001736 flags=ParseGeometry(argv[i+1],&geometry_info);
1737 if ((flags & SigmaValue) == 0)
1738 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001739 mogrify_image=GaussianBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00001740 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001741 break;
1742 }
1743 if (LocaleCompare("geometry",option+1) == 0)
1744 {
anthonye9c27192011-03-27 08:07:06 +00001745 /*
1746 Record Image offset, Resize last image.
1747 */
cristy6b3da3a2010-06-20 02:21:46 +00001748 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001749 if (*option == '+')
1750 {
1751 if ((*image)->geometry != (char *) NULL)
1752 (*image)->geometry=DestroyString((*image)->geometry);
1753 break;
1754 }
1755 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1756 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1757 (void) CloneString(&(*image)->geometry,argv[i+1]);
1758 else
cristyd241f442011-03-29 13:50:49 +00001759 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
anthonye9c27192011-03-27 08:07:06 +00001760 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00001761 break;
1762 }
1763 if (LocaleCompare("gravity",option+1) == 0)
1764 {
1765 if (*option == '+')
1766 {
1767 draw_info->gravity=UndefinedGravity;
1768 break;
1769 }
1770 draw_info->gravity=(GravityType) ParseMagickOption(
1771 MagickGravityOptions,MagickFalse,argv[i+1]);
1772 break;
1773 }
1774 break;
1775 }
1776 case 'h':
1777 {
1778 if (LocaleCompare("highlight-color",option+1) == 0)
1779 {
1780 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1781 break;
1782 }
1783 break;
1784 }
1785 case 'i':
1786 {
1787 if (LocaleCompare("identify",option+1) == 0)
1788 {
1789 char
1790 *text;
1791
cristy6b3da3a2010-06-20 02:21:46 +00001792 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001793 if (format == (char *) NULL)
1794 {
cristy6b3da3a2010-06-20 02:21:46 +00001795 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001796 InheritException(exception,&(*image)->exception);
1797 break;
1798 }
cristy6b3da3a2010-06-20 02:21:46 +00001799 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001800 InheritException(exception,&(*image)->exception);
1801 if (text == (char *) NULL)
1802 break;
1803 (void) fputs(text,stdout);
1804 (void) fputc('\n',stdout);
1805 text=DestroyString(text);
1806 break;
1807 }
1808 if (LocaleCompare("implode",option+1) == 0)
1809 {
cristy3ed852e2009-09-05 21:47:34 +00001810 /*
1811 Implode image.
1812 */
cristy6b3da3a2010-06-20 02:21:46 +00001813 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001814 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00001815 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001816 break;
1817 }
cristyb32b90a2009-09-07 21:45:48 +00001818 if (LocaleCompare("interline-spacing",option+1) == 0)
1819 {
1820 if (*option == '+')
1821 (void) ParseGeometry("0",&geometry_info);
1822 else
1823 (void) ParseGeometry(argv[i+1],&geometry_info);
1824 draw_info->interline_spacing=geometry_info.rho;
1825 break;
1826 }
cristy3ed852e2009-09-05 21:47:34 +00001827 if (LocaleCompare("interword-spacing",option+1) == 0)
1828 {
1829 if (*option == '+')
1830 (void) ParseGeometry("0",&geometry_info);
1831 else
1832 (void) ParseGeometry(argv[i+1],&geometry_info);
1833 draw_info->interword_spacing=geometry_info.rho;
1834 break;
1835 }
1836 break;
1837 }
1838 case 'k':
1839 {
1840 if (LocaleCompare("kerning",option+1) == 0)
1841 {
1842 if (*option == '+')
1843 (void) ParseGeometry("0",&geometry_info);
1844 else
1845 (void) ParseGeometry(argv[i+1],&geometry_info);
1846 draw_info->kerning=geometry_info.rho;
1847 break;
1848 }
1849 break;
1850 }
1851 case 'l':
1852 {
1853 if (LocaleCompare("lat",option+1) == 0)
1854 {
cristy3ed852e2009-09-05 21:47:34 +00001855 /*
1856 Local adaptive threshold image.
1857 */
cristy6b3da3a2010-06-20 02:21:46 +00001858 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001859 flags=ParseGeometry(argv[i+1],&geometry_info);
1860 if ((flags & PercentValue) != 0)
1861 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00001862 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1863 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1864 geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001865 break;
1866 }
1867 if (LocaleCompare("level",option+1) == 0)
1868 {
cristy3ed852e2009-09-05 21:47:34 +00001869 MagickRealType
1870 black_point,
1871 gamma,
1872 white_point;
1873
1874 MagickStatusType
1875 flags;
1876
1877 /*
1878 Parse levels.
1879 */
cristy6b3da3a2010-06-20 02:21:46 +00001880 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001881 flags=ParseGeometry(argv[i+1],&geometry_info);
1882 black_point=geometry_info.rho;
1883 white_point=(MagickRealType) QuantumRange;
1884 if ((flags & SigmaValue) != 0)
1885 white_point=geometry_info.sigma;
1886 gamma=1.0;
1887 if ((flags & XiValue) != 0)
1888 gamma=geometry_info.xi;
1889 if ((flags & PercentValue) != 0)
1890 {
1891 black_point*=(MagickRealType) (QuantumRange/100.0);
1892 white_point*=(MagickRealType) (QuantumRange/100.0);
1893 }
1894 if ((flags & SigmaValue) == 0)
1895 white_point=(MagickRealType) QuantumRange-black_point;
1896 if ((*option == '+') || ((flags & AspectValue) != 0))
1897 (void) LevelizeImageChannel(*image,channel,black_point,
1898 white_point,gamma);
1899 else
1900 (void) LevelImageChannel(*image,channel,black_point,white_point,
1901 gamma);
1902 InheritException(exception,&(*image)->exception);
1903 break;
1904 }
1905 if (LocaleCompare("level-colors",option+1) == 0)
1906 {
1907 char
1908 token[MaxTextExtent];
1909
1910 const char
1911 *p;
1912
1913 MagickPixelPacket
1914 black_point,
1915 white_point;
1916
1917 p=(const char *) argv[i+1];
1918 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00001919 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001920 (void) QueryMagickColor(token,&black_point,exception);
1921 else
cristyee0f8d72009-09-19 00:58:29 +00001922 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001923 if (isalpha((int) token[0]) || (token[0] == '#'))
1924 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00001925 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00001926 white_point=black_point; /* set everything to that color */
1927 else
1928 {
cristyee0f8d72009-09-19 00:58:29 +00001929 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
anthonye9c27192011-03-27 08:07:06 +00001930 GetMagickToken(p,&p,token); /* Get white point color. */
cristyee0f8d72009-09-19 00:58:29 +00001931 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001932 (void) QueryMagickColor(token,&white_point,exception);
1933 else
cristyee0f8d72009-09-19 00:58:29 +00001934 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001935 }
cristy74fe8f12009-10-03 19:09:01 +00001936 (void) LevelColorsImageChannel(*image,channel,&black_point,
1937 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001938 break;
1939 }
1940 if (LocaleCompare("linear-stretch",option+1) == 0)
1941 {
1942 double
1943 black_point,
1944 white_point;
1945
cristy3ed852e2009-09-05 21:47:34 +00001946 MagickStatusType
1947 flags;
1948
cristy6b3da3a2010-06-20 02:21:46 +00001949 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001950 flags=ParseGeometry(argv[i+1],&geometry_info);
1951 black_point=geometry_info.rho;
1952 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1953 if ((flags & SigmaValue) != 0)
1954 white_point=geometry_info.sigma;
1955 if ((flags & PercentValue) != 0)
1956 {
1957 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1958 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1959 }
1960 if ((flags & SigmaValue) == 0)
1961 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1962 black_point;
1963 (void) LinearStretchImage(*image,black_point,white_point);
1964 InheritException(exception,&(*image)->exception);
1965 break;
1966 }
1967 if (LocaleCompare("linewidth",option+1) == 0)
1968 {
cristyf2f27272009-12-17 14:48:46 +00001969 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001970 break;
1971 }
1972 if (LocaleCompare("liquid-rescale",option+1) == 0)
1973 {
cristy3ed852e2009-09-05 21:47:34 +00001974 /*
1975 Liquid rescale image.
1976 */
cristy6b3da3a2010-06-20 02:21:46 +00001977 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001978 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1979 if ((flags & XValue) == 0)
1980 geometry.x=1;
1981 if ((flags & YValue) == 0)
1982 geometry.y=0;
cristyd241f442011-03-29 13:50:49 +00001983 mogrify_image=LiquidRescaleImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +00001984 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00001985 break;
1986 }
1987 if (LocaleCompare("lowlight-color",option+1) == 0)
1988 {
1989 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1990 break;
1991 }
1992 break;
1993 }
1994 case 'm':
1995 {
1996 if (LocaleCompare("map",option+1) == 0)
1997 {
1998 Image
1999 *remap_image;
2000
2001 /*
2002 Transform image colors to match this set of colors.
2003 */
cristy6b3da3a2010-06-20 02:21:46 +00002004 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002005 if (*option == '+')
2006 break;
cristy6b3da3a2010-06-20 02:21:46 +00002007 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002008 if (remap_image == (Image *) NULL)
2009 break;
2010 (void) RemapImage(quantize_info,*image,remap_image);
2011 InheritException(exception,&(*image)->exception);
2012 remap_image=DestroyImage(remap_image);
2013 break;
2014 }
2015 if (LocaleCompare("mask",option+1) == 0)
2016 {
2017 Image
2018 *mask;
2019
cristy6b3da3a2010-06-20 02:21:46 +00002020 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002021 if (*option == '+')
2022 {
2023 /*
2024 Remove a mask.
2025 */
2026 (void) SetImageMask(*image,(Image *) NULL);
2027 InheritException(exception,&(*image)->exception);
2028 break;
2029 }
2030 /*
2031 Set the image mask.
2032 */
cristy6b3da3a2010-06-20 02:21:46 +00002033 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002034 if (mask == (Image *) NULL)
2035 break;
2036 (void) SetImageMask(*image,mask);
2037 mask=DestroyImage(mask);
2038 InheritException(exception,&(*image)->exception);
2039 break;
2040 }
2041 if (LocaleCompare("matte",option+1) == 0)
2042 {
2043 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2044 SetAlphaChannel : DeactivateAlphaChannel );
2045 InheritException(exception,&(*image)->exception);
2046 break;
2047 }
2048 if (LocaleCompare("median",option+1) == 0)
2049 {
cristy3ed852e2009-09-05 21:47:34 +00002050 /*
2051 Median filter image.
2052 */
cristy6b3da3a2010-06-20 02:21:46 +00002053 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002054 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002055 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
cristy95c38342011-03-18 22:39:51 +00002056 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002057 break;
2058 }
cristy69ec32d2011-02-27 23:57:09 +00002059 if (LocaleCompare("mode",option+1) == 0)
2060 {
cristy69ec32d2011-02-27 23:57:09 +00002061 /*
2062 Mode image.
2063 */
2064 (void) SyncImageSettings(mogrify_info,*image);
2065 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002066 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
cristy95c38342011-03-18 22:39:51 +00002067 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy69ec32d2011-02-27 23:57:09 +00002068 break;
2069 }
cristy3ed852e2009-09-05 21:47:34 +00002070 if (LocaleCompare("modulate",option+1) == 0)
2071 {
cristy6b3da3a2010-06-20 02:21:46 +00002072 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002073 (void) ModulateImage(*image,argv[i+1]);
2074 InheritException(exception,&(*image)->exception);
2075 break;
2076 }
2077 if (LocaleCompare("monitor",option+1) == 0)
2078 {
cristy7d34ef22010-03-25 01:11:22 +00002079 if (*option == '+')
2080 {
2081 (void) SetImageProgressMonitor(*image,
2082 (MagickProgressMonitor) NULL,(void *) NULL);
2083 break;
2084 }
cristy3ed852e2009-09-05 21:47:34 +00002085 (void) SetImageProgressMonitor(*image,MonitorProgress,
2086 (void *) NULL);
2087 break;
2088 }
2089 if (LocaleCompare("monochrome",option+1) == 0)
2090 {
cristy6b3da3a2010-06-20 02:21:46 +00002091 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002092 (void) SetImageType(*image,BilevelType);
2093 InheritException(exception,&(*image)->exception);
2094 break;
2095 }
anthony29188a82010-01-22 10:12:34 +00002096 if (LocaleCompare("morphology",option+1) == 0)
2097 {
anthony29188a82010-01-22 10:12:34 +00002098 char
2099 token[MaxTextExtent];
2100
2101 const char
2102 *p;
2103
cristye96405a2010-05-19 02:24:31 +00002104 KernelInfo
2105 *kernel;
2106
cristye96405a2010-05-19 02:24:31 +00002107 MorphologyMethod
2108 method;
2109
cristy9d314ff2011-03-09 01:30:28 +00002110 ssize_t
2111 iterations;
2112
anthony29188a82010-01-22 10:12:34 +00002113 /*
2114 Morphological Image Operation
2115 */
cristy6b3da3a2010-06-20 02:21:46 +00002116 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002117 p=argv[i+1];
2118 GetMagickToken(p,&p,token);
2119 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002120 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002121 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002122 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002123 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002124 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002125 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002126 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002127 kernel=AcquireKernelInfo(argv[i+2]);
2128 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002129 {
2130 (void) ThrowMagickException(exception,GetMagickModule(),
2131 OptionError,"UnabletoParseKernel","morphology");
2132 status=MagickFalse;
2133 break;
2134 }
cristyd241f442011-03-29 13:50:49 +00002135 mogrify_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002136 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002137 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002138 break;
2139 }
cristy3ed852e2009-09-05 21:47:34 +00002140 if (LocaleCompare("motion-blur",option+1) == 0)
2141 {
cristy3ed852e2009-09-05 21:47:34 +00002142 /*
2143 Motion blur image.
2144 */
cristy6b3da3a2010-06-20 02:21:46 +00002145 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002146 flags=ParseGeometry(argv[i+1],&geometry_info);
2147 if ((flags & SigmaValue) == 0)
2148 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002149 mogrify_image=MotionBlurImageChannel(*image,channel,
2150 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002151 break;
2152 }
2153 break;
2154 }
2155 case 'n':
2156 {
2157 if (LocaleCompare("negate",option+1) == 0)
2158 {
cristy6b3da3a2010-06-20 02:21:46 +00002159 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002160 (void) NegateImageChannel(*image,channel,*option == '+' ?
2161 MagickTrue : MagickFalse);
2162 InheritException(exception,&(*image)->exception);
2163 break;
2164 }
2165 if (LocaleCompare("noise",option+1) == 0)
2166 {
cristy6b3da3a2010-06-20 02:21:46 +00002167 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002168 if (*option == '-')
2169 {
2170 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002171 mogrify_image=StatisticImageChannel(*image,channel,
cristy95c38342011-03-18 22:39:51 +00002172 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2173 geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002174 }
2175 else
2176 {
2177 NoiseType
2178 noise;
2179
2180 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2181 MagickFalse,argv[i+1]);
cristyd241f442011-03-29 13:50:49 +00002182 mogrify_image=AddNoiseImageChannel(*image,channel,noise,
cristy3ed852e2009-09-05 21:47:34 +00002183 exception);
2184 }
cristy3ed852e2009-09-05 21:47:34 +00002185 break;
2186 }
2187 if (LocaleCompare("normalize",option+1) == 0)
2188 {
cristy6b3da3a2010-06-20 02:21:46 +00002189 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002190 (void) NormalizeImageChannel(*image,channel);
2191 InheritException(exception,&(*image)->exception);
2192 break;
2193 }
2194 break;
2195 }
2196 case 'o':
2197 {
2198 if (LocaleCompare("opaque",option+1) == 0)
2199 {
2200 MagickPixelPacket
2201 target;
2202
cristy6b3da3a2010-06-20 02:21:46 +00002203 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002204 (void) QueryMagickColor(argv[i+1],&target,exception);
2205 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2206 *option == '-' ? MagickFalse : MagickTrue);
2207 break;
2208 }
2209 if (LocaleCompare("ordered-dither",option+1) == 0)
2210 {
cristy6b3da3a2010-06-20 02:21:46 +00002211 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002212 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2213 exception);
2214 break;
2215 }
2216 break;
2217 }
2218 case 'p':
2219 {
2220 if (LocaleCompare("paint",option+1) == 0)
2221 {
2222 Image
2223 *paint_image;
2224
2225 /*
2226 Oil paint image.
2227 */
cristy6b3da3a2010-06-20 02:21:46 +00002228 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002229 (void) ParseGeometry(argv[i+1],&geometry_info);
2230 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2231 if (paint_image == (Image *) NULL)
2232 break;
2233 *image=DestroyImage(*image);
2234 *image=paint_image;
2235 break;
2236 }
2237 if (LocaleCompare("pen",option+1) == 0)
2238 {
2239 if (*option == '+')
2240 {
2241 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2242 break;
2243 }
2244 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2245 break;
2246 }
2247 if (LocaleCompare("pointsize",option+1) == 0)
2248 {
2249 if (*option == '+')
2250 (void) ParseGeometry("12",&geometry_info);
2251 else
2252 (void) ParseGeometry(argv[i+1],&geometry_info);
2253 draw_info->pointsize=geometry_info.rho;
2254 break;
2255 }
2256 if (LocaleCompare("polaroid",option+1) == 0)
2257 {
2258 double
2259 angle;
2260
cristy3ed852e2009-09-05 21:47:34 +00002261 RandomInfo
2262 *random_info;
2263
2264 /*
2265 Simulate a Polaroid picture.
2266 */
cristy6b3da3a2010-06-20 02:21:46 +00002267 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002268 random_info=AcquireRandomInfo();
2269 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2270 random_info=DestroyRandomInfo(random_info);
2271 if (*option == '-')
2272 {
2273 SetGeometryInfo(&geometry_info);
2274 flags=ParseGeometry(argv[i+1],&geometry_info);
2275 angle=geometry_info.rho;
2276 }
cristyd241f442011-03-29 13:50:49 +00002277 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
cristy3ed852e2009-09-05 21:47:34 +00002278 break;
2279 }
2280 if (LocaleCompare("posterize",option+1) == 0)
2281 {
2282 /*
2283 Posterize image.
2284 */
cristy6b3da3a2010-06-20 02:21:46 +00002285 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002286 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002287 quantize_info->dither);
2288 InheritException(exception,&(*image)->exception);
2289 break;
2290 }
2291 if (LocaleCompare("preview",option+1) == 0)
2292 {
cristy3ed852e2009-09-05 21:47:34 +00002293 PreviewType
2294 preview_type;
2295
2296 /*
2297 Preview image.
2298 */
cristy6b3da3a2010-06-20 02:21:46 +00002299 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002300 if (*option == '+')
2301 preview_type=UndefinedPreview;
2302 else
2303 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2304 MagickFalse,argv[i+1]);
cristyd241f442011-03-29 13:50:49 +00002305 mogrify_image=PreviewImage(*image,preview_type,exception);
cristy3ed852e2009-09-05 21:47:34 +00002306 break;
2307 }
2308 if (LocaleCompare("profile",option+1) == 0)
2309 {
2310 const char
2311 *name;
2312
2313 const StringInfo
2314 *profile;
2315
2316 Image
2317 *profile_image;
2318
2319 ImageInfo
2320 *profile_info;
2321
cristy6b3da3a2010-06-20 02:21:46 +00002322 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002323 if (*option == '+')
2324 {
2325 /*
2326 Remove a profile from the image.
2327 */
2328 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2329 NULL,0,MagickTrue);
2330 InheritException(exception,&(*image)->exception);
2331 break;
2332 }
2333 /*
2334 Associate a profile with the image.
2335 */
cristy6b3da3a2010-06-20 02:21:46 +00002336 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002337 profile=GetImageProfile(*image,"iptc");
2338 if (profile != (StringInfo *) NULL)
2339 profile_info->profile=(void *) CloneStringInfo(profile);
2340 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2341 profile_info=DestroyImageInfo(profile_info);
2342 if (profile_image == (Image *) NULL)
2343 {
cristy3ed852e2009-09-05 21:47:34 +00002344 StringInfo
2345 *profile;
2346
cristy6b3da3a2010-06-20 02:21:46 +00002347 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002348 (void) CopyMagickString(profile_info->filename,argv[i+1],
2349 MaxTextExtent);
2350 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002351 if (profile != (StringInfo *) NULL)
2352 {
cristy071dd7b2010-04-09 13:04:54 +00002353 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002354 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002355 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002356 profile=DestroyStringInfo(profile);
2357 }
cristy071dd7b2010-04-09 13:04:54 +00002358 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002359 break;
2360 }
2361 ResetImageProfileIterator(profile_image);
2362 name=GetNextImageProfile(profile_image);
2363 while (name != (const char *) NULL)
2364 {
2365 profile=GetImageProfile(profile_image,name);
2366 if (profile != (StringInfo *) NULL)
2367 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002368 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002369 name=GetNextImageProfile(profile_image);
2370 }
2371 profile_image=DestroyImage(profile_image);
2372 break;
2373 }
2374 break;
2375 }
2376 case 'q':
2377 {
2378 if (LocaleCompare("quantize",option+1) == 0)
2379 {
2380 if (*option == '+')
2381 {
2382 quantize_info->colorspace=UndefinedColorspace;
2383 break;
2384 }
2385 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2386 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2387 break;
2388 }
2389 break;
2390 }
2391 case 'r':
2392 {
2393 if (LocaleCompare("radial-blur",option+1) == 0)
2394 {
cristy3ed852e2009-09-05 21:47:34 +00002395 /*
2396 Radial blur image.
2397 */
cristy6b3da3a2010-06-20 02:21:46 +00002398 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002399 mogrify_image=RadialBlurImageChannel(*image,channel,
cristya5447be2010-01-11 00:20:51 +00002400 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002401 break;
2402 }
2403 if (LocaleCompare("raise",option+1) == 0)
2404 {
2405 /*
2406 Surround image with a raise of solid color.
2407 */
2408 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2409 if ((flags & SigmaValue) == 0)
2410 geometry.height=geometry.width;
2411 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2412 MagickFalse);
2413 InheritException(exception,&(*image)->exception);
2414 break;
2415 }
2416 if (LocaleCompare("random-threshold",option+1) == 0)
2417 {
2418 /*
2419 Threshold image.
2420 */
cristy6b3da3a2010-06-20 02:21:46 +00002421 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002422 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2423 exception);
2424 break;
2425 }
2426 if (LocaleCompare("recolor",option+1) == 0)
2427 {
cristyf055ae42010-04-02 23:01:38 +00002428 KernelInfo
2429 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002430
cristy6b3da3a2010-06-20 02:21:46 +00002431 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002432 kernel=AcquireKernelInfo(argv[i+1]);
2433 if (kernel == (KernelInfo *) NULL)
2434 break;
cristyd241f442011-03-29 13:50:49 +00002435 mogrify_image=ColorMatrixImage(*image,kernel,exception);
cristyf055ae42010-04-02 23:01:38 +00002436 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00002437 break;
2438 }
2439 if (LocaleCompare("region",option+1) == 0)
2440 {
cristy6b3da3a2010-06-20 02:21:46 +00002441 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002442 if (region_image != (Image *) NULL)
2443 {
2444 /*
2445 Composite region.
2446 */
anthonye9c27192011-03-27 08:07:06 +00002447 (void) CompositeImage(region_image, CopyCompositeOp,*image,
cristy3ed852e2009-09-05 21:47:34 +00002448 region_geometry.x,region_geometry.y);
2449 InheritException(exception,&region_image->exception);
2450 *image=DestroyImage(*image);
2451 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00002452 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002453 }
2454 if (*option == '+')
anthonye9c27192011-03-27 08:07:06 +00002455 break;
cristy3ed852e2009-09-05 21:47:34 +00002456 /*
2457 Apply transformations to a selected region of the image.
2458 */
2459 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2460 exception);
cristyd241f442011-03-29 13:50:49 +00002461 mogrify_image=CropImage(*image,&region_geometry,exception);
2462 if (mogrify_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002463 break;
2464 region_image=(*image);
cristyd241f442011-03-29 13:50:49 +00002465 *image=mogrify_image;
2466 mogrify_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002467 break;
2468 }
2469 if (LocaleCompare("render",option+1) == 0)
2470 {
cristy6b3da3a2010-06-20 02:21:46 +00002471 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002472 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2473 break;
2474 }
2475 if (LocaleCompare("remap",option+1) == 0)
2476 {
2477 Image
2478 *remap_image;
2479
2480 /*
2481 Transform image colors to match this set of colors.
2482 */
cristy6b3da3a2010-06-20 02:21:46 +00002483 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002484 if (*option == '+')
2485 break;
cristy6b3da3a2010-06-20 02:21:46 +00002486 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002487 if (remap_image == (Image *) NULL)
2488 break;
2489 (void) RemapImage(quantize_info,*image,remap_image);
2490 InheritException(exception,&(*image)->exception);
2491 remap_image=DestroyImage(remap_image);
2492 break;
2493 }
2494 if (LocaleCompare("repage",option+1) == 0)
2495 {
2496 if (*option == '+')
2497 {
2498 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2499 break;
2500 }
2501 (void) ResetImagePage(*image,argv[i+1]);
2502 InheritException(exception,&(*image)->exception);
2503 break;
2504 }
2505 if (LocaleCompare("resample",option+1) == 0)
2506 {
cristy3ed852e2009-09-05 21:47:34 +00002507 /*
2508 Resample image.
2509 */
cristy6b3da3a2010-06-20 02:21:46 +00002510 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002511 flags=ParseGeometry(argv[i+1],&geometry_info);
2512 if ((flags & SigmaValue) == 0)
2513 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002514 mogrify_image=ResampleImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002515 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002516 break;
2517 }
2518 if (LocaleCompare("resize",option+1) == 0)
2519 {
cristy3ed852e2009-09-05 21:47:34 +00002520 /*
2521 Resize image.
2522 */
cristy6b3da3a2010-06-20 02:21:46 +00002523 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002524 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002525 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002526 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002527 break;
2528 }
cristy3ed852e2009-09-05 21:47:34 +00002529 if (LocaleCompare("roll",option+1) == 0)
2530 {
cristy3ed852e2009-09-05 21:47:34 +00002531 /*
2532 Roll image.
2533 */
cristy6b3da3a2010-06-20 02:21:46 +00002534 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002535 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002536 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00002537 break;
2538 }
2539 if (LocaleCompare("rotate",option+1) == 0)
2540 {
2541 char
2542 *geometry;
2543
cristy3ed852e2009-09-05 21:47:34 +00002544 /*
2545 Check for conditional image rotation.
2546 */
cristy6b3da3a2010-06-20 02:21:46 +00002547 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002548 if (strchr(argv[i+1],'>') != (char *) NULL)
2549 if ((*image)->columns <= (*image)->rows)
2550 break;
2551 if (strchr(argv[i+1],'<') != (char *) NULL)
2552 if ((*image)->columns >= (*image)->rows)
2553 break;
2554 /*
2555 Rotate image.
2556 */
2557 geometry=ConstantString(argv[i+1]);
2558 (void) SubstituteString(&geometry,">","");
2559 (void) SubstituteString(&geometry,"<","");
2560 (void) ParseGeometry(geometry,&geometry_info);
2561 geometry=DestroyString(geometry);
cristyd241f442011-03-29 13:50:49 +00002562 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002563 break;
2564 }
2565 break;
2566 }
2567 case 's':
2568 {
2569 if (LocaleCompare("sample",option+1) == 0)
2570 {
cristy3ed852e2009-09-05 21:47:34 +00002571 /*
2572 Sample image with pixel replication.
2573 */
cristy6b3da3a2010-06-20 02:21:46 +00002574 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002575 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002576 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002577 exception);
cristy3ed852e2009-09-05 21:47:34 +00002578 break;
2579 }
2580 if (LocaleCompare("scale",option+1) == 0)
2581 {
cristy3ed852e2009-09-05 21:47:34 +00002582 /*
2583 Resize image.
2584 */
cristy6b3da3a2010-06-20 02:21:46 +00002585 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002586 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002587 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002588 exception);
cristy3ed852e2009-09-05 21:47:34 +00002589 break;
2590 }
2591 if (LocaleCompare("selective-blur",option+1) == 0)
2592 {
cristy3ed852e2009-09-05 21:47:34 +00002593 /*
2594 Selectively blur pixels within a contrast threshold.
2595 */
cristy6b3da3a2010-06-20 02:21:46 +00002596 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002597 flags=ParseGeometry(argv[i+1],&geometry_info);
2598 if ((flags & PercentValue) != 0)
2599 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00002600 mogrify_image=SelectiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00002601 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002602 break;
2603 }
2604 if (LocaleCompare("separate",option+1) == 0)
2605 {
cristy3ed852e2009-09-05 21:47:34 +00002606 /*
2607 Break channels into separate images.
anthonye9c27192011-03-27 08:07:06 +00002608 WARNING: This can generate multiple images!
cristy3ed852e2009-09-05 21:47:34 +00002609 */
cristy6b3da3a2010-06-20 02:21:46 +00002610 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002611 mogrify_image=SeparateImages(*image,channel,exception);
cristy3ed852e2009-09-05 21:47:34 +00002612 break;
2613 }
2614 if (LocaleCompare("sepia-tone",option+1) == 0)
2615 {
2616 double
2617 threshold;
2618
cristy3ed852e2009-09-05 21:47:34 +00002619 /*
2620 Sepia-tone image.
2621 */
cristy6b3da3a2010-06-20 02:21:46 +00002622 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002623 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00002624 mogrify_image=SepiaToneImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00002625 break;
2626 }
2627 if (LocaleCompare("segment",option+1) == 0)
2628 {
2629 /*
2630 Segment image.
2631 */
cristy6b3da3a2010-06-20 02:21:46 +00002632 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002633 flags=ParseGeometry(argv[i+1],&geometry_info);
2634 if ((flags & SigmaValue) == 0)
2635 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002636 (void) SegmentImage(*image,(*image)->colorspace,
2637 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002638 InheritException(exception,&(*image)->exception);
2639 break;
2640 }
2641 if (LocaleCompare("set",option+1) == 0)
2642 {
cristy6d9a1292010-05-31 14:17:06 +00002643 char
2644 *value;
2645
cristy3ed852e2009-09-05 21:47:34 +00002646 /*
2647 Set image option.
2648 */
cristy6d9a1292010-05-31 14:17:06 +00002649 if (*option == '+')
2650 {
2651 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2652 (void) DeleteImageRegistry(argv[i+1]+9);
2653 else
2654 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002655 {
cristy6b3da3a2010-06-20 02:21:46 +00002656 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002657 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2658 }
cristy6d9a1292010-05-31 14:17:06 +00002659 else
2660 (void) DeleteImageProperty(*image,argv[i+1]);
2661 break;
2662 }
cristy6b3da3a2010-06-20 02:21:46 +00002663 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002664 if (value == (char *) NULL)
2665 break;
cristy3ed852e2009-09-05 21:47:34 +00002666 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002667 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2668 exception);
cristy3ed852e2009-09-05 21:47:34 +00002669 else
2670 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002671 {
cristy7f02ba12010-09-21 12:39:28 +00002672 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002673 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002674 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2675 }
cristy3ed852e2009-09-05 21:47:34 +00002676 else
cristy6d9a1292010-05-31 14:17:06 +00002677 (void) SetImageProperty(*image,argv[i+1],value);
2678 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002679 break;
2680 }
2681 if (LocaleCompare("shade",option+1) == 0)
2682 {
cristy3ed852e2009-09-05 21:47:34 +00002683 /*
2684 Shade image.
2685 */
cristy6b3da3a2010-06-20 02:21:46 +00002686 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002687 flags=ParseGeometry(argv[i+1],&geometry_info);
2688 if ((flags & SigmaValue) == 0)
2689 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002690 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
cristy3ed852e2009-09-05 21:47:34 +00002691 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002692 break;
2693 }
2694 if (LocaleCompare("shadow",option+1) == 0)
2695 {
cristy3ed852e2009-09-05 21:47:34 +00002696 /*
2697 Shadow image.
2698 */
cristy6b3da3a2010-06-20 02:21:46 +00002699 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002700 flags=ParseGeometry(argv[i+1],&geometry_info);
2701 if ((flags & SigmaValue) == 0)
2702 geometry_info.sigma=1.0;
2703 if ((flags & XiValue) == 0)
2704 geometry_info.xi=4.0;
2705 if ((flags & PsiValue) == 0)
2706 geometry_info.psi=4.0;
cristyd241f442011-03-29 13:50:49 +00002707 mogrify_image=ShadowImage(*image,geometry_info.rho,
2708 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2709 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002710 break;
2711 }
2712 if (LocaleCompare("sharpen",option+1) == 0)
2713 {
cristy3ed852e2009-09-05 21:47:34 +00002714 /*
2715 Sharpen image.
2716 */
cristy6b3da3a2010-06-20 02:21:46 +00002717 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002718 flags=ParseGeometry(argv[i+1],&geometry_info);
2719 if ((flags & SigmaValue) == 0)
2720 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002721 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002722 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002723 break;
2724 }
2725 if (LocaleCompare("shave",option+1) == 0)
2726 {
cristy3ed852e2009-09-05 21:47:34 +00002727 /*
2728 Shave the image edges.
2729 */
cristy6b3da3a2010-06-20 02:21:46 +00002730 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002731 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002732 mogrify_image=ShaveImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002733 break;
2734 }
2735 if (LocaleCompare("shear",option+1) == 0)
2736 {
cristy3ed852e2009-09-05 21:47:34 +00002737 /*
2738 Shear image.
2739 */
cristy6b3da3a2010-06-20 02:21:46 +00002740 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002741 flags=ParseGeometry(argv[i+1],&geometry_info);
2742 if ((flags & SigmaValue) == 0)
2743 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002744 mogrify_image=ShearImage(*image,geometry_info.rho,
2745 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002746 break;
2747 }
2748 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2749 {
2750 /*
2751 Sigmoidal non-linearity contrast control.
2752 */
cristy6b3da3a2010-06-20 02:21:46 +00002753 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002754 flags=ParseGeometry(argv[i+1],&geometry_info);
2755 if ((flags & SigmaValue) == 0)
2756 geometry_info.sigma=(double) QuantumRange/2.0;
2757 if ((flags & PercentValue) != 0)
2758 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2759 100.0;
2760 (void) SigmoidalContrastImageChannel(*image,channel,
2761 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2762 geometry_info.sigma);
2763 InheritException(exception,&(*image)->exception);
2764 break;
2765 }
2766 if (LocaleCompare("sketch",option+1) == 0)
2767 {
cristy3ed852e2009-09-05 21:47:34 +00002768 /*
2769 Sketch image.
2770 */
cristy6b3da3a2010-06-20 02:21:46 +00002771 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002772 flags=ParseGeometry(argv[i+1],&geometry_info);
2773 if ((flags & SigmaValue) == 0)
2774 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002775 mogrify_image=SketchImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002776 geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002777 break;
2778 }
2779 if (LocaleCompare("solarize",option+1) == 0)
2780 {
2781 double
2782 threshold;
2783
cristy6b3da3a2010-06-20 02:21:46 +00002784 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002785 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002786 (void) SolarizeImage(*image,threshold);
2787 InheritException(exception,&(*image)->exception);
2788 break;
2789 }
2790 if (LocaleCompare("sparse-color",option+1) == 0)
2791 {
cristy3ed852e2009-09-05 21:47:34 +00002792 SparseColorMethod
2793 method;
2794
2795 char
2796 *arguments;
2797
2798 /*
2799 Sparse Color Interpolated Gradient
2800 */
cristy6b3da3a2010-06-20 02:21:46 +00002801 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002802 method=(SparseColorMethod) ParseMagickOption(
2803 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00002804 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00002805 InheritException(exception,&(*image)->exception);
2806 if (arguments == (char *) NULL)
2807 break;
cristyd241f442011-03-29 13:50:49 +00002808 mogrify_image=SparseColorOption(*image,channel,method,arguments,
cristy3ed852e2009-09-05 21:47:34 +00002809 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2810 arguments=DestroyString(arguments);
cristy3ed852e2009-09-05 21:47:34 +00002811 break;
2812 }
2813 if (LocaleCompare("splice",option+1) == 0)
2814 {
cristy3ed852e2009-09-05 21:47:34 +00002815 /*
2816 Splice a solid color into the image.
2817 */
cristy6b3da3a2010-06-20 02:21:46 +00002818 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002819 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002820 mogrify_image=SpliceImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002821 break;
2822 }
2823 if (LocaleCompare("spread",option+1) == 0)
2824 {
cristy3ed852e2009-09-05 21:47:34 +00002825 /*
2826 Spread an image.
2827 */
cristy6b3da3a2010-06-20 02:21:46 +00002828 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002829 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002830 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002831 break;
2832 }
cristy0834d642011-03-18 18:26:08 +00002833 if (LocaleCompare("statistic",option+1) == 0)
2834 {
cristy0834d642011-03-18 18:26:08 +00002835 StatisticType
2836 type;
2837
2838 (void) SyncImageSettings(mogrify_info,*image);
2839 type=(StatisticType) ParseMagickOption(MagickStatisticOptions,
2840 MagickFalse,argv[i+1]);
2841 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002842 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2843 geometry_info.rho,(size_t) geometry_info.sigma,exception);
cristy0834d642011-03-18 18:26:08 +00002844 break;
2845 }
cristy3ed852e2009-09-05 21:47:34 +00002846 if (LocaleCompare("stretch",option+1) == 0)
2847 {
2848 if (*option == '+')
2849 {
2850 draw_info->stretch=UndefinedStretch;
2851 break;
2852 }
2853 draw_info->stretch=(StretchType) ParseMagickOption(
2854 MagickStretchOptions,MagickFalse,argv[i+1]);
2855 break;
2856 }
2857 if (LocaleCompare("strip",option+1) == 0)
2858 {
2859 /*
2860 Strip image of profiles and comments.
2861 */
cristy6b3da3a2010-06-20 02:21:46 +00002862 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00002863 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00002864 InheritException(exception,&(*image)->exception);
2865 break;
2866 }
2867 if (LocaleCompare("stroke",option+1) == 0)
2868 {
2869 ExceptionInfo
2870 *sans;
2871
2872 if (*option == '+')
2873 {
2874 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2875 if (draw_info->stroke_pattern != (Image *) NULL)
2876 draw_info->stroke_pattern=DestroyImage(
2877 draw_info->stroke_pattern);
2878 break;
2879 }
2880 sans=AcquireExceptionInfo();
2881 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2882 sans=DestroyExceptionInfo(sans);
2883 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00002884 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002885 exception);
2886 break;
2887 }
2888 if (LocaleCompare("strokewidth",option+1) == 0)
2889 {
cristyf2f27272009-12-17 14:48:46 +00002890 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002891 break;
2892 }
2893 if (LocaleCompare("style",option+1) == 0)
2894 {
2895 if (*option == '+')
2896 {
2897 draw_info->style=UndefinedStyle;
2898 break;
2899 }
2900 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
2901 MagickFalse,argv[i+1]);
2902 break;
2903 }
2904 if (LocaleCompare("swirl",option+1) == 0)
2905 {
cristy3ed852e2009-09-05 21:47:34 +00002906 /*
2907 Swirl image.
2908 */
cristy6b3da3a2010-06-20 02:21:46 +00002909 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002910 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002911 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002912 break;
2913 }
2914 break;
2915 }
2916 case 't':
2917 {
2918 if (LocaleCompare("threshold",option+1) == 0)
2919 {
2920 double
2921 threshold;
2922
2923 /*
2924 Threshold image.
2925 */
cristy6b3da3a2010-06-20 02:21:46 +00002926 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002927 if (*option == '+')
2928 threshold=(double) QuantumRange/2.5;
2929 else
cristyf2f27272009-12-17 14:48:46 +00002930 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002931 (void) BilevelImageChannel(*image,channel,threshold);
2932 InheritException(exception,&(*image)->exception);
2933 break;
2934 }
2935 if (LocaleCompare("thumbnail",option+1) == 0)
2936 {
cristy3ed852e2009-09-05 21:47:34 +00002937 /*
2938 Thumbnail image.
2939 */
cristy6b3da3a2010-06-20 02:21:46 +00002940 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002941 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002942 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2943 exception);
cristy3ed852e2009-09-05 21:47:34 +00002944 break;
2945 }
2946 if (LocaleCompare("tile",option+1) == 0)
2947 {
2948 if (*option == '+')
2949 {
2950 if (draw_info->fill_pattern != (Image *) NULL)
2951 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2952 break;
2953 }
cristy6b3da3a2010-06-20 02:21:46 +00002954 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002955 exception);
2956 break;
2957 }
2958 if (LocaleCompare("tint",option+1) == 0)
2959 {
cristy3ed852e2009-09-05 21:47:34 +00002960 /*
2961 Tint the image.
2962 */
cristy6b3da3a2010-06-20 02:21:46 +00002963 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002964 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
cristy3ed852e2009-09-05 21:47:34 +00002965 break;
2966 }
2967 if (LocaleCompare("transform",option+1) == 0)
2968 {
cristy3ed852e2009-09-05 21:47:34 +00002969 /*
2970 Affine transform image.
2971 */
cristy6b3da3a2010-06-20 02:21:46 +00002972 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002973 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
cristy3ed852e2009-09-05 21:47:34 +00002974 exception);
cristy3ed852e2009-09-05 21:47:34 +00002975 break;
2976 }
2977 if (LocaleCompare("transparent",option+1) == 0)
2978 {
2979 MagickPixelPacket
2980 target;
2981
cristy6b3da3a2010-06-20 02:21:46 +00002982 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002983 (void) QueryMagickColor(argv[i+1],&target,exception);
2984 (void) TransparentPaintImage(*image,&target,(Quantum)
2985 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
2986 InheritException(exception,&(*image)->exception);
2987 break;
2988 }
2989 if (LocaleCompare("transpose",option+1) == 0)
2990 {
cristy3ed852e2009-09-05 21:47:34 +00002991 /*
2992 Transpose image scanlines.
2993 */
cristy6b3da3a2010-06-20 02:21:46 +00002994 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002995 mogrify_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002996 break;
2997 }
2998 if (LocaleCompare("transverse",option+1) == 0)
2999 {
cristy3ed852e2009-09-05 21:47:34 +00003000 /*
3001 Transverse image scanlines.
3002 */
cristy6b3da3a2010-06-20 02:21:46 +00003003 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003004 mogrify_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003005 break;
3006 }
3007 if (LocaleCompare("treedepth",option+1) == 0)
3008 {
cristye27293e2009-12-18 02:53:20 +00003009 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003010 break;
3011 }
3012 if (LocaleCompare("trim",option+1) == 0)
3013 {
cristy3ed852e2009-09-05 21:47:34 +00003014 /*
3015 Trim image.
3016 */
cristy6b3da3a2010-06-20 02:21:46 +00003017 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003018 mogrify_image=TrimImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003019 break;
3020 }
3021 if (LocaleCompare("type",option+1) == 0)
3022 {
3023 ImageType
3024 type;
3025
cristy6b3da3a2010-06-20 02:21:46 +00003026 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003027 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003028 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003029 else
3030 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3031 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003032 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003033 (void) SetImageType(*image,type);
3034 InheritException(exception,&(*image)->exception);
3035 break;
3036 }
3037 break;
3038 }
3039 case 'u':
3040 {
3041 if (LocaleCompare("undercolor",option+1) == 0)
3042 {
3043 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3044 exception);
3045 break;
3046 }
cristy045bd902010-01-30 18:56:24 +00003047 if (LocaleCompare("unique",option+1) == 0)
3048 {
3049 if (*option == '+')
3050 {
cristy83fae872010-04-22 15:04:16 +00003051 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003052 break;
3053 }
cristy83fae872010-04-22 15:04:16 +00003054 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003055 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003056 break;
3057 }
cristy3ed852e2009-09-05 21:47:34 +00003058 if (LocaleCompare("unique-colors",option+1) == 0)
3059 {
cristy3ed852e2009-09-05 21:47:34 +00003060 /*
3061 Unique image colors.
3062 */
cristy6b3da3a2010-06-20 02:21:46 +00003063 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003064 mogrify_image=UniqueImageColors(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003065 break;
3066 }
3067 if (LocaleCompare("unsharp",option+1) == 0)
3068 {
cristy3ed852e2009-09-05 21:47:34 +00003069 /*
3070 Unsharp mask image.
3071 */
cristy6b3da3a2010-06-20 02:21:46 +00003072 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003073 flags=ParseGeometry(argv[i+1],&geometry_info);
3074 if ((flags & SigmaValue) == 0)
3075 geometry_info.sigma=1.0;
3076 if ((flags & XiValue) == 0)
3077 geometry_info.xi=1.0;
3078 if ((flags & PsiValue) == 0)
3079 geometry_info.psi=0.05;
cristyd241f442011-03-29 13:50:49 +00003080 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3081 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3082 geometry_info.psi,exception);
cristy3ed852e2009-09-05 21:47:34 +00003083 break;
3084 }
3085 break;
3086 }
3087 case 'v':
3088 {
3089 if (LocaleCompare("verbose",option+1) == 0)
3090 {
3091 (void) SetImageArtifact(*image,option+1,
3092 *option == '+' ? "false" : "true");
3093 break;
3094 }
3095 if (LocaleCompare("vignette",option+1) == 0)
3096 {
cristy3ed852e2009-09-05 21:47:34 +00003097 /*
3098 Vignette image.
3099 */
cristy6b3da3a2010-06-20 02:21:46 +00003100 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003101 flags=ParseGeometry(argv[i+1],&geometry_info);
3102 if ((flags & SigmaValue) == 0)
3103 geometry_info.sigma=1.0;
3104 if ((flags & XiValue) == 0)
3105 geometry_info.xi=0.1*(*image)->columns;
3106 if ((flags & PsiValue) == 0)
3107 geometry_info.psi=0.1*(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00003108 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003109 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003110 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003111 break;
3112 }
3113 if (LocaleCompare("virtual-pixel",option+1) == 0)
3114 {
3115 if (*option == '+')
3116 {
3117 (void) SetImageVirtualPixelMethod(*image,
3118 UndefinedVirtualPixelMethod);
3119 break;
3120 }
3121 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3122 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3123 argv[i+1]));
3124 break;
3125 }
3126 break;
3127 }
3128 case 'w':
3129 {
3130 if (LocaleCompare("wave",option+1) == 0)
3131 {
cristy3ed852e2009-09-05 21:47:34 +00003132 /*
3133 Wave image.
3134 */
cristy6b3da3a2010-06-20 02:21:46 +00003135 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003136 flags=ParseGeometry(argv[i+1],&geometry_info);
3137 if ((flags & SigmaValue) == 0)
3138 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00003139 mogrify_image=WaveImage(*image,geometry_info.rho,
3140 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00003141 break;
3142 }
3143 if (LocaleCompare("weight",option+1) == 0)
3144 {
cristye27293e2009-12-18 02:53:20 +00003145 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003146 if (LocaleCompare(argv[i+1],"all") == 0)
3147 draw_info->weight=0;
3148 if (LocaleCompare(argv[i+1],"bold") == 0)
3149 draw_info->weight=700;
3150 if (LocaleCompare(argv[i+1],"bolder") == 0)
3151 if (draw_info->weight <= 800)
3152 draw_info->weight+=100;
3153 if (LocaleCompare(argv[i+1],"lighter") == 0)
3154 if (draw_info->weight >= 100)
3155 draw_info->weight-=100;
3156 if (LocaleCompare(argv[i+1],"normal") == 0)
3157 draw_info->weight=400;
3158 break;
3159 }
3160 if (LocaleCompare("white-threshold",option+1) == 0)
3161 {
3162 /*
3163 White threshold image.
3164 */
cristy6b3da3a2010-06-20 02:21:46 +00003165 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003166 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3167 exception);
3168 InheritException(exception,&(*image)->exception);
3169 break;
3170 }
3171 break;
3172 }
3173 default:
3174 break;
3175 }
anthonye9c27192011-03-27 08:07:06 +00003176 /*
3177 Replace current image with any image that was generated
3178 */
cristyd241f442011-03-29 13:50:49 +00003179 if (mogrify_image != (Image *) NULL)
3180 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003181 i+=count;
3182 }
3183 if (region_image != (Image *) NULL)
3184 {
3185 /*
3186 Composite transformed region onto image.
3187 */
cristy6b3da3a2010-06-20 02:21:46 +00003188 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00003189 (void) CompositeImage(region_image,CopyCompositeOp,*image,
3190 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003191 InheritException(exception,&region_image->exception);
3192 *image=DestroyImage(*image);
3193 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003194 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003195 }
3196 /*
3197 Free resources.
3198 */
3199 quantize_info=DestroyQuantizeInfo(quantize_info);
3200 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003201 mogrify_info=DestroyImageInfo(mogrify_info);
cristy72988482011-03-29 16:34:38 +00003202 status=(*image)->exception.severity == UndefinedException ? 1 : 0;
3203 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003204}
3205
3206/*
3207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3208% %
3209% %
3210% %
cristy5063d812010-10-19 16:28:10 +00003211+ 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 +00003212% %
3213% %
3214% %
3215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3216%
3217% MogrifyImageCommand() transforms an image or a sequence of images. These
3218% transforms include image scaling, image rotation, color reduction, and
3219% others. The transmogrified image overwrites the original image.
3220%
3221% The format of the MogrifyImageCommand method is:
3222%
3223% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3224% const char **argv,char **metadata,ExceptionInfo *exception)
3225%
3226% A description of each parameter follows:
3227%
3228% o image_info: the image info.
3229%
3230% o argc: the number of elements in the argument vector.
3231%
3232% o argv: A text array containing the command line arguments.
3233%
3234% o metadata: any metadata is returned here.
3235%
3236% o exception: return any errors or warnings in this structure.
3237%
3238*/
3239
3240static MagickBooleanType MogrifyUsage(void)
3241{
3242 static const char
3243 *miscellaneous[]=
3244 {
3245 "-debug events display copious debugging information",
3246 "-help print program options",
3247 "-list type print a list of supported option arguments",
3248 "-log format format of debugging information",
3249 "-version print version information",
3250 (char *) NULL
3251 },
3252 *operators[]=
3253 {
3254 "-adaptive-blur geometry",
3255 " adaptively blur pixels; decrease effect near edges",
3256 "-adaptive-resize geometry",
3257 " adaptively resize image using 'mesh' interpolation",
3258 "-adaptive-sharpen geometry",
3259 " adaptively sharpen pixels; increase effect near edges",
3260 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3261 " transparent, extract, background, or shape",
3262 "-annotate geometry text",
3263 " annotate the image with text",
3264 "-auto-gamma automagically adjust gamma level of image",
3265 "-auto-level automagically adjust color levels of image",
3266 "-auto-orient automagically orient (rotate) image",
3267 "-bench iterations measure performance",
3268 "-black-threshold value",
3269 " force all pixels below the threshold into black",
3270 "-blue-shift simulate a scene at nighttime in the moonlight",
3271 "-blur geometry reduce image noise and reduce detail levels",
3272 "-border geometry surround image with a border of color",
3273 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003274 "-brightness-contrast geometry",
3275 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003276 "-cdl filename color correct with a color decision list",
3277 "-charcoal radius simulate a charcoal drawing",
3278 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003279 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003280 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003281 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003282 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003283 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003284 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003285 "-contrast enhance or reduce the image contrast",
3286 "-contrast-stretch geometry",
3287 " improve contrast by `stretching' the intensity range",
3288 "-convolve coefficients",
3289 " apply a convolution kernel to the image",
3290 "-cycle amount cycle the image colormap",
3291 "-decipher filename convert cipher pixels to plain pixels",
3292 "-deskew threshold straighten an image",
3293 "-despeckle reduce the speckles within an image",
3294 "-distort method args",
3295 " distort images according to given method ad args",
3296 "-draw string annotate the image with a graphic primitive",
3297 "-edge radius apply a filter to detect edges in the image",
3298 "-encipher filename convert plain pixels to cipher pixels",
3299 "-emboss radius emboss an image",
3300 "-enhance apply a digital filter to enhance a noisy image",
3301 "-equalize perform histogram equalization to an image",
3302 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003303 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003304 "-extent geometry set the image size",
3305 "-extract geometry extract area from image",
3306 "-fft implements the discrete Fourier transform (DFT)",
3307 "-flip flip image vertically",
3308 "-floodfill geometry color",
3309 " floodfill the image with color",
3310 "-flop flop image horizontally",
3311 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003312 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003313 " apply function over image values",
3314 "-gamma value level of gamma correction",
3315 "-gaussian-blur geometry",
3316 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003317 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003318 "-identify identify the format and characteristics of the image",
3319 "-ift implements the inverse discrete Fourier transform (DFT)",
3320 "-implode amount implode image pixels about the center",
3321 "-lat geometry local adaptive thresholding",
3322 "-layers method optimize, merge, or compare image layers",
3323 "-level value adjust the level of image contrast",
3324 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003325 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003326 "-linear-stretch geometry",
3327 " improve contrast by `stretching with saturation'",
3328 "-liquid-rescale geometry",
3329 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003330 "-median geometry apply a median filter to the image",
3331 "-mode geometry make each pixel the 'predominate color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003332 "-modulate value vary the brightness, saturation, and hue",
3333 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003334 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003335 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003336 "-motion-blur geometry",
3337 " simulate motion blur",
3338 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003339 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003340 "-normalize transform image to span the full range of colors",
3341 "-opaque color change this color to the fill color",
3342 "-ordered-dither NxN",
3343 " add a noise pattern to the image with specific",
3344 " amplitudes",
3345 "-paint radius simulate an oil painting",
3346 "-polaroid angle simulate a Polaroid picture",
3347 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003348 "-profile filename add, delete, or apply an image profile",
3349 "-quantize colorspace reduce colors in this colorspace",
3350 "-radial-blur angle radial blur the image",
3351 "-raise value lighten/darken image edges to create a 3-D effect",
3352 "-random-threshold low,high",
3353 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003354 "-region geometry apply options to a portion of the image",
3355 "-render render vector graphics",
3356 "-repage geometry size and location of an image canvas",
3357 "-resample geometry change the resolution of an image",
3358 "-resize geometry resize the image",
3359 "-roll geometry roll an image vertically or horizontally",
3360 "-rotate degrees apply Paeth rotation to the image",
3361 "-sample geometry scale image with pixel sampling",
3362 "-scale geometry scale the image",
3363 "-segment values segment an image",
3364 "-selective-blur geometry",
3365 " selectively blur pixels within a contrast threshold",
3366 "-sepia-tone threshold",
3367 " simulate a sepia-toned photo",
3368 "-set property value set an image property",
3369 "-shade degrees shade the image using a distant light source",
3370 "-shadow geometry simulate an image shadow",
3371 "-sharpen geometry sharpen the image",
3372 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003373 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003374 "-sigmoidal-contrast geometry",
3375 " increase the contrast without saturating highlights or shadows",
3376 "-sketch geometry simulate a pencil sketch",
3377 "-solarize threshold negate all pixels above the threshold level",
3378 "-sparse-color method args",
3379 " fill in a image based on a few color points",
3380 "-splice geometry splice the background color into the image",
3381 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003382 "-statistic type radius",
3383 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003384 "-strip strip image of all profiles and comments",
3385 "-swirl degrees swirl image pixels about the center",
3386 "-threshold value threshold the image",
3387 "-thumbnail geometry create a thumbnail of the image",
3388 "-tile filename tile image when filling a graphic primitive",
3389 "-tint value tint the image with the fill color",
3390 "-transform affine transform image",
3391 "-transparent color make this color transparent within the image",
3392 "-transpose flip image vertically and rotate 90 degrees",
3393 "-transverse flop image horizontally and rotate 270 degrees",
3394 "-trim trim image edges",
3395 "-type type image type",
3396 "-unique-colors discard all but one of any pixel color",
3397 "-unsharp geometry sharpen the image",
3398 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003399 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003400 "-white-threshold value",
3401 " force all pixels above the threshold into white",
3402 (char *) NULL
3403 },
3404 *sequence_operators[]=
3405 {
cristy4285d782011-02-09 20:12:28 +00003406 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003407 "-clut apply a color lookup table to the image",
3408 "-coalesce merge a sequence of images",
3409 "-combine combine a sequence of images",
3410 "-composite composite image",
3411 "-crop geometry cut out a rectangular region of the image",
3412 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003413 "-evaluate-sequence operator",
3414 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003415 "-flatten flatten a sequence of images",
3416 "-fx expression apply mathematical expression to an image channel(s)",
3417 "-hald-clut apply a Hald color lookup table to the image",
3418 "-morph value morph an image sequence",
3419 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003420 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003421 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003422 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003423 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003424 "-write filename write images to this file",
3425 (char *) NULL
3426 },
3427 *settings[]=
3428 {
3429 "-adjoin join images into a single multi-image file",
3430 "-affine matrix affine transform matrix",
3431 "-alpha option activate, deactivate, reset, or set the alpha channel",
3432 "-antialias remove pixel-aliasing",
3433 "-authenticate password",
3434 " decipher image with this password",
3435 "-attenuate value lessen (or intensify) when adding noise to an image",
3436 "-background color background color",
3437 "-bias value add bias when convolving an image",
3438 "-black-point-compensation",
3439 " use black point compensation",
3440 "-blue-primary point chromaticity blue primary point",
3441 "-bordercolor color border color",
3442 "-caption string assign a caption to an image",
3443 "-channel type apply option to select image channels",
3444 "-colors value preferred number of colors in the image",
3445 "-colorspace type alternate image colorspace",
3446 "-comment string annotate image with comment",
3447 "-compose operator set image composite operator",
3448 "-compress type type of pixel compression when writing the image",
3449 "-define format:option",
3450 " define one or more image format options",
3451 "-delay value display the next image after pausing",
3452 "-density geometry horizontal and vertical density of the image",
3453 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003454 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003455 "-display server get image or font from this X server",
3456 "-dispose method layer disposal method",
3457 "-dither method apply error diffusion to image",
3458 "-encoding type text encoding type",
3459 "-endian type endianness (MSB or LSB) of the image",
3460 "-family name render text with this font family",
3461 "-fill color color to use when filling a graphic primitive",
3462 "-filter type use this filter when resizing an image",
3463 "-font name render text with this font",
3464 "-format \"string\" output formatted image characteristics",
3465 "-fuzz distance colors within this distance are considered equal",
3466 "-gravity type horizontal and vertical text placement",
3467 "-green-primary point chromaticity green primary point",
3468 "-intent type type of rendering intent when managing the image color",
3469 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003470 "-interline-spacing value",
3471 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003472 "-interpolate method pixel color interpolation method",
3473 "-interword-spacing value",
3474 " set the space between two words",
3475 "-kerning value set the space between two letters",
3476 "-label string assign a label to an image",
3477 "-limit type value pixel cache resource limit",
3478 "-loop iterations add Netscape loop extension to your GIF animation",
3479 "-mask filename associate a mask with the image",
3480 "-mattecolor color frame color",
3481 "-monitor monitor progress",
3482 "-orient type image orientation",
3483 "-page geometry size and location of an image canvas (setting)",
3484 "-ping efficiently determine image attributes",
3485 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003486 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003487 "-preview type image preview type",
3488 "-quality value JPEG/MIFF/PNG compression level",
3489 "-quiet suppress all warning messages",
3490 "-red-primary point chromaticity red primary point",
3491 "-regard-warnings pay attention to warning messages",
3492 "-remap filename transform image colors to match this set of colors",
3493 "-respect-parentheses settings remain in effect until parenthesis boundary",
3494 "-sampling-factor geometry",
3495 " horizontal and vertical sampling factor",
3496 "-scene value image scene number",
3497 "-seed value seed a new sequence of pseudo-random numbers",
3498 "-size geometry width and height of image",
3499 "-stretch type render text with this font stretch",
3500 "-stroke color graphic primitive stroke color",
3501 "-strokewidth value graphic primitive stroke width",
3502 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003503 "-synchronize synchronize image to storage device",
3504 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003505 "-texture filename name of texture to tile onto the image background",
3506 "-tile-offset geometry",
3507 " tile offset",
3508 "-treedepth value color tree depth",
3509 "-transparent-color color",
3510 " transparent color",
3511 "-undercolor color annotation bounding box color",
3512 "-units type the units of image resolution",
3513 "-verbose print detailed information about the image",
3514 "-view FlashPix viewing transforms",
3515 "-virtual-pixel method",
3516 " virtual pixel access method",
3517 "-weight type render text with this font weight",
3518 "-white-point point chromaticity white point",
3519 (char *) NULL
3520 },
3521 *stack_operators[]=
3522 {
anthonyb69c4b32011-03-23 04:37:44 +00003523 "-delete indexes delete the image from the image sequence",
3524 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003525 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003526 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003527 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003528 "-swap indexes swap two images in the image sequence",
3529 (char *) NULL
3530 };
3531
3532 const char
3533 **p;
3534
cristybb503372010-05-27 20:51:26 +00003535 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003536 (void) printf("Copyright: %s\n",GetMagickCopyright());
3537 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003538 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3539 GetClientName());
3540 (void) printf("\nImage Settings:\n");
3541 for (p=settings; *p != (char *) NULL; p++)
3542 (void) printf(" %s\n",*p);
3543 (void) printf("\nImage Operators:\n");
3544 for (p=operators; *p != (char *) NULL; p++)
3545 (void) printf(" %s\n",*p);
3546 (void) printf("\nImage Sequence Operators:\n");
3547 for (p=sequence_operators; *p != (char *) NULL; p++)
3548 (void) printf(" %s\n",*p);
3549 (void) printf("\nImage Stack Operators:\n");
3550 for (p=stack_operators; *p != (char *) NULL; p++)
3551 (void) printf(" %s\n",*p);
3552 (void) printf("\nMiscellaneous Options:\n");
3553 for (p=miscellaneous; *p != (char *) NULL; p++)
3554 (void) printf(" %s\n",*p);
3555 (void) printf(
3556 "\nBy default, the image format of `file' is determined by its magic\n");
3557 (void) printf(
3558 "number. To specify a particular image format, precede the filename\n");
3559 (void) printf(
3560 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3561 (void) printf(
3562 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3563 (void) printf("'-' for standard input or output.\n");
3564 return(MagickFalse);
3565}
3566
3567WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3568 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3569{
3570#define DestroyMogrify() \
3571{ \
3572 if (format != (char *) NULL) \
3573 format=DestroyString(format); \
3574 if (path != (char *) NULL) \
3575 path=DestroyString(path); \
3576 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003577 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003578 argv[i]=DestroyString(argv[i]); \
3579 argv=(char **) RelinquishMagickMemory(argv); \
3580}
3581#define ThrowMogrifyException(asperity,tag,option) \
3582{ \
3583 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3584 option); \
3585 DestroyMogrify(); \
3586 return(MagickFalse); \
3587}
3588#define ThrowMogrifyInvalidArgumentException(option,argument) \
3589{ \
3590 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3591 "InvalidArgument","`%s': %s",argument,option); \
3592 DestroyMogrify(); \
3593 return(MagickFalse); \
3594}
3595
3596 char
3597 *format,
3598 *option,
3599 *path;
3600
3601 Image
3602 *image;
3603
3604 ImageStack
3605 image_stack[MaxImageStackDepth+1];
3606
cristy3ed852e2009-09-05 21:47:34 +00003607 MagickBooleanType
3608 global_colormap;
3609
3610 MagickBooleanType
3611 fire,
cristyebbcfea2011-02-25 02:43:54 +00003612 pend,
3613 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003614
3615 MagickStatusType
3616 status;
3617
cristyebbcfea2011-02-25 02:43:54 +00003618 register ssize_t
3619 i;
3620
3621 ssize_t
3622 j,
3623 k;
3624
cristy3ed852e2009-09-05 21:47:34 +00003625 /*
3626 Set defaults.
3627 */
3628 assert(image_info != (ImageInfo *) NULL);
3629 assert(image_info->signature == MagickSignature);
3630 if (image_info->debug != MagickFalse)
3631 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3632 assert(exception != (ExceptionInfo *) NULL);
3633 if (argc == 2)
3634 {
3635 option=argv[1];
3636 if ((LocaleCompare("version",option+1) == 0) ||
3637 (LocaleCompare("-version",option+1) == 0))
3638 {
3639 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003640 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003641 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
3642 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003643 return(MagickFalse);
3644 }
3645 }
3646 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003647 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003648 format=(char *) NULL;
3649 path=(char *) NULL;
3650 global_colormap=MagickFalse;
3651 k=0;
3652 j=1;
3653 NewImageStack();
3654 option=(char *) NULL;
3655 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003656 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003657 status=MagickTrue;
3658 /*
3659 Parse command line.
3660 */
3661 ReadCommandlLine(argc,&argv);
3662 status=ExpandFilenames(&argc,&argv);
3663 if (status == MagickFalse)
3664 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3665 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003666 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003667 {
3668 option=argv[i];
3669 if (LocaleCompare(option,"(") == 0)
3670 {
3671 FireImageStack(MagickFalse,MagickTrue,pend);
3672 if (k == MaxImageStackDepth)
3673 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3674 option);
3675 PushImageStack();
3676 continue;
3677 }
3678 if (LocaleCompare(option,")") == 0)
3679 {
3680 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3681 if (k == 0)
3682 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3683 PopImageStack();
3684 continue;
3685 }
3686 if (IsMagickOption(option) == MagickFalse)
3687 {
3688 char
3689 backup_filename[MaxTextExtent],
3690 *filename;
3691
3692 Image
3693 *images;
3694
3695 /*
3696 Option is a file name: begin by reading image from specified file.
3697 */
3698 FireImageStack(MagickFalse,MagickFalse,pend);
3699 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003700 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003701 filename=argv[++i];
3702 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3703 images=ReadImages(image_info,exception);
3704 status&=(images != (Image *) NULL) &&
3705 (exception->severity < ErrorException);
3706 if (images == (Image *) NULL)
3707 continue;
cristydaa76602010-06-30 13:05:11 +00003708 if (format != (char *) NULL)
3709 (void) CopyMagickString(images->filename,images->magick_filename,
3710 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003711 if (path != (char *) NULL)
3712 {
3713 GetPathComponent(option,TailPath,filename);
3714 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
3715 path,*DirectorySeparator,filename);
3716 }
3717 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003718 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003719 AppendImageStack(images);
3720 FinalizeImageSettings(image_info,image,MagickFalse);
3721 if (global_colormap != MagickFalse)
3722 {
3723 QuantizeInfo
3724 *quantize_info;
3725
3726 quantize_info=AcquireQuantizeInfo(image_info);
3727 (void) RemapImages(quantize_info,images,(Image *) NULL);
3728 quantize_info=DestroyQuantizeInfo(quantize_info);
3729 }
3730 *backup_filename='\0';
3731 if ((LocaleCompare(image->filename,"-") != 0) &&
3732 (IsPathWritable(image->filename) != MagickFalse))
3733 {
cristybb503372010-05-27 20:51:26 +00003734 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003735 i;
3736
3737 /*
3738 Rename image file as backup.
3739 */
3740 (void) CopyMagickString(backup_filename,image->filename,
3741 MaxTextExtent);
3742 for (i=0; i < 6; i++)
3743 {
3744 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3745 if (IsPathAccessible(backup_filename) == MagickFalse)
3746 break;
3747 }
3748 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3749 (rename(image->filename,backup_filename) != 0))
3750 *backup_filename='\0';
3751 }
3752 /*
3753 Write transmogrified image to disk.
3754 */
3755 image_info->synchronize=MagickTrue;
3756 status&=WriteImages(image_info,image,image->filename,exception);
3757 if ((status == MagickFalse) && (*backup_filename != '\0'))
3758 (void) remove(backup_filename);
3759 RemoveAllImageStack();
3760 continue;
3761 }
3762 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3763 switch (*(option+1))
3764 {
3765 case 'a':
3766 {
3767 if (LocaleCompare("adaptive-blur",option+1) == 0)
3768 {
3769 i++;
cristybb503372010-05-27 20:51:26 +00003770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003771 ThrowMogrifyException(OptionError,"MissingArgument",option);
3772 if (IsGeometry(argv[i]) == MagickFalse)
3773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3774 break;
3775 }
3776 if (LocaleCompare("adaptive-resize",option+1) == 0)
3777 {
3778 i++;
cristybb503372010-05-27 20:51:26 +00003779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003780 ThrowMogrifyException(OptionError,"MissingArgument",option);
3781 if (IsGeometry(argv[i]) == MagickFalse)
3782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3783 break;
3784 }
3785 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3786 {
3787 i++;
cristybb503372010-05-27 20:51:26 +00003788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003789 ThrowMogrifyException(OptionError,"MissingArgument",option);
3790 if (IsGeometry(argv[i]) == MagickFalse)
3791 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3792 break;
3793 }
3794 if (LocaleCompare("affine",option+1) == 0)
3795 {
3796 if (*option == '+')
3797 break;
3798 i++;
cristybb503372010-05-27 20:51:26 +00003799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003800 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003801 break;
3802 }
3803 if (LocaleCompare("alpha",option+1) == 0)
3804 {
cristybb503372010-05-27 20:51:26 +00003805 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003806 type;
3807
3808 if (*option == '+')
3809 break;
3810 i++;
cristybb503372010-05-27 20:51:26 +00003811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003812 ThrowMogrifyException(OptionError,"MissingArgument",option);
3813 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
3814 if (type < 0)
3815 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3816 argv[i]);
3817 break;
3818 }
3819 if (LocaleCompare("annotate",option+1) == 0)
3820 {
3821 if (*option == '+')
3822 break;
3823 i++;
cristybb503372010-05-27 20:51:26 +00003824 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003825 ThrowMogrifyException(OptionError,"MissingArgument",option);
3826 if (IsGeometry(argv[i]) == MagickFalse)
3827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003828 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003829 ThrowMogrifyException(OptionError,"MissingArgument",option);
3830 i++;
3831 break;
3832 }
3833 if (LocaleCompare("antialias",option+1) == 0)
3834 break;
3835 if (LocaleCompare("append",option+1) == 0)
3836 break;
3837 if (LocaleCompare("attenuate",option+1) == 0)
3838 {
3839 if (*option == '+')
3840 break;
3841 i++;
cristybb503372010-05-27 20:51:26 +00003842 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003843 ThrowMogrifyException(OptionError,"MissingArgument",option);
3844 if (IsGeometry(argv[i]) == MagickFalse)
3845 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3846 break;
3847 }
3848 if (LocaleCompare("authenticate",option+1) == 0)
3849 {
3850 if (*option == '+')
3851 break;
3852 i++;
cristybb503372010-05-27 20:51:26 +00003853 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003854 ThrowMogrifyException(OptionError,"MissingArgument",option);
3855 break;
3856 }
3857 if (LocaleCompare("auto-gamma",option+1) == 0)
3858 break;
3859 if (LocaleCompare("auto-level",option+1) == 0)
3860 break;
3861 if (LocaleCompare("auto-orient",option+1) == 0)
3862 break;
3863 if (LocaleCompare("average",option+1) == 0)
3864 break;
3865 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3866 }
3867 case 'b':
3868 {
3869 if (LocaleCompare("background",option+1) == 0)
3870 {
3871 if (*option == '+')
3872 break;
3873 i++;
cristybb503372010-05-27 20:51:26 +00003874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003875 ThrowMogrifyException(OptionError,"MissingArgument",option);
3876 break;
3877 }
3878 if (LocaleCompare("bias",option+1) == 0)
3879 {
3880 if (*option == '+')
3881 break;
3882 i++;
cristybb503372010-05-27 20:51:26 +00003883 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003884 ThrowMogrifyException(OptionError,"MissingArgument",option);
3885 if (IsGeometry(argv[i]) == MagickFalse)
3886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3887 break;
3888 }
3889 if (LocaleCompare("black-point-compensation",option+1) == 0)
3890 break;
3891 if (LocaleCompare("black-threshold",option+1) == 0)
3892 {
3893 if (*option == '+')
3894 break;
3895 i++;
cristybb503372010-05-27 20:51:26 +00003896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003897 ThrowMogrifyException(OptionError,"MissingArgument",option);
3898 if (IsGeometry(argv[i]) == MagickFalse)
3899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3900 break;
3901 }
3902 if (LocaleCompare("blue-primary",option+1) == 0)
3903 {
3904 if (*option == '+')
3905 break;
3906 i++;
cristybb503372010-05-27 20:51:26 +00003907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003908 ThrowMogrifyException(OptionError,"MissingArgument",option);
3909 if (IsGeometry(argv[i]) == MagickFalse)
3910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3911 break;
3912 }
3913 if (LocaleCompare("blue-shift",option+1) == 0)
3914 {
3915 i++;
cristybb503372010-05-27 20:51:26 +00003916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003917 ThrowMogrifyException(OptionError,"MissingArgument",option);
3918 if (IsGeometry(argv[i]) == MagickFalse)
3919 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3920 break;
3921 }
3922 if (LocaleCompare("blur",option+1) == 0)
3923 {
3924 i++;
cristybb503372010-05-27 20:51:26 +00003925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003926 ThrowMogrifyException(OptionError,"MissingArgument",option);
3927 if (IsGeometry(argv[i]) == MagickFalse)
3928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3929 break;
3930 }
3931 if (LocaleCompare("border",option+1) == 0)
3932 {
3933 if (*option == '+')
3934 break;
3935 i++;
cristybb503372010-05-27 20:51:26 +00003936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003937 ThrowMogrifyException(OptionError,"MissingArgument",option);
3938 if (IsGeometry(argv[i]) == MagickFalse)
3939 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3940 break;
3941 }
3942 if (LocaleCompare("bordercolor",option+1) == 0)
3943 {
3944 if (*option == '+')
3945 break;
3946 i++;
cristybb503372010-05-27 20:51:26 +00003947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003948 ThrowMogrifyException(OptionError,"MissingArgument",option);
3949 break;
3950 }
3951 if (LocaleCompare("box",option+1) == 0)
3952 {
3953 if (*option == '+')
3954 break;
3955 i++;
cristybb503372010-05-27 20:51:26 +00003956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003957 ThrowMogrifyException(OptionError,"MissingArgument",option);
3958 break;
3959 }
cristya28d6b82010-01-11 20:03:47 +00003960 if (LocaleCompare("brightness-contrast",option+1) == 0)
3961 {
3962 i++;
cristybb503372010-05-27 20:51:26 +00003963 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003964 ThrowMogrifyException(OptionError,"MissingArgument",option);
3965 if (IsGeometry(argv[i]) == MagickFalse)
3966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3967 break;
3968 }
cristy3ed852e2009-09-05 21:47:34 +00003969 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3970 }
3971 case 'c':
3972 {
3973 if (LocaleCompare("cache",option+1) == 0)
3974 {
3975 if (*option == '+')
3976 break;
3977 i++;
cristybb503372010-05-27 20:51:26 +00003978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003979 ThrowMogrifyException(OptionError,"MissingArgument",option);
3980 if (IsGeometry(argv[i]) == MagickFalse)
3981 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3982 break;
3983 }
3984 if (LocaleCompare("caption",option+1) == 0)
3985 {
3986 if (*option == '+')
3987 break;
3988 i++;
cristybb503372010-05-27 20:51:26 +00003989 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003990 ThrowMogrifyException(OptionError,"MissingArgument",option);
3991 break;
3992 }
3993 if (LocaleCompare("channel",option+1) == 0)
3994 {
cristybb503372010-05-27 20:51:26 +00003995 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003996 channel;
3997
3998 if (*option == '+')
3999 break;
4000 i++;
cristybb503372010-05-27 20:51:26 +00004001 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004002 ThrowMogrifyException(OptionError,"MissingArgument",option);
4003 channel=ParseChannelOption(argv[i]);
4004 if (channel < 0)
4005 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4006 argv[i]);
4007 break;
4008 }
4009 if (LocaleCompare("cdl",option+1) == 0)
4010 {
4011 if (*option == '+')
4012 break;
4013 i++;
cristybb503372010-05-27 20:51:26 +00004014 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004015 ThrowMogrifyException(OptionError,"MissingArgument",option);
4016 break;
4017 }
4018 if (LocaleCompare("charcoal",option+1) == 0)
4019 {
4020 if (*option == '+')
4021 break;
4022 i++;
cristybb503372010-05-27 20:51:26 +00004023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004024 ThrowMogrifyException(OptionError,"MissingArgument",option);
4025 if (IsGeometry(argv[i]) == MagickFalse)
4026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4027 break;
4028 }
4029 if (LocaleCompare("chop",option+1) == 0)
4030 {
4031 if (*option == '+')
4032 break;
4033 i++;
cristybb503372010-05-27 20:51:26 +00004034 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004035 ThrowMogrifyException(OptionError,"MissingArgument",option);
4036 if (IsGeometry(argv[i]) == MagickFalse)
4037 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4038 break;
4039 }
cristy1eb45dd2009-09-25 16:38:06 +00004040 if (LocaleCompare("clamp",option+1) == 0)
4041 break;
4042 if (LocaleCompare("clip",option+1) == 0)
4043 break;
cristy3ed852e2009-09-05 21:47:34 +00004044 if (LocaleCompare("clip-mask",option+1) == 0)
4045 {
4046 if (*option == '+')
4047 break;
4048 i++;
cristybb503372010-05-27 20:51:26 +00004049 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004050 ThrowMogrifyException(OptionError,"MissingArgument",option);
4051 break;
4052 }
4053 if (LocaleCompare("clut",option+1) == 0)
4054 break;
4055 if (LocaleCompare("coalesce",option+1) == 0)
4056 break;
4057 if (LocaleCompare("colorize",option+1) == 0)
4058 {
4059 if (*option == '+')
4060 break;
4061 i++;
cristybb503372010-05-27 20:51:26 +00004062 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004063 ThrowMogrifyException(OptionError,"MissingArgument",option);
4064 if (IsGeometry(argv[i]) == MagickFalse)
4065 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4066 break;
4067 }
cristye6365592010-04-02 17:31:23 +00004068 if (LocaleCompare("color-matrix",option+1) == 0)
4069 {
cristyb6bd4ad2010-08-08 01:12:27 +00004070 KernelInfo
4071 *kernel_info;
4072
cristye6365592010-04-02 17:31:23 +00004073 if (*option == '+')
4074 break;
4075 i++;
cristybb503372010-05-27 20:51:26 +00004076 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004077 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004078 kernel_info=AcquireKernelInfo(argv[i]);
4079 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004080 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004081 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004082 break;
4083 }
cristy3ed852e2009-09-05 21:47:34 +00004084 if (LocaleCompare("colors",option+1) == 0)
4085 {
4086 if (*option == '+')
4087 break;
4088 i++;
cristybb503372010-05-27 20:51:26 +00004089 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004090 ThrowMogrifyException(OptionError,"MissingArgument",option);
4091 if (IsGeometry(argv[i]) == MagickFalse)
4092 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4093 break;
4094 }
4095 if (LocaleCompare("colorspace",option+1) == 0)
4096 {
cristybb503372010-05-27 20:51:26 +00004097 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004098 colorspace;
4099
4100 if (*option == '+')
4101 break;
4102 i++;
cristybb503372010-05-27 20:51:26 +00004103 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004104 ThrowMogrifyException(OptionError,"MissingArgument",option);
4105 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4106 argv[i]);
4107 if (colorspace < 0)
4108 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4109 argv[i]);
4110 break;
4111 }
4112 if (LocaleCompare("combine",option+1) == 0)
4113 break;
4114 if (LocaleCompare("comment",option+1) == 0)
4115 {
4116 if (*option == '+')
4117 break;
4118 i++;
cristybb503372010-05-27 20:51:26 +00004119 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004120 ThrowMogrifyException(OptionError,"MissingArgument",option);
4121 break;
4122 }
4123 if (LocaleCompare("composite",option+1) == 0)
4124 break;
4125 if (LocaleCompare("compress",option+1) == 0)
4126 {
cristybb503372010-05-27 20:51:26 +00004127 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004128 compress;
4129
4130 if (*option == '+')
4131 break;
4132 i++;
cristybb503372010-05-27 20:51:26 +00004133 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004134 ThrowMogrifyException(OptionError,"MissingArgument",option);
4135 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4136 argv[i]);
4137 if (compress < 0)
4138 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4139 argv[i]);
4140 break;
4141 }
cristy22879752009-10-25 23:55:40 +00004142 if (LocaleCompare("concurrent",option+1) == 0)
4143 break;
cristy3ed852e2009-09-05 21:47:34 +00004144 if (LocaleCompare("contrast",option+1) == 0)
4145 break;
4146 if (LocaleCompare("contrast-stretch",option+1) == 0)
4147 {
4148 i++;
cristybb503372010-05-27 20:51:26 +00004149 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004150 ThrowMogrifyException(OptionError,"MissingArgument",option);
4151 if (IsGeometry(argv[i]) == MagickFalse)
4152 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4153 break;
4154 }
4155 if (LocaleCompare("convolve",option+1) == 0)
4156 {
cristyb6bd4ad2010-08-08 01:12:27 +00004157 KernelInfo
4158 *kernel_info;
4159
cristy3ed852e2009-09-05 21:47:34 +00004160 if (*option == '+')
4161 break;
4162 i++;
cristybb503372010-05-27 20:51:26 +00004163 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004164 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004165 kernel_info=AcquireKernelInfo(argv[i]);
4166 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004167 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004168 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004169 break;
4170 }
4171 if (LocaleCompare("crop",option+1) == 0)
4172 {
4173 if (*option == '+')
4174 break;
4175 i++;
cristybb503372010-05-27 20:51:26 +00004176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004177 ThrowMogrifyException(OptionError,"MissingArgument",option);
4178 if (IsGeometry(argv[i]) == MagickFalse)
4179 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4180 break;
4181 }
4182 if (LocaleCompare("cycle",option+1) == 0)
4183 {
4184 if (*option == '+')
4185 break;
4186 i++;
cristybb503372010-05-27 20:51:26 +00004187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004188 ThrowMogrifyException(OptionError,"MissingArgument",option);
4189 if (IsGeometry(argv[i]) == MagickFalse)
4190 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4191 break;
4192 }
4193 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4194 }
4195 case 'd':
4196 {
4197 if (LocaleCompare("decipher",option+1) == 0)
4198 {
4199 if (*option == '+')
4200 break;
4201 i++;
cristybb503372010-05-27 20:51:26 +00004202 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004203 ThrowMogrifyException(OptionError,"MissingArgument",option);
4204 break;
4205 }
4206 if (LocaleCompare("deconstruct",option+1) == 0)
4207 break;
4208 if (LocaleCompare("debug",option+1) == 0)
4209 {
cristybb503372010-05-27 20:51:26 +00004210 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004211 event;
4212
4213 if (*option == '+')
4214 break;
4215 i++;
cristybb503372010-05-27 20:51:26 +00004216 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004217 ThrowMogrifyException(OptionError,"MissingArgument",option);
4218 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4219 if (event < 0)
4220 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4221 argv[i]);
4222 (void) SetLogEventMask(argv[i]);
4223 break;
4224 }
4225 if (LocaleCompare("define",option+1) == 0)
4226 {
4227 i++;
cristybb503372010-05-27 20:51:26 +00004228 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004229 ThrowMogrifyException(OptionError,"MissingArgument",option);
4230 if (*option == '+')
4231 {
4232 const char
4233 *define;
4234
4235 define=GetImageOption(image_info,argv[i]);
4236 if (define == (const char *) NULL)
4237 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4238 break;
4239 }
4240 break;
4241 }
4242 if (LocaleCompare("delay",option+1) == 0)
4243 {
4244 if (*option == '+')
4245 break;
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (IsGeometry(argv[i]) == MagickFalse)
4250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4251 break;
4252 }
cristyecb10ff2011-03-22 13:14:03 +00004253 if (LocaleCompare("delete",option+1) == 0)
4254 {
4255 if (*option == '+')
4256 break;
4257 i++;
4258 if (i == (ssize_t) (argc-1))
4259 ThrowMogrifyException(OptionError,"MissingArgument",option);
4260 if (IsGeometry(argv[i]) == MagickFalse)
4261 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4262 break;
4263 }
cristy3ed852e2009-09-05 21:47:34 +00004264 if (LocaleCompare("density",option+1) == 0)
4265 {
4266 if (*option == '+')
4267 break;
4268 i++;
cristybb503372010-05-27 20:51:26 +00004269 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004270 ThrowMogrifyException(OptionError,"MissingArgument",option);
4271 if (IsGeometry(argv[i]) == MagickFalse)
4272 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4273 break;
4274 }
4275 if (LocaleCompare("depth",option+1) == 0)
4276 {
4277 if (*option == '+')
4278 break;
4279 i++;
cristybb503372010-05-27 20:51:26 +00004280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004281 ThrowMogrifyException(OptionError,"MissingArgument",option);
4282 if (IsGeometry(argv[i]) == MagickFalse)
4283 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4284 break;
4285 }
4286 if (LocaleCompare("deskew",option+1) == 0)
4287 {
4288 if (*option == '+')
4289 break;
4290 i++;
cristybb503372010-05-27 20:51:26 +00004291 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004292 ThrowMogrifyException(OptionError,"MissingArgument",option);
4293 if (IsGeometry(argv[i]) == MagickFalse)
4294 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4295 break;
4296 }
4297 if (LocaleCompare("despeckle",option+1) == 0)
4298 break;
4299 if (LocaleCompare("dft",option+1) == 0)
4300 break;
cristyc9b12952010-03-28 01:12:28 +00004301 if (LocaleCompare("direction",option+1) == 0)
4302 {
cristybb503372010-05-27 20:51:26 +00004303 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004304 direction;
4305
4306 if (*option == '+')
4307 break;
4308 i++;
cristybb503372010-05-27 20:51:26 +00004309 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004310 ThrowMogrifyException(OptionError,"MissingArgument",option);
4311 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4312 argv[i]);
4313 if (direction < 0)
4314 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4315 argv[i]);
4316 break;
4317 }
cristy3ed852e2009-09-05 21:47:34 +00004318 if (LocaleCompare("display",option+1) == 0)
4319 {
4320 if (*option == '+')
4321 break;
4322 i++;
cristybb503372010-05-27 20:51:26 +00004323 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004324 ThrowMogrifyException(OptionError,"MissingArgument",option);
4325 break;
4326 }
4327 if (LocaleCompare("dispose",option+1) == 0)
4328 {
cristybb503372010-05-27 20:51:26 +00004329 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004330 dispose;
4331
4332 if (*option == '+')
4333 break;
4334 i++;
cristybb503372010-05-27 20:51:26 +00004335 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004336 ThrowMogrifyException(OptionError,"MissingArgument",option);
4337 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4338 if (dispose < 0)
4339 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4340 argv[i]);
4341 break;
4342 }
4343 if (LocaleCompare("distort",option+1) == 0)
4344 {
cristybb503372010-05-27 20:51:26 +00004345 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004346 op;
4347
4348 i++;
cristybb503372010-05-27 20:51:26 +00004349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004350 ThrowMogrifyException(OptionError,"MissingArgument",option);
4351 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4352 if (op < 0)
4353 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4354 argv[i]);
4355 i++;
cristybb503372010-05-27 20:51:26 +00004356 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004357 ThrowMogrifyException(OptionError,"MissingArgument",option);
4358 break;
4359 }
4360 if (LocaleCompare("dither",option+1) == 0)
4361 {
cristybb503372010-05-27 20:51:26 +00004362 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004363 method;
4364
4365 if (*option == '+')
4366 break;
4367 i++;
cristybb503372010-05-27 20:51:26 +00004368 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004369 ThrowMogrifyException(OptionError,"MissingArgument",option);
4370 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4371 if (method < 0)
4372 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4373 argv[i]);
4374 break;
4375 }
4376 if (LocaleCompare("draw",option+1) == 0)
4377 {
4378 if (*option == '+')
4379 break;
4380 i++;
cristybb503372010-05-27 20:51:26 +00004381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004382 ThrowMogrifyException(OptionError,"MissingArgument",option);
4383 break;
4384 }
cristyecb10ff2011-03-22 13:14:03 +00004385 if (LocaleCompare("duplicate",option+1) == 0)
4386 {
4387 if (*option == '+')
4388 break;
4389 i++;
4390 if (i == (ssize_t) (argc-1))
4391 ThrowMogrifyException(OptionError,"MissingArgument",option);
4392 if (IsGeometry(argv[i]) == MagickFalse)
4393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4394 break;
4395 }
cristy22879752009-10-25 23:55:40 +00004396 if (LocaleCompare("duration",option+1) == 0)
4397 {
4398 if (*option == '+')
4399 break;
4400 i++;
cristybb503372010-05-27 20:51:26 +00004401 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004402 ThrowMogrifyException(OptionError,"MissingArgument",option);
4403 if (IsGeometry(argv[i]) == MagickFalse)
4404 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4405 break;
4406 }
cristy3ed852e2009-09-05 21:47:34 +00004407 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4408 }
4409 case 'e':
4410 {
4411 if (LocaleCompare("edge",option+1) == 0)
4412 {
4413 if (*option == '+')
4414 break;
4415 i++;
cristybb503372010-05-27 20:51:26 +00004416 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004417 ThrowMogrifyException(OptionError,"MissingArgument",option);
4418 if (IsGeometry(argv[i]) == MagickFalse)
4419 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4420 break;
4421 }
4422 if (LocaleCompare("emboss",option+1) == 0)
4423 {
4424 if (*option == '+')
4425 break;
4426 i++;
cristybb503372010-05-27 20:51:26 +00004427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004428 ThrowMogrifyException(OptionError,"MissingArgument",option);
4429 if (IsGeometry(argv[i]) == MagickFalse)
4430 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4431 break;
4432 }
4433 if (LocaleCompare("encipher",option+1) == 0)
4434 {
4435 if (*option == '+')
4436 break;
4437 i++;
cristybb503372010-05-27 20:51:26 +00004438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004439 ThrowMogrifyException(OptionError,"MissingArgument",option);
4440 break;
4441 }
4442 if (LocaleCompare("encoding",option+1) == 0)
4443 {
4444 if (*option == '+')
4445 break;
4446 i++;
cristybb503372010-05-27 20:51:26 +00004447 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004448 ThrowMogrifyException(OptionError,"MissingArgument",option);
4449 break;
4450 }
4451 if (LocaleCompare("endian",option+1) == 0)
4452 {
cristybb503372010-05-27 20:51:26 +00004453 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004454 endian;
4455
4456 if (*option == '+')
4457 break;
4458 i++;
cristybb503372010-05-27 20:51:26 +00004459 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004460 ThrowMogrifyException(OptionError,"MissingArgument",option);
4461 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4462 if (endian < 0)
4463 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4464 argv[i]);
4465 break;
4466 }
4467 if (LocaleCompare("enhance",option+1) == 0)
4468 break;
4469 if (LocaleCompare("equalize",option+1) == 0)
4470 break;
4471 if (LocaleCompare("evaluate",option+1) == 0)
4472 {
cristybb503372010-05-27 20:51:26 +00004473 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004474 op;
4475
4476 if (*option == '+')
4477 break;
4478 i++;
cristybb503372010-05-27 20:51:26 +00004479 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004480 ThrowMogrifyException(OptionError,"MissingArgument",option);
4481 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4482 if (op < 0)
4483 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4484 argv[i]);
4485 i++;
cristybb503372010-05-27 20:51:26 +00004486 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004487 ThrowMogrifyException(OptionError,"MissingArgument",option);
4488 if (IsGeometry(argv[i]) == MagickFalse)
4489 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4490 break;
4491 }
cristyd18ae7c2010-03-07 17:39:52 +00004492 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4493 {
cristybb503372010-05-27 20:51:26 +00004494 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004495 op;
4496
4497 if (*option == '+')
4498 break;
4499 i++;
cristybb503372010-05-27 20:51:26 +00004500 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004501 ThrowMogrifyException(OptionError,"MissingArgument",option);
4502 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4503 if (op < 0)
4504 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4505 argv[i]);
4506 break;
4507 }
cristy3ed852e2009-09-05 21:47:34 +00004508 if (LocaleCompare("extent",option+1) == 0)
4509 {
4510 if (*option == '+')
4511 break;
4512 i++;
cristybb503372010-05-27 20:51:26 +00004513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004514 ThrowMogrifyException(OptionError,"MissingArgument",option);
4515 if (IsGeometry(argv[i]) == MagickFalse)
4516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4517 break;
4518 }
4519 if (LocaleCompare("extract",option+1) == 0)
4520 {
4521 if (*option == '+')
4522 break;
4523 i++;
cristybb503372010-05-27 20:51:26 +00004524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004525 ThrowMogrifyException(OptionError,"MissingArgument",option);
4526 if (IsGeometry(argv[i]) == MagickFalse)
4527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4528 break;
4529 }
4530 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4531 }
4532 case 'f':
4533 {
4534 if (LocaleCompare("family",option+1) == 0)
4535 {
4536 if (*option == '+')
4537 break;
4538 i++;
cristybb503372010-05-27 20:51:26 +00004539 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004540 ThrowMogrifyException(OptionError,"MissingArgument",option);
4541 break;
4542 }
4543 if (LocaleCompare("fill",option+1) == 0)
4544 {
4545 if (*option == '+')
4546 break;
4547 i++;
cristybb503372010-05-27 20:51:26 +00004548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004549 ThrowMogrifyException(OptionError,"MissingArgument",option);
4550 break;
4551 }
4552 if (LocaleCompare("filter",option+1) == 0)
4553 {
cristybb503372010-05-27 20:51:26 +00004554 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004555 filter;
4556
4557 if (*option == '+')
4558 break;
4559 i++;
cristybb503372010-05-27 20:51:26 +00004560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004561 ThrowMogrifyException(OptionError,"MissingArgument",option);
4562 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4563 if (filter < 0)
4564 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4565 argv[i]);
4566 break;
4567 }
4568 if (LocaleCompare("flatten",option+1) == 0)
4569 break;
4570 if (LocaleCompare("flip",option+1) == 0)
4571 break;
4572 if (LocaleCompare("flop",option+1) == 0)
4573 break;
4574 if (LocaleCompare("floodfill",option+1) == 0)
4575 {
4576 if (*option == '+')
4577 break;
4578 i++;
cristybb503372010-05-27 20:51:26 +00004579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004580 ThrowMogrifyException(OptionError,"MissingArgument",option);
4581 if (IsGeometry(argv[i]) == MagickFalse)
4582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4583 i++;
cristybb503372010-05-27 20:51:26 +00004584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004585 ThrowMogrifyException(OptionError,"MissingArgument",option);
4586 break;
4587 }
4588 if (LocaleCompare("font",option+1) == 0)
4589 {
4590 if (*option == '+')
4591 break;
4592 i++;
cristybb503372010-05-27 20:51:26 +00004593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004594 ThrowMogrifyException(OptionError,"MissingArgument",option);
4595 break;
4596 }
4597 if (LocaleCompare("format",option+1) == 0)
4598 {
4599 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4600 (void) CloneString(&format,(char *) NULL);
4601 if (*option == '+')
4602 break;
4603 i++;
cristybb503372010-05-27 20:51:26 +00004604 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004605 ThrowMogrifyException(OptionError,"MissingArgument",option);
4606 (void) CloneString(&format,argv[i]);
4607 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4608 (void) ConcatenateMagickString(image_info->filename,":",
4609 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004610 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004611 if (*image_info->magick == '\0')
4612 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4613 format);
4614 break;
4615 }
4616 if (LocaleCompare("frame",option+1) == 0)
4617 {
4618 if (*option == '+')
4619 break;
4620 i++;
cristybb503372010-05-27 20:51:26 +00004621 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004622 ThrowMogrifyException(OptionError,"MissingArgument",option);
4623 if (IsGeometry(argv[i]) == MagickFalse)
4624 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4625 break;
4626 }
4627 if (LocaleCompare("function",option+1) == 0)
4628 {
cristybb503372010-05-27 20:51:26 +00004629 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004630 op;
4631
4632 if (*option == '+')
4633 break;
4634 i++;
cristybb503372010-05-27 20:51:26 +00004635 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004636 ThrowMogrifyException(OptionError,"MissingArgument",option);
4637 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4638 if (op < 0)
4639 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4640 i++;
cristybb503372010-05-27 20:51:26 +00004641 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004642 ThrowMogrifyException(OptionError,"MissingArgument",option);
4643 break;
4644 }
4645 if (LocaleCompare("fuzz",option+1) == 0)
4646 {
4647 if (*option == '+')
4648 break;
4649 i++;
cristybb503372010-05-27 20:51:26 +00004650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004651 ThrowMogrifyException(OptionError,"MissingArgument",option);
4652 if (IsGeometry(argv[i]) == MagickFalse)
4653 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4654 break;
4655 }
4656 if (LocaleCompare("fx",option+1) == 0)
4657 {
4658 if (*option == '+')
4659 break;
4660 i++;
cristybb503372010-05-27 20:51:26 +00004661 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004662 ThrowMogrifyException(OptionError,"MissingArgument",option);
4663 break;
4664 }
4665 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4666 }
4667 case 'g':
4668 {
4669 if (LocaleCompare("gamma",option+1) == 0)
4670 {
4671 i++;
cristybb503372010-05-27 20:51:26 +00004672 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 if (IsGeometry(argv[i]) == MagickFalse)
4675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676 break;
4677 }
4678 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4679 (LocaleCompare("gaussian",option+1) == 0))
4680 {
4681 i++;
cristybb503372010-05-27 20:51:26 +00004682 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004683 ThrowMogrifyException(OptionError,"MissingArgument",option);
4684 if (IsGeometry(argv[i]) == MagickFalse)
4685 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4686 break;
4687 }
4688 if (LocaleCompare("geometry",option+1) == 0)
4689 {
4690 if (*option == '+')
4691 break;
4692 i++;
cristybb503372010-05-27 20:51:26 +00004693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004694 ThrowMogrifyException(OptionError,"MissingArgument",option);
4695 if (IsGeometry(argv[i]) == MagickFalse)
4696 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4697 break;
4698 }
4699 if (LocaleCompare("gravity",option+1) == 0)
4700 {
cristybb503372010-05-27 20:51:26 +00004701 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004702 gravity;
4703
4704 if (*option == '+')
4705 break;
4706 i++;
cristybb503372010-05-27 20:51:26 +00004707 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004708 ThrowMogrifyException(OptionError,"MissingArgument",option);
4709 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
4710 if (gravity < 0)
4711 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4712 argv[i]);
4713 break;
4714 }
4715 if (LocaleCompare("green-primary",option+1) == 0)
4716 {
4717 if (*option == '+')
4718 break;
4719 i++;
cristybb503372010-05-27 20:51:26 +00004720 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004721 ThrowMogrifyException(OptionError,"MissingArgument",option);
4722 if (IsGeometry(argv[i]) == MagickFalse)
4723 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4724 break;
4725 }
4726 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4727 }
4728 case 'h':
4729 {
4730 if (LocaleCompare("hald-clut",option+1) == 0)
4731 break;
4732 if ((LocaleCompare("help",option+1) == 0) ||
4733 (LocaleCompare("-help",option+1) == 0))
4734 return(MogrifyUsage());
4735 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4736 }
4737 case 'i':
4738 {
4739 if (LocaleCompare("identify",option+1) == 0)
4740 break;
4741 if (LocaleCompare("idft",option+1) == 0)
4742 break;
4743 if (LocaleCompare("implode",option+1) == 0)
4744 {
4745 if (*option == '+')
4746 break;
4747 i++;
cristybb503372010-05-27 20:51:26 +00004748 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004749 ThrowMogrifyException(OptionError,"MissingArgument",option);
4750 if (IsGeometry(argv[i]) == MagickFalse)
4751 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4752 break;
4753 }
4754 if (LocaleCompare("intent",option+1) == 0)
4755 {
cristybb503372010-05-27 20:51:26 +00004756 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004757 intent;
4758
4759 if (*option == '+')
4760 break;
4761 i++;
cristybb503372010-05-27 20:51:26 +00004762 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004763 ThrowMogrifyException(OptionError,"MissingArgument",option);
4764 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
4765 if (intent < 0)
4766 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4767 argv[i]);
4768 break;
4769 }
4770 if (LocaleCompare("interlace",option+1) == 0)
4771 {
cristybb503372010-05-27 20:51:26 +00004772 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004773 interlace;
4774
4775 if (*option == '+')
4776 break;
4777 i++;
cristybb503372010-05-27 20:51:26 +00004778 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004779 ThrowMogrifyException(OptionError,"MissingArgument",option);
4780 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
4781 argv[i]);
4782 if (interlace < 0)
4783 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4784 argv[i]);
4785 break;
4786 }
cristyb32b90a2009-09-07 21:45:48 +00004787 if (LocaleCompare("interline-spacing",option+1) == 0)
4788 {
4789 if (*option == '+')
4790 break;
4791 i++;
cristybb503372010-05-27 20:51:26 +00004792 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004793 ThrowMogrifyException(OptionError,"MissingArgument",option);
4794 if (IsGeometry(argv[i]) == MagickFalse)
4795 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4796 break;
4797 }
cristy3ed852e2009-09-05 21:47:34 +00004798 if (LocaleCompare("interpolate",option+1) == 0)
4799 {
cristybb503372010-05-27 20:51:26 +00004800 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004801 interpolate;
4802
4803 if (*option == '+')
4804 break;
4805 i++;
cristybb503372010-05-27 20:51:26 +00004806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004807 ThrowMogrifyException(OptionError,"MissingArgument",option);
4808 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
4809 argv[i]);
4810 if (interpolate < 0)
4811 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4812 argv[i]);
4813 break;
4814 }
4815 if (LocaleCompare("interword-spacing",option+1) == 0)
4816 {
4817 if (*option == '+')
4818 break;
4819 i++;
cristybb503372010-05-27 20:51:26 +00004820 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004821 ThrowMogrifyException(OptionError,"MissingArgument",option);
4822 if (IsGeometry(argv[i]) == MagickFalse)
4823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4824 break;
4825 }
4826 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4827 }
4828 case 'k':
4829 {
4830 if (LocaleCompare("kerning",option+1) == 0)
4831 {
4832 if (*option == '+')
4833 break;
4834 i++;
cristybb503372010-05-27 20:51:26 +00004835 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004836 ThrowMogrifyException(OptionError,"MissingArgument",option);
4837 if (IsGeometry(argv[i]) == MagickFalse)
4838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4839 break;
4840 }
4841 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4842 }
4843 case 'l':
4844 {
4845 if (LocaleCompare("label",option+1) == 0)
4846 {
4847 if (*option == '+')
4848 break;
4849 i++;
cristybb503372010-05-27 20:51:26 +00004850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004851 ThrowMogrifyException(OptionError,"MissingArgument",option);
4852 break;
4853 }
4854 if (LocaleCompare("lat",option+1) == 0)
4855 {
4856 if (*option == '+')
4857 break;
4858 i++;
cristybb503372010-05-27 20:51:26 +00004859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004860 ThrowMogrifyException(OptionError,"MissingArgument",option);
4861 if (IsGeometry(argv[i]) == MagickFalse)
4862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4863 }
4864 if (LocaleCompare("layers",option+1) == 0)
4865 {
cristybb503372010-05-27 20:51:26 +00004866 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004867 type;
4868
4869 if (*option == '+')
4870 break;
4871 i++;
cristybb503372010-05-27 20:51:26 +00004872 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004873 ThrowMogrifyException(OptionError,"MissingArgument",option);
4874 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
4875 if (type < 0)
4876 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4877 argv[i]);
4878 break;
4879 }
4880 if (LocaleCompare("level",option+1) == 0)
4881 {
4882 i++;
cristybb503372010-05-27 20:51:26 +00004883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004884 ThrowMogrifyException(OptionError,"MissingArgument",option);
4885 if (IsGeometry(argv[i]) == MagickFalse)
4886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4887 break;
4888 }
4889 if (LocaleCompare("level-colors",option+1) == 0)
4890 {
4891 i++;
cristybb503372010-05-27 20:51:26 +00004892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004893 ThrowMogrifyException(OptionError,"MissingArgument",option);
4894 break;
4895 }
4896 if (LocaleCompare("linewidth",option+1) == 0)
4897 {
4898 if (*option == '+')
4899 break;
4900 i++;
cristybb503372010-05-27 20:51:26 +00004901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004902 ThrowMogrifyException(OptionError,"MissingArgument",option);
4903 if (IsGeometry(argv[i]) == MagickFalse)
4904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4905 break;
4906 }
4907 if (LocaleCompare("limit",option+1) == 0)
4908 {
4909 char
4910 *p;
4911
4912 double
4913 value;
4914
cristybb503372010-05-27 20:51:26 +00004915 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004916 resource;
4917
4918 if (*option == '+')
4919 break;
4920 i++;
cristybb503372010-05-27 20:51:26 +00004921 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004922 ThrowMogrifyException(OptionError,"MissingArgument",option);
4923 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
4924 argv[i]);
4925 if (resource < 0)
4926 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4927 argv[i]);
4928 i++;
cristybb503372010-05-27 20:51:26 +00004929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004930 ThrowMogrifyException(OptionError,"MissingArgument",option);
4931 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004932 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004933 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4934 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4935 break;
4936 }
4937 if (LocaleCompare("liquid-rescale",option+1) == 0)
4938 {
4939 i++;
cristybb503372010-05-27 20:51:26 +00004940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004941 ThrowMogrifyException(OptionError,"MissingArgument",option);
4942 if (IsGeometry(argv[i]) == MagickFalse)
4943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4944 break;
4945 }
4946 if (LocaleCompare("list",option+1) == 0)
4947 {
cristybb503372010-05-27 20:51:26 +00004948 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004949 list;
4950
4951 if (*option == '+')
4952 break;
4953 i++;
cristybb503372010-05-27 20:51:26 +00004954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004955 ThrowMogrifyException(OptionError,"MissingArgument",option);
4956 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
4957 if (list < 0)
4958 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004959 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004960 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004961 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004962 }
4963 if (LocaleCompare("log",option+1) == 0)
4964 {
4965 if (*option == '+')
4966 break;
4967 i++;
cristybb503372010-05-27 20:51:26 +00004968 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004969 (strchr(argv[i],'%') == (char *) NULL))
4970 ThrowMogrifyException(OptionError,"MissingArgument",option);
4971 break;
4972 }
4973 if (LocaleCompare("loop",option+1) == 0)
4974 {
4975 if (*option == '+')
4976 break;
4977 i++;
cristybb503372010-05-27 20:51:26 +00004978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004979 ThrowMogrifyException(OptionError,"MissingArgument",option);
4980 if (IsGeometry(argv[i]) == MagickFalse)
4981 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4982 break;
4983 }
4984 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4985 }
4986 case 'm':
4987 {
4988 if (LocaleCompare("map",option+1) == 0)
4989 {
4990 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4991 if (*option == '+')
4992 break;
4993 i++;
cristybb503372010-05-27 20:51:26 +00004994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004995 ThrowMogrifyException(OptionError,"MissingArgument",option);
4996 break;
4997 }
4998 if (LocaleCompare("mask",option+1) == 0)
4999 {
5000 if (*option == '+')
5001 break;
5002 i++;
cristybb503372010-05-27 20:51:26 +00005003 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005004 ThrowMogrifyException(OptionError,"MissingArgument",option);
5005 break;
5006 }
5007 if (LocaleCompare("matte",option+1) == 0)
5008 break;
5009 if (LocaleCompare("mattecolor",option+1) == 0)
5010 {
5011 if (*option == '+')
5012 break;
5013 i++;
cristybb503372010-05-27 20:51:26 +00005014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005015 ThrowMogrifyException(OptionError,"MissingArgument",option);
5016 break;
5017 }
cristyf40785b2010-03-06 02:27:27 +00005018 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005019 break;
cristyf40785b2010-03-06 02:27:27 +00005020 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005021 break;
cristy3ed852e2009-09-05 21:47:34 +00005022 if (LocaleCompare("modulate",option+1) == 0)
5023 {
5024 if (*option == '+')
5025 break;
5026 i++;
cristybb503372010-05-27 20:51:26 +00005027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005028 ThrowMogrifyException(OptionError,"MissingArgument",option);
5029 if (IsGeometry(argv[i]) == MagickFalse)
5030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5031 break;
5032 }
5033 if (LocaleCompare("median",option+1) == 0)
5034 {
5035 if (*option == '+')
5036 break;
5037 i++;
cristybb503372010-05-27 20:51:26 +00005038 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005039 ThrowMogrifyException(OptionError,"MissingArgument",option);
5040 if (IsGeometry(argv[i]) == MagickFalse)
5041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5042 break;
5043 }
cristy69ec32d2011-02-27 23:57:09 +00005044 if (LocaleCompare("mode",option+1) == 0)
5045 {
5046 if (*option == '+')
5047 break;
5048 i++;
5049 if (i == (ssize_t) argc)
5050 ThrowMogrifyException(OptionError,"MissingArgument",option);
5051 if (IsGeometry(argv[i]) == MagickFalse)
5052 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5053 break;
5054 }
cristy3ed852e2009-09-05 21:47:34 +00005055 if (LocaleCompare("monitor",option+1) == 0)
5056 break;
5057 if (LocaleCompare("monochrome",option+1) == 0)
5058 break;
5059 if (LocaleCompare("morph",option+1) == 0)
5060 {
5061 if (*option == '+')
5062 break;
5063 i++;
cristybb503372010-05-27 20:51:26 +00005064 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005065 ThrowMogrifyException(OptionError,"MissingArgument",option);
5066 if (IsGeometry(argv[i]) == MagickFalse)
5067 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5068 break;
5069 }
anthony29188a82010-01-22 10:12:34 +00005070 if (LocaleCompare("morphology",option+1) == 0)
5071 {
anthony29188a82010-01-22 10:12:34 +00005072 char
5073 token[MaxTextExtent];
5074
cristyb6bd4ad2010-08-08 01:12:27 +00005075 KernelInfo
5076 *kernel_info;
5077
5078 ssize_t
5079 op;
5080
anthony29188a82010-01-22 10:12:34 +00005081 i++;
cristybb503372010-05-27 20:51:26 +00005082 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005083 ThrowMogrifyException(OptionError,"MissingArgument",option);
5084 GetMagickToken(argv[i],NULL,token);
5085 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5086 if (op < 0)
5087 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005088 token);
anthony29188a82010-01-22 10:12:34 +00005089 i++;
cristybb503372010-05-27 20:51:26 +00005090 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005091 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005092 kernel_info=AcquireKernelInfo(argv[i]);
5093 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005094 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005095 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005096 break;
5097 }
cristy3ed852e2009-09-05 21:47:34 +00005098 if (LocaleCompare("mosaic",option+1) == 0)
5099 break;
5100 if (LocaleCompare("motion-blur",option+1) == 0)
5101 {
5102 if (*option == '+')
5103 break;
5104 i++;
cristybb503372010-05-27 20:51:26 +00005105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005106 ThrowMogrifyException(OptionError,"MissingArgument",option);
5107 if (IsGeometry(argv[i]) == MagickFalse)
5108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5109 break;
5110 }
5111 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5112 }
5113 case 'n':
5114 {
5115 if (LocaleCompare("negate",option+1) == 0)
5116 break;
5117 if (LocaleCompare("noise",option+1) == 0)
5118 {
5119 i++;
cristybb503372010-05-27 20:51:26 +00005120 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005121 ThrowMogrifyException(OptionError,"MissingArgument",option);
5122 if (*option == '+')
5123 {
cristybb503372010-05-27 20:51:26 +00005124 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005125 noise;
5126
5127 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5128 if (noise < 0)
5129 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5130 argv[i]);
5131 break;
5132 }
5133 if (IsGeometry(argv[i]) == MagickFalse)
5134 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5135 break;
5136 }
5137 if (LocaleCompare("noop",option+1) == 0)
5138 break;
5139 if (LocaleCompare("normalize",option+1) == 0)
5140 break;
5141 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5142 }
5143 case 'o':
5144 {
5145 if (LocaleCompare("opaque",option+1) == 0)
5146 {
cristy3ed852e2009-09-05 21:47:34 +00005147 i++;
cristybb503372010-05-27 20:51:26 +00005148 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005149 ThrowMogrifyException(OptionError,"MissingArgument",option);
5150 break;
5151 }
5152 if (LocaleCompare("ordered-dither",option+1) == 0)
5153 {
5154 if (*option == '+')
5155 break;
5156 i++;
cristybb503372010-05-27 20:51:26 +00005157 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005158 ThrowMogrifyException(OptionError,"MissingArgument",option);
5159 break;
5160 }
5161 if (LocaleCompare("orient",option+1) == 0)
5162 {
cristybb503372010-05-27 20:51:26 +00005163 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005164 orientation;
5165
5166 orientation=UndefinedOrientation;
5167 if (*option == '+')
5168 break;
5169 i++;
cristybb503372010-05-27 20:51:26 +00005170 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005171 ThrowMogrifyException(OptionError,"MissingArgument",option);
5172 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5173 argv[i]);
5174 if (orientation < 0)
5175 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5176 argv[i]);
5177 break;
5178 }
5179 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5180 }
5181 case 'p':
5182 {
5183 if (LocaleCompare("page",option+1) == 0)
5184 {
5185 if (*option == '+')
5186 break;
5187 i++;
cristybb503372010-05-27 20:51:26 +00005188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005189 ThrowMogrifyException(OptionError,"MissingArgument",option);
5190 break;
5191 }
5192 if (LocaleCompare("paint",option+1) == 0)
5193 {
5194 if (*option == '+')
5195 break;
5196 i++;
cristybb503372010-05-27 20:51:26 +00005197 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005198 ThrowMogrifyException(OptionError,"MissingArgument",option);
5199 if (IsGeometry(argv[i]) == MagickFalse)
5200 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5201 break;
5202 }
5203 if (LocaleCompare("path",option+1) == 0)
5204 {
5205 (void) CloneString(&path,(char *) NULL);
5206 if (*option == '+')
5207 break;
5208 i++;
cristybb503372010-05-27 20:51:26 +00005209 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005210 ThrowMogrifyException(OptionError,"MissingArgument",option);
5211 (void) CloneString(&path,argv[i]);
5212 break;
5213 }
5214 if (LocaleCompare("pointsize",option+1) == 0)
5215 {
5216 if (*option == '+')
5217 break;
5218 i++;
cristybb503372010-05-27 20:51:26 +00005219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005220 ThrowMogrifyException(OptionError,"MissingArgument",option);
5221 if (IsGeometry(argv[i]) == MagickFalse)
5222 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5223 break;
5224 }
5225 if (LocaleCompare("polaroid",option+1) == 0)
5226 {
5227 if (*option == '+')
5228 break;
5229 i++;
cristybb503372010-05-27 20:51:26 +00005230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005231 ThrowMogrifyException(OptionError,"MissingArgument",option);
5232 if (IsGeometry(argv[i]) == MagickFalse)
5233 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5234 break;
5235 }
5236 if (LocaleCompare("posterize",option+1) == 0)
5237 {
5238 if (*option == '+')
5239 break;
5240 i++;
cristybb503372010-05-27 20:51:26 +00005241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005242 ThrowMogrifyException(OptionError,"MissingArgument",option);
5243 if (IsGeometry(argv[i]) == MagickFalse)
5244 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5245 break;
5246 }
cristye7f51092010-01-17 00:39:37 +00005247 if (LocaleCompare("precision",option+1) == 0)
5248 {
5249 if (*option == '+')
5250 break;
5251 i++;
cristybb503372010-05-27 20:51:26 +00005252 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005253 ThrowMogrifyException(OptionError,"MissingArgument",option);
5254 if (IsGeometry(argv[i]) == MagickFalse)
5255 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5256 break;
5257 }
cristy3ed852e2009-09-05 21:47:34 +00005258 if (LocaleCompare("print",option+1) == 0)
5259 {
5260 if (*option == '+')
5261 break;
5262 i++;
cristybb503372010-05-27 20:51:26 +00005263 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005264 ThrowMogrifyException(OptionError,"MissingArgument",option);
5265 break;
5266 }
5267 if (LocaleCompare("process",option+1) == 0)
5268 {
5269 if (*option == '+')
5270 break;
5271 i++;
cristybb503372010-05-27 20:51:26 +00005272 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005273 ThrowMogrifyException(OptionError,"MissingArgument",option);
5274 break;
5275 }
5276 if (LocaleCompare("profile",option+1) == 0)
5277 {
5278 i++;
cristybb503372010-05-27 20:51:26 +00005279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005280 ThrowMogrifyException(OptionError,"MissingArgument",option);
5281 break;
5282 }
5283 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5284 }
5285 case 'q':
5286 {
5287 if (LocaleCompare("quality",option+1) == 0)
5288 {
5289 if (*option == '+')
5290 break;
5291 i++;
cristybb503372010-05-27 20:51:26 +00005292 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005293 ThrowMogrifyException(OptionError,"MissingArgument",option);
5294 if (IsGeometry(argv[i]) == MagickFalse)
5295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5296 break;
5297 }
5298 if (LocaleCompare("quantize",option+1) == 0)
5299 {
cristybb503372010-05-27 20:51:26 +00005300 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005301 colorspace;
5302
5303 if (*option == '+')
5304 break;
5305 i++;
cristybb503372010-05-27 20:51:26 +00005306 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005307 ThrowMogrifyException(OptionError,"MissingArgument",option);
5308 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5309 argv[i]);
5310 if (colorspace < 0)
5311 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5312 argv[i]);
5313 break;
5314 }
5315 if (LocaleCompare("quiet",option+1) == 0)
5316 break;
5317 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5318 }
5319 case 'r':
5320 {
5321 if (LocaleCompare("radial-blur",option+1) == 0)
5322 {
5323 i++;
cristybb503372010-05-27 20:51:26 +00005324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005325 ThrowMogrifyException(OptionError,"MissingArgument",option);
5326 if (IsGeometry(argv[i]) == MagickFalse)
5327 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5328 break;
5329 }
5330 if (LocaleCompare("raise",option+1) == 0)
5331 {
5332 i++;
cristybb503372010-05-27 20:51:26 +00005333 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005334 ThrowMogrifyException(OptionError,"MissingArgument",option);
5335 if (IsGeometry(argv[i]) == MagickFalse)
5336 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5337 break;
5338 }
5339 if (LocaleCompare("random-threshold",option+1) == 0)
5340 {
5341 if (*option == '+')
5342 break;
5343 i++;
cristybb503372010-05-27 20:51:26 +00005344 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005345 ThrowMogrifyException(OptionError,"MissingArgument",option);
5346 if (IsGeometry(argv[i]) == MagickFalse)
5347 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5348 break;
5349 }
cristye6365592010-04-02 17:31:23 +00005350 if (LocaleCompare("recolor",option+1) == 0)
5351 {
5352 if (*option == '+')
5353 break;
5354 i++;
cristybb503372010-05-27 20:51:26 +00005355 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005356 ThrowMogrifyException(OptionError,"MissingArgument",option);
5357 if (IsGeometry(argv[i]) == MagickFalse)
5358 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5359 break;
5360 }
cristy3ed852e2009-09-05 21:47:34 +00005361 if (LocaleCompare("red-primary",option+1) == 0)
5362 {
5363 if (*option == '+')
5364 break;
5365 i++;
cristybb503372010-05-27 20:51:26 +00005366 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005367 ThrowMogrifyException(OptionError,"MissingArgument",option);
5368 if (IsGeometry(argv[i]) == MagickFalse)
5369 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5370 }
cristy9f2083a2010-04-22 19:48:05 +00005371 if (LocaleCompare("regard-warnings",option+1) == 0)
5372 break;
cristy3ed852e2009-09-05 21:47:34 +00005373 if (LocaleCompare("region",option+1) == 0)
5374 {
5375 if (*option == '+')
5376 break;
5377 i++;
cristybb503372010-05-27 20:51:26 +00005378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005379 ThrowMogrifyException(OptionError,"MissingArgument",option);
5380 if (IsGeometry(argv[i]) == MagickFalse)
5381 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5382 break;
5383 }
cristyf0c78232010-03-15 12:53:40 +00005384 if (LocaleCompare("remap",option+1) == 0)
5385 {
5386 if (*option == '+')
5387 break;
5388 i++;
cristybb503372010-05-27 20:51:26 +00005389 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005390 ThrowMogrifyException(OptionError,"MissingArgument",option);
5391 break;
5392 }
cristy3ed852e2009-09-05 21:47:34 +00005393 if (LocaleCompare("render",option+1) == 0)
5394 break;
5395 if (LocaleCompare("repage",option+1) == 0)
5396 {
5397 if (*option == '+')
5398 break;
5399 i++;
cristybb503372010-05-27 20:51:26 +00005400 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005401 ThrowMogrifyException(OptionError,"MissingArgument",option);
5402 if (IsGeometry(argv[i]) == MagickFalse)
5403 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5404 break;
5405 }
5406 if (LocaleCompare("resample",option+1) == 0)
5407 {
5408 if (*option == '+')
5409 break;
5410 i++;
cristybb503372010-05-27 20:51:26 +00005411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005412 ThrowMogrifyException(OptionError,"MissingArgument",option);
5413 if (IsGeometry(argv[i]) == MagickFalse)
5414 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5415 break;
5416 }
5417 if (LocaleCompare("resize",option+1) == 0)
5418 {
5419 if (*option == '+')
5420 break;
5421 i++;
cristybb503372010-05-27 20:51:26 +00005422 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005423 ThrowMogrifyException(OptionError,"MissingArgument",option);
5424 if (IsGeometry(argv[i]) == MagickFalse)
5425 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5426 break;
5427 }
cristyebbcfea2011-02-25 02:43:54 +00005428 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5429 {
5430 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5431 break;
5432 }
cristy3ed852e2009-09-05 21:47:34 +00005433 if (LocaleCompare("reverse",option+1) == 0)
5434 break;
5435 if (LocaleCompare("roll",option+1) == 0)
5436 {
5437 if (*option == '+')
5438 break;
5439 i++;
cristybb503372010-05-27 20:51:26 +00005440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005441 ThrowMogrifyException(OptionError,"MissingArgument",option);
5442 if (IsGeometry(argv[i]) == MagickFalse)
5443 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5444 break;
5445 }
5446 if (LocaleCompare("rotate",option+1) == 0)
5447 {
5448 i++;
cristybb503372010-05-27 20:51:26 +00005449 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005450 ThrowMogrifyException(OptionError,"MissingArgument",option);
5451 if (IsGeometry(argv[i]) == MagickFalse)
5452 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5453 break;
5454 }
5455 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5456 }
5457 case 's':
5458 {
5459 if (LocaleCompare("sample",option+1) == 0)
5460 {
5461 if (*option == '+')
5462 break;
5463 i++;
cristybb503372010-05-27 20:51:26 +00005464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005465 ThrowMogrifyException(OptionError,"MissingArgument",option);
5466 if (IsGeometry(argv[i]) == MagickFalse)
5467 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5468 break;
5469 }
5470 if (LocaleCompare("sampling-factor",option+1) == 0)
5471 {
5472 if (*option == '+')
5473 break;
5474 i++;
cristybb503372010-05-27 20:51:26 +00005475 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005476 ThrowMogrifyException(OptionError,"MissingArgument",option);
5477 if (IsGeometry(argv[i]) == MagickFalse)
5478 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5479 break;
5480 }
5481 if (LocaleCompare("scale",option+1) == 0)
5482 {
5483 if (*option == '+')
5484 break;
5485 i++;
cristybb503372010-05-27 20:51:26 +00005486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005487 ThrowMogrifyException(OptionError,"MissingArgument",option);
5488 if (IsGeometry(argv[i]) == MagickFalse)
5489 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5490 break;
5491 }
5492 if (LocaleCompare("scene",option+1) == 0)
5493 {
5494 if (*option == '+')
5495 break;
5496 i++;
cristybb503372010-05-27 20:51:26 +00005497 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005498 ThrowMogrifyException(OptionError,"MissingArgument",option);
5499 if (IsGeometry(argv[i]) == MagickFalse)
5500 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5501 break;
5502 }
5503 if (LocaleCompare("seed",option+1) == 0)
5504 {
5505 if (*option == '+')
5506 break;
5507 i++;
cristybb503372010-05-27 20:51:26 +00005508 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005509 ThrowMogrifyException(OptionError,"MissingArgument",option);
5510 if (IsGeometry(argv[i]) == MagickFalse)
5511 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5512 break;
5513 }
5514 if (LocaleCompare("segment",option+1) == 0)
5515 {
5516 if (*option == '+')
5517 break;
5518 i++;
cristybb503372010-05-27 20:51:26 +00005519 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005520 ThrowMogrifyException(OptionError,"MissingArgument",option);
5521 if (IsGeometry(argv[i]) == MagickFalse)
5522 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5523 break;
5524 }
5525 if (LocaleCompare("selective-blur",option+1) == 0)
5526 {
5527 i++;
cristybb503372010-05-27 20:51:26 +00005528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005529 ThrowMogrifyException(OptionError,"MissingArgument",option);
5530 if (IsGeometry(argv[i]) == MagickFalse)
5531 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5532 break;
5533 }
5534 if (LocaleCompare("separate",option+1) == 0)
5535 break;
5536 if (LocaleCompare("sepia-tone",option+1) == 0)
5537 {
5538 if (*option == '+')
5539 break;
5540 i++;
cristybb503372010-05-27 20:51:26 +00005541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005542 ThrowMogrifyException(OptionError,"MissingArgument",option);
5543 if (IsGeometry(argv[i]) == MagickFalse)
5544 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5545 break;
5546 }
5547 if (LocaleCompare("set",option+1) == 0)
5548 {
5549 i++;
cristybb503372010-05-27 20:51:26 +00005550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005551 ThrowMogrifyException(OptionError,"MissingArgument",option);
5552 if (*option == '+')
5553 break;
5554 i++;
cristybb503372010-05-27 20:51:26 +00005555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005556 ThrowMogrifyException(OptionError,"MissingArgument",option);
5557 break;
5558 }
5559 if (LocaleCompare("shade",option+1) == 0)
5560 {
5561 i++;
cristybb503372010-05-27 20:51:26 +00005562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005563 ThrowMogrifyException(OptionError,"MissingArgument",option);
5564 if (IsGeometry(argv[i]) == MagickFalse)
5565 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5566 break;
5567 }
5568 if (LocaleCompare("shadow",option+1) == 0)
5569 {
5570 if (*option == '+')
5571 break;
5572 i++;
cristybb503372010-05-27 20:51:26 +00005573 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005574 ThrowMogrifyException(OptionError,"MissingArgument",option);
5575 if (IsGeometry(argv[i]) == MagickFalse)
5576 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5577 break;
5578 }
5579 if (LocaleCompare("sharpen",option+1) == 0)
5580 {
5581 i++;
cristybb503372010-05-27 20:51:26 +00005582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005583 ThrowMogrifyException(OptionError,"MissingArgument",option);
5584 if (IsGeometry(argv[i]) == MagickFalse)
5585 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5586 break;
5587 }
5588 if (LocaleCompare("shave",option+1) == 0)
5589 {
5590 if (*option == '+')
5591 break;
5592 i++;
cristybb503372010-05-27 20:51:26 +00005593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005594 ThrowMogrifyException(OptionError,"MissingArgument",option);
5595 if (IsGeometry(argv[i]) == MagickFalse)
5596 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5597 break;
5598 }
5599 if (LocaleCompare("shear",option+1) == 0)
5600 {
5601 i++;
cristybb503372010-05-27 20:51:26 +00005602 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005603 ThrowMogrifyException(OptionError,"MissingArgument",option);
5604 if (IsGeometry(argv[i]) == MagickFalse)
5605 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5606 break;
5607 }
5608 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5609 {
5610 i++;
cristybb503372010-05-27 20:51:26 +00005611 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005612 ThrowMogrifyException(OptionError,"MissingArgument",option);
5613 if (IsGeometry(argv[i]) == MagickFalse)
5614 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5615 break;
5616 }
5617 if (LocaleCompare("size",option+1) == 0)
5618 {
5619 if (*option == '+')
5620 break;
5621 i++;
cristybb503372010-05-27 20:51:26 +00005622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005623 ThrowMogrifyException(OptionError,"MissingArgument",option);
5624 if (IsGeometry(argv[i]) == MagickFalse)
5625 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5626 break;
5627 }
5628 if (LocaleCompare("sketch",option+1) == 0)
5629 {
5630 if (*option == '+')
5631 break;
5632 i++;
cristybb503372010-05-27 20:51:26 +00005633 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005634 ThrowMogrifyException(OptionError,"MissingArgument",option);
5635 if (IsGeometry(argv[i]) == MagickFalse)
5636 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5637 break;
5638 }
cristy4285d782011-02-09 20:12:28 +00005639 if (LocaleCompare("smush",option+1) == 0)
5640 {
cristy4285d782011-02-09 20:12:28 +00005641 i++;
5642 if (i == (ssize_t) argc)
5643 ThrowMogrifyException(OptionError,"MissingArgument",option);
5644 if (IsGeometry(argv[i]) == MagickFalse)
5645 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005646 i++;
5647 break;
5648 }
cristy3ed852e2009-09-05 21:47:34 +00005649 if (LocaleCompare("solarize",option+1) == 0)
5650 {
5651 if (*option == '+')
5652 break;
5653 i++;
cristybb503372010-05-27 20:51:26 +00005654 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005655 ThrowMogrifyException(OptionError,"MissingArgument",option);
5656 if (IsGeometry(argv[i]) == MagickFalse)
5657 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5658 break;
5659 }
5660 if (LocaleCompare("sparse-color",option+1) == 0)
5661 {
cristybb503372010-05-27 20:51:26 +00005662 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005663 op;
5664
5665 i++;
cristybb503372010-05-27 20:51:26 +00005666 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005667 ThrowMogrifyException(OptionError,"MissingArgument",option);
5668 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5669 if (op < 0)
5670 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5671 argv[i]);
5672 i++;
cristybb503372010-05-27 20:51:26 +00005673 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005674 ThrowMogrifyException(OptionError,"MissingArgument",option);
5675 break;
5676 }
5677 if (LocaleCompare("spread",option+1) == 0)
5678 {
5679 if (*option == '+')
5680 break;
5681 i++;
cristybb503372010-05-27 20:51:26 +00005682 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005683 ThrowMogrifyException(OptionError,"MissingArgument",option);
5684 if (IsGeometry(argv[i]) == MagickFalse)
5685 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5686 break;
5687 }
cristy0834d642011-03-18 18:26:08 +00005688 if (LocaleCompare("statistic",option+1) == 0)
5689 {
5690 ssize_t
5691 op;
5692
5693 if (*option == '+')
5694 break;
5695 i++;
5696 if (i == (ssize_t) argc)
5697 ThrowMogrifyException(OptionError,"MissingArgument",option);
5698 op=ParseMagickOption(MagickStatisticOptions,MagickFalse,argv[i]);
5699 if (op < 0)
5700 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5701 argv[i]);
5702 i++;
5703 if (i == (ssize_t) (argc-1))
5704 ThrowMogrifyException(OptionError,"MissingArgument",option);
5705 if (IsGeometry(argv[i]) == MagickFalse)
5706 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5707 break;
5708 }
cristy3ed852e2009-09-05 21:47:34 +00005709 if (LocaleCompare("stretch",option+1) == 0)
5710 {
cristybb503372010-05-27 20:51:26 +00005711 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005712 stretch;
5713
5714 if (*option == '+')
5715 break;
5716 i++;
cristybb503372010-05-27 20:51:26 +00005717 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005718 ThrowMogrifyException(OptionError,"MissingArgument",option);
5719 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
5720 if (stretch < 0)
5721 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5722 argv[i]);
5723 break;
5724 }
5725 if (LocaleCompare("strip",option+1) == 0)
5726 break;
5727 if (LocaleCompare("stroke",option+1) == 0)
5728 {
5729 if (*option == '+')
5730 break;
5731 i++;
cristybb503372010-05-27 20:51:26 +00005732 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005733 ThrowMogrifyException(OptionError,"MissingArgument",option);
5734 break;
5735 }
5736 if (LocaleCompare("strokewidth",option+1) == 0)
5737 {
5738 if (*option == '+')
5739 break;
5740 i++;
cristybb503372010-05-27 20:51:26 +00005741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005742 ThrowMogrifyException(OptionError,"MissingArgument",option);
5743 if (IsGeometry(argv[i]) == MagickFalse)
5744 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5745 break;
5746 }
5747 if (LocaleCompare("style",option+1) == 0)
5748 {
cristybb503372010-05-27 20:51:26 +00005749 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005750 style;
5751
5752 if (*option == '+')
5753 break;
5754 i++;
cristybb503372010-05-27 20:51:26 +00005755 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005756 ThrowMogrifyException(OptionError,"MissingArgument",option);
5757 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
5758 if (style < 0)
5759 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5760 argv[i]);
5761 break;
5762 }
cristyecb10ff2011-03-22 13:14:03 +00005763 if (LocaleCompare("swap",option+1) == 0)
5764 {
5765 if (*option == '+')
5766 break;
5767 i++;
5768 if (i == (ssize_t) (argc-1))
5769 ThrowMogrifyException(OptionError,"MissingArgument",option);
5770 if (IsGeometry(argv[i]) == MagickFalse)
5771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5772 break;
5773 }
cristy3ed852e2009-09-05 21:47:34 +00005774 if (LocaleCompare("swirl",option+1) == 0)
5775 {
5776 if (*option == '+')
5777 break;
5778 i++;
cristybb503372010-05-27 20:51:26 +00005779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005780 ThrowMogrifyException(OptionError,"MissingArgument",option);
5781 if (IsGeometry(argv[i]) == MagickFalse)
5782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5783 break;
5784 }
cristyd9a29192010-10-16 16:49:53 +00005785 if (LocaleCompare("synchronize",option+1) == 0)
5786 break;
cristy3ed852e2009-09-05 21:47:34 +00005787 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5788 }
5789 case 't':
5790 {
5791 if (LocaleCompare("taint",option+1) == 0)
5792 break;
5793 if (LocaleCompare("texture",option+1) == 0)
5794 {
5795 if (*option == '+')
5796 break;
5797 i++;
cristybb503372010-05-27 20:51:26 +00005798 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005799 ThrowMogrifyException(OptionError,"MissingArgument",option);
5800 break;
5801 }
5802 if (LocaleCompare("tile",option+1) == 0)
5803 {
5804 if (*option == '+')
5805 break;
5806 i++;
cristybb503372010-05-27 20:51:26 +00005807 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005808 ThrowMogrifyException(OptionError,"MissingArgument",option);
5809 break;
5810 }
5811 if (LocaleCompare("tile-offset",option+1) == 0)
5812 {
5813 if (*option == '+')
5814 break;
5815 i++;
cristybb503372010-05-27 20:51:26 +00005816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005817 ThrowMogrifyException(OptionError,"MissingArgument",option);
5818 if (IsGeometry(argv[i]) == MagickFalse)
5819 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5820 break;
5821 }
5822 if (LocaleCompare("tint",option+1) == 0)
5823 {
5824 if (*option == '+')
5825 break;
5826 i++;
cristybb503372010-05-27 20:51:26 +00005827 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005828 ThrowMogrifyException(OptionError,"MissingArgument",option);
5829 if (IsGeometry(argv[i]) == MagickFalse)
5830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5831 break;
5832 }
5833 if (LocaleCompare("transform",option+1) == 0)
5834 break;
5835 if (LocaleCompare("transpose",option+1) == 0)
5836 break;
5837 if (LocaleCompare("transverse",option+1) == 0)
5838 break;
5839 if (LocaleCompare("threshold",option+1) == 0)
5840 {
5841 if (*option == '+')
5842 break;
5843 i++;
cristybb503372010-05-27 20:51:26 +00005844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005845 ThrowMogrifyException(OptionError,"MissingArgument",option);
5846 if (IsGeometry(argv[i]) == MagickFalse)
5847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5848 break;
5849 }
5850 if (LocaleCompare("thumbnail",option+1) == 0)
5851 {
5852 if (*option == '+')
5853 break;
5854 i++;
cristybb503372010-05-27 20:51:26 +00005855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005856 ThrowMogrifyException(OptionError,"MissingArgument",option);
5857 if (IsGeometry(argv[i]) == MagickFalse)
5858 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5859 break;
5860 }
5861 if (LocaleCompare("transparent",option+1) == 0)
5862 {
5863 i++;
cristybb503372010-05-27 20:51:26 +00005864 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005865 ThrowMogrifyException(OptionError,"MissingArgument",option);
5866 break;
5867 }
5868 if (LocaleCompare("transparent-color",option+1) == 0)
5869 {
5870 if (*option == '+')
5871 break;
5872 i++;
cristybb503372010-05-27 20:51:26 +00005873 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005874 ThrowMogrifyException(OptionError,"MissingArgument",option);
5875 break;
5876 }
5877 if (LocaleCompare("treedepth",option+1) == 0)
5878 {
5879 if (*option == '+')
5880 break;
5881 i++;
cristybb503372010-05-27 20:51:26 +00005882 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005883 ThrowMogrifyException(OptionError,"MissingArgument",option);
5884 if (IsGeometry(argv[i]) == MagickFalse)
5885 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5886 break;
5887 }
5888 if (LocaleCompare("trim",option+1) == 0)
5889 break;
5890 if (LocaleCompare("type",option+1) == 0)
5891 {
cristybb503372010-05-27 20:51:26 +00005892 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005893 type;
5894
5895 if (*option == '+')
5896 break;
5897 i++;
cristybb503372010-05-27 20:51:26 +00005898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005899 ThrowMogrifyException(OptionError,"MissingArgument",option);
5900 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
5901 if (type < 0)
5902 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5903 argv[i]);
5904 break;
5905 }
5906 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5907 }
5908 case 'u':
5909 {
5910 if (LocaleCompare("undercolor",option+1) == 0)
5911 {
5912 if (*option == '+')
5913 break;
5914 i++;
cristybb503372010-05-27 20:51:26 +00005915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005916 ThrowMogrifyException(OptionError,"MissingArgument",option);
5917 break;
5918 }
5919 if (LocaleCompare("unique-colors",option+1) == 0)
5920 break;
5921 if (LocaleCompare("units",option+1) == 0)
5922 {
cristybb503372010-05-27 20:51:26 +00005923 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005924 units;
5925
5926 if (*option == '+')
5927 break;
5928 i++;
cristybb503372010-05-27 20:51:26 +00005929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005930 ThrowMogrifyException(OptionError,"MissingArgument",option);
5931 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
5932 argv[i]);
5933 if (units < 0)
5934 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5935 argv[i]);
5936 break;
5937 }
5938 if (LocaleCompare("unsharp",option+1) == 0)
5939 {
5940 i++;
cristybb503372010-05-27 20:51:26 +00005941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005942 ThrowMogrifyException(OptionError,"MissingArgument",option);
5943 if (IsGeometry(argv[i]) == MagickFalse)
5944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5945 break;
5946 }
5947 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5948 }
5949 case 'v':
5950 {
5951 if (LocaleCompare("verbose",option+1) == 0)
5952 {
5953 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5954 break;
5955 }
5956 if ((LocaleCompare("version",option+1) == 0) ||
5957 (LocaleCompare("-version",option+1) == 0))
5958 {
5959 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005960 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00005961 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
5962 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005963 break;
5964 }
5965 if (LocaleCompare("view",option+1) == 0)
5966 {
5967 if (*option == '+')
5968 break;
5969 i++;
cristybb503372010-05-27 20:51:26 +00005970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005971 ThrowMogrifyException(OptionError,"MissingArgument",option);
5972 break;
5973 }
5974 if (LocaleCompare("vignette",option+1) == 0)
5975 {
5976 if (*option == '+')
5977 break;
5978 i++;
cristybb503372010-05-27 20:51:26 +00005979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005980 ThrowMogrifyException(OptionError,"MissingArgument",option);
5981 if (IsGeometry(argv[i]) == MagickFalse)
5982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5983 break;
5984 }
5985 if (LocaleCompare("virtual-pixel",option+1) == 0)
5986 {
cristybb503372010-05-27 20:51:26 +00005987 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005988 method;
5989
5990 if (*option == '+')
5991 break;
5992 i++;
cristybb503372010-05-27 20:51:26 +00005993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005994 ThrowMogrifyException(OptionError,"MissingArgument",option);
5995 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
5996 argv[i]);
5997 if (method < 0)
5998 ThrowMogrifyException(OptionError,
5999 "UnrecognizedVirtualPixelMethod",argv[i]);
6000 break;
6001 }
6002 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6003 }
6004 case 'w':
6005 {
6006 if (LocaleCompare("wave",option+1) == 0)
6007 {
6008 i++;
cristybb503372010-05-27 20:51:26 +00006009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006010 ThrowMogrifyException(OptionError,"MissingArgument",option);
6011 if (IsGeometry(argv[i]) == MagickFalse)
6012 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6013 break;
6014 }
6015 if (LocaleCompare("weight",option+1) == 0)
6016 {
6017 if (*option == '+')
6018 break;
6019 i++;
cristybb503372010-05-27 20:51:26 +00006020 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006021 ThrowMogrifyException(OptionError,"MissingArgument",option);
6022 break;
6023 }
6024 if (LocaleCompare("white-point",option+1) == 0)
6025 {
6026 if (*option == '+')
6027 break;
6028 i++;
cristybb503372010-05-27 20:51:26 +00006029 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006030 ThrowMogrifyException(OptionError,"MissingArgument",option);
6031 if (IsGeometry(argv[i]) == MagickFalse)
6032 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6033 break;
6034 }
6035 if (LocaleCompare("white-threshold",option+1) == 0)
6036 {
6037 if (*option == '+')
6038 break;
6039 i++;
cristybb503372010-05-27 20:51:26 +00006040 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006041 ThrowMogrifyException(OptionError,"MissingArgument",option);
6042 if (IsGeometry(argv[i]) == MagickFalse)
6043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6044 break;
6045 }
6046 if (LocaleCompare("write",option+1) == 0)
6047 {
6048 i++;
cristybb503372010-05-27 20:51:26 +00006049 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006050 ThrowMogrifyException(OptionError,"MissingArgument",option);
6051 break;
6052 }
6053 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6054 }
6055 case '?':
6056 break;
6057 default:
6058 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6059 }
6060 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6061 MagickFalse : MagickTrue;
6062 if (fire != MagickFalse)
6063 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6064 }
6065 if (k != 0)
6066 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006067 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006068 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6069 DestroyMogrify();
6070 return(status != 0 ? MagickTrue : MagickFalse);
6071}
6072
6073/*
6074%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6075% %
6076% %
6077% %
6078+ M o g r i f y I m a g e I n f o %
6079% %
6080% %
6081% %
6082%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6083%
6084% MogrifyImageInfo() applies image processing settings to the image as
6085% prescribed by command line options.
6086%
6087% The format of the MogrifyImageInfo method is:
6088%
6089% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6090% const char **argv,ExceptionInfo *exception)
6091%
6092% A description of each parameter follows:
6093%
6094% o image_info: the image info..
6095%
6096% o argc: Specifies a pointer to an integer describing the number of
6097% elements in the argument vector.
6098%
6099% o argv: Specifies a pointer to a text array containing the command line
6100% arguments.
6101%
6102% o exception: return any errors or warnings in this structure.
6103%
6104*/
6105WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6106 const int argc,const char **argv,ExceptionInfo *exception)
6107{
6108 const char
6109 *option;
6110
6111 GeometryInfo
6112 geometry_info;
6113
cristybb503372010-05-27 20:51:26 +00006114 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006115 count;
6116
cristybb503372010-05-27 20:51:26 +00006117 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006118 i;
6119
6120 /*
6121 Initialize method variables.
6122 */
6123 assert(image_info != (ImageInfo *) NULL);
6124 assert(image_info->signature == MagickSignature);
6125 if (image_info->debug != MagickFalse)
6126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6127 image_info->filename);
6128 if (argc < 0)
6129 return(MagickTrue);
6130 /*
6131 Set the image settings.
6132 */
cristybb503372010-05-27 20:51:26 +00006133 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006134 {
6135 option=argv[i];
6136 if (IsMagickOption(option) == MagickFalse)
6137 continue;
6138 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6139 0L);
cristycee97112010-05-28 00:44:52 +00006140 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006141 break;
6142 switch (*(option+1))
6143 {
6144 case 'a':
6145 {
6146 if (LocaleCompare("adjoin",option+1) == 0)
6147 {
6148 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6149 break;
6150 }
6151 if (LocaleCompare("antialias",option+1) == 0)
6152 {
6153 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6154 break;
6155 }
6156 if (LocaleCompare("attenuate",option+1) == 0)
6157 {
6158 if (*option == '+')
6159 {
6160 (void) DeleteImageOption(image_info,option+1);
6161 break;
6162 }
6163 (void) SetImageOption(image_info,option+1,argv[i+1]);
6164 break;
6165 }
6166 if (LocaleCompare("authenticate",option+1) == 0)
6167 {
6168 if (*option == '+')
6169 (void) CloneString(&image_info->authenticate,(char *) NULL);
6170 else
6171 (void) CloneString(&image_info->authenticate,argv[i+1]);
6172 break;
6173 }
6174 break;
6175 }
6176 case 'b':
6177 {
6178 if (LocaleCompare("background",option+1) == 0)
6179 {
6180 if (*option == '+')
6181 {
6182 (void) DeleteImageOption(image_info,option+1);
6183 (void) QueryColorDatabase(BackgroundColor,
6184 &image_info->background_color,exception);
6185 break;
6186 }
6187 (void) SetImageOption(image_info,option+1,argv[i+1]);
6188 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6189 exception);
6190 break;
6191 }
6192 if (LocaleCompare("bias",option+1) == 0)
6193 {
6194 if (*option == '+')
6195 {
6196 (void) SetImageOption(image_info,option+1,"0.0");
6197 break;
6198 }
6199 (void) SetImageOption(image_info,option+1,argv[i+1]);
6200 break;
6201 }
6202 if (LocaleCompare("black-point-compensation",option+1) == 0)
6203 {
6204 if (*option == '+')
6205 {
6206 (void) SetImageOption(image_info,option+1,"false");
6207 break;
6208 }
6209 (void) SetImageOption(image_info,option+1,"true");
6210 break;
6211 }
6212 if (LocaleCompare("blue-primary",option+1) == 0)
6213 {
6214 if (*option == '+')
6215 {
6216 (void) SetImageOption(image_info,option+1,"0.0");
6217 break;
6218 }
6219 (void) SetImageOption(image_info,option+1,argv[i+1]);
6220 break;
6221 }
6222 if (LocaleCompare("bordercolor",option+1) == 0)
6223 {
6224 if (*option == '+')
6225 {
6226 (void) DeleteImageOption(image_info,option+1);
6227 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6228 exception);
6229 break;
6230 }
6231 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6232 exception);
6233 (void) SetImageOption(image_info,option+1,argv[i+1]);
6234 break;
6235 }
6236 if (LocaleCompare("box",option+1) == 0)
6237 {
6238 if (*option == '+')
6239 {
6240 (void) SetImageOption(image_info,"undercolor","none");
6241 break;
6242 }
6243 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6244 break;
6245 }
6246 break;
6247 }
6248 case 'c':
6249 {
6250 if (LocaleCompare("cache",option+1) == 0)
6251 {
6252 MagickSizeType
6253 limit;
6254
6255 limit=MagickResourceInfinity;
6256 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006257 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006258 (void) SetMagickResourceLimit(MemoryResource,limit);
6259 (void) SetMagickResourceLimit(MapResource,2*limit);
6260 break;
6261 }
6262 if (LocaleCompare("caption",option+1) == 0)
6263 {
6264 if (*option == '+')
6265 {
6266 (void) DeleteImageOption(image_info,option+1);
6267 break;
6268 }
6269 (void) SetImageOption(image_info,option+1,argv[i+1]);
6270 break;
6271 }
6272 if (LocaleCompare("channel",option+1) == 0)
6273 {
6274 if (*option == '+')
6275 {
6276 image_info->channel=DefaultChannels;
6277 break;
6278 }
6279 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6280 break;
6281 }
6282 if (LocaleCompare("colors",option+1) == 0)
6283 {
cristye27293e2009-12-18 02:53:20 +00006284 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006285 break;
6286 }
6287 if (LocaleCompare("colorspace",option+1) == 0)
6288 {
6289 if (*option == '+')
6290 {
6291 image_info->colorspace=UndefinedColorspace;
6292 (void) SetImageOption(image_info,option+1,"undefined");
6293 break;
6294 }
6295 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6296 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6297 (void) SetImageOption(image_info,option+1,argv[i+1]);
6298 break;
6299 }
6300 if (LocaleCompare("compress",option+1) == 0)
6301 {
6302 if (*option == '+')
6303 {
6304 image_info->compression=UndefinedCompression;
6305 (void) SetImageOption(image_info,option+1,"undefined");
6306 break;
6307 }
6308 image_info->compression=(CompressionType) ParseMagickOption(
6309 MagickCompressOptions,MagickFalse,argv[i+1]);
6310 (void) SetImageOption(image_info,option+1,argv[i+1]);
6311 break;
6312 }
6313 if (LocaleCompare("comment",option+1) == 0)
6314 {
6315 if (*option == '+')
6316 {
6317 (void) DeleteImageOption(image_info,option+1);
6318 break;
6319 }
6320 (void) SetImageOption(image_info,option+1,argv[i+1]);
6321 break;
6322 }
6323 if (LocaleCompare("compose",option+1) == 0)
6324 {
6325 if (*option == '+')
6326 {
6327 (void) SetImageOption(image_info,option+1,"undefined");
6328 break;
6329 }
6330 (void) SetImageOption(image_info,option+1,argv[i+1]);
6331 break;
6332 }
6333 if (LocaleCompare("compress",option+1) == 0)
6334 {
6335 if (*option == '+')
6336 {
6337 image_info->compression=UndefinedCompression;
6338 (void) SetImageOption(image_info,option+1,"undefined");
6339 break;
6340 }
6341 image_info->compression=(CompressionType) ParseMagickOption(
6342 MagickCompressOptions,MagickFalse,argv[i+1]);
6343 (void) SetImageOption(image_info,option+1,argv[i+1]);
6344 break;
6345 }
6346 break;
6347 }
6348 case 'd':
6349 {
6350 if (LocaleCompare("debug",option+1) == 0)
6351 {
6352 if (*option == '+')
6353 (void) SetLogEventMask("none");
6354 else
6355 (void) SetLogEventMask(argv[i+1]);
6356 image_info->debug=IsEventLogging();
6357 break;
6358 }
6359 if (LocaleCompare("define",option+1) == 0)
6360 {
6361 if (*option == '+')
6362 {
6363 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6364 (void) DeleteImageRegistry(argv[i+1]+9);
6365 else
6366 (void) DeleteImageOption(image_info,argv[i+1]);
6367 break;
6368 }
6369 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6370 {
6371 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6372 exception);
6373 break;
6374 }
6375 (void) DefineImageOption(image_info,argv[i+1]);
6376 break;
6377 }
6378 if (LocaleCompare("delay",option+1) == 0)
6379 {
6380 if (*option == '+')
6381 {
6382 (void) SetImageOption(image_info,option+1,"0");
6383 break;
6384 }
6385 (void) SetImageOption(image_info,option+1,argv[i+1]);
6386 break;
6387 }
6388 if (LocaleCompare("density",option+1) == 0)
6389 {
6390 /*
6391 Set image density.
6392 */
6393 if (*option == '+')
6394 {
6395 if (image_info->density != (char *) NULL)
6396 image_info->density=DestroyString(image_info->density);
6397 (void) SetImageOption(image_info,option+1,"72");
6398 break;
6399 }
6400 (void) CloneString(&image_info->density,argv[i+1]);
6401 (void) SetImageOption(image_info,option+1,argv[i+1]);
6402 break;
6403 }
6404 if (LocaleCompare("depth",option+1) == 0)
6405 {
6406 if (*option == '+')
6407 {
6408 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6409 break;
6410 }
cristye27293e2009-12-18 02:53:20 +00006411 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006412 break;
6413 }
cristyc9b12952010-03-28 01:12:28 +00006414 if (LocaleCompare("direction",option+1) == 0)
6415 {
6416 if (*option == '+')
6417 {
6418 (void) SetImageOption(image_info,option+1,"undefined");
6419 break;
6420 }
6421 (void) SetImageOption(image_info,option+1,argv[i+1]);
6422 break;
6423 }
cristy3ed852e2009-09-05 21:47:34 +00006424 if (LocaleCompare("display",option+1) == 0)
6425 {
6426 if (*option == '+')
6427 {
6428 if (image_info->server_name != (char *) NULL)
6429 image_info->server_name=DestroyString(
6430 image_info->server_name);
6431 break;
6432 }
6433 (void) CloneString(&image_info->server_name,argv[i+1]);
6434 break;
6435 }
6436 if (LocaleCompare("dispose",option+1) == 0)
6437 {
6438 if (*option == '+')
6439 {
6440 (void) SetImageOption(image_info,option+1,"undefined");
6441 break;
6442 }
6443 (void) SetImageOption(image_info,option+1,argv[i+1]);
6444 break;
6445 }
6446 if (LocaleCompare("dither",option+1) == 0)
6447 {
6448 if (*option == '+')
6449 {
6450 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006451 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006452 break;
6453 }
6454 (void) SetImageOption(image_info,option+1,argv[i+1]);
6455 image_info->dither=MagickTrue;
6456 break;
6457 }
6458 break;
6459 }
6460 case 'e':
6461 {
6462 if (LocaleCompare("encoding",option+1) == 0)
6463 {
6464 if (*option == '+')
6465 {
6466 (void) SetImageOption(image_info,option+1,"undefined");
6467 break;
6468 }
6469 (void) SetImageOption(image_info,option+1,argv[i+1]);
6470 break;
6471 }
6472 if (LocaleCompare("endian",option+1) == 0)
6473 {
6474 if (*option == '+')
6475 {
6476 image_info->endian=UndefinedEndian;
6477 (void) SetImageOption(image_info,option+1,"undefined");
6478 break;
6479 }
6480 image_info->endian=(EndianType) ParseMagickOption(
6481 MagickEndianOptions,MagickFalse,argv[i+1]);
6482 (void) SetImageOption(image_info,option+1,argv[i+1]);
6483 break;
6484 }
6485 if (LocaleCompare("extract",option+1) == 0)
6486 {
6487 /*
6488 Set image extract geometry.
6489 */
6490 if (*option == '+')
6491 {
6492 if (image_info->extract != (char *) NULL)
6493 image_info->extract=DestroyString(image_info->extract);
6494 break;
6495 }
6496 (void) CloneString(&image_info->extract,argv[i+1]);
6497 break;
6498 }
6499 break;
6500 }
6501 case 'f':
6502 {
6503 if (LocaleCompare("fill",option+1) == 0)
6504 {
6505 if (*option == '+')
6506 {
6507 (void) SetImageOption(image_info,option+1,"none");
6508 break;
6509 }
6510 (void) SetImageOption(image_info,option+1,argv[i+1]);
6511 break;
6512 }
6513 if (LocaleCompare("filter",option+1) == 0)
6514 {
6515 if (*option == '+')
6516 {
6517 (void) SetImageOption(image_info,option+1,"undefined");
6518 break;
6519 }
6520 (void) SetImageOption(image_info,option+1,argv[i+1]);
6521 break;
6522 }
6523 if (LocaleCompare("font",option+1) == 0)
6524 {
6525 if (*option == '+')
6526 {
6527 if (image_info->font != (char *) NULL)
6528 image_info->font=DestroyString(image_info->font);
6529 break;
6530 }
6531 (void) CloneString(&image_info->font,argv[i+1]);
6532 break;
6533 }
6534 if (LocaleCompare("format",option+1) == 0)
6535 {
6536 register const char
6537 *q;
6538
6539 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006540 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006541 image_info->ping=MagickFalse;
6542 (void) SetImageOption(image_info,option+1,argv[i+1]);
6543 break;
6544 }
6545 if (LocaleCompare("fuzz",option+1) == 0)
6546 {
6547 if (*option == '+')
6548 {
6549 image_info->fuzz=0.0;
6550 (void) SetImageOption(image_info,option+1,"0");
6551 break;
6552 }
cristyf2f27272009-12-17 14:48:46 +00006553 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006554 1.0);
6555 (void) SetImageOption(image_info,option+1,argv[i+1]);
6556 break;
6557 }
6558 break;
6559 }
6560 case 'g':
6561 {
6562 if (LocaleCompare("gravity",option+1) == 0)
6563 {
6564 if (*option == '+')
6565 {
6566 (void) SetImageOption(image_info,option+1,"undefined");
6567 break;
6568 }
6569 (void) SetImageOption(image_info,option+1,argv[i+1]);
6570 break;
6571 }
6572 if (LocaleCompare("green-primary",option+1) == 0)
6573 {
6574 if (*option == '+')
6575 {
6576 (void) SetImageOption(image_info,option+1,"0.0");
6577 break;
6578 }
6579 (void) SetImageOption(image_info,option+1,argv[i+1]);
6580 break;
6581 }
6582 break;
6583 }
6584 case 'i':
6585 {
6586 if (LocaleCompare("intent",option+1) == 0)
6587 {
6588 if (*option == '+')
6589 {
6590 (void) SetImageOption(image_info,option+1,"undefined");
6591 break;
6592 }
6593 (void) SetImageOption(image_info,option+1,argv[i+1]);
6594 break;
6595 }
6596 if (LocaleCompare("interlace",option+1) == 0)
6597 {
6598 if (*option == '+')
6599 {
6600 image_info->interlace=UndefinedInterlace;
6601 (void) SetImageOption(image_info,option+1,"undefined");
6602 break;
6603 }
6604 image_info->interlace=(InterlaceType) ParseMagickOption(
6605 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6606 (void) SetImageOption(image_info,option+1,argv[i+1]);
6607 break;
6608 }
cristyb32b90a2009-09-07 21:45:48 +00006609 if (LocaleCompare("interline-spacing",option+1) == 0)
6610 {
6611 if (*option == '+')
6612 {
6613 (void) SetImageOption(image_info,option+1,"undefined");
6614 break;
6615 }
6616 (void) SetImageOption(image_info,option+1,argv[i+1]);
6617 break;
6618 }
cristy3ed852e2009-09-05 21:47:34 +00006619 if (LocaleCompare("interpolate",option+1) == 0)
6620 {
6621 if (*option == '+')
6622 {
6623 (void) SetImageOption(image_info,option+1,"undefined");
6624 break;
6625 }
6626 (void) SetImageOption(image_info,option+1,argv[i+1]);
6627 break;
6628 }
6629 if (LocaleCompare("interword-spacing",option+1) == 0)
6630 {
6631 if (*option == '+')
6632 {
6633 (void) SetImageOption(image_info,option+1,"undefined");
6634 break;
6635 }
6636 (void) SetImageOption(image_info,option+1,argv[i+1]);
6637 break;
6638 }
6639 break;
6640 }
6641 case 'k':
6642 {
6643 if (LocaleCompare("kerning",option+1) == 0)
6644 {
6645 if (*option == '+')
6646 {
6647 (void) SetImageOption(image_info,option+1,"undefined");
6648 break;
6649 }
6650 (void) SetImageOption(image_info,option+1,argv[i+1]);
6651 break;
6652 }
6653 break;
6654 }
6655 case 'l':
6656 {
6657 if (LocaleCompare("label",option+1) == 0)
6658 {
6659 if (*option == '+')
6660 {
6661 (void) DeleteImageOption(image_info,option+1);
6662 break;
6663 }
6664 (void) SetImageOption(image_info,option+1,argv[i+1]);
6665 break;
6666 }
6667 if (LocaleCompare("limit",option+1) == 0)
6668 {
6669 MagickSizeType
6670 limit;
6671
6672 ResourceType
6673 type;
6674
6675 if (*option == '+')
6676 break;
6677 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6678 MagickFalse,argv[i+1]);
6679 limit=MagickResourceInfinity;
6680 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006681 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006682 (void) SetMagickResourceLimit(type,limit);
6683 break;
6684 }
6685 if (LocaleCompare("list",option+1) == 0)
6686 {
cristybb503372010-05-27 20:51:26 +00006687 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006688 list;
6689
6690 /*
6691 Display configuration list.
6692 */
6693 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6694 switch (list)
6695 {
6696 case MagickCoderOptions:
6697 {
6698 (void) ListCoderInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickColorOptions:
6702 {
6703 (void) ListColorInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickConfigureOptions:
6707 {
6708 (void) ListConfigureInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickDelegateOptions:
6712 {
6713 (void) ListDelegateInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickFontOptions:
6717 {
6718 (void) ListTypeInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickFormatOptions:
6722 {
6723 (void) ListMagickInfo((FILE *) NULL,exception);
6724 break;
6725 }
6726 case MagickLocaleOptions:
6727 {
6728 (void) ListLocaleInfo((FILE *) NULL,exception);
6729 break;
6730 }
6731 case MagickLogOptions:
6732 {
6733 (void) ListLogInfo((FILE *) NULL,exception);
6734 break;
6735 }
6736 case MagickMagicOptions:
6737 {
6738 (void) ListMagicInfo((FILE *) NULL,exception);
6739 break;
6740 }
6741 case MagickMimeOptions:
6742 {
6743 (void) ListMimeInfo((FILE *) NULL,exception);
6744 break;
6745 }
6746 case MagickModuleOptions:
6747 {
6748 (void) ListModuleInfo((FILE *) NULL,exception);
6749 break;
6750 }
6751 case MagickPolicyOptions:
6752 {
6753 (void) ListPolicyInfo((FILE *) NULL,exception);
6754 break;
6755 }
6756 case MagickResourceOptions:
6757 {
6758 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6759 break;
6760 }
6761 case MagickThresholdOptions:
6762 {
6763 (void) ListThresholdMaps((FILE *) NULL,exception);
6764 break;
6765 }
6766 default:
6767 {
6768 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
6769 exception);
6770 break;
6771 }
6772 }
cristyaeb2cbc2010-05-07 13:28:58 +00006773 break;
cristy3ed852e2009-09-05 21:47:34 +00006774 }
6775 if (LocaleCompare("log",option+1) == 0)
6776 {
6777 if (*option == '+')
6778 break;
6779 (void) SetLogFormat(argv[i+1]);
6780 break;
6781 }
6782 if (LocaleCompare("loop",option+1) == 0)
6783 {
6784 if (*option == '+')
6785 {
6786 (void) SetImageOption(image_info,option+1,"0");
6787 break;
6788 }
6789 (void) SetImageOption(image_info,option+1,argv[i+1]);
6790 break;
6791 }
6792 break;
6793 }
6794 case 'm':
6795 {
6796 if (LocaleCompare("matte",option+1) == 0)
6797 {
6798 if (*option == '+')
6799 {
6800 (void) SetImageOption(image_info,option+1,"false");
6801 break;
6802 }
6803 (void) SetImageOption(image_info,option+1,"true");
6804 break;
6805 }
6806 if (LocaleCompare("mattecolor",option+1) == 0)
6807 {
6808 if (*option == '+')
6809 {
6810 (void) SetImageOption(image_info,option+1,argv[i+1]);
6811 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6812 exception);
6813 break;
6814 }
6815 (void) SetImageOption(image_info,option+1,argv[i+1]);
6816 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6817 exception);
6818 break;
6819 }
6820 if (LocaleCompare("monitor",option+1) == 0)
6821 {
6822 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6823 (void *) NULL);
6824 break;
6825 }
6826 if (LocaleCompare("monochrome",option+1) == 0)
6827 {
6828 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6829 break;
6830 }
6831 break;
6832 }
6833 case 'o':
6834 {
6835 if (LocaleCompare("orient",option+1) == 0)
6836 {
6837 if (*option == '+')
6838 {
6839 image_info->orientation=UndefinedOrientation;
6840 (void) SetImageOption(image_info,option+1,"undefined");
6841 break;
6842 }
6843 image_info->orientation=(OrientationType) ParseMagickOption(
6844 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006845 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006846 break;
6847 }
6848 }
6849 case 'p':
6850 {
6851 if (LocaleCompare("page",option+1) == 0)
6852 {
6853 char
6854 *canonical_page,
6855 page[MaxTextExtent];
6856
6857 const char
6858 *image_option;
6859
6860 MagickStatusType
6861 flags;
6862
6863 RectangleInfo
6864 geometry;
6865
6866 if (*option == '+')
6867 {
6868 (void) DeleteImageOption(image_info,option+1);
6869 (void) CloneString(&image_info->page,(char *) NULL);
6870 break;
6871 }
6872 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6873 image_option=GetImageOption(image_info,"page");
6874 if (image_option != (const char *) NULL)
6875 flags=ParseAbsoluteGeometry(image_option,&geometry);
6876 canonical_page=GetPageGeometry(argv[i+1]);
6877 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6878 canonical_page=DestroyString(canonical_page);
6879 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006880 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006881 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6882 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006883 (unsigned long) geometry.width,(unsigned long) geometry.height,
6884 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006885 (void) SetImageOption(image_info,option+1,page);
6886 (void) CloneString(&image_info->page,page);
6887 break;
6888 }
6889 if (LocaleCompare("pen",option+1) == 0)
6890 {
6891 if (*option == '+')
6892 {
6893 (void) SetImageOption(image_info,option+1,"none");
6894 break;
6895 }
6896 (void) SetImageOption(image_info,option+1,argv[i+1]);
6897 break;
6898 }
6899 if (LocaleCompare("ping",option+1) == 0)
6900 {
6901 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6902 break;
6903 }
6904 if (LocaleCompare("pointsize",option+1) == 0)
6905 {
6906 if (*option == '+')
6907 geometry_info.rho=0.0;
6908 else
6909 (void) ParseGeometry(argv[i+1],&geometry_info);
6910 image_info->pointsize=geometry_info.rho;
6911 break;
6912 }
cristye7f51092010-01-17 00:39:37 +00006913 if (LocaleCompare("precision",option+1) == 0)
6914 {
cristybf2766a2010-01-17 03:33:23 +00006915 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006916 break;
6917 }
cristy3ed852e2009-09-05 21:47:34 +00006918 if (LocaleCompare("preview",option+1) == 0)
6919 {
6920 /*
6921 Preview image.
6922 */
6923 if (*option == '+')
6924 {
6925 image_info->preview_type=UndefinedPreview;
6926 break;
6927 }
6928 image_info->preview_type=(PreviewType) ParseMagickOption(
6929 MagickPreviewOptions,MagickFalse,argv[i+1]);
6930 break;
6931 }
6932 break;
6933 }
6934 case 'q':
6935 {
6936 if (LocaleCompare("quality",option+1) == 0)
6937 {
6938 /*
6939 Set image compression quality.
6940 */
6941 if (*option == '+')
6942 {
6943 image_info->quality=UndefinedCompressionQuality;
6944 (void) SetImageOption(image_info,option+1,"0");
6945 break;
6946 }
cristye27293e2009-12-18 02:53:20 +00006947 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006948 (void) SetImageOption(image_info,option+1,argv[i+1]);
6949 break;
6950 }
6951 if (LocaleCompare("quiet",option+1) == 0)
6952 {
6953 static WarningHandler
6954 warning_handler = (WarningHandler) NULL;
6955
6956 if (*option == '+')
6957 {
6958 /*
6959 Restore error or warning messages.
6960 */
6961 warning_handler=SetWarningHandler(warning_handler);
6962 break;
6963 }
6964 /*
6965 Suppress error or warning messages.
6966 */
6967 warning_handler=SetWarningHandler((WarningHandler) NULL);
6968 break;
6969 }
6970 break;
6971 }
6972 case 'r':
6973 {
6974 if (LocaleCompare("red-primary",option+1) == 0)
6975 {
6976 if (*option == '+')
6977 {
6978 (void) SetImageOption(image_info,option+1,"0.0");
6979 break;
6980 }
6981 (void) SetImageOption(image_info,option+1,argv[i+1]);
6982 break;
6983 }
6984 break;
6985 }
6986 case 's':
6987 {
6988 if (LocaleCompare("sampling-factor",option+1) == 0)
6989 {
6990 /*
6991 Set image sampling factor.
6992 */
6993 if (*option == '+')
6994 {
6995 if (image_info->sampling_factor != (char *) NULL)
6996 image_info->sampling_factor=DestroyString(
6997 image_info->sampling_factor);
6998 break;
6999 }
7000 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7001 break;
7002 }
7003 if (LocaleCompare("scene",option+1) == 0)
7004 {
7005 /*
7006 Set image scene.
7007 */
7008 if (*option == '+')
7009 {
7010 image_info->scene=0;
7011 (void) SetImageOption(image_info,option+1,"0");
7012 break;
7013 }
cristye27293e2009-12-18 02:53:20 +00007014 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007015 (void) SetImageOption(image_info,option+1,argv[i+1]);
7016 break;
7017 }
7018 if (LocaleCompare("seed",option+1) == 0)
7019 {
cristybb503372010-05-27 20:51:26 +00007020 size_t
cristy3ed852e2009-09-05 21:47:34 +00007021 seed;
7022
7023 if (*option == '+')
7024 {
cristybb503372010-05-27 20:51:26 +00007025 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007026 SeedPseudoRandomGenerator(seed);
7027 break;
7028 }
cristye27293e2009-12-18 02:53:20 +00007029 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007030 SeedPseudoRandomGenerator(seed);
7031 break;
7032 }
7033 if (LocaleCompare("size",option+1) == 0)
7034 {
7035 if (*option == '+')
7036 {
7037 if (image_info->size != (char *) NULL)
7038 image_info->size=DestroyString(image_info->size);
7039 break;
7040 }
7041 (void) CloneString(&image_info->size,argv[i+1]);
7042 break;
7043 }
7044 if (LocaleCompare("stroke",option+1) == 0)
7045 {
7046 if (*option == '+')
7047 {
7048 (void) SetImageOption(image_info,option+1,"none");
7049 break;
7050 }
7051 (void) SetImageOption(image_info,option+1,argv[i+1]);
7052 break;
7053 }
7054 if (LocaleCompare("strokewidth",option+1) == 0)
7055 {
7056 if (*option == '+')
7057 {
7058 (void) SetImageOption(image_info,option+1,"0");
7059 break;
7060 }
7061 (void) SetImageOption(image_info,option+1,argv[i+1]);
7062 break;
7063 }
cristyd9a29192010-10-16 16:49:53 +00007064 if (LocaleCompare("synchronize",option+1) == 0)
7065 {
7066 if (*option == '+')
7067 {
7068 image_info->synchronize=MagickFalse;
7069 break;
7070 }
7071 image_info->synchronize=MagickTrue;
7072 break;
7073 }
cristy3ed852e2009-09-05 21:47:34 +00007074 break;
7075 }
7076 case 't':
7077 {
7078 if (LocaleCompare("taint",option+1) == 0)
7079 {
7080 if (*option == '+')
7081 {
7082 (void) SetImageOption(image_info,option+1,"false");
7083 break;
7084 }
7085 (void) SetImageOption(image_info,option+1,"true");
7086 break;
7087 }
7088 if (LocaleCompare("texture",option+1) == 0)
7089 {
7090 if (*option == '+')
7091 {
7092 if (image_info->texture != (char *) NULL)
7093 image_info->texture=DestroyString(image_info->texture);
7094 break;
7095 }
7096 (void) CloneString(&image_info->texture,argv[i+1]);
7097 break;
7098 }
7099 if (LocaleCompare("tile-offset",option+1) == 0)
7100 {
7101 if (*option == '+')
7102 {
7103 (void) SetImageOption(image_info,option+1,"0");
7104 break;
7105 }
7106 (void) SetImageOption(image_info,option+1,argv[i+1]);
7107 break;
7108 }
7109 if (LocaleCompare("transparent-color",option+1) == 0)
7110 {
7111 if (*option == '+')
7112 {
7113 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7114 (void) SetImageOption(image_info,option+1,"none");
7115 break;
7116 }
7117 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7118 exception);
7119 (void) SetImageOption(image_info,option+1,argv[i+1]);
7120 break;
7121 }
7122 if (LocaleCompare("type",option+1) == 0)
7123 {
7124 if (*option == '+')
7125 {
cristy5f1c1ff2010-12-23 21:38:06 +00007126 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007127 (void) SetImageOption(image_info,option+1,"undefined");
7128 break;
7129 }
7130 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7131 MagickFalse,argv[i+1]);
7132 (void) SetImageOption(image_info,option+1,argv[i+1]);
7133 break;
7134 }
7135 break;
7136 }
7137 case 'u':
7138 {
7139 if (LocaleCompare("undercolor",option+1) == 0)
7140 {
7141 if (*option == '+')
7142 {
7143 (void) DeleteImageOption(image_info,option+1);
7144 break;
7145 }
7146 (void) SetImageOption(image_info,option+1,argv[i+1]);
7147 break;
7148 }
7149 if (LocaleCompare("units",option+1) == 0)
7150 {
7151 if (*option == '+')
7152 {
7153 image_info->units=UndefinedResolution;
7154 (void) SetImageOption(image_info,option+1,"undefined");
7155 break;
7156 }
7157 image_info->units=(ResolutionType) ParseMagickOption(
7158 MagickResolutionOptions,MagickFalse,argv[i+1]);
7159 (void) SetImageOption(image_info,option+1,argv[i+1]);
7160 break;
7161 }
7162 break;
7163 }
7164 case 'v':
7165 {
7166 if (LocaleCompare("verbose",option+1) == 0)
7167 {
7168 if (*option == '+')
7169 {
7170 image_info->verbose=MagickFalse;
7171 break;
7172 }
7173 image_info->verbose=MagickTrue;
7174 image_info->ping=MagickFalse;
7175 break;
7176 }
7177 if (LocaleCompare("view",option+1) == 0)
7178 {
7179 if (*option == '+')
7180 {
7181 if (image_info->view != (char *) NULL)
7182 image_info->view=DestroyString(image_info->view);
7183 break;
7184 }
7185 (void) CloneString(&image_info->view,argv[i+1]);
7186 break;
7187 }
7188 if (LocaleCompare("virtual-pixel",option+1) == 0)
7189 {
7190 if (*option == '+')
7191 {
7192 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7193 (void) SetImageOption(image_info,option+1,"undefined");
7194 break;
7195 }
7196 image_info->virtual_pixel_method=(VirtualPixelMethod)
7197 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7198 argv[i+1]);
7199 (void) SetImageOption(image_info,option+1,argv[i+1]);
7200 break;
7201 }
7202 break;
7203 }
7204 case 'w':
7205 {
7206 if (LocaleCompare("white-point",option+1) == 0)
7207 {
7208 if (*option == '+')
7209 {
7210 (void) SetImageOption(image_info,option+1,"0.0");
7211 break;
7212 }
7213 (void) SetImageOption(image_info,option+1,argv[i+1]);
7214 break;
7215 }
7216 break;
7217 }
7218 default:
7219 break;
7220 }
7221 i+=count;
7222 }
7223 return(MagickTrue);
7224}
7225
7226/*
7227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7228% %
7229% %
7230% %
7231+ M o g r i f y I m a g e L i s t %
7232% %
7233% %
7234% %
7235%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7236%
7237% MogrifyImageList() applies any command line options that might affect the
7238% entire image list (e.g. -append, -coalesce, etc.).
7239%
7240% The format of the MogrifyImage method is:
7241%
7242% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7243% const char **argv,Image **images,ExceptionInfo *exception)
7244%
7245% A description of each parameter follows:
7246%
7247% o image_info: the image info..
7248%
7249% o argc: Specifies a pointer to an integer describing the number of
7250% elements in the argument vector.
7251%
7252% o argv: Specifies a pointer to a text array containing the command line
7253% arguments.
7254%
anthonye9c27192011-03-27 08:07:06 +00007255% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007256%
7257% o exception: return any errors or warnings in this structure.
7258%
7259*/
7260WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7261 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7262{
7263 ChannelType
7264 channel;
7265
7266 const char
7267 *option;
7268
cristy6b3da3a2010-06-20 02:21:46 +00007269 ImageInfo
7270 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007271
7272 MagickStatusType
7273 status;
7274
7275 QuantizeInfo
7276 *quantize_info;
7277
cristybb503372010-05-27 20:51:26 +00007278 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007279 i;
7280
cristy6b3da3a2010-06-20 02:21:46 +00007281 ssize_t
7282 count,
7283 index;
7284
cristy3ed852e2009-09-05 21:47:34 +00007285 /*
7286 Apply options to the image list.
7287 */
7288 assert(image_info != (ImageInfo *) NULL);
7289 assert(image_info->signature == MagickSignature);
7290 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007291 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007292 assert((*images)->signature == MagickSignature);
7293 if ((*images)->debug != MagickFalse)
7294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7295 (*images)->filename);
7296 if ((argc <= 0) || (*argv == (char *) NULL))
7297 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007298 mogrify_info=CloneImageInfo(image_info);
7299 quantize_info=AcquireQuantizeInfo(mogrify_info);
7300 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007301 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007302 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007303 {
cristy74fe8f12009-10-03 19:09:01 +00007304 if (*images == (Image *) NULL)
7305 break;
cristy3ed852e2009-09-05 21:47:34 +00007306 option=argv[i];
7307 if (IsMagickOption(option) == MagickFalse)
7308 continue;
7309 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7310 0L);
cristycee97112010-05-28 00:44:52 +00007311 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007312 break;
cristy6b3da3a2010-06-20 02:21:46 +00007313 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007314 switch (*(option+1))
7315 {
7316 case 'a':
7317 {
7318 if (LocaleCompare("affinity",option+1) == 0)
7319 {
cristy6b3da3a2010-06-20 02:21:46 +00007320 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007321 if (*option == '+')
7322 {
7323 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7324 InheritException(exception,&(*images)->exception);
7325 break;
7326 }
7327 i++;
7328 break;
7329 }
7330 if (LocaleCompare("append",option+1) == 0)
7331 {
7332 Image
7333 *append_image;
7334
cristy6b3da3a2010-06-20 02:21:46 +00007335 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007336 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7337 MagickFalse,exception);
7338 if (append_image == (Image *) NULL)
7339 {
7340 status=MagickFalse;
7341 break;
7342 }
7343 *images=DestroyImageList(*images);
7344 *images=append_image;
7345 break;
7346 }
7347 if (LocaleCompare("average",option+1) == 0)
7348 {
7349 Image
7350 *average_image;
7351
cristyd18ae7c2010-03-07 17:39:52 +00007352 /*
7353 Average an image sequence (deprecated).
7354 */
cristy6b3da3a2010-06-20 02:21:46 +00007355 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007356 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7357 exception);
cristy3ed852e2009-09-05 21:47:34 +00007358 if (average_image == (Image *) NULL)
7359 {
7360 status=MagickFalse;
7361 break;
7362 }
7363 *images=DestroyImageList(*images);
7364 *images=average_image;
7365 break;
7366 }
7367 break;
7368 }
7369 case 'c':
7370 {
7371 if (LocaleCompare("channel",option+1) == 0)
7372 {
7373 if (*option == '+')
7374 {
7375 channel=DefaultChannels;
7376 break;
7377 }
7378 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7379 break;
7380 }
7381 if (LocaleCompare("clut",option+1) == 0)
7382 {
7383 Image
7384 *clut_image,
7385 *image;
7386
cristy6b3da3a2010-06-20 02:21:46 +00007387 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007388 image=RemoveFirstImageFromList(images);
7389 clut_image=RemoveFirstImageFromList(images);
7390 if (clut_image == (Image *) NULL)
7391 {
7392 status=MagickFalse;
7393 break;
7394 }
7395 (void) ClutImageChannel(image,channel,clut_image);
7396 clut_image=DestroyImage(clut_image);
7397 InheritException(exception,&image->exception);
7398 *images=DestroyImageList(*images);
7399 *images=image;
7400 break;
7401 }
7402 if (LocaleCompare("coalesce",option+1) == 0)
7403 {
7404 Image
7405 *coalesce_image;
7406
cristy6b3da3a2010-06-20 02:21:46 +00007407 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007408 coalesce_image=CoalesceImages(*images,exception);
7409 if (coalesce_image == (Image *) NULL)
7410 {
7411 status=MagickFalse;
7412 break;
7413 }
7414 *images=DestroyImageList(*images);
7415 *images=coalesce_image;
7416 break;
7417 }
7418 if (LocaleCompare("combine",option+1) == 0)
7419 {
7420 Image
7421 *combine_image;
7422
cristy6b3da3a2010-06-20 02:21:46 +00007423 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007424 combine_image=CombineImages(*images,channel,exception);
7425 if (combine_image == (Image *) NULL)
7426 {
7427 status=MagickFalse;
7428 break;
7429 }
7430 *images=DestroyImageList(*images);
7431 *images=combine_image;
7432 break;
7433 }
7434 if (LocaleCompare("composite",option+1) == 0)
7435 {
7436 Image
7437 *mask_image,
7438 *composite_image,
7439 *image;
7440
7441 RectangleInfo
7442 geometry;
7443
cristy6b3da3a2010-06-20 02:21:46 +00007444 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007445 image=RemoveFirstImageFromList(images);
7446 composite_image=RemoveFirstImageFromList(images);
7447 if (composite_image == (Image *) NULL)
7448 {
7449 status=MagickFalse;
7450 break;
7451 }
7452 (void) TransformImage(&composite_image,(char *) NULL,
7453 composite_image->geometry);
7454 SetGeometry(composite_image,&geometry);
7455 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7456 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7457 &geometry);
7458 mask_image=RemoveFirstImageFromList(images);
7459 if (mask_image != (Image *) NULL)
7460 {
7461 if ((image->compose == DisplaceCompositeOp) ||
7462 (image->compose == DistortCompositeOp))
7463 {
7464 /*
7465 Merge Y displacement into X displacement image.
7466 */
7467 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7468 mask_image,0,0);
7469 mask_image=DestroyImage(mask_image);
7470 }
7471 else
7472 {
7473 /*
7474 Set a blending mask for the composition.
7475 */
7476 image->mask=mask_image;
7477 (void) NegateImage(image->mask,MagickFalse);
7478 }
7479 }
7480 (void) CompositeImageChannel(image,channel,image->compose,
7481 composite_image,geometry.x,geometry.y);
7482 if (image->mask != (Image *) NULL)
7483 image->mask=DestroyImage(image->mask);
7484 composite_image=DestroyImage(composite_image);
7485 InheritException(exception,&image->exception);
7486 *images=DestroyImageList(*images);
7487 *images=image;
7488 break;
7489 }
anthony9f4f0342011-03-28 11:47:22 +00007490#if 0
7491This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007492 if (LocaleCompare("crop",option+1) == 0)
7493 {
7494 MagickStatusType
7495 flags;
7496
7497 RectangleInfo
7498 geometry;
7499
anthonye9c27192011-03-27 08:07:06 +00007500 /*
anthony9f4f0342011-03-28 11:47:22 +00007501 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007502 */
cristy6b3da3a2010-06-20 02:21:46 +00007503 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007504 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7505 if (((geometry.width == 0) && (geometry.height == 0)) ||
7506 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7507 break;
7508 (void) TransformImages(images,argv[i+1],(char *) NULL);
7509 InheritException(exception,&(*images)->exception);
7510 break;
7511 }
anthony9f4f0342011-03-28 11:47:22 +00007512#endif
cristy3ed852e2009-09-05 21:47:34 +00007513 break;
7514 }
7515 case 'd':
7516 {
7517 if (LocaleCompare("deconstruct",option+1) == 0)
7518 {
7519 Image
7520 *deconstruct_image;
7521
cristy6b3da3a2010-06-20 02:21:46 +00007522 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007523 deconstruct_image=DeconstructImages(*images,exception);
7524 if (deconstruct_image == (Image *) NULL)
7525 {
7526 status=MagickFalse;
7527 break;
7528 }
7529 *images=DestroyImageList(*images);
7530 *images=deconstruct_image;
7531 break;
7532 }
7533 if (LocaleCompare("delete",option+1) == 0)
7534 {
7535 if (*option == '+')
7536 DeleteImages(images,"-1",exception);
7537 else
7538 DeleteImages(images,argv[i+1],exception);
7539 break;
7540 }
7541 if (LocaleCompare("dither",option+1) == 0)
7542 {
7543 if (*option == '+')
7544 {
7545 quantize_info->dither=MagickFalse;
7546 break;
7547 }
7548 quantize_info->dither=MagickTrue;
7549 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7550 MagickDitherOptions,MagickFalse,argv[i+1]);
7551 break;
7552 }
cristyecb10ff2011-03-22 13:14:03 +00007553 if (LocaleCompare("duplicate",option+1) == 0)
7554 {
cristy72988482011-03-29 16:34:38 +00007555 Image
7556 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007557
anthony2b6bcae2011-03-23 13:05:34 +00007558 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007559 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7560 else
7561 {
7562 const char
7563 *p;
7564
anthony2b6bcae2011-03-23 13:05:34 +00007565 size_t
7566 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007567
anthony2b6bcae2011-03-23 13:05:34 +00007568 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007569 p=strchr(argv[i+1],',');
7570 if (p == (const char *) NULL)
7571 duplicate_images=DuplicateImages(*images,number_duplicates,
7572 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007573 else
cristy72988482011-03-29 16:34:38 +00007574 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7575 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007576 }
7577 AppendImageToList(images, duplicate_images);
7578 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007579 break;
7580 }
cristy3ed852e2009-09-05 21:47:34 +00007581 break;
7582 }
cristyd18ae7c2010-03-07 17:39:52 +00007583 case 'e':
7584 {
7585 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7586 {
7587 Image
7588 *evaluate_image;
7589
7590 MagickEvaluateOperator
7591 op;
7592
cristy6b3da3a2010-06-20 02:21:46 +00007593 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007594 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7595 MagickFalse,argv[i+1]);
7596 evaluate_image=EvaluateImages(*images,op,exception);
7597 if (evaluate_image == (Image *) NULL)
7598 {
7599 status=MagickFalse;
7600 break;
7601 }
7602 *images=DestroyImageList(*images);
7603 *images=evaluate_image;
7604 break;
7605 }
7606 break;
7607 }
cristy3ed852e2009-09-05 21:47:34 +00007608 case 'f':
7609 {
cristyf0a247f2009-10-04 00:20:03 +00007610 if (LocaleCompare("fft",option+1) == 0)
7611 {
7612 Image
7613 *fourier_image;
7614
7615 /*
7616 Implements the discrete Fourier transform (DFT).
7617 */
cristy6b3da3a2010-06-20 02:21:46 +00007618 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007619 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7620 MagickTrue : MagickFalse,exception);
7621 if (fourier_image == (Image *) NULL)
7622 break;
7623 *images=DestroyImage(*images);
7624 *images=fourier_image;
7625 break;
7626 }
cristy3ed852e2009-09-05 21:47:34 +00007627 if (LocaleCompare("flatten",option+1) == 0)
7628 {
7629 Image
7630 *flatten_image;
7631
cristy6b3da3a2010-06-20 02:21:46 +00007632 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007633 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7634 if (flatten_image == (Image *) NULL)
7635 break;
7636 *images=DestroyImageList(*images);
7637 *images=flatten_image;
7638 break;
7639 }
7640 if (LocaleCompare("fx",option+1) == 0)
7641 {
7642 Image
7643 *fx_image;
7644
cristy6b3da3a2010-06-20 02:21:46 +00007645 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007646 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7647 if (fx_image == (Image *) NULL)
7648 {
7649 status=MagickFalse;
7650 break;
7651 }
7652 *images=DestroyImageList(*images);
7653 *images=fx_image;
7654 break;
7655 }
7656 break;
7657 }
7658 case 'h':
7659 {
7660 if (LocaleCompare("hald-clut",option+1) == 0)
7661 {
7662 Image
7663 *hald_image,
7664 *image;
7665
cristy6b3da3a2010-06-20 02:21:46 +00007666 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007667 image=RemoveFirstImageFromList(images);
7668 hald_image=RemoveFirstImageFromList(images);
7669 if (hald_image == (Image *) NULL)
7670 {
7671 status=MagickFalse;
7672 break;
7673 }
7674 (void) HaldClutImageChannel(image,channel,hald_image);
7675 hald_image=DestroyImage(hald_image);
7676 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007677 if (*images != (Image *) NULL)
7678 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007679 *images=image;
7680 break;
7681 }
7682 break;
7683 }
7684 case 'i':
7685 {
7686 if (LocaleCompare("ift",option+1) == 0)
7687 {
7688 Image
cristy8587f882009-11-13 20:28:49 +00007689 *fourier_image,
7690 *magnitude_image,
7691 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007692
7693 /*
7694 Implements the inverse fourier discrete Fourier transform (DFT).
7695 */
cristy6b3da3a2010-06-20 02:21:46 +00007696 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007697 magnitude_image=RemoveFirstImageFromList(images);
7698 phase_image=RemoveFirstImageFromList(images);
7699 if (phase_image == (Image *) NULL)
7700 {
7701 status=MagickFalse;
7702 break;
7703 }
7704 fourier_image=InverseFourierTransformImage(magnitude_image,
7705 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007706 if (fourier_image == (Image *) NULL)
7707 break;
cristy0aff6ea2009-11-14 01:40:53 +00007708 if (*images != (Image *) NULL)
7709 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007710 *images=fourier_image;
7711 break;
7712 }
7713 if (LocaleCompare("insert",option+1) == 0)
7714 {
7715 Image
7716 *p,
7717 *q;
7718
7719 index=0;
7720 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007721 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007722 p=RemoveLastImageFromList(images);
7723 if (p == (Image *) NULL)
7724 {
7725 (void) ThrowMagickException(exception,GetMagickModule(),
7726 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7727 status=MagickFalse;
7728 break;
7729 }
7730 q=p;
7731 if (index == 0)
7732 PrependImageToList(images,q);
7733 else
cristybb503372010-05-27 20:51:26 +00007734 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007735 AppendImageToList(images,q);
7736 else
7737 {
7738 q=GetImageFromList(*images,index-1);
7739 if (q == (Image *) NULL)
7740 {
7741 (void) ThrowMagickException(exception,GetMagickModule(),
7742 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7743 status=MagickFalse;
7744 break;
7745 }
7746 InsertImageInList(&q,p);
7747 }
7748 *images=GetFirstImageInList(q);
7749 break;
7750 }
7751 break;
7752 }
7753 case 'l':
7754 {
7755 if (LocaleCompare("layers",option+1) == 0)
7756 {
7757 Image
7758 *layers;
7759
7760 ImageLayerMethod
7761 method;
7762
cristy6b3da3a2010-06-20 02:21:46 +00007763 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007764 layers=(Image *) NULL;
7765 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7766 MagickFalse,argv[i+1]);
7767 switch (method)
7768 {
7769 case CoalesceLayer:
7770 {
7771 layers=CoalesceImages(*images,exception);
7772 break;
7773 }
7774 case CompareAnyLayer:
7775 case CompareClearLayer:
7776 case CompareOverlayLayer:
7777 default:
7778 {
7779 layers=CompareImageLayers(*images,method,exception);
7780 break;
7781 }
7782 case MergeLayer:
7783 case FlattenLayer:
7784 case MosaicLayer:
7785 case TrimBoundsLayer:
7786 {
7787 layers=MergeImageLayers(*images,method,exception);
7788 break;
7789 }
7790 case DisposeLayer:
7791 {
7792 layers=DisposeImages(*images,exception);
7793 break;
7794 }
7795 case OptimizeImageLayer:
7796 {
7797 layers=OptimizeImageLayers(*images,exception);
7798 break;
7799 }
7800 case OptimizePlusLayer:
7801 {
7802 layers=OptimizePlusImageLayers(*images,exception);
7803 break;
7804 }
7805 case OptimizeTransLayer:
7806 {
7807 OptimizeImageTransparency(*images,exception);
7808 break;
7809 }
7810 case RemoveDupsLayer:
7811 {
7812 RemoveDuplicateLayers(images,exception);
7813 break;
7814 }
7815 case RemoveZeroLayer:
7816 {
7817 RemoveZeroDelayLayers(images,exception);
7818 break;
7819 }
7820 case OptimizeLayer:
7821 {
7822 /*
7823 General Purpose, GIF Animation Optimizer.
7824 */
7825 layers=CoalesceImages(*images,exception);
7826 if (layers == (Image *) NULL)
7827 {
7828 status=MagickFalse;
7829 break;
7830 }
7831 InheritException(exception,&layers->exception);
7832 *images=DestroyImageList(*images);
7833 *images=layers;
7834 layers=OptimizeImageLayers(*images,exception);
7835 if (layers == (Image *) NULL)
7836 {
7837 status=MagickFalse;
7838 break;
7839 }
7840 InheritException(exception,&layers->exception);
7841 *images=DestroyImageList(*images);
7842 *images=layers;
7843 layers=(Image *) NULL;
7844 OptimizeImageTransparency(*images,exception);
7845 InheritException(exception,&(*images)->exception);
7846 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7847 break;
7848 }
7849 case CompositeLayer:
7850 {
7851 CompositeOperator
7852 compose;
7853
7854 Image
7855 *source;
7856
7857 RectangleInfo
7858 geometry;
7859
7860 /*
7861 Split image sequence at the first 'NULL:' image.
7862 */
7863 source=(*images);
7864 while (source != (Image *) NULL)
7865 {
7866 source=GetNextImageInList(source);
7867 if ((source != (Image *) NULL) &&
7868 (LocaleCompare(source->magick,"NULL") == 0))
7869 break;
7870 }
7871 if (source != (Image *) NULL)
7872 {
7873 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7874 (GetNextImageInList(source) == (Image *) NULL))
7875 source=(Image *) NULL;
7876 else
7877 {
7878 /*
7879 Separate the two lists, junk the null: image.
7880 */
7881 source=SplitImageList(source->previous);
7882 DeleteImageFromList(&source);
7883 }
7884 }
7885 if (source == (Image *) NULL)
7886 {
7887 (void) ThrowMagickException(exception,GetMagickModule(),
7888 OptionError,"MissingNullSeparator","layers Composite");
7889 status=MagickFalse;
7890 break;
7891 }
7892 /*
7893 Adjust offset with gravity and virtual canvas.
7894 */
7895 SetGeometry(*images,&geometry);
7896 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7897 geometry.width=source->page.width != 0 ?
7898 source->page.width : source->columns;
7899 geometry.height=source->page.height != 0 ?
7900 source->page.height : source->rows;
7901 GravityAdjustGeometry((*images)->page.width != 0 ?
7902 (*images)->page.width : (*images)->columns,
7903 (*images)->page.height != 0 ? (*images)->page.height :
7904 (*images)->rows,(*images)->gravity,&geometry);
7905 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007906 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007907 if (option != (const char *) NULL)
7908 compose=(CompositeOperator) ParseMagickOption(
7909 MagickComposeOptions,MagickFalse,option);
7910 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7911 exception);
7912 source=DestroyImageList(source);
7913 break;
7914 }
7915 }
7916 if (layers == (Image *) NULL)
7917 break;
7918 InheritException(exception,&layers->exception);
7919 *images=DestroyImageList(*images);
7920 *images=layers;
7921 break;
7922 }
7923 break;
7924 }
7925 case 'm':
7926 {
7927 if (LocaleCompare("map",option+1) == 0)
7928 {
cristy6b3da3a2010-06-20 02:21:46 +00007929 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007930 if (*option == '+')
7931 {
7932 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7933 InheritException(exception,&(*images)->exception);
7934 break;
7935 }
7936 i++;
7937 break;
7938 }
cristyf40785b2010-03-06 02:27:27 +00007939 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007940 {
7941 Image
cristyf40785b2010-03-06 02:27:27 +00007942 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007943
cristyd18ae7c2010-03-07 17:39:52 +00007944 /*
7945 Maximum image sequence (deprecated).
7946 */
cristy6b3da3a2010-06-20 02:21:46 +00007947 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007948 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007949 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007950 {
7951 status=MagickFalse;
7952 break;
7953 }
7954 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007955 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007956 break;
7957 }
cristyf40785b2010-03-06 02:27:27 +00007958 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007959 {
7960 Image
cristyf40785b2010-03-06 02:27:27 +00007961 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007962
cristyd18ae7c2010-03-07 17:39:52 +00007963 /*
7964 Minimum image sequence (deprecated).
7965 */
cristy6b3da3a2010-06-20 02:21:46 +00007966 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007967 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007968 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007969 {
7970 status=MagickFalse;
7971 break;
7972 }
7973 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007974 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007975 break;
7976 }
cristy3ed852e2009-09-05 21:47:34 +00007977 if (LocaleCompare("morph",option+1) == 0)
7978 {
7979 Image
7980 *morph_image;
7981
cristy6b3da3a2010-06-20 02:21:46 +00007982 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007983 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007984 exception);
7985 if (morph_image == (Image *) NULL)
7986 {
7987 status=MagickFalse;
7988 break;
7989 }
7990 *images=DestroyImageList(*images);
7991 *images=morph_image;
7992 break;
7993 }
7994 if (LocaleCompare("mosaic",option+1) == 0)
7995 {
7996 Image
7997 *mosaic_image;
7998
cristy6b3da3a2010-06-20 02:21:46 +00007999 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008000 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8001 if (mosaic_image == (Image *) NULL)
8002 {
8003 status=MagickFalse;
8004 break;
8005 }
8006 *images=DestroyImageList(*images);
8007 *images=mosaic_image;
8008 break;
8009 }
8010 break;
8011 }
8012 case 'p':
8013 {
8014 if (LocaleCompare("print",option+1) == 0)
8015 {
8016 char
8017 *string;
8018
cristy6b3da3a2010-06-20 02:21:46 +00008019 (void) SyncImagesSettings(mogrify_info,*images);
8020 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008021 if (string == (char *) NULL)
8022 break;
8023 InheritException(exception,&(*images)->exception);
8024 (void) fprintf(stdout,"%s",string);
8025 string=DestroyString(string);
8026 }
8027 if (LocaleCompare("process",option+1) == 0)
8028 {
8029 char
8030 **arguments;
8031
8032 int
8033 j,
8034 number_arguments;
8035
cristy6b3da3a2010-06-20 02:21:46 +00008036 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008037 arguments=StringToArgv(argv[i+1],&number_arguments);
8038 if (arguments == (char **) NULL)
8039 break;
8040 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8041 {
8042 char
8043 breaker,
8044 quote,
8045 *token;
8046
8047 const char
8048 *arguments;
8049
8050 int
8051 next,
8052 status;
8053
8054 size_t
8055 length;
8056
8057 TokenInfo
8058 *token_info;
8059
8060 /*
8061 Support old style syntax, filter="-option arg".
8062 */
8063 length=strlen(argv[i+1]);
8064 token=(char *) NULL;
8065 if (~length >= MaxTextExtent)
8066 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8067 sizeof(*token));
8068 if (token == (char *) NULL)
8069 break;
8070 next=0;
8071 arguments=argv[i+1];
8072 token_info=AcquireTokenInfo();
8073 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8074 "\"",'\0',&breaker,&next,&quote);
8075 token_info=DestroyTokenInfo(token_info);
8076 if (status == 0)
8077 {
8078 const char
8079 *argv;
8080
8081 argv=(&(arguments[next]));
8082 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8083 exception);
8084 }
8085 token=DestroyString(token);
8086 break;
8087 }
cristy91c0da22010-05-02 01:44:07 +00008088 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008089 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8090 number_arguments-2,(const char **) arguments+2,exception);
8091 for (j=0; j < number_arguments; j++)
8092 arguments[j]=DestroyString(arguments[j]);
8093 arguments=(char **) RelinquishMagickMemory(arguments);
8094 break;
8095 }
8096 break;
8097 }
8098 case 'r':
8099 {
8100 if (LocaleCompare("reverse",option+1) == 0)
8101 {
8102 ReverseImageList(images);
8103 InheritException(exception,&(*images)->exception);
8104 break;
8105 }
8106 break;
8107 }
8108 case 's':
8109 {
cristy4285d782011-02-09 20:12:28 +00008110 if (LocaleCompare("smush",option+1) == 0)
8111 {
8112 Image
8113 *smush_image;
8114
8115 ssize_t
8116 offset;
8117
8118 (void) SyncImagesSettings(mogrify_info,*images);
8119 offset=(ssize_t) StringToLong(argv[i+1]);
8120 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8121 MagickFalse,offset,exception);
8122 if (smush_image == (Image *) NULL)
8123 {
8124 status=MagickFalse;
8125 break;
8126 }
8127 *images=DestroyImageList(*images);
8128 *images=smush_image;
8129 break;
8130 }
cristy3ed852e2009-09-05 21:47:34 +00008131 if (LocaleCompare("swap",option+1) == 0)
8132 {
8133 Image
8134 *p,
8135 *q,
8136 *swap;
8137
cristybb503372010-05-27 20:51:26 +00008138 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008139 swap_index;
8140
8141 index=(-1);
8142 swap_index=(-2);
8143 if (*option != '+')
8144 {
8145 GeometryInfo
8146 geometry_info;
8147
8148 MagickStatusType
8149 flags;
8150
8151 swap_index=(-1);
8152 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008153 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008154 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008155 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008156 }
8157 p=GetImageFromList(*images,index);
8158 q=GetImageFromList(*images,swap_index);
8159 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8160 {
8161 (void) ThrowMagickException(exception,GetMagickModule(),
8162 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8163 status=MagickFalse;
8164 break;
8165 }
8166 if (p == q)
8167 break;
8168 swap=CloneImage(p,0,0,MagickTrue,exception);
8169 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8170 ReplaceImageInList(&q,swap);
8171 *images=GetFirstImageInList(q);
8172 break;
8173 }
8174 break;
8175 }
8176 case 'w':
8177 {
8178 if (LocaleCompare("write",option+1) == 0)
8179 {
cristy071dd7b2010-04-09 13:04:54 +00008180 char
cristy06609ee2010-03-17 20:21:27 +00008181 key[MaxTextExtent];
8182
cristy3ed852e2009-09-05 21:47:34 +00008183 Image
8184 *write_images;
8185
8186 ImageInfo
8187 *write_info;
8188
cristy6b3da3a2010-06-20 02:21:46 +00008189 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008190 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8191 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008192 write_images=(*images);
8193 if (*option == '+')
8194 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008195 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008196 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8197 write_info=DestroyImageInfo(write_info);
8198 if (*option == '+')
8199 write_images=DestroyImageList(write_images);
8200 break;
8201 }
8202 break;
8203 }
8204 default:
8205 break;
8206 }
8207 i+=count;
8208 }
8209 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008210 mogrify_info=DestroyImageInfo(mogrify_info);
8211 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008212 return(status != 0 ? MagickTrue : MagickFalse);
8213}
8214
8215/*
8216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8217% %
8218% %
8219% %
8220+ M o g r i f y I m a g e s %
8221% %
8222% %
8223% %
8224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8225%
8226% MogrifyImages() applies image processing options to a sequence of images as
8227% prescribed by command line options.
8228%
8229% The format of the MogrifyImage method is:
8230%
8231% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8232% const MagickBooleanType post,const int argc,const char **argv,
8233% Image **images,Exceptioninfo *exception)
8234%
8235% A description of each parameter follows:
8236%
8237% o image_info: the image info..
8238%
8239% o post: If true, post process image list operators otherwise pre-process.
8240%
8241% o argc: Specifies a pointer to an integer describing the number of
8242% elements in the argument vector.
8243%
8244% o argv: Specifies a pointer to a text array containing the command line
8245% arguments.
8246%
anthonye9c27192011-03-27 08:07:06 +00008247% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008248%
8249% o exception: return any errors or warnings in this structure.
8250%
8251*/
8252WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8253 const MagickBooleanType post,const int argc,const char **argv,
8254 Image **images,ExceptionInfo *exception)
8255{
8256#define MogrifyImageTag "Mogrify/Image"
8257
anthonye9c27192011-03-27 08:07:06 +00008258 MagickStatusType
8259 status;
cristy3ed852e2009-09-05 21:47:34 +00008260
cristy0e9f9c12010-02-11 03:00:47 +00008261 MagickBooleanType
8262 proceed;
8263
anthonye9c27192011-03-27 08:07:06 +00008264 size_t
8265 n;
cristy3ed852e2009-09-05 21:47:34 +00008266
cristybb503372010-05-27 20:51:26 +00008267 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008268 i;
8269
cristy3ed852e2009-09-05 21:47:34 +00008270 assert(image_info != (ImageInfo *) NULL);
8271 assert(image_info->signature == MagickSignature);
8272 if (images == (Image **) NULL)
8273 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008274 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008275 assert((*images)->signature == MagickSignature);
8276 if ((*images)->debug != MagickFalse)
8277 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8278 (*images)->filename);
8279 if ((argc <= 0) || (*argv == (char *) NULL))
8280 return(MagickTrue);
8281 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8282 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008283 status=0;
anthonye9c27192011-03-27 08:07:06 +00008284
8285 /*
8286 Pre-process multi-image sequence operators
8287 */
cristy3ed852e2009-09-05 21:47:34 +00008288 if (post == MagickFalse)
8289 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008290
8291 /*
8292 For each image, process simple single image operators
8293 */
8294 i=0;
8295 n=GetImageListLength(*images);
8296 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008297 {
anthonye9c27192011-03-27 08:07:06 +00008298 status&=MogrifyImage(image_info,argc,argv,images,exception);
8299 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008300 if (proceed == MagickFalse)
8301 break;
anthonye9c27192011-03-27 08:07:06 +00008302 if ( (*images)->next == (Image *) NULL )
8303 break;
8304 *images=(*images)->next;
8305 i++;
cristy3ed852e2009-09-05 21:47:34 +00008306 }
anthonye9c27192011-03-27 08:07:06 +00008307 assert( *images != (Image *) NULL );
8308
8309 /*
8310 Post-process, multi-image sequence operators
8311 */
8312 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008313 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008314 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008315 return(status != 0 ? MagickTrue : MagickFalse);
8316}