blob: 2cf42d835a0c025b1905eb4d8485d08a51ec1ef9 [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 */
anthonya129f702011-04-14 01:08:48 +00002447 (void) CompositeImage(region_image,region_image->matte !=
2448 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2449 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00002450 InheritException(exception,&region_image->exception);
2451 *image=DestroyImage(*image);
2452 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00002453 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002454 }
2455 if (*option == '+')
anthonye9c27192011-03-27 08:07:06 +00002456 break;
cristy3ed852e2009-09-05 21:47:34 +00002457 /*
2458 Apply transformations to a selected region of the image.
2459 */
2460 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2461 exception);
cristyd241f442011-03-29 13:50:49 +00002462 mogrify_image=CropImage(*image,&region_geometry,exception);
2463 if (mogrify_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002464 break;
2465 region_image=(*image);
cristyd241f442011-03-29 13:50:49 +00002466 *image=mogrify_image;
2467 mogrify_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002468 break;
2469 }
2470 if (LocaleCompare("render",option+1) == 0)
2471 {
cristy6b3da3a2010-06-20 02:21:46 +00002472 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002473 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2474 break;
2475 }
2476 if (LocaleCompare("remap",option+1) == 0)
2477 {
2478 Image
2479 *remap_image;
2480
2481 /*
2482 Transform image colors to match this set of colors.
2483 */
cristy6b3da3a2010-06-20 02:21:46 +00002484 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002485 if (*option == '+')
2486 break;
cristy6b3da3a2010-06-20 02:21:46 +00002487 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002488 if (remap_image == (Image *) NULL)
2489 break;
2490 (void) RemapImage(quantize_info,*image,remap_image);
2491 InheritException(exception,&(*image)->exception);
2492 remap_image=DestroyImage(remap_image);
2493 break;
2494 }
2495 if (LocaleCompare("repage",option+1) == 0)
2496 {
2497 if (*option == '+')
2498 {
2499 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2500 break;
2501 }
2502 (void) ResetImagePage(*image,argv[i+1]);
2503 InheritException(exception,&(*image)->exception);
2504 break;
2505 }
2506 if (LocaleCompare("resample",option+1) == 0)
2507 {
cristy3ed852e2009-09-05 21:47:34 +00002508 /*
2509 Resample image.
2510 */
cristy6b3da3a2010-06-20 02:21:46 +00002511 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002512 flags=ParseGeometry(argv[i+1],&geometry_info);
2513 if ((flags & SigmaValue) == 0)
2514 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002515 mogrify_image=ResampleImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002516 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002517 break;
2518 }
2519 if (LocaleCompare("resize",option+1) == 0)
2520 {
cristy3ed852e2009-09-05 21:47:34 +00002521 /*
2522 Resize image.
2523 */
cristy6b3da3a2010-06-20 02:21:46 +00002524 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002525 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002526 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002527 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002528 break;
2529 }
cristy3ed852e2009-09-05 21:47:34 +00002530 if (LocaleCompare("roll",option+1) == 0)
2531 {
cristy3ed852e2009-09-05 21:47:34 +00002532 /*
2533 Roll image.
2534 */
cristy6b3da3a2010-06-20 02:21:46 +00002535 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002536 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002537 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00002538 break;
2539 }
2540 if (LocaleCompare("rotate",option+1) == 0)
2541 {
2542 char
2543 *geometry;
2544
cristy3ed852e2009-09-05 21:47:34 +00002545 /*
2546 Check for conditional image rotation.
2547 */
cristy6b3da3a2010-06-20 02:21:46 +00002548 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002549 if (strchr(argv[i+1],'>') != (char *) NULL)
2550 if ((*image)->columns <= (*image)->rows)
2551 break;
2552 if (strchr(argv[i+1],'<') != (char *) NULL)
2553 if ((*image)->columns >= (*image)->rows)
2554 break;
2555 /*
2556 Rotate image.
2557 */
2558 geometry=ConstantString(argv[i+1]);
2559 (void) SubstituteString(&geometry,">","");
2560 (void) SubstituteString(&geometry,"<","");
2561 (void) ParseGeometry(geometry,&geometry_info);
2562 geometry=DestroyString(geometry);
cristyd241f442011-03-29 13:50:49 +00002563 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002564 break;
2565 }
2566 break;
2567 }
2568 case 's':
2569 {
2570 if (LocaleCompare("sample",option+1) == 0)
2571 {
cristy3ed852e2009-09-05 21:47:34 +00002572 /*
2573 Sample image with pixel replication.
2574 */
cristy6b3da3a2010-06-20 02:21:46 +00002575 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002576 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002577 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002578 exception);
cristy3ed852e2009-09-05 21:47:34 +00002579 break;
2580 }
2581 if (LocaleCompare("scale",option+1) == 0)
2582 {
cristy3ed852e2009-09-05 21:47:34 +00002583 /*
2584 Resize image.
2585 */
cristy6b3da3a2010-06-20 02:21:46 +00002586 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002587 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002588 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002589 exception);
cristy3ed852e2009-09-05 21:47:34 +00002590 break;
2591 }
2592 if (LocaleCompare("selective-blur",option+1) == 0)
2593 {
cristy3ed852e2009-09-05 21:47:34 +00002594 /*
2595 Selectively blur pixels within a contrast threshold.
2596 */
cristy6b3da3a2010-06-20 02:21:46 +00002597 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002598 flags=ParseGeometry(argv[i+1],&geometry_info);
2599 if ((flags & PercentValue) != 0)
2600 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00002601 mogrify_image=SelectiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00002602 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002603 break;
2604 }
2605 if (LocaleCompare("separate",option+1) == 0)
2606 {
cristy3ed852e2009-09-05 21:47:34 +00002607 /*
2608 Break channels into separate images.
anthonye9c27192011-03-27 08:07:06 +00002609 WARNING: This can generate multiple images!
cristy3ed852e2009-09-05 21:47:34 +00002610 */
cristy6b3da3a2010-06-20 02:21:46 +00002611 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002612 mogrify_image=SeparateImages(*image,channel,exception);
cristy3ed852e2009-09-05 21:47:34 +00002613 break;
2614 }
2615 if (LocaleCompare("sepia-tone",option+1) == 0)
2616 {
2617 double
2618 threshold;
2619
cristy3ed852e2009-09-05 21:47:34 +00002620 /*
2621 Sepia-tone image.
2622 */
cristy6b3da3a2010-06-20 02:21:46 +00002623 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002624 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00002625 mogrify_image=SepiaToneImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00002626 break;
2627 }
2628 if (LocaleCompare("segment",option+1) == 0)
2629 {
2630 /*
2631 Segment image.
2632 */
cristy6b3da3a2010-06-20 02:21:46 +00002633 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002634 flags=ParseGeometry(argv[i+1],&geometry_info);
2635 if ((flags & SigmaValue) == 0)
2636 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002637 (void) SegmentImage(*image,(*image)->colorspace,
2638 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002639 InheritException(exception,&(*image)->exception);
2640 break;
2641 }
2642 if (LocaleCompare("set",option+1) == 0)
2643 {
cristy6d9a1292010-05-31 14:17:06 +00002644 char
2645 *value;
2646
cristy3ed852e2009-09-05 21:47:34 +00002647 /*
2648 Set image option.
2649 */
cristy6d9a1292010-05-31 14:17:06 +00002650 if (*option == '+')
2651 {
2652 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2653 (void) DeleteImageRegistry(argv[i+1]+9);
2654 else
2655 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002656 {
cristy6b3da3a2010-06-20 02:21:46 +00002657 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002658 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2659 }
cristy6d9a1292010-05-31 14:17:06 +00002660 else
2661 (void) DeleteImageProperty(*image,argv[i+1]);
2662 break;
2663 }
cristy6b3da3a2010-06-20 02:21:46 +00002664 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002665 if (value == (char *) NULL)
2666 break;
cristy3ed852e2009-09-05 21:47:34 +00002667 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002668 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2669 exception);
cristy3ed852e2009-09-05 21:47:34 +00002670 else
2671 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002672 {
cristy7f02ba12010-09-21 12:39:28 +00002673 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002674 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002675 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2676 }
cristy3ed852e2009-09-05 21:47:34 +00002677 else
cristy6d9a1292010-05-31 14:17:06 +00002678 (void) SetImageProperty(*image,argv[i+1],value);
2679 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002680 break;
2681 }
2682 if (LocaleCompare("shade",option+1) == 0)
2683 {
cristy3ed852e2009-09-05 21:47:34 +00002684 /*
2685 Shade image.
2686 */
cristy6b3da3a2010-06-20 02:21:46 +00002687 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002688 flags=ParseGeometry(argv[i+1],&geometry_info);
2689 if ((flags & SigmaValue) == 0)
2690 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002691 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
cristy3ed852e2009-09-05 21:47:34 +00002692 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002693 break;
2694 }
2695 if (LocaleCompare("shadow",option+1) == 0)
2696 {
cristy3ed852e2009-09-05 21:47:34 +00002697 /*
2698 Shadow image.
2699 */
cristy6b3da3a2010-06-20 02:21:46 +00002700 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002701 flags=ParseGeometry(argv[i+1],&geometry_info);
2702 if ((flags & SigmaValue) == 0)
2703 geometry_info.sigma=1.0;
2704 if ((flags & XiValue) == 0)
2705 geometry_info.xi=4.0;
2706 if ((flags & PsiValue) == 0)
2707 geometry_info.psi=4.0;
cristyd241f442011-03-29 13:50:49 +00002708 mogrify_image=ShadowImage(*image,geometry_info.rho,
2709 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2710 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002711 break;
2712 }
2713 if (LocaleCompare("sharpen",option+1) == 0)
2714 {
cristy3ed852e2009-09-05 21:47:34 +00002715 /*
2716 Sharpen image.
2717 */
cristy6b3da3a2010-06-20 02:21:46 +00002718 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002719 flags=ParseGeometry(argv[i+1],&geometry_info);
2720 if ((flags & SigmaValue) == 0)
2721 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002722 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002723 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002724 break;
2725 }
2726 if (LocaleCompare("shave",option+1) == 0)
2727 {
cristy3ed852e2009-09-05 21:47:34 +00002728 /*
2729 Shave the image edges.
2730 */
cristy6b3da3a2010-06-20 02:21:46 +00002731 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002732 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002733 mogrify_image=ShaveImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002734 break;
2735 }
2736 if (LocaleCompare("shear",option+1) == 0)
2737 {
cristy3ed852e2009-09-05 21:47:34 +00002738 /*
2739 Shear image.
2740 */
cristy6b3da3a2010-06-20 02:21:46 +00002741 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002742 flags=ParseGeometry(argv[i+1],&geometry_info);
2743 if ((flags & SigmaValue) == 0)
2744 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002745 mogrify_image=ShearImage(*image,geometry_info.rho,
2746 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002747 break;
2748 }
2749 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2750 {
2751 /*
2752 Sigmoidal non-linearity contrast control.
2753 */
cristy6b3da3a2010-06-20 02:21:46 +00002754 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002755 flags=ParseGeometry(argv[i+1],&geometry_info);
2756 if ((flags & SigmaValue) == 0)
2757 geometry_info.sigma=(double) QuantumRange/2.0;
2758 if ((flags & PercentValue) != 0)
2759 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2760 100.0;
2761 (void) SigmoidalContrastImageChannel(*image,channel,
2762 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2763 geometry_info.sigma);
2764 InheritException(exception,&(*image)->exception);
2765 break;
2766 }
2767 if (LocaleCompare("sketch",option+1) == 0)
2768 {
cristy3ed852e2009-09-05 21:47:34 +00002769 /*
2770 Sketch image.
2771 */
cristy6b3da3a2010-06-20 02:21:46 +00002772 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002773 flags=ParseGeometry(argv[i+1],&geometry_info);
2774 if ((flags & SigmaValue) == 0)
2775 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002776 mogrify_image=SketchImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002777 geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002778 break;
2779 }
2780 if (LocaleCompare("solarize",option+1) == 0)
2781 {
2782 double
2783 threshold;
2784
cristy6b3da3a2010-06-20 02:21:46 +00002785 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002786 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002787 (void) SolarizeImage(*image,threshold);
2788 InheritException(exception,&(*image)->exception);
2789 break;
2790 }
2791 if (LocaleCompare("sparse-color",option+1) == 0)
2792 {
cristy3ed852e2009-09-05 21:47:34 +00002793 SparseColorMethod
2794 method;
2795
2796 char
2797 *arguments;
2798
2799 /*
2800 Sparse Color Interpolated Gradient
2801 */
cristy6b3da3a2010-06-20 02:21:46 +00002802 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002803 method=(SparseColorMethod) ParseMagickOption(
2804 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00002805 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00002806 InheritException(exception,&(*image)->exception);
2807 if (arguments == (char *) NULL)
2808 break;
cristyd241f442011-03-29 13:50:49 +00002809 mogrify_image=SparseColorOption(*image,channel,method,arguments,
cristy3ed852e2009-09-05 21:47:34 +00002810 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2811 arguments=DestroyString(arguments);
cristy3ed852e2009-09-05 21:47:34 +00002812 break;
2813 }
2814 if (LocaleCompare("splice",option+1) == 0)
2815 {
cristy3ed852e2009-09-05 21:47:34 +00002816 /*
2817 Splice a solid color into the image.
2818 */
cristy6b3da3a2010-06-20 02:21:46 +00002819 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002820 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002821 mogrify_image=SpliceImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002822 break;
2823 }
2824 if (LocaleCompare("spread",option+1) == 0)
2825 {
cristy3ed852e2009-09-05 21:47:34 +00002826 /*
2827 Spread an image.
2828 */
cristy6b3da3a2010-06-20 02:21:46 +00002829 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002830 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002831 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002832 break;
2833 }
cristy0834d642011-03-18 18:26:08 +00002834 if (LocaleCompare("statistic",option+1) == 0)
2835 {
cristy0834d642011-03-18 18:26:08 +00002836 StatisticType
2837 type;
2838
2839 (void) SyncImageSettings(mogrify_info,*image);
2840 type=(StatisticType) ParseMagickOption(MagickStatisticOptions,
2841 MagickFalse,argv[i+1]);
2842 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002843 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2844 geometry_info.rho,(size_t) geometry_info.sigma,exception);
cristy0834d642011-03-18 18:26:08 +00002845 break;
2846 }
cristy3ed852e2009-09-05 21:47:34 +00002847 if (LocaleCompare("stretch",option+1) == 0)
2848 {
2849 if (*option == '+')
2850 {
2851 draw_info->stretch=UndefinedStretch;
2852 break;
2853 }
2854 draw_info->stretch=(StretchType) ParseMagickOption(
2855 MagickStretchOptions,MagickFalse,argv[i+1]);
2856 break;
2857 }
2858 if (LocaleCompare("strip",option+1) == 0)
2859 {
2860 /*
2861 Strip image of profiles and comments.
2862 */
cristy6b3da3a2010-06-20 02:21:46 +00002863 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00002864 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00002865 InheritException(exception,&(*image)->exception);
2866 break;
2867 }
2868 if (LocaleCompare("stroke",option+1) == 0)
2869 {
2870 ExceptionInfo
2871 *sans;
2872
2873 if (*option == '+')
2874 {
2875 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2876 if (draw_info->stroke_pattern != (Image *) NULL)
2877 draw_info->stroke_pattern=DestroyImage(
2878 draw_info->stroke_pattern);
2879 break;
2880 }
2881 sans=AcquireExceptionInfo();
2882 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2883 sans=DestroyExceptionInfo(sans);
2884 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00002885 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002886 exception);
2887 break;
2888 }
2889 if (LocaleCompare("strokewidth",option+1) == 0)
2890 {
cristyf2f27272009-12-17 14:48:46 +00002891 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002892 break;
2893 }
2894 if (LocaleCompare("style",option+1) == 0)
2895 {
2896 if (*option == '+')
2897 {
2898 draw_info->style=UndefinedStyle;
2899 break;
2900 }
2901 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
2902 MagickFalse,argv[i+1]);
2903 break;
2904 }
2905 if (LocaleCompare("swirl",option+1) == 0)
2906 {
cristy3ed852e2009-09-05 21:47:34 +00002907 /*
2908 Swirl image.
2909 */
cristy6b3da3a2010-06-20 02:21:46 +00002910 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002911 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002912 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002913 break;
2914 }
2915 break;
2916 }
2917 case 't':
2918 {
2919 if (LocaleCompare("threshold",option+1) == 0)
2920 {
2921 double
2922 threshold;
2923
2924 /*
2925 Threshold image.
2926 */
cristy6b3da3a2010-06-20 02:21:46 +00002927 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002928 if (*option == '+')
2929 threshold=(double) QuantumRange/2.5;
2930 else
cristyf2f27272009-12-17 14:48:46 +00002931 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002932 (void) BilevelImageChannel(*image,channel,threshold);
2933 InheritException(exception,&(*image)->exception);
2934 break;
2935 }
2936 if (LocaleCompare("thumbnail",option+1) == 0)
2937 {
cristy3ed852e2009-09-05 21:47:34 +00002938 /*
2939 Thumbnail image.
2940 */
cristy6b3da3a2010-06-20 02:21:46 +00002941 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002942 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002943 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2944 exception);
cristy3ed852e2009-09-05 21:47:34 +00002945 break;
2946 }
2947 if (LocaleCompare("tile",option+1) == 0)
2948 {
2949 if (*option == '+')
2950 {
2951 if (draw_info->fill_pattern != (Image *) NULL)
2952 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2953 break;
2954 }
cristy6b3da3a2010-06-20 02:21:46 +00002955 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002956 exception);
2957 break;
2958 }
2959 if (LocaleCompare("tint",option+1) == 0)
2960 {
cristy3ed852e2009-09-05 21:47:34 +00002961 /*
2962 Tint the image.
2963 */
cristy6b3da3a2010-06-20 02:21:46 +00002964 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002965 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
cristy3ed852e2009-09-05 21:47:34 +00002966 break;
2967 }
2968 if (LocaleCompare("transform",option+1) == 0)
2969 {
cristy3ed852e2009-09-05 21:47:34 +00002970 /*
2971 Affine transform image.
2972 */
cristy6b3da3a2010-06-20 02:21:46 +00002973 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002974 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
cristy3ed852e2009-09-05 21:47:34 +00002975 exception);
cristy3ed852e2009-09-05 21:47:34 +00002976 break;
2977 }
2978 if (LocaleCompare("transparent",option+1) == 0)
2979 {
2980 MagickPixelPacket
2981 target;
2982
cristy6b3da3a2010-06-20 02:21:46 +00002983 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002984 (void) QueryMagickColor(argv[i+1],&target,exception);
2985 (void) TransparentPaintImage(*image,&target,(Quantum)
2986 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
2987 InheritException(exception,&(*image)->exception);
2988 break;
2989 }
2990 if (LocaleCompare("transpose",option+1) == 0)
2991 {
cristy3ed852e2009-09-05 21:47:34 +00002992 /*
2993 Transpose image scanlines.
2994 */
cristy6b3da3a2010-06-20 02:21:46 +00002995 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002996 mogrify_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002997 break;
2998 }
2999 if (LocaleCompare("transverse",option+1) == 0)
3000 {
cristy3ed852e2009-09-05 21:47:34 +00003001 /*
3002 Transverse image scanlines.
3003 */
cristy6b3da3a2010-06-20 02:21:46 +00003004 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003005 mogrify_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003006 break;
3007 }
3008 if (LocaleCompare("treedepth",option+1) == 0)
3009 {
cristye27293e2009-12-18 02:53:20 +00003010 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003011 break;
3012 }
3013 if (LocaleCompare("trim",option+1) == 0)
3014 {
cristy3ed852e2009-09-05 21:47:34 +00003015 /*
3016 Trim image.
3017 */
cristy6b3da3a2010-06-20 02:21:46 +00003018 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003019 mogrify_image=TrimImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003020 break;
3021 }
3022 if (LocaleCompare("type",option+1) == 0)
3023 {
3024 ImageType
3025 type;
3026
cristy6b3da3a2010-06-20 02:21:46 +00003027 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003028 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003029 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003030 else
3031 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3032 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003033 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003034 (void) SetImageType(*image,type);
3035 InheritException(exception,&(*image)->exception);
3036 break;
3037 }
3038 break;
3039 }
3040 case 'u':
3041 {
3042 if (LocaleCompare("undercolor",option+1) == 0)
3043 {
3044 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3045 exception);
3046 break;
3047 }
cristy045bd902010-01-30 18:56:24 +00003048 if (LocaleCompare("unique",option+1) == 0)
3049 {
3050 if (*option == '+')
3051 {
cristy83fae872010-04-22 15:04:16 +00003052 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003053 break;
3054 }
cristy83fae872010-04-22 15:04:16 +00003055 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003056 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003057 break;
3058 }
cristy3ed852e2009-09-05 21:47:34 +00003059 if (LocaleCompare("unique-colors",option+1) == 0)
3060 {
cristy3ed852e2009-09-05 21:47:34 +00003061 /*
3062 Unique image colors.
3063 */
cristy6b3da3a2010-06-20 02:21:46 +00003064 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003065 mogrify_image=UniqueImageColors(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003066 break;
3067 }
3068 if (LocaleCompare("unsharp",option+1) == 0)
3069 {
cristy3ed852e2009-09-05 21:47:34 +00003070 /*
3071 Unsharp mask image.
3072 */
cristy6b3da3a2010-06-20 02:21:46 +00003073 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003074 flags=ParseGeometry(argv[i+1],&geometry_info);
3075 if ((flags & SigmaValue) == 0)
3076 geometry_info.sigma=1.0;
3077 if ((flags & XiValue) == 0)
3078 geometry_info.xi=1.0;
3079 if ((flags & PsiValue) == 0)
3080 geometry_info.psi=0.05;
cristyd241f442011-03-29 13:50:49 +00003081 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3082 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3083 geometry_info.psi,exception);
cristy3ed852e2009-09-05 21:47:34 +00003084 break;
3085 }
3086 break;
3087 }
3088 case 'v':
3089 {
3090 if (LocaleCompare("verbose",option+1) == 0)
3091 {
3092 (void) SetImageArtifact(*image,option+1,
3093 *option == '+' ? "false" : "true");
3094 break;
3095 }
3096 if (LocaleCompare("vignette",option+1) == 0)
3097 {
cristy3ed852e2009-09-05 21:47:34 +00003098 /*
3099 Vignette image.
3100 */
cristy6b3da3a2010-06-20 02:21:46 +00003101 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003102 flags=ParseGeometry(argv[i+1],&geometry_info);
3103 if ((flags & SigmaValue) == 0)
3104 geometry_info.sigma=1.0;
3105 if ((flags & XiValue) == 0)
3106 geometry_info.xi=0.1*(*image)->columns;
3107 if ((flags & PsiValue) == 0)
3108 geometry_info.psi=0.1*(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00003109 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003110 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003111 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003112 break;
3113 }
3114 if (LocaleCompare("virtual-pixel",option+1) == 0)
3115 {
3116 if (*option == '+')
3117 {
3118 (void) SetImageVirtualPixelMethod(*image,
3119 UndefinedVirtualPixelMethod);
3120 break;
3121 }
3122 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3123 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3124 argv[i+1]));
3125 break;
3126 }
3127 break;
3128 }
3129 case 'w':
3130 {
3131 if (LocaleCompare("wave",option+1) == 0)
3132 {
cristy3ed852e2009-09-05 21:47:34 +00003133 /*
3134 Wave image.
3135 */
cristy6b3da3a2010-06-20 02:21:46 +00003136 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003137 flags=ParseGeometry(argv[i+1],&geometry_info);
3138 if ((flags & SigmaValue) == 0)
3139 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00003140 mogrify_image=WaveImage(*image,geometry_info.rho,
3141 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00003142 break;
3143 }
3144 if (LocaleCompare("weight",option+1) == 0)
3145 {
cristye27293e2009-12-18 02:53:20 +00003146 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003147 if (LocaleCompare(argv[i+1],"all") == 0)
3148 draw_info->weight=0;
3149 if (LocaleCompare(argv[i+1],"bold") == 0)
3150 draw_info->weight=700;
3151 if (LocaleCompare(argv[i+1],"bolder") == 0)
3152 if (draw_info->weight <= 800)
3153 draw_info->weight+=100;
3154 if (LocaleCompare(argv[i+1],"lighter") == 0)
3155 if (draw_info->weight >= 100)
3156 draw_info->weight-=100;
3157 if (LocaleCompare(argv[i+1],"normal") == 0)
3158 draw_info->weight=400;
3159 break;
3160 }
3161 if (LocaleCompare("white-threshold",option+1) == 0)
3162 {
3163 /*
3164 White threshold image.
3165 */
cristy6b3da3a2010-06-20 02:21:46 +00003166 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003167 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3168 exception);
3169 InheritException(exception,&(*image)->exception);
3170 break;
3171 }
3172 break;
3173 }
3174 default:
3175 break;
3176 }
anthonye9c27192011-03-27 08:07:06 +00003177 /*
3178 Replace current image with any image that was generated
3179 */
cristyd241f442011-03-29 13:50:49 +00003180 if (mogrify_image != (Image *) NULL)
3181 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003182 i+=count;
3183 }
3184 if (region_image != (Image *) NULL)
3185 {
3186 /*
3187 Composite transformed region onto image.
3188 */
cristy6b3da3a2010-06-20 02:21:46 +00003189 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003190 (void) CompositeImage(region_image,region_image->matte !=
3191 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
anthonye9c27192011-03-27 08:07:06 +00003192 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003193 InheritException(exception,&region_image->exception);
3194 *image=DestroyImage(*image);
3195 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003196 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003197 }
3198 /*
3199 Free resources.
3200 */
3201 quantize_info=DestroyQuantizeInfo(quantize_info);
3202 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003203 mogrify_info=DestroyImageInfo(mogrify_info);
cristy72988482011-03-29 16:34:38 +00003204 status=(*image)->exception.severity == UndefinedException ? 1 : 0;
3205 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003206}
3207
3208/*
3209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3210% %
3211% %
3212% %
cristy5063d812010-10-19 16:28:10 +00003213+ 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 +00003214% %
3215% %
3216% %
3217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3218%
3219% MogrifyImageCommand() transforms an image or a sequence of images. These
3220% transforms include image scaling, image rotation, color reduction, and
3221% others. The transmogrified image overwrites the original image.
3222%
3223% The format of the MogrifyImageCommand method is:
3224%
3225% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3226% const char **argv,char **metadata,ExceptionInfo *exception)
3227%
3228% A description of each parameter follows:
3229%
3230% o image_info: the image info.
3231%
3232% o argc: the number of elements in the argument vector.
3233%
3234% o argv: A text array containing the command line arguments.
3235%
3236% o metadata: any metadata is returned here.
3237%
3238% o exception: return any errors or warnings in this structure.
3239%
3240*/
3241
3242static MagickBooleanType MogrifyUsage(void)
3243{
3244 static const char
3245 *miscellaneous[]=
3246 {
3247 "-debug events display copious debugging information",
3248 "-help print program options",
3249 "-list type print a list of supported option arguments",
3250 "-log format format of debugging information",
3251 "-version print version information",
3252 (char *) NULL
3253 },
3254 *operators[]=
3255 {
3256 "-adaptive-blur geometry",
3257 " adaptively blur pixels; decrease effect near edges",
3258 "-adaptive-resize geometry",
3259 " adaptively resize image using 'mesh' interpolation",
3260 "-adaptive-sharpen geometry",
3261 " adaptively sharpen pixels; increase effect near edges",
3262 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3263 " transparent, extract, background, or shape",
3264 "-annotate geometry text",
3265 " annotate the image with text",
3266 "-auto-gamma automagically adjust gamma level of image",
3267 "-auto-level automagically adjust color levels of image",
3268 "-auto-orient automagically orient (rotate) image",
3269 "-bench iterations measure performance",
3270 "-black-threshold value",
3271 " force all pixels below the threshold into black",
3272 "-blue-shift simulate a scene at nighttime in the moonlight",
3273 "-blur geometry reduce image noise and reduce detail levels",
3274 "-border geometry surround image with a border of color",
3275 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003276 "-brightness-contrast geometry",
3277 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003278 "-cdl filename color correct with a color decision list",
3279 "-charcoal radius simulate a charcoal drawing",
3280 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003281 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003282 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003283 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003284 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003285 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003286 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003287 "-contrast enhance or reduce the image contrast",
3288 "-contrast-stretch geometry",
3289 " improve contrast by `stretching' the intensity range",
3290 "-convolve coefficients",
3291 " apply a convolution kernel to the image",
3292 "-cycle amount cycle the image colormap",
3293 "-decipher filename convert cipher pixels to plain pixels",
3294 "-deskew threshold straighten an image",
3295 "-despeckle reduce the speckles within an image",
3296 "-distort method args",
3297 " distort images according to given method ad args",
3298 "-draw string annotate the image with a graphic primitive",
3299 "-edge radius apply a filter to detect edges in the image",
3300 "-encipher filename convert plain pixels to cipher pixels",
3301 "-emboss radius emboss an image",
3302 "-enhance apply a digital filter to enhance a noisy image",
3303 "-equalize perform histogram equalization to an image",
3304 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003305 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-extent geometry set the image size",
3307 "-extract geometry extract area from image",
3308 "-fft implements the discrete Fourier transform (DFT)",
3309 "-flip flip image vertically",
3310 "-floodfill geometry color",
3311 " floodfill the image with color",
3312 "-flop flop image horizontally",
3313 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003314 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003315 " apply function over image values",
3316 "-gamma value level of gamma correction",
3317 "-gaussian-blur geometry",
3318 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003319 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003320 "-identify identify the format and characteristics of the image",
3321 "-ift implements the inverse discrete Fourier transform (DFT)",
3322 "-implode amount implode image pixels about the center",
3323 "-lat geometry local adaptive thresholding",
3324 "-layers method optimize, merge, or compare image layers",
3325 "-level value adjust the level of image contrast",
3326 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003327 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003328 "-linear-stretch geometry",
3329 " improve contrast by `stretching with saturation'",
3330 "-liquid-rescale geometry",
3331 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003332 "-median geometry apply a median filter to the image",
3333 "-mode geometry make each pixel the 'predominate color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003334 "-modulate value vary the brightness, saturation, and hue",
3335 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003336 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003337 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003338 "-motion-blur geometry",
3339 " simulate motion blur",
3340 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003341 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003342 "-normalize transform image to span the full range of colors",
3343 "-opaque color change this color to the fill color",
3344 "-ordered-dither NxN",
3345 " add a noise pattern to the image with specific",
3346 " amplitudes",
3347 "-paint radius simulate an oil painting",
3348 "-polaroid angle simulate a Polaroid picture",
3349 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003350 "-profile filename add, delete, or apply an image profile",
3351 "-quantize colorspace reduce colors in this colorspace",
3352 "-radial-blur angle radial blur the image",
3353 "-raise value lighten/darken image edges to create a 3-D effect",
3354 "-random-threshold low,high",
3355 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003356 "-region geometry apply options to a portion of the image",
3357 "-render render vector graphics",
3358 "-repage geometry size and location of an image canvas",
3359 "-resample geometry change the resolution of an image",
3360 "-resize geometry resize the image",
3361 "-roll geometry roll an image vertically or horizontally",
3362 "-rotate degrees apply Paeth rotation to the image",
3363 "-sample geometry scale image with pixel sampling",
3364 "-scale geometry scale the image",
3365 "-segment values segment an image",
3366 "-selective-blur geometry",
3367 " selectively blur pixels within a contrast threshold",
3368 "-sepia-tone threshold",
3369 " simulate a sepia-toned photo",
3370 "-set property value set an image property",
3371 "-shade degrees shade the image using a distant light source",
3372 "-shadow geometry simulate an image shadow",
3373 "-sharpen geometry sharpen the image",
3374 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003375 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003376 "-sigmoidal-contrast geometry",
3377 " increase the contrast without saturating highlights or shadows",
3378 "-sketch geometry simulate a pencil sketch",
3379 "-solarize threshold negate all pixels above the threshold level",
3380 "-sparse-color method args",
3381 " fill in a image based on a few color points",
3382 "-splice geometry splice the background color into the image",
3383 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003384 "-statistic type radius",
3385 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003386 "-strip strip image of all profiles and comments",
3387 "-swirl degrees swirl image pixels about the center",
3388 "-threshold value threshold the image",
3389 "-thumbnail geometry create a thumbnail of the image",
3390 "-tile filename tile image when filling a graphic primitive",
3391 "-tint value tint the image with the fill color",
3392 "-transform affine transform image",
3393 "-transparent color make this color transparent within the image",
3394 "-transpose flip image vertically and rotate 90 degrees",
3395 "-transverse flop image horizontally and rotate 270 degrees",
3396 "-trim trim image edges",
3397 "-type type image type",
3398 "-unique-colors discard all but one of any pixel color",
3399 "-unsharp geometry sharpen the image",
3400 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003401 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003402 "-white-threshold value",
3403 " force all pixels above the threshold into white",
3404 (char *) NULL
3405 },
3406 *sequence_operators[]=
3407 {
cristy4285d782011-02-09 20:12:28 +00003408 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003409 "-clut apply a color lookup table to the image",
3410 "-coalesce merge a sequence of images",
3411 "-combine combine a sequence of images",
3412 "-composite composite image",
3413 "-crop geometry cut out a rectangular region of the image",
3414 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003415 "-evaluate-sequence operator",
3416 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003417 "-flatten flatten a sequence of images",
3418 "-fx expression apply mathematical expression to an image channel(s)",
3419 "-hald-clut apply a Hald color lookup table to the image",
3420 "-morph value morph an image sequence",
3421 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003422 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003423 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003424 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003425 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003426 "-write filename write images to this file",
3427 (char *) NULL
3428 },
3429 *settings[]=
3430 {
3431 "-adjoin join images into a single multi-image file",
3432 "-affine matrix affine transform matrix",
3433 "-alpha option activate, deactivate, reset, or set the alpha channel",
3434 "-antialias remove pixel-aliasing",
3435 "-authenticate password",
3436 " decipher image with this password",
3437 "-attenuate value lessen (or intensify) when adding noise to an image",
3438 "-background color background color",
3439 "-bias value add bias when convolving an image",
3440 "-black-point-compensation",
3441 " use black point compensation",
3442 "-blue-primary point chromaticity blue primary point",
3443 "-bordercolor color border color",
3444 "-caption string assign a caption to an image",
3445 "-channel type apply option to select image channels",
3446 "-colors value preferred number of colors in the image",
3447 "-colorspace type alternate image colorspace",
3448 "-comment string annotate image with comment",
3449 "-compose operator set image composite operator",
3450 "-compress type type of pixel compression when writing the image",
3451 "-define format:option",
3452 " define one or more image format options",
3453 "-delay value display the next image after pausing",
3454 "-density geometry horizontal and vertical density of the image",
3455 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003456 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003457 "-display server get image or font from this X server",
3458 "-dispose method layer disposal method",
3459 "-dither method apply error diffusion to image",
3460 "-encoding type text encoding type",
3461 "-endian type endianness (MSB or LSB) of the image",
3462 "-family name render text with this font family",
3463 "-fill color color to use when filling a graphic primitive",
3464 "-filter type use this filter when resizing an image",
3465 "-font name render text with this font",
3466 "-format \"string\" output formatted image characteristics",
3467 "-fuzz distance colors within this distance are considered equal",
3468 "-gravity type horizontal and vertical text placement",
3469 "-green-primary point chromaticity green primary point",
3470 "-intent type type of rendering intent when managing the image color",
3471 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003472 "-interline-spacing value",
3473 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003474 "-interpolate method pixel color interpolation method",
3475 "-interword-spacing value",
3476 " set the space between two words",
3477 "-kerning value set the space between two letters",
3478 "-label string assign a label to an image",
3479 "-limit type value pixel cache resource limit",
3480 "-loop iterations add Netscape loop extension to your GIF animation",
3481 "-mask filename associate a mask with the image",
3482 "-mattecolor color frame color",
3483 "-monitor monitor progress",
3484 "-orient type image orientation",
3485 "-page geometry size and location of an image canvas (setting)",
3486 "-ping efficiently determine image attributes",
3487 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003488 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003489 "-preview type image preview type",
3490 "-quality value JPEG/MIFF/PNG compression level",
3491 "-quiet suppress all warning messages",
3492 "-red-primary point chromaticity red primary point",
3493 "-regard-warnings pay attention to warning messages",
3494 "-remap filename transform image colors to match this set of colors",
3495 "-respect-parentheses settings remain in effect until parenthesis boundary",
3496 "-sampling-factor geometry",
3497 " horizontal and vertical sampling factor",
3498 "-scene value image scene number",
3499 "-seed value seed a new sequence of pseudo-random numbers",
3500 "-size geometry width and height of image",
3501 "-stretch type render text with this font stretch",
3502 "-stroke color graphic primitive stroke color",
3503 "-strokewidth value graphic primitive stroke width",
3504 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003505 "-synchronize synchronize image to storage device",
3506 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003507 "-texture filename name of texture to tile onto the image background",
3508 "-tile-offset geometry",
3509 " tile offset",
3510 "-treedepth value color tree depth",
3511 "-transparent-color color",
3512 " transparent color",
3513 "-undercolor color annotation bounding box color",
3514 "-units type the units of image resolution",
3515 "-verbose print detailed information about the image",
3516 "-view FlashPix viewing transforms",
3517 "-virtual-pixel method",
3518 " virtual pixel access method",
3519 "-weight type render text with this font weight",
3520 "-white-point point chromaticity white point",
3521 (char *) NULL
3522 },
3523 *stack_operators[]=
3524 {
anthonyb69c4b32011-03-23 04:37:44 +00003525 "-delete indexes delete the image from the image sequence",
3526 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003527 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003528 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003529 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003530 "-swap indexes swap two images in the image sequence",
3531 (char *) NULL
3532 };
3533
3534 const char
3535 **p;
3536
cristybb503372010-05-27 20:51:26 +00003537 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003538 (void) printf("Copyright: %s\n",GetMagickCopyright());
3539 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003540 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3541 GetClientName());
3542 (void) printf("\nImage Settings:\n");
3543 for (p=settings; *p != (char *) NULL; p++)
3544 (void) printf(" %s\n",*p);
3545 (void) printf("\nImage Operators:\n");
3546 for (p=operators; *p != (char *) NULL; p++)
3547 (void) printf(" %s\n",*p);
3548 (void) printf("\nImage Sequence Operators:\n");
3549 for (p=sequence_operators; *p != (char *) NULL; p++)
3550 (void) printf(" %s\n",*p);
3551 (void) printf("\nImage Stack Operators:\n");
3552 for (p=stack_operators; *p != (char *) NULL; p++)
3553 (void) printf(" %s\n",*p);
3554 (void) printf("\nMiscellaneous Options:\n");
3555 for (p=miscellaneous; *p != (char *) NULL; p++)
3556 (void) printf(" %s\n",*p);
3557 (void) printf(
3558 "\nBy default, the image format of `file' is determined by its magic\n");
3559 (void) printf(
3560 "number. To specify a particular image format, precede the filename\n");
3561 (void) printf(
3562 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3563 (void) printf(
3564 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3565 (void) printf("'-' for standard input or output.\n");
3566 return(MagickFalse);
3567}
3568
3569WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3570 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3571{
3572#define DestroyMogrify() \
3573{ \
3574 if (format != (char *) NULL) \
3575 format=DestroyString(format); \
3576 if (path != (char *) NULL) \
3577 path=DestroyString(path); \
3578 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003579 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003580 argv[i]=DestroyString(argv[i]); \
3581 argv=(char **) RelinquishMagickMemory(argv); \
3582}
3583#define ThrowMogrifyException(asperity,tag,option) \
3584{ \
3585 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3586 option); \
3587 DestroyMogrify(); \
3588 return(MagickFalse); \
3589}
3590#define ThrowMogrifyInvalidArgumentException(option,argument) \
3591{ \
3592 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3593 "InvalidArgument","`%s': %s",argument,option); \
3594 DestroyMogrify(); \
3595 return(MagickFalse); \
3596}
3597
3598 char
3599 *format,
3600 *option,
3601 *path;
3602
3603 Image
3604 *image;
3605
3606 ImageStack
3607 image_stack[MaxImageStackDepth+1];
3608
cristy3ed852e2009-09-05 21:47:34 +00003609 MagickBooleanType
3610 global_colormap;
3611
3612 MagickBooleanType
3613 fire,
cristyebbcfea2011-02-25 02:43:54 +00003614 pend,
3615 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003616
3617 MagickStatusType
3618 status;
3619
cristyebbcfea2011-02-25 02:43:54 +00003620 register ssize_t
3621 i;
3622
3623 ssize_t
3624 j,
3625 k;
3626
cristy3ed852e2009-09-05 21:47:34 +00003627 /*
3628 Set defaults.
3629 */
3630 assert(image_info != (ImageInfo *) NULL);
3631 assert(image_info->signature == MagickSignature);
3632 if (image_info->debug != MagickFalse)
3633 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3634 assert(exception != (ExceptionInfo *) NULL);
3635 if (argc == 2)
3636 {
3637 option=argv[1];
3638 if ((LocaleCompare("version",option+1) == 0) ||
3639 (LocaleCompare("-version",option+1) == 0))
3640 {
3641 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003642 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003643 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
3644 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003645 return(MagickFalse);
3646 }
3647 }
3648 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003649 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003650 format=(char *) NULL;
3651 path=(char *) NULL;
3652 global_colormap=MagickFalse;
3653 k=0;
3654 j=1;
3655 NewImageStack();
3656 option=(char *) NULL;
3657 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003658 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003659 status=MagickTrue;
3660 /*
3661 Parse command line.
3662 */
3663 ReadCommandlLine(argc,&argv);
3664 status=ExpandFilenames(&argc,&argv);
3665 if (status == MagickFalse)
3666 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3667 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003668 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003669 {
3670 option=argv[i];
3671 if (LocaleCompare(option,"(") == 0)
3672 {
3673 FireImageStack(MagickFalse,MagickTrue,pend);
3674 if (k == MaxImageStackDepth)
3675 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3676 option);
3677 PushImageStack();
3678 continue;
3679 }
3680 if (LocaleCompare(option,")") == 0)
3681 {
3682 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3683 if (k == 0)
3684 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3685 PopImageStack();
3686 continue;
3687 }
3688 if (IsMagickOption(option) == MagickFalse)
3689 {
3690 char
3691 backup_filename[MaxTextExtent],
3692 *filename;
3693
3694 Image
3695 *images;
3696
3697 /*
3698 Option is a file name: begin by reading image from specified file.
3699 */
3700 FireImageStack(MagickFalse,MagickFalse,pend);
3701 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003702 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003703 filename=argv[++i];
3704 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3705 images=ReadImages(image_info,exception);
3706 status&=(images != (Image *) NULL) &&
3707 (exception->severity < ErrorException);
3708 if (images == (Image *) NULL)
3709 continue;
cristydaa76602010-06-30 13:05:11 +00003710 if (format != (char *) NULL)
3711 (void) CopyMagickString(images->filename,images->magick_filename,
3712 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003713 if (path != (char *) NULL)
3714 {
3715 GetPathComponent(option,TailPath,filename);
3716 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
3717 path,*DirectorySeparator,filename);
3718 }
3719 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003720 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003721 AppendImageStack(images);
3722 FinalizeImageSettings(image_info,image,MagickFalse);
3723 if (global_colormap != MagickFalse)
3724 {
3725 QuantizeInfo
3726 *quantize_info;
3727
3728 quantize_info=AcquireQuantizeInfo(image_info);
3729 (void) RemapImages(quantize_info,images,(Image *) NULL);
3730 quantize_info=DestroyQuantizeInfo(quantize_info);
3731 }
3732 *backup_filename='\0';
3733 if ((LocaleCompare(image->filename,"-") != 0) &&
3734 (IsPathWritable(image->filename) != MagickFalse))
3735 {
cristybb503372010-05-27 20:51:26 +00003736 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003737 i;
3738
3739 /*
3740 Rename image file as backup.
3741 */
3742 (void) CopyMagickString(backup_filename,image->filename,
3743 MaxTextExtent);
3744 for (i=0; i < 6; i++)
3745 {
3746 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3747 if (IsPathAccessible(backup_filename) == MagickFalse)
3748 break;
3749 }
3750 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3751 (rename(image->filename,backup_filename) != 0))
3752 *backup_filename='\0';
3753 }
3754 /*
3755 Write transmogrified image to disk.
3756 */
3757 image_info->synchronize=MagickTrue;
3758 status&=WriteImages(image_info,image,image->filename,exception);
3759 if ((status == MagickFalse) && (*backup_filename != '\0'))
3760 (void) remove(backup_filename);
3761 RemoveAllImageStack();
3762 continue;
3763 }
3764 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3765 switch (*(option+1))
3766 {
3767 case 'a':
3768 {
3769 if (LocaleCompare("adaptive-blur",option+1) == 0)
3770 {
3771 i++;
cristybb503372010-05-27 20:51:26 +00003772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003773 ThrowMogrifyException(OptionError,"MissingArgument",option);
3774 if (IsGeometry(argv[i]) == MagickFalse)
3775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3776 break;
3777 }
3778 if (LocaleCompare("adaptive-resize",option+1) == 0)
3779 {
3780 i++;
cristybb503372010-05-27 20:51:26 +00003781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003782 ThrowMogrifyException(OptionError,"MissingArgument",option);
3783 if (IsGeometry(argv[i]) == MagickFalse)
3784 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3785 break;
3786 }
3787 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3788 {
3789 i++;
cristybb503372010-05-27 20:51:26 +00003790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003791 ThrowMogrifyException(OptionError,"MissingArgument",option);
3792 if (IsGeometry(argv[i]) == MagickFalse)
3793 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3794 break;
3795 }
3796 if (LocaleCompare("affine",option+1) == 0)
3797 {
3798 if (*option == '+')
3799 break;
3800 i++;
cristybb503372010-05-27 20:51:26 +00003801 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003802 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003803 break;
3804 }
3805 if (LocaleCompare("alpha",option+1) == 0)
3806 {
cristybb503372010-05-27 20:51:26 +00003807 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003808 type;
3809
3810 if (*option == '+')
3811 break;
3812 i++;
cristybb503372010-05-27 20:51:26 +00003813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003814 ThrowMogrifyException(OptionError,"MissingArgument",option);
3815 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
3816 if (type < 0)
3817 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3818 argv[i]);
3819 break;
3820 }
3821 if (LocaleCompare("annotate",option+1) == 0)
3822 {
3823 if (*option == '+')
3824 break;
3825 i++;
cristybb503372010-05-27 20:51:26 +00003826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003827 ThrowMogrifyException(OptionError,"MissingArgument",option);
3828 if (IsGeometry(argv[i]) == MagickFalse)
3829 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003831 ThrowMogrifyException(OptionError,"MissingArgument",option);
3832 i++;
3833 break;
3834 }
3835 if (LocaleCompare("antialias",option+1) == 0)
3836 break;
3837 if (LocaleCompare("append",option+1) == 0)
3838 break;
3839 if (LocaleCompare("attenuate",option+1) == 0)
3840 {
3841 if (*option == '+')
3842 break;
3843 i++;
cristybb503372010-05-27 20:51:26 +00003844 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003845 ThrowMogrifyException(OptionError,"MissingArgument",option);
3846 if (IsGeometry(argv[i]) == MagickFalse)
3847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3848 break;
3849 }
3850 if (LocaleCompare("authenticate",option+1) == 0)
3851 {
3852 if (*option == '+')
3853 break;
3854 i++;
cristybb503372010-05-27 20:51:26 +00003855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003856 ThrowMogrifyException(OptionError,"MissingArgument",option);
3857 break;
3858 }
3859 if (LocaleCompare("auto-gamma",option+1) == 0)
3860 break;
3861 if (LocaleCompare("auto-level",option+1) == 0)
3862 break;
3863 if (LocaleCompare("auto-orient",option+1) == 0)
3864 break;
3865 if (LocaleCompare("average",option+1) == 0)
3866 break;
3867 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3868 }
3869 case 'b':
3870 {
3871 if (LocaleCompare("background",option+1) == 0)
3872 {
3873 if (*option == '+')
3874 break;
3875 i++;
cristybb503372010-05-27 20:51:26 +00003876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003877 ThrowMogrifyException(OptionError,"MissingArgument",option);
3878 break;
3879 }
3880 if (LocaleCompare("bias",option+1) == 0)
3881 {
3882 if (*option == '+')
3883 break;
3884 i++;
cristybb503372010-05-27 20:51:26 +00003885 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003886 ThrowMogrifyException(OptionError,"MissingArgument",option);
3887 if (IsGeometry(argv[i]) == MagickFalse)
3888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3889 break;
3890 }
3891 if (LocaleCompare("black-point-compensation",option+1) == 0)
3892 break;
3893 if (LocaleCompare("black-threshold",option+1) == 0)
3894 {
3895 if (*option == '+')
3896 break;
3897 i++;
cristybb503372010-05-27 20:51:26 +00003898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003899 ThrowMogrifyException(OptionError,"MissingArgument",option);
3900 if (IsGeometry(argv[i]) == MagickFalse)
3901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3902 break;
3903 }
3904 if (LocaleCompare("blue-primary",option+1) == 0)
3905 {
3906 if (*option == '+')
3907 break;
3908 i++;
cristybb503372010-05-27 20:51:26 +00003909 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003910 ThrowMogrifyException(OptionError,"MissingArgument",option);
3911 if (IsGeometry(argv[i]) == MagickFalse)
3912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3913 break;
3914 }
3915 if (LocaleCompare("blue-shift",option+1) == 0)
3916 {
3917 i++;
cristybb503372010-05-27 20:51:26 +00003918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003919 ThrowMogrifyException(OptionError,"MissingArgument",option);
3920 if (IsGeometry(argv[i]) == MagickFalse)
3921 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3922 break;
3923 }
3924 if (LocaleCompare("blur",option+1) == 0)
3925 {
3926 i++;
cristybb503372010-05-27 20:51:26 +00003927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003928 ThrowMogrifyException(OptionError,"MissingArgument",option);
3929 if (IsGeometry(argv[i]) == MagickFalse)
3930 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3931 break;
3932 }
3933 if (LocaleCompare("border",option+1) == 0)
3934 {
3935 if (*option == '+')
3936 break;
3937 i++;
cristybb503372010-05-27 20:51:26 +00003938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003939 ThrowMogrifyException(OptionError,"MissingArgument",option);
3940 if (IsGeometry(argv[i]) == MagickFalse)
3941 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3942 break;
3943 }
3944 if (LocaleCompare("bordercolor",option+1) == 0)
3945 {
3946 if (*option == '+')
3947 break;
3948 i++;
cristybb503372010-05-27 20:51:26 +00003949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003950 ThrowMogrifyException(OptionError,"MissingArgument",option);
3951 break;
3952 }
3953 if (LocaleCompare("box",option+1) == 0)
3954 {
3955 if (*option == '+')
3956 break;
3957 i++;
cristybb503372010-05-27 20:51:26 +00003958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003959 ThrowMogrifyException(OptionError,"MissingArgument",option);
3960 break;
3961 }
cristya28d6b82010-01-11 20:03:47 +00003962 if (LocaleCompare("brightness-contrast",option+1) == 0)
3963 {
3964 i++;
cristybb503372010-05-27 20:51:26 +00003965 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003966 ThrowMogrifyException(OptionError,"MissingArgument",option);
3967 if (IsGeometry(argv[i]) == MagickFalse)
3968 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3969 break;
3970 }
cristy3ed852e2009-09-05 21:47:34 +00003971 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3972 }
3973 case 'c':
3974 {
3975 if (LocaleCompare("cache",option+1) == 0)
3976 {
3977 if (*option == '+')
3978 break;
3979 i++;
cristybb503372010-05-27 20:51:26 +00003980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003981 ThrowMogrifyException(OptionError,"MissingArgument",option);
3982 if (IsGeometry(argv[i]) == MagickFalse)
3983 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3984 break;
3985 }
3986 if (LocaleCompare("caption",option+1) == 0)
3987 {
3988 if (*option == '+')
3989 break;
3990 i++;
cristybb503372010-05-27 20:51:26 +00003991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003992 ThrowMogrifyException(OptionError,"MissingArgument",option);
3993 break;
3994 }
3995 if (LocaleCompare("channel",option+1) == 0)
3996 {
cristybb503372010-05-27 20:51:26 +00003997 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003998 channel;
3999
4000 if (*option == '+')
4001 break;
4002 i++;
cristybb503372010-05-27 20:51:26 +00004003 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004004 ThrowMogrifyException(OptionError,"MissingArgument",option);
4005 channel=ParseChannelOption(argv[i]);
4006 if (channel < 0)
4007 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4008 argv[i]);
4009 break;
4010 }
4011 if (LocaleCompare("cdl",option+1) == 0)
4012 {
4013 if (*option == '+')
4014 break;
4015 i++;
cristybb503372010-05-27 20:51:26 +00004016 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004017 ThrowMogrifyException(OptionError,"MissingArgument",option);
4018 break;
4019 }
4020 if (LocaleCompare("charcoal",option+1) == 0)
4021 {
4022 if (*option == '+')
4023 break;
4024 i++;
cristybb503372010-05-27 20:51:26 +00004025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004026 ThrowMogrifyException(OptionError,"MissingArgument",option);
4027 if (IsGeometry(argv[i]) == MagickFalse)
4028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4029 break;
4030 }
4031 if (LocaleCompare("chop",option+1) == 0)
4032 {
4033 if (*option == '+')
4034 break;
4035 i++;
cristybb503372010-05-27 20:51:26 +00004036 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004037 ThrowMogrifyException(OptionError,"MissingArgument",option);
4038 if (IsGeometry(argv[i]) == MagickFalse)
4039 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4040 break;
4041 }
cristy1eb45dd2009-09-25 16:38:06 +00004042 if (LocaleCompare("clamp",option+1) == 0)
4043 break;
4044 if (LocaleCompare("clip",option+1) == 0)
4045 break;
cristy3ed852e2009-09-05 21:47:34 +00004046 if (LocaleCompare("clip-mask",option+1) == 0)
4047 {
4048 if (*option == '+')
4049 break;
4050 i++;
cristybb503372010-05-27 20:51:26 +00004051 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004052 ThrowMogrifyException(OptionError,"MissingArgument",option);
4053 break;
4054 }
4055 if (LocaleCompare("clut",option+1) == 0)
4056 break;
4057 if (LocaleCompare("coalesce",option+1) == 0)
4058 break;
4059 if (LocaleCompare("colorize",option+1) == 0)
4060 {
4061 if (*option == '+')
4062 break;
4063 i++;
cristybb503372010-05-27 20:51:26 +00004064 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004065 ThrowMogrifyException(OptionError,"MissingArgument",option);
4066 if (IsGeometry(argv[i]) == MagickFalse)
4067 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4068 break;
4069 }
cristye6365592010-04-02 17:31:23 +00004070 if (LocaleCompare("color-matrix",option+1) == 0)
4071 {
cristyb6bd4ad2010-08-08 01:12:27 +00004072 KernelInfo
4073 *kernel_info;
4074
cristye6365592010-04-02 17:31:23 +00004075 if (*option == '+')
4076 break;
4077 i++;
cristybb503372010-05-27 20:51:26 +00004078 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004079 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004080 kernel_info=AcquireKernelInfo(argv[i]);
4081 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004082 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004083 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004084 break;
4085 }
cristy3ed852e2009-09-05 21:47:34 +00004086 if (LocaleCompare("colors",option+1) == 0)
4087 {
4088 if (*option == '+')
4089 break;
4090 i++;
cristybb503372010-05-27 20:51:26 +00004091 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004092 ThrowMogrifyException(OptionError,"MissingArgument",option);
4093 if (IsGeometry(argv[i]) == MagickFalse)
4094 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4095 break;
4096 }
4097 if (LocaleCompare("colorspace",option+1) == 0)
4098 {
cristybb503372010-05-27 20:51:26 +00004099 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004100 colorspace;
4101
4102 if (*option == '+')
4103 break;
4104 i++;
cristybb503372010-05-27 20:51:26 +00004105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004106 ThrowMogrifyException(OptionError,"MissingArgument",option);
4107 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4108 argv[i]);
4109 if (colorspace < 0)
4110 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4111 argv[i]);
4112 break;
4113 }
4114 if (LocaleCompare("combine",option+1) == 0)
4115 break;
4116 if (LocaleCompare("comment",option+1) == 0)
4117 {
4118 if (*option == '+')
4119 break;
4120 i++;
cristybb503372010-05-27 20:51:26 +00004121 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004122 ThrowMogrifyException(OptionError,"MissingArgument",option);
4123 break;
4124 }
4125 if (LocaleCompare("composite",option+1) == 0)
4126 break;
4127 if (LocaleCompare("compress",option+1) == 0)
4128 {
cristybb503372010-05-27 20:51:26 +00004129 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004130 compress;
4131
4132 if (*option == '+')
4133 break;
4134 i++;
cristybb503372010-05-27 20:51:26 +00004135 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004136 ThrowMogrifyException(OptionError,"MissingArgument",option);
4137 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4138 argv[i]);
4139 if (compress < 0)
4140 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4141 argv[i]);
4142 break;
4143 }
cristy22879752009-10-25 23:55:40 +00004144 if (LocaleCompare("concurrent",option+1) == 0)
4145 break;
cristy3ed852e2009-09-05 21:47:34 +00004146 if (LocaleCompare("contrast",option+1) == 0)
4147 break;
4148 if (LocaleCompare("contrast-stretch",option+1) == 0)
4149 {
4150 i++;
cristybb503372010-05-27 20:51:26 +00004151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004152 ThrowMogrifyException(OptionError,"MissingArgument",option);
4153 if (IsGeometry(argv[i]) == MagickFalse)
4154 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4155 break;
4156 }
4157 if (LocaleCompare("convolve",option+1) == 0)
4158 {
cristyb6bd4ad2010-08-08 01:12:27 +00004159 KernelInfo
4160 *kernel_info;
4161
cristy3ed852e2009-09-05 21:47:34 +00004162 if (*option == '+')
4163 break;
4164 i++;
cristybb503372010-05-27 20:51:26 +00004165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004166 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004167 kernel_info=AcquireKernelInfo(argv[i]);
4168 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004169 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004170 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004171 break;
4172 }
4173 if (LocaleCompare("crop",option+1) == 0)
4174 {
4175 if (*option == '+')
4176 break;
4177 i++;
cristybb503372010-05-27 20:51:26 +00004178 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004179 ThrowMogrifyException(OptionError,"MissingArgument",option);
4180 if (IsGeometry(argv[i]) == MagickFalse)
4181 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4182 break;
4183 }
4184 if (LocaleCompare("cycle",option+1) == 0)
4185 {
4186 if (*option == '+')
4187 break;
4188 i++;
cristybb503372010-05-27 20:51:26 +00004189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004190 ThrowMogrifyException(OptionError,"MissingArgument",option);
4191 if (IsGeometry(argv[i]) == MagickFalse)
4192 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4193 break;
4194 }
4195 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4196 }
4197 case 'd':
4198 {
4199 if (LocaleCompare("decipher",option+1) == 0)
4200 {
4201 if (*option == '+')
4202 break;
4203 i++;
cristybb503372010-05-27 20:51:26 +00004204 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004205 ThrowMogrifyException(OptionError,"MissingArgument",option);
4206 break;
4207 }
4208 if (LocaleCompare("deconstruct",option+1) == 0)
4209 break;
4210 if (LocaleCompare("debug",option+1) == 0)
4211 {
cristybb503372010-05-27 20:51:26 +00004212 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004213 event;
4214
4215 if (*option == '+')
4216 break;
4217 i++;
cristybb503372010-05-27 20:51:26 +00004218 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004219 ThrowMogrifyException(OptionError,"MissingArgument",option);
4220 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4221 if (event < 0)
4222 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4223 argv[i]);
4224 (void) SetLogEventMask(argv[i]);
4225 break;
4226 }
4227 if (LocaleCompare("define",option+1) == 0)
4228 {
4229 i++;
cristybb503372010-05-27 20:51:26 +00004230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004231 ThrowMogrifyException(OptionError,"MissingArgument",option);
4232 if (*option == '+')
4233 {
4234 const char
4235 *define;
4236
4237 define=GetImageOption(image_info,argv[i]);
4238 if (define == (const char *) NULL)
4239 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4240 break;
4241 }
4242 break;
4243 }
4244 if (LocaleCompare("delay",option+1) == 0)
4245 {
4246 if (*option == '+')
4247 break;
4248 i++;
cristybb503372010-05-27 20:51:26 +00004249 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004250 ThrowMogrifyException(OptionError,"MissingArgument",option);
4251 if (IsGeometry(argv[i]) == MagickFalse)
4252 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4253 break;
4254 }
cristyecb10ff2011-03-22 13:14:03 +00004255 if (LocaleCompare("delete",option+1) == 0)
4256 {
4257 if (*option == '+')
4258 break;
4259 i++;
4260 if (i == (ssize_t) (argc-1))
4261 ThrowMogrifyException(OptionError,"MissingArgument",option);
4262 if (IsGeometry(argv[i]) == MagickFalse)
4263 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4264 break;
4265 }
cristy3ed852e2009-09-05 21:47:34 +00004266 if (LocaleCompare("density",option+1) == 0)
4267 {
4268 if (*option == '+')
4269 break;
4270 i++;
cristybb503372010-05-27 20:51:26 +00004271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004272 ThrowMogrifyException(OptionError,"MissingArgument",option);
4273 if (IsGeometry(argv[i]) == MagickFalse)
4274 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4275 break;
4276 }
4277 if (LocaleCompare("depth",option+1) == 0)
4278 {
4279 if (*option == '+')
4280 break;
4281 i++;
cristybb503372010-05-27 20:51:26 +00004282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004283 ThrowMogrifyException(OptionError,"MissingArgument",option);
4284 if (IsGeometry(argv[i]) == MagickFalse)
4285 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4286 break;
4287 }
4288 if (LocaleCompare("deskew",option+1) == 0)
4289 {
4290 if (*option == '+')
4291 break;
4292 i++;
cristybb503372010-05-27 20:51:26 +00004293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004294 ThrowMogrifyException(OptionError,"MissingArgument",option);
4295 if (IsGeometry(argv[i]) == MagickFalse)
4296 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4297 break;
4298 }
4299 if (LocaleCompare("despeckle",option+1) == 0)
4300 break;
4301 if (LocaleCompare("dft",option+1) == 0)
4302 break;
cristyc9b12952010-03-28 01:12:28 +00004303 if (LocaleCompare("direction",option+1) == 0)
4304 {
cristybb503372010-05-27 20:51:26 +00004305 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004306 direction;
4307
4308 if (*option == '+')
4309 break;
4310 i++;
cristybb503372010-05-27 20:51:26 +00004311 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004312 ThrowMogrifyException(OptionError,"MissingArgument",option);
4313 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4314 argv[i]);
4315 if (direction < 0)
4316 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4317 argv[i]);
4318 break;
4319 }
cristy3ed852e2009-09-05 21:47:34 +00004320 if (LocaleCompare("display",option+1) == 0)
4321 {
4322 if (*option == '+')
4323 break;
4324 i++;
cristybb503372010-05-27 20:51:26 +00004325 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004326 ThrowMogrifyException(OptionError,"MissingArgument",option);
4327 break;
4328 }
4329 if (LocaleCompare("dispose",option+1) == 0)
4330 {
cristybb503372010-05-27 20:51:26 +00004331 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004332 dispose;
4333
4334 if (*option == '+')
4335 break;
4336 i++;
cristybb503372010-05-27 20:51:26 +00004337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004338 ThrowMogrifyException(OptionError,"MissingArgument",option);
4339 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4340 if (dispose < 0)
4341 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4342 argv[i]);
4343 break;
4344 }
4345 if (LocaleCompare("distort",option+1) == 0)
4346 {
cristybb503372010-05-27 20:51:26 +00004347 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004348 op;
4349
4350 i++;
cristybb503372010-05-27 20:51:26 +00004351 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004352 ThrowMogrifyException(OptionError,"MissingArgument",option);
4353 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4354 if (op < 0)
4355 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4356 argv[i]);
4357 i++;
cristybb503372010-05-27 20:51:26 +00004358 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004359 ThrowMogrifyException(OptionError,"MissingArgument",option);
4360 break;
4361 }
4362 if (LocaleCompare("dither",option+1) == 0)
4363 {
cristybb503372010-05-27 20:51:26 +00004364 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004365 method;
4366
4367 if (*option == '+')
4368 break;
4369 i++;
cristybb503372010-05-27 20:51:26 +00004370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004371 ThrowMogrifyException(OptionError,"MissingArgument",option);
4372 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4373 if (method < 0)
4374 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4375 argv[i]);
4376 break;
4377 }
4378 if (LocaleCompare("draw",option+1) == 0)
4379 {
4380 if (*option == '+')
4381 break;
4382 i++;
cristybb503372010-05-27 20:51:26 +00004383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004384 ThrowMogrifyException(OptionError,"MissingArgument",option);
4385 break;
4386 }
cristyecb10ff2011-03-22 13:14:03 +00004387 if (LocaleCompare("duplicate",option+1) == 0)
4388 {
4389 if (*option == '+')
4390 break;
4391 i++;
4392 if (i == (ssize_t) (argc-1))
4393 ThrowMogrifyException(OptionError,"MissingArgument",option);
4394 if (IsGeometry(argv[i]) == MagickFalse)
4395 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4396 break;
4397 }
cristy22879752009-10-25 23:55:40 +00004398 if (LocaleCompare("duration",option+1) == 0)
4399 {
4400 if (*option == '+')
4401 break;
4402 i++;
cristybb503372010-05-27 20:51:26 +00004403 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004404 ThrowMogrifyException(OptionError,"MissingArgument",option);
4405 if (IsGeometry(argv[i]) == MagickFalse)
4406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4407 break;
4408 }
cristy3ed852e2009-09-05 21:47:34 +00004409 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4410 }
4411 case 'e':
4412 {
4413 if (LocaleCompare("edge",option+1) == 0)
4414 {
4415 if (*option == '+')
4416 break;
4417 i++;
cristybb503372010-05-27 20:51:26 +00004418 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004419 ThrowMogrifyException(OptionError,"MissingArgument",option);
4420 if (IsGeometry(argv[i]) == MagickFalse)
4421 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4422 break;
4423 }
4424 if (LocaleCompare("emboss",option+1) == 0)
4425 {
4426 if (*option == '+')
4427 break;
4428 i++;
cristybb503372010-05-27 20:51:26 +00004429 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004430 ThrowMogrifyException(OptionError,"MissingArgument",option);
4431 if (IsGeometry(argv[i]) == MagickFalse)
4432 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4433 break;
4434 }
4435 if (LocaleCompare("encipher",option+1) == 0)
4436 {
4437 if (*option == '+')
4438 break;
4439 i++;
cristybb503372010-05-27 20:51:26 +00004440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004441 ThrowMogrifyException(OptionError,"MissingArgument",option);
4442 break;
4443 }
4444 if (LocaleCompare("encoding",option+1) == 0)
4445 {
4446 if (*option == '+')
4447 break;
4448 i++;
cristybb503372010-05-27 20:51:26 +00004449 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004450 ThrowMogrifyException(OptionError,"MissingArgument",option);
4451 break;
4452 }
4453 if (LocaleCompare("endian",option+1) == 0)
4454 {
cristybb503372010-05-27 20:51:26 +00004455 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004456 endian;
4457
4458 if (*option == '+')
4459 break;
4460 i++;
cristybb503372010-05-27 20:51:26 +00004461 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004462 ThrowMogrifyException(OptionError,"MissingArgument",option);
4463 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4464 if (endian < 0)
4465 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4466 argv[i]);
4467 break;
4468 }
4469 if (LocaleCompare("enhance",option+1) == 0)
4470 break;
4471 if (LocaleCompare("equalize",option+1) == 0)
4472 break;
4473 if (LocaleCompare("evaluate",option+1) == 0)
4474 {
cristybb503372010-05-27 20:51:26 +00004475 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004476 op;
4477
4478 if (*option == '+')
4479 break;
4480 i++;
cristybb503372010-05-27 20:51:26 +00004481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004482 ThrowMogrifyException(OptionError,"MissingArgument",option);
4483 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4484 if (op < 0)
4485 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4486 argv[i]);
4487 i++;
cristybb503372010-05-27 20:51:26 +00004488 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004489 ThrowMogrifyException(OptionError,"MissingArgument",option);
4490 if (IsGeometry(argv[i]) == MagickFalse)
4491 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4492 break;
4493 }
cristyd18ae7c2010-03-07 17:39:52 +00004494 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4495 {
cristybb503372010-05-27 20:51:26 +00004496 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004497 op;
4498
4499 if (*option == '+')
4500 break;
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
4504 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4505 if (op < 0)
4506 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4507 argv[i]);
4508 break;
4509 }
cristy3ed852e2009-09-05 21:47:34 +00004510 if (LocaleCompare("extent",option+1) == 0)
4511 {
4512 if (*option == '+')
4513 break;
4514 i++;
cristybb503372010-05-27 20:51:26 +00004515 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004516 ThrowMogrifyException(OptionError,"MissingArgument",option);
4517 if (IsGeometry(argv[i]) == MagickFalse)
4518 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4519 break;
4520 }
4521 if (LocaleCompare("extract",option+1) == 0)
4522 {
4523 if (*option == '+')
4524 break;
4525 i++;
cristybb503372010-05-27 20:51:26 +00004526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004527 ThrowMogrifyException(OptionError,"MissingArgument",option);
4528 if (IsGeometry(argv[i]) == MagickFalse)
4529 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4530 break;
4531 }
4532 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4533 }
4534 case 'f':
4535 {
4536 if (LocaleCompare("family",option+1) == 0)
4537 {
4538 if (*option == '+')
4539 break;
4540 i++;
cristybb503372010-05-27 20:51:26 +00004541 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004542 ThrowMogrifyException(OptionError,"MissingArgument",option);
4543 break;
4544 }
4545 if (LocaleCompare("fill",option+1) == 0)
4546 {
4547 if (*option == '+')
4548 break;
4549 i++;
cristybb503372010-05-27 20:51:26 +00004550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004551 ThrowMogrifyException(OptionError,"MissingArgument",option);
4552 break;
4553 }
4554 if (LocaleCompare("filter",option+1) == 0)
4555 {
cristybb503372010-05-27 20:51:26 +00004556 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004557 filter;
4558
4559 if (*option == '+')
4560 break;
4561 i++;
cristybb503372010-05-27 20:51:26 +00004562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004563 ThrowMogrifyException(OptionError,"MissingArgument",option);
4564 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4565 if (filter < 0)
4566 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4567 argv[i]);
4568 break;
4569 }
4570 if (LocaleCompare("flatten",option+1) == 0)
4571 break;
4572 if (LocaleCompare("flip",option+1) == 0)
4573 break;
4574 if (LocaleCompare("flop",option+1) == 0)
4575 break;
4576 if (LocaleCompare("floodfill",option+1) == 0)
4577 {
4578 if (*option == '+')
4579 break;
4580 i++;
cristybb503372010-05-27 20:51:26 +00004581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004582 ThrowMogrifyException(OptionError,"MissingArgument",option);
4583 if (IsGeometry(argv[i]) == MagickFalse)
4584 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4585 i++;
cristybb503372010-05-27 20:51:26 +00004586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004587 ThrowMogrifyException(OptionError,"MissingArgument",option);
4588 break;
4589 }
4590 if (LocaleCompare("font",option+1) == 0)
4591 {
4592 if (*option == '+')
4593 break;
4594 i++;
cristybb503372010-05-27 20:51:26 +00004595 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004596 ThrowMogrifyException(OptionError,"MissingArgument",option);
4597 break;
4598 }
4599 if (LocaleCompare("format",option+1) == 0)
4600 {
4601 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4602 (void) CloneString(&format,(char *) NULL);
4603 if (*option == '+')
4604 break;
4605 i++;
cristybb503372010-05-27 20:51:26 +00004606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004607 ThrowMogrifyException(OptionError,"MissingArgument",option);
4608 (void) CloneString(&format,argv[i]);
4609 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4610 (void) ConcatenateMagickString(image_info->filename,":",
4611 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004612 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004613 if (*image_info->magick == '\0')
4614 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4615 format);
4616 break;
4617 }
4618 if (LocaleCompare("frame",option+1) == 0)
4619 {
4620 if (*option == '+')
4621 break;
4622 i++;
cristybb503372010-05-27 20:51:26 +00004623 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004624 ThrowMogrifyException(OptionError,"MissingArgument",option);
4625 if (IsGeometry(argv[i]) == MagickFalse)
4626 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4627 break;
4628 }
4629 if (LocaleCompare("function",option+1) == 0)
4630 {
cristybb503372010-05-27 20:51:26 +00004631 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004632 op;
4633
4634 if (*option == '+')
4635 break;
4636 i++;
cristybb503372010-05-27 20:51:26 +00004637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004638 ThrowMogrifyException(OptionError,"MissingArgument",option);
4639 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4640 if (op < 0)
4641 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4642 i++;
cristybb503372010-05-27 20:51:26 +00004643 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004644 ThrowMogrifyException(OptionError,"MissingArgument",option);
4645 break;
4646 }
4647 if (LocaleCompare("fuzz",option+1) == 0)
4648 {
4649 if (*option == '+')
4650 break;
4651 i++;
cristybb503372010-05-27 20:51:26 +00004652 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004653 ThrowMogrifyException(OptionError,"MissingArgument",option);
4654 if (IsGeometry(argv[i]) == MagickFalse)
4655 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4656 break;
4657 }
4658 if (LocaleCompare("fx",option+1) == 0)
4659 {
4660 if (*option == '+')
4661 break;
4662 i++;
cristybb503372010-05-27 20:51:26 +00004663 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004664 ThrowMogrifyException(OptionError,"MissingArgument",option);
4665 break;
4666 }
4667 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4668 }
4669 case 'g':
4670 {
4671 if (LocaleCompare("gamma",option+1) == 0)
4672 {
4673 i++;
cristybb503372010-05-27 20:51:26 +00004674 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004675 ThrowMogrifyException(OptionError,"MissingArgument",option);
4676 if (IsGeometry(argv[i]) == MagickFalse)
4677 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4678 break;
4679 }
4680 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4681 (LocaleCompare("gaussian",option+1) == 0))
4682 {
4683 i++;
cristybb503372010-05-27 20:51:26 +00004684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004685 ThrowMogrifyException(OptionError,"MissingArgument",option);
4686 if (IsGeometry(argv[i]) == MagickFalse)
4687 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4688 break;
4689 }
4690 if (LocaleCompare("geometry",option+1) == 0)
4691 {
4692 if (*option == '+')
4693 break;
4694 i++;
cristybb503372010-05-27 20:51:26 +00004695 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004696 ThrowMogrifyException(OptionError,"MissingArgument",option);
4697 if (IsGeometry(argv[i]) == MagickFalse)
4698 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4699 break;
4700 }
4701 if (LocaleCompare("gravity",option+1) == 0)
4702 {
cristybb503372010-05-27 20:51:26 +00004703 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004704 gravity;
4705
4706 if (*option == '+')
4707 break;
4708 i++;
cristybb503372010-05-27 20:51:26 +00004709 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004710 ThrowMogrifyException(OptionError,"MissingArgument",option);
4711 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
4712 if (gravity < 0)
4713 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4714 argv[i]);
4715 break;
4716 }
4717 if (LocaleCompare("green-primary",option+1) == 0)
4718 {
4719 if (*option == '+')
4720 break;
4721 i++;
cristybb503372010-05-27 20:51:26 +00004722 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004723 ThrowMogrifyException(OptionError,"MissingArgument",option);
4724 if (IsGeometry(argv[i]) == MagickFalse)
4725 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4726 break;
4727 }
4728 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4729 }
4730 case 'h':
4731 {
4732 if (LocaleCompare("hald-clut",option+1) == 0)
4733 break;
4734 if ((LocaleCompare("help",option+1) == 0) ||
4735 (LocaleCompare("-help",option+1) == 0))
4736 return(MogrifyUsage());
4737 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4738 }
4739 case 'i':
4740 {
4741 if (LocaleCompare("identify",option+1) == 0)
4742 break;
4743 if (LocaleCompare("idft",option+1) == 0)
4744 break;
4745 if (LocaleCompare("implode",option+1) == 0)
4746 {
4747 if (*option == '+')
4748 break;
4749 i++;
cristybb503372010-05-27 20:51:26 +00004750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004751 ThrowMogrifyException(OptionError,"MissingArgument",option);
4752 if (IsGeometry(argv[i]) == MagickFalse)
4753 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4754 break;
4755 }
4756 if (LocaleCompare("intent",option+1) == 0)
4757 {
cristybb503372010-05-27 20:51:26 +00004758 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004759 intent;
4760
4761 if (*option == '+')
4762 break;
4763 i++;
cristybb503372010-05-27 20:51:26 +00004764 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004765 ThrowMogrifyException(OptionError,"MissingArgument",option);
4766 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
4767 if (intent < 0)
4768 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4769 argv[i]);
4770 break;
4771 }
4772 if (LocaleCompare("interlace",option+1) == 0)
4773 {
cristybb503372010-05-27 20:51:26 +00004774 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004775 interlace;
4776
4777 if (*option == '+')
4778 break;
4779 i++;
cristybb503372010-05-27 20:51:26 +00004780 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004781 ThrowMogrifyException(OptionError,"MissingArgument",option);
4782 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
4783 argv[i]);
4784 if (interlace < 0)
4785 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4786 argv[i]);
4787 break;
4788 }
cristyb32b90a2009-09-07 21:45:48 +00004789 if (LocaleCompare("interline-spacing",option+1) == 0)
4790 {
4791 if (*option == '+')
4792 break;
4793 i++;
cristybb503372010-05-27 20:51:26 +00004794 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004795 ThrowMogrifyException(OptionError,"MissingArgument",option);
4796 if (IsGeometry(argv[i]) == MagickFalse)
4797 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4798 break;
4799 }
cristy3ed852e2009-09-05 21:47:34 +00004800 if (LocaleCompare("interpolate",option+1) == 0)
4801 {
cristybb503372010-05-27 20:51:26 +00004802 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004803 interpolate;
4804
4805 if (*option == '+')
4806 break;
4807 i++;
cristybb503372010-05-27 20:51:26 +00004808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004809 ThrowMogrifyException(OptionError,"MissingArgument",option);
4810 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
4811 argv[i]);
4812 if (interpolate < 0)
4813 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4814 argv[i]);
4815 break;
4816 }
4817 if (LocaleCompare("interword-spacing",option+1) == 0)
4818 {
4819 if (*option == '+')
4820 break;
4821 i++;
cristybb503372010-05-27 20:51:26 +00004822 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004823 ThrowMogrifyException(OptionError,"MissingArgument",option);
4824 if (IsGeometry(argv[i]) == MagickFalse)
4825 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4826 break;
4827 }
4828 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4829 }
4830 case 'k':
4831 {
4832 if (LocaleCompare("kerning",option+1) == 0)
4833 {
4834 if (*option == '+')
4835 break;
4836 i++;
cristybb503372010-05-27 20:51:26 +00004837 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004838 ThrowMogrifyException(OptionError,"MissingArgument",option);
4839 if (IsGeometry(argv[i]) == MagickFalse)
4840 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4841 break;
4842 }
4843 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4844 }
4845 case 'l':
4846 {
4847 if (LocaleCompare("label",option+1) == 0)
4848 {
4849 if (*option == '+')
4850 break;
4851 i++;
cristybb503372010-05-27 20:51:26 +00004852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004853 ThrowMogrifyException(OptionError,"MissingArgument",option);
4854 break;
4855 }
4856 if (LocaleCompare("lat",option+1) == 0)
4857 {
4858 if (*option == '+')
4859 break;
4860 i++;
cristybb503372010-05-27 20:51:26 +00004861 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004862 ThrowMogrifyException(OptionError,"MissingArgument",option);
4863 if (IsGeometry(argv[i]) == MagickFalse)
4864 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4865 }
4866 if (LocaleCompare("layers",option+1) == 0)
4867 {
cristybb503372010-05-27 20:51:26 +00004868 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004869 type;
4870
4871 if (*option == '+')
4872 break;
4873 i++;
cristybb503372010-05-27 20:51:26 +00004874 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004875 ThrowMogrifyException(OptionError,"MissingArgument",option);
4876 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
4877 if (type < 0)
4878 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4879 argv[i]);
4880 break;
4881 }
4882 if (LocaleCompare("level",option+1) == 0)
4883 {
4884 i++;
cristybb503372010-05-27 20:51:26 +00004885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004886 ThrowMogrifyException(OptionError,"MissingArgument",option);
4887 if (IsGeometry(argv[i]) == MagickFalse)
4888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4889 break;
4890 }
4891 if (LocaleCompare("level-colors",option+1) == 0)
4892 {
4893 i++;
cristybb503372010-05-27 20:51:26 +00004894 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004895 ThrowMogrifyException(OptionError,"MissingArgument",option);
4896 break;
4897 }
4898 if (LocaleCompare("linewidth",option+1) == 0)
4899 {
4900 if (*option == '+')
4901 break;
4902 i++;
cristybb503372010-05-27 20:51:26 +00004903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004904 ThrowMogrifyException(OptionError,"MissingArgument",option);
4905 if (IsGeometry(argv[i]) == MagickFalse)
4906 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4907 break;
4908 }
4909 if (LocaleCompare("limit",option+1) == 0)
4910 {
4911 char
4912 *p;
4913
4914 double
4915 value;
4916
cristybb503372010-05-27 20:51:26 +00004917 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004918 resource;
4919
4920 if (*option == '+')
4921 break;
4922 i++;
cristybb503372010-05-27 20:51:26 +00004923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004924 ThrowMogrifyException(OptionError,"MissingArgument",option);
4925 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
4926 argv[i]);
4927 if (resource < 0)
4928 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4929 argv[i]);
4930 i++;
cristybb503372010-05-27 20:51:26 +00004931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004932 ThrowMogrifyException(OptionError,"MissingArgument",option);
4933 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004934 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004935 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4937 break;
4938 }
4939 if (LocaleCompare("liquid-rescale",option+1) == 0)
4940 {
4941 i++;
cristybb503372010-05-27 20:51:26 +00004942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004943 ThrowMogrifyException(OptionError,"MissingArgument",option);
4944 if (IsGeometry(argv[i]) == MagickFalse)
4945 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4946 break;
4947 }
4948 if (LocaleCompare("list",option+1) == 0)
4949 {
cristybb503372010-05-27 20:51:26 +00004950 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004951 list;
4952
4953 if (*option == '+')
4954 break;
4955 i++;
cristybb503372010-05-27 20:51:26 +00004956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004957 ThrowMogrifyException(OptionError,"MissingArgument",option);
4958 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
4959 if (list < 0)
4960 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004961 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004962 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004963 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004964 }
4965 if (LocaleCompare("log",option+1) == 0)
4966 {
4967 if (*option == '+')
4968 break;
4969 i++;
cristybb503372010-05-27 20:51:26 +00004970 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004971 (strchr(argv[i],'%') == (char *) NULL))
4972 ThrowMogrifyException(OptionError,"MissingArgument",option);
4973 break;
4974 }
4975 if (LocaleCompare("loop",option+1) == 0)
4976 {
4977 if (*option == '+')
4978 break;
4979 i++;
cristybb503372010-05-27 20:51:26 +00004980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004981 ThrowMogrifyException(OptionError,"MissingArgument",option);
4982 if (IsGeometry(argv[i]) == MagickFalse)
4983 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4984 break;
4985 }
4986 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4987 }
4988 case 'm':
4989 {
4990 if (LocaleCompare("map",option+1) == 0)
4991 {
4992 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4993 if (*option == '+')
4994 break;
4995 i++;
cristybb503372010-05-27 20:51:26 +00004996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004997 ThrowMogrifyException(OptionError,"MissingArgument",option);
4998 break;
4999 }
5000 if (LocaleCompare("mask",option+1) == 0)
5001 {
5002 if (*option == '+')
5003 break;
5004 i++;
cristybb503372010-05-27 20:51:26 +00005005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005006 ThrowMogrifyException(OptionError,"MissingArgument",option);
5007 break;
5008 }
5009 if (LocaleCompare("matte",option+1) == 0)
5010 break;
5011 if (LocaleCompare("mattecolor",option+1) == 0)
5012 {
5013 if (*option == '+')
5014 break;
5015 i++;
cristybb503372010-05-27 20:51:26 +00005016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005017 ThrowMogrifyException(OptionError,"MissingArgument",option);
5018 break;
5019 }
cristyf40785b2010-03-06 02:27:27 +00005020 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005021 break;
cristyf40785b2010-03-06 02:27:27 +00005022 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005023 break;
cristy3ed852e2009-09-05 21:47:34 +00005024 if (LocaleCompare("modulate",option+1) == 0)
5025 {
5026 if (*option == '+')
5027 break;
5028 i++;
cristybb503372010-05-27 20:51:26 +00005029 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005030 ThrowMogrifyException(OptionError,"MissingArgument",option);
5031 if (IsGeometry(argv[i]) == MagickFalse)
5032 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5033 break;
5034 }
5035 if (LocaleCompare("median",option+1) == 0)
5036 {
5037 if (*option == '+')
5038 break;
5039 i++;
cristybb503372010-05-27 20:51:26 +00005040 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005041 ThrowMogrifyException(OptionError,"MissingArgument",option);
5042 if (IsGeometry(argv[i]) == MagickFalse)
5043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5044 break;
5045 }
cristy69ec32d2011-02-27 23:57:09 +00005046 if (LocaleCompare("mode",option+1) == 0)
5047 {
5048 if (*option == '+')
5049 break;
5050 i++;
5051 if (i == (ssize_t) argc)
5052 ThrowMogrifyException(OptionError,"MissingArgument",option);
5053 if (IsGeometry(argv[i]) == MagickFalse)
5054 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5055 break;
5056 }
cristy3ed852e2009-09-05 21:47:34 +00005057 if (LocaleCompare("monitor",option+1) == 0)
5058 break;
5059 if (LocaleCompare("monochrome",option+1) == 0)
5060 break;
5061 if (LocaleCompare("morph",option+1) == 0)
5062 {
5063 if (*option == '+')
5064 break;
5065 i++;
cristybb503372010-05-27 20:51:26 +00005066 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005067 ThrowMogrifyException(OptionError,"MissingArgument",option);
5068 if (IsGeometry(argv[i]) == MagickFalse)
5069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5070 break;
5071 }
anthony29188a82010-01-22 10:12:34 +00005072 if (LocaleCompare("morphology",option+1) == 0)
5073 {
anthony29188a82010-01-22 10:12:34 +00005074 char
5075 token[MaxTextExtent];
5076
cristyb6bd4ad2010-08-08 01:12:27 +00005077 KernelInfo
5078 *kernel_info;
5079
5080 ssize_t
5081 op;
5082
anthony29188a82010-01-22 10:12:34 +00005083 i++;
cristybb503372010-05-27 20:51:26 +00005084 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005085 ThrowMogrifyException(OptionError,"MissingArgument",option);
5086 GetMagickToken(argv[i],NULL,token);
5087 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5088 if (op < 0)
5089 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005090 token);
anthony29188a82010-01-22 10:12:34 +00005091 i++;
cristybb503372010-05-27 20:51:26 +00005092 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005093 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005094 kernel_info=AcquireKernelInfo(argv[i]);
5095 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005097 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005098 break;
5099 }
cristy3ed852e2009-09-05 21:47:34 +00005100 if (LocaleCompare("mosaic",option+1) == 0)
5101 break;
5102 if (LocaleCompare("motion-blur",option+1) == 0)
5103 {
5104 if (*option == '+')
5105 break;
5106 i++;
cristybb503372010-05-27 20:51:26 +00005107 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005108 ThrowMogrifyException(OptionError,"MissingArgument",option);
5109 if (IsGeometry(argv[i]) == MagickFalse)
5110 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5111 break;
5112 }
5113 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5114 }
5115 case 'n':
5116 {
5117 if (LocaleCompare("negate",option+1) == 0)
5118 break;
5119 if (LocaleCompare("noise",option+1) == 0)
5120 {
5121 i++;
cristybb503372010-05-27 20:51:26 +00005122 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005123 ThrowMogrifyException(OptionError,"MissingArgument",option);
5124 if (*option == '+')
5125 {
cristybb503372010-05-27 20:51:26 +00005126 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005127 noise;
5128
5129 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5130 if (noise < 0)
5131 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5132 argv[i]);
5133 break;
5134 }
5135 if (IsGeometry(argv[i]) == MagickFalse)
5136 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5137 break;
5138 }
5139 if (LocaleCompare("noop",option+1) == 0)
5140 break;
5141 if (LocaleCompare("normalize",option+1) == 0)
5142 break;
5143 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5144 }
5145 case 'o':
5146 {
5147 if (LocaleCompare("opaque",option+1) == 0)
5148 {
cristy3ed852e2009-09-05 21:47:34 +00005149 i++;
cristybb503372010-05-27 20:51:26 +00005150 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005151 ThrowMogrifyException(OptionError,"MissingArgument",option);
5152 break;
5153 }
5154 if (LocaleCompare("ordered-dither",option+1) == 0)
5155 {
5156 if (*option == '+')
5157 break;
5158 i++;
cristybb503372010-05-27 20:51:26 +00005159 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005160 ThrowMogrifyException(OptionError,"MissingArgument",option);
5161 break;
5162 }
5163 if (LocaleCompare("orient",option+1) == 0)
5164 {
cristybb503372010-05-27 20:51:26 +00005165 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005166 orientation;
5167
5168 orientation=UndefinedOrientation;
5169 if (*option == '+')
5170 break;
5171 i++;
cristybb503372010-05-27 20:51:26 +00005172 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005173 ThrowMogrifyException(OptionError,"MissingArgument",option);
5174 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5175 argv[i]);
5176 if (orientation < 0)
5177 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5178 argv[i]);
5179 break;
5180 }
5181 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5182 }
5183 case 'p':
5184 {
5185 if (LocaleCompare("page",option+1) == 0)
5186 {
5187 if (*option == '+')
5188 break;
5189 i++;
cristybb503372010-05-27 20:51:26 +00005190 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005191 ThrowMogrifyException(OptionError,"MissingArgument",option);
5192 break;
5193 }
5194 if (LocaleCompare("paint",option+1) == 0)
5195 {
5196 if (*option == '+')
5197 break;
5198 i++;
cristybb503372010-05-27 20:51:26 +00005199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005200 ThrowMogrifyException(OptionError,"MissingArgument",option);
5201 if (IsGeometry(argv[i]) == MagickFalse)
5202 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5203 break;
5204 }
5205 if (LocaleCompare("path",option+1) == 0)
5206 {
5207 (void) CloneString(&path,(char *) NULL);
5208 if (*option == '+')
5209 break;
5210 i++;
cristybb503372010-05-27 20:51:26 +00005211 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005212 ThrowMogrifyException(OptionError,"MissingArgument",option);
5213 (void) CloneString(&path,argv[i]);
5214 break;
5215 }
5216 if (LocaleCompare("pointsize",option+1) == 0)
5217 {
5218 if (*option == '+')
5219 break;
5220 i++;
cristybb503372010-05-27 20:51:26 +00005221 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005222 ThrowMogrifyException(OptionError,"MissingArgument",option);
5223 if (IsGeometry(argv[i]) == MagickFalse)
5224 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5225 break;
5226 }
5227 if (LocaleCompare("polaroid",option+1) == 0)
5228 {
5229 if (*option == '+')
5230 break;
5231 i++;
cristybb503372010-05-27 20:51:26 +00005232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005233 ThrowMogrifyException(OptionError,"MissingArgument",option);
5234 if (IsGeometry(argv[i]) == MagickFalse)
5235 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5236 break;
5237 }
5238 if (LocaleCompare("posterize",option+1) == 0)
5239 {
5240 if (*option == '+')
5241 break;
5242 i++;
cristybb503372010-05-27 20:51:26 +00005243 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005244 ThrowMogrifyException(OptionError,"MissingArgument",option);
5245 if (IsGeometry(argv[i]) == MagickFalse)
5246 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5247 break;
5248 }
cristye7f51092010-01-17 00:39:37 +00005249 if (LocaleCompare("precision",option+1) == 0)
5250 {
5251 if (*option == '+')
5252 break;
5253 i++;
cristybb503372010-05-27 20:51:26 +00005254 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005255 ThrowMogrifyException(OptionError,"MissingArgument",option);
5256 if (IsGeometry(argv[i]) == MagickFalse)
5257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5258 break;
5259 }
cristy3ed852e2009-09-05 21:47:34 +00005260 if (LocaleCompare("print",option+1) == 0)
5261 {
5262 if (*option == '+')
5263 break;
5264 i++;
cristybb503372010-05-27 20:51:26 +00005265 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005266 ThrowMogrifyException(OptionError,"MissingArgument",option);
5267 break;
5268 }
5269 if (LocaleCompare("process",option+1) == 0)
5270 {
5271 if (*option == '+')
5272 break;
5273 i++;
cristybb503372010-05-27 20:51:26 +00005274 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005275 ThrowMogrifyException(OptionError,"MissingArgument",option);
5276 break;
5277 }
5278 if (LocaleCompare("profile",option+1) == 0)
5279 {
5280 i++;
cristybb503372010-05-27 20:51:26 +00005281 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005282 ThrowMogrifyException(OptionError,"MissingArgument",option);
5283 break;
5284 }
5285 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5286 }
5287 case 'q':
5288 {
5289 if (LocaleCompare("quality",option+1) == 0)
5290 {
5291 if (*option == '+')
5292 break;
5293 i++;
cristybb503372010-05-27 20:51:26 +00005294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005295 ThrowMogrifyException(OptionError,"MissingArgument",option);
5296 if (IsGeometry(argv[i]) == MagickFalse)
5297 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5298 break;
5299 }
5300 if (LocaleCompare("quantize",option+1) == 0)
5301 {
cristybb503372010-05-27 20:51:26 +00005302 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005303 colorspace;
5304
5305 if (*option == '+')
5306 break;
5307 i++;
cristybb503372010-05-27 20:51:26 +00005308 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005309 ThrowMogrifyException(OptionError,"MissingArgument",option);
5310 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5311 argv[i]);
5312 if (colorspace < 0)
5313 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5314 argv[i]);
5315 break;
5316 }
5317 if (LocaleCompare("quiet",option+1) == 0)
5318 break;
5319 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5320 }
5321 case 'r':
5322 {
5323 if (LocaleCompare("radial-blur",option+1) == 0)
5324 {
5325 i++;
cristybb503372010-05-27 20:51:26 +00005326 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005327 ThrowMogrifyException(OptionError,"MissingArgument",option);
5328 if (IsGeometry(argv[i]) == MagickFalse)
5329 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5330 break;
5331 }
5332 if (LocaleCompare("raise",option+1) == 0)
5333 {
5334 i++;
cristybb503372010-05-27 20:51:26 +00005335 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005336 ThrowMogrifyException(OptionError,"MissingArgument",option);
5337 if (IsGeometry(argv[i]) == MagickFalse)
5338 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5339 break;
5340 }
5341 if (LocaleCompare("random-threshold",option+1) == 0)
5342 {
5343 if (*option == '+')
5344 break;
5345 i++;
cristybb503372010-05-27 20:51:26 +00005346 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005347 ThrowMogrifyException(OptionError,"MissingArgument",option);
5348 if (IsGeometry(argv[i]) == MagickFalse)
5349 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5350 break;
5351 }
cristye6365592010-04-02 17:31:23 +00005352 if (LocaleCompare("recolor",option+1) == 0)
5353 {
5354 if (*option == '+')
5355 break;
5356 i++;
cristybb503372010-05-27 20:51:26 +00005357 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005358 ThrowMogrifyException(OptionError,"MissingArgument",option);
5359 if (IsGeometry(argv[i]) == MagickFalse)
5360 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5361 break;
5362 }
cristy3ed852e2009-09-05 21:47:34 +00005363 if (LocaleCompare("red-primary",option+1) == 0)
5364 {
5365 if (*option == '+')
5366 break;
5367 i++;
cristybb503372010-05-27 20:51:26 +00005368 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005369 ThrowMogrifyException(OptionError,"MissingArgument",option);
5370 if (IsGeometry(argv[i]) == MagickFalse)
5371 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5372 }
cristy9f2083a2010-04-22 19:48:05 +00005373 if (LocaleCompare("regard-warnings",option+1) == 0)
5374 break;
cristy3ed852e2009-09-05 21:47:34 +00005375 if (LocaleCompare("region",option+1) == 0)
5376 {
5377 if (*option == '+')
5378 break;
5379 i++;
cristybb503372010-05-27 20:51:26 +00005380 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005381 ThrowMogrifyException(OptionError,"MissingArgument",option);
5382 if (IsGeometry(argv[i]) == MagickFalse)
5383 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5384 break;
5385 }
cristyf0c78232010-03-15 12:53:40 +00005386 if (LocaleCompare("remap",option+1) == 0)
5387 {
5388 if (*option == '+')
5389 break;
5390 i++;
cristybb503372010-05-27 20:51:26 +00005391 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005392 ThrowMogrifyException(OptionError,"MissingArgument",option);
5393 break;
5394 }
cristy3ed852e2009-09-05 21:47:34 +00005395 if (LocaleCompare("render",option+1) == 0)
5396 break;
5397 if (LocaleCompare("repage",option+1) == 0)
5398 {
5399 if (*option == '+')
5400 break;
5401 i++;
cristybb503372010-05-27 20:51:26 +00005402 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005403 ThrowMogrifyException(OptionError,"MissingArgument",option);
5404 if (IsGeometry(argv[i]) == MagickFalse)
5405 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5406 break;
5407 }
5408 if (LocaleCompare("resample",option+1) == 0)
5409 {
5410 if (*option == '+')
5411 break;
5412 i++;
cristybb503372010-05-27 20:51:26 +00005413 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005414 ThrowMogrifyException(OptionError,"MissingArgument",option);
5415 if (IsGeometry(argv[i]) == MagickFalse)
5416 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5417 break;
5418 }
5419 if (LocaleCompare("resize",option+1) == 0)
5420 {
5421 if (*option == '+')
5422 break;
5423 i++;
cristybb503372010-05-27 20:51:26 +00005424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005425 ThrowMogrifyException(OptionError,"MissingArgument",option);
5426 if (IsGeometry(argv[i]) == MagickFalse)
5427 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5428 break;
5429 }
cristyebbcfea2011-02-25 02:43:54 +00005430 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5431 {
5432 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5433 break;
5434 }
cristy3ed852e2009-09-05 21:47:34 +00005435 if (LocaleCompare("reverse",option+1) == 0)
5436 break;
5437 if (LocaleCompare("roll",option+1) == 0)
5438 {
5439 if (*option == '+')
5440 break;
5441 i++;
cristybb503372010-05-27 20:51:26 +00005442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005443 ThrowMogrifyException(OptionError,"MissingArgument",option);
5444 if (IsGeometry(argv[i]) == MagickFalse)
5445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5446 break;
5447 }
5448 if (LocaleCompare("rotate",option+1) == 0)
5449 {
5450 i++;
cristybb503372010-05-27 20:51:26 +00005451 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005452 ThrowMogrifyException(OptionError,"MissingArgument",option);
5453 if (IsGeometry(argv[i]) == MagickFalse)
5454 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5455 break;
5456 }
5457 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5458 }
5459 case 's':
5460 {
5461 if (LocaleCompare("sample",option+1) == 0)
5462 {
5463 if (*option == '+')
5464 break;
5465 i++;
cristybb503372010-05-27 20:51:26 +00005466 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005467 ThrowMogrifyException(OptionError,"MissingArgument",option);
5468 if (IsGeometry(argv[i]) == MagickFalse)
5469 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5470 break;
5471 }
5472 if (LocaleCompare("sampling-factor",option+1) == 0)
5473 {
5474 if (*option == '+')
5475 break;
5476 i++;
cristybb503372010-05-27 20:51:26 +00005477 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005478 ThrowMogrifyException(OptionError,"MissingArgument",option);
5479 if (IsGeometry(argv[i]) == MagickFalse)
5480 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5481 break;
5482 }
5483 if (LocaleCompare("scale",option+1) == 0)
5484 {
5485 if (*option == '+')
5486 break;
5487 i++;
cristybb503372010-05-27 20:51:26 +00005488 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005489 ThrowMogrifyException(OptionError,"MissingArgument",option);
5490 if (IsGeometry(argv[i]) == MagickFalse)
5491 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5492 break;
5493 }
5494 if (LocaleCompare("scene",option+1) == 0)
5495 {
5496 if (*option == '+')
5497 break;
5498 i++;
cristybb503372010-05-27 20:51:26 +00005499 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005500 ThrowMogrifyException(OptionError,"MissingArgument",option);
5501 if (IsGeometry(argv[i]) == MagickFalse)
5502 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5503 break;
5504 }
5505 if (LocaleCompare("seed",option+1) == 0)
5506 {
5507 if (*option == '+')
5508 break;
5509 i++;
cristybb503372010-05-27 20:51:26 +00005510 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005511 ThrowMogrifyException(OptionError,"MissingArgument",option);
5512 if (IsGeometry(argv[i]) == MagickFalse)
5513 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5514 break;
5515 }
5516 if (LocaleCompare("segment",option+1) == 0)
5517 {
5518 if (*option == '+')
5519 break;
5520 i++;
cristybb503372010-05-27 20:51:26 +00005521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005522 ThrowMogrifyException(OptionError,"MissingArgument",option);
5523 if (IsGeometry(argv[i]) == MagickFalse)
5524 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5525 break;
5526 }
5527 if (LocaleCompare("selective-blur",option+1) == 0)
5528 {
5529 i++;
cristybb503372010-05-27 20:51:26 +00005530 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005531 ThrowMogrifyException(OptionError,"MissingArgument",option);
5532 if (IsGeometry(argv[i]) == MagickFalse)
5533 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5534 break;
5535 }
5536 if (LocaleCompare("separate",option+1) == 0)
5537 break;
5538 if (LocaleCompare("sepia-tone",option+1) == 0)
5539 {
5540 if (*option == '+')
5541 break;
5542 i++;
cristybb503372010-05-27 20:51:26 +00005543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005544 ThrowMogrifyException(OptionError,"MissingArgument",option);
5545 if (IsGeometry(argv[i]) == MagickFalse)
5546 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5547 break;
5548 }
5549 if (LocaleCompare("set",option+1) == 0)
5550 {
5551 i++;
cristybb503372010-05-27 20:51:26 +00005552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005553 ThrowMogrifyException(OptionError,"MissingArgument",option);
5554 if (*option == '+')
5555 break;
5556 i++;
cristybb503372010-05-27 20:51:26 +00005557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005558 ThrowMogrifyException(OptionError,"MissingArgument",option);
5559 break;
5560 }
5561 if (LocaleCompare("shade",option+1) == 0)
5562 {
5563 i++;
cristybb503372010-05-27 20:51:26 +00005564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005565 ThrowMogrifyException(OptionError,"MissingArgument",option);
5566 if (IsGeometry(argv[i]) == MagickFalse)
5567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5568 break;
5569 }
5570 if (LocaleCompare("shadow",option+1) == 0)
5571 {
5572 if (*option == '+')
5573 break;
5574 i++;
cristybb503372010-05-27 20:51:26 +00005575 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005576 ThrowMogrifyException(OptionError,"MissingArgument",option);
5577 if (IsGeometry(argv[i]) == MagickFalse)
5578 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5579 break;
5580 }
5581 if (LocaleCompare("sharpen",option+1) == 0)
5582 {
5583 i++;
cristybb503372010-05-27 20:51:26 +00005584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005585 ThrowMogrifyException(OptionError,"MissingArgument",option);
5586 if (IsGeometry(argv[i]) == MagickFalse)
5587 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5588 break;
5589 }
5590 if (LocaleCompare("shave",option+1) == 0)
5591 {
5592 if (*option == '+')
5593 break;
5594 i++;
cristybb503372010-05-27 20:51:26 +00005595 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005596 ThrowMogrifyException(OptionError,"MissingArgument",option);
5597 if (IsGeometry(argv[i]) == MagickFalse)
5598 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5599 break;
5600 }
5601 if (LocaleCompare("shear",option+1) == 0)
5602 {
5603 i++;
cristybb503372010-05-27 20:51:26 +00005604 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005605 ThrowMogrifyException(OptionError,"MissingArgument",option);
5606 if (IsGeometry(argv[i]) == MagickFalse)
5607 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5608 break;
5609 }
5610 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5611 {
5612 i++;
cristybb503372010-05-27 20:51:26 +00005613 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005614 ThrowMogrifyException(OptionError,"MissingArgument",option);
5615 if (IsGeometry(argv[i]) == MagickFalse)
5616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5617 break;
5618 }
5619 if (LocaleCompare("size",option+1) == 0)
5620 {
5621 if (*option == '+')
5622 break;
5623 i++;
cristybb503372010-05-27 20:51:26 +00005624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005625 ThrowMogrifyException(OptionError,"MissingArgument",option);
5626 if (IsGeometry(argv[i]) == MagickFalse)
5627 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5628 break;
5629 }
5630 if (LocaleCompare("sketch",option+1) == 0)
5631 {
5632 if (*option == '+')
5633 break;
5634 i++;
cristybb503372010-05-27 20:51:26 +00005635 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005636 ThrowMogrifyException(OptionError,"MissingArgument",option);
5637 if (IsGeometry(argv[i]) == MagickFalse)
5638 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5639 break;
5640 }
cristy4285d782011-02-09 20:12:28 +00005641 if (LocaleCompare("smush",option+1) == 0)
5642 {
cristy4285d782011-02-09 20:12:28 +00005643 i++;
5644 if (i == (ssize_t) argc)
5645 ThrowMogrifyException(OptionError,"MissingArgument",option);
5646 if (IsGeometry(argv[i]) == MagickFalse)
5647 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005648 i++;
5649 break;
5650 }
cristy3ed852e2009-09-05 21:47:34 +00005651 if (LocaleCompare("solarize",option+1) == 0)
5652 {
5653 if (*option == '+')
5654 break;
5655 i++;
cristybb503372010-05-27 20:51:26 +00005656 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005657 ThrowMogrifyException(OptionError,"MissingArgument",option);
5658 if (IsGeometry(argv[i]) == MagickFalse)
5659 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5660 break;
5661 }
5662 if (LocaleCompare("sparse-color",option+1) == 0)
5663 {
cristybb503372010-05-27 20:51:26 +00005664 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005665 op;
5666
5667 i++;
cristybb503372010-05-27 20:51:26 +00005668 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005669 ThrowMogrifyException(OptionError,"MissingArgument",option);
5670 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5671 if (op < 0)
5672 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5673 argv[i]);
5674 i++;
cristybb503372010-05-27 20:51:26 +00005675 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005676 ThrowMogrifyException(OptionError,"MissingArgument",option);
5677 break;
5678 }
5679 if (LocaleCompare("spread",option+1) == 0)
5680 {
5681 if (*option == '+')
5682 break;
5683 i++;
cristybb503372010-05-27 20:51:26 +00005684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005685 ThrowMogrifyException(OptionError,"MissingArgument",option);
5686 if (IsGeometry(argv[i]) == MagickFalse)
5687 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5688 break;
5689 }
cristy0834d642011-03-18 18:26:08 +00005690 if (LocaleCompare("statistic",option+1) == 0)
5691 {
5692 ssize_t
5693 op;
5694
5695 if (*option == '+')
5696 break;
5697 i++;
5698 if (i == (ssize_t) argc)
5699 ThrowMogrifyException(OptionError,"MissingArgument",option);
5700 op=ParseMagickOption(MagickStatisticOptions,MagickFalse,argv[i]);
5701 if (op < 0)
5702 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5703 argv[i]);
5704 i++;
5705 if (i == (ssize_t) (argc-1))
5706 ThrowMogrifyException(OptionError,"MissingArgument",option);
5707 if (IsGeometry(argv[i]) == MagickFalse)
5708 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5709 break;
5710 }
cristy3ed852e2009-09-05 21:47:34 +00005711 if (LocaleCompare("stretch",option+1) == 0)
5712 {
cristybb503372010-05-27 20:51:26 +00005713 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005714 stretch;
5715
5716 if (*option == '+')
5717 break;
5718 i++;
cristybb503372010-05-27 20:51:26 +00005719 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005720 ThrowMogrifyException(OptionError,"MissingArgument",option);
5721 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
5722 if (stretch < 0)
5723 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5724 argv[i]);
5725 break;
5726 }
5727 if (LocaleCompare("strip",option+1) == 0)
5728 break;
5729 if (LocaleCompare("stroke",option+1) == 0)
5730 {
5731 if (*option == '+')
5732 break;
5733 i++;
cristybb503372010-05-27 20:51:26 +00005734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005735 ThrowMogrifyException(OptionError,"MissingArgument",option);
5736 break;
5737 }
5738 if (LocaleCompare("strokewidth",option+1) == 0)
5739 {
5740 if (*option == '+')
5741 break;
5742 i++;
cristybb503372010-05-27 20:51:26 +00005743 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005744 ThrowMogrifyException(OptionError,"MissingArgument",option);
5745 if (IsGeometry(argv[i]) == MagickFalse)
5746 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5747 break;
5748 }
5749 if (LocaleCompare("style",option+1) == 0)
5750 {
cristybb503372010-05-27 20:51:26 +00005751 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005752 style;
5753
5754 if (*option == '+')
5755 break;
5756 i++;
cristybb503372010-05-27 20:51:26 +00005757 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005758 ThrowMogrifyException(OptionError,"MissingArgument",option);
5759 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
5760 if (style < 0)
5761 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5762 argv[i]);
5763 break;
5764 }
cristyecb10ff2011-03-22 13:14:03 +00005765 if (LocaleCompare("swap",option+1) == 0)
5766 {
5767 if (*option == '+')
5768 break;
5769 i++;
5770 if (i == (ssize_t) (argc-1))
5771 ThrowMogrifyException(OptionError,"MissingArgument",option);
5772 if (IsGeometry(argv[i]) == MagickFalse)
5773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5774 break;
5775 }
cristy3ed852e2009-09-05 21:47:34 +00005776 if (LocaleCompare("swirl",option+1) == 0)
5777 {
5778 if (*option == '+')
5779 break;
5780 i++;
cristybb503372010-05-27 20:51:26 +00005781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005782 ThrowMogrifyException(OptionError,"MissingArgument",option);
5783 if (IsGeometry(argv[i]) == MagickFalse)
5784 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5785 break;
5786 }
cristyd9a29192010-10-16 16:49:53 +00005787 if (LocaleCompare("synchronize",option+1) == 0)
5788 break;
cristy3ed852e2009-09-05 21:47:34 +00005789 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5790 }
5791 case 't':
5792 {
5793 if (LocaleCompare("taint",option+1) == 0)
5794 break;
5795 if (LocaleCompare("texture",option+1) == 0)
5796 {
5797 if (*option == '+')
5798 break;
5799 i++;
cristybb503372010-05-27 20:51:26 +00005800 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005801 ThrowMogrifyException(OptionError,"MissingArgument",option);
5802 break;
5803 }
5804 if (LocaleCompare("tile",option+1) == 0)
5805 {
5806 if (*option == '+')
5807 break;
5808 i++;
cristybb503372010-05-27 20:51:26 +00005809 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005810 ThrowMogrifyException(OptionError,"MissingArgument",option);
5811 break;
5812 }
5813 if (LocaleCompare("tile-offset",option+1) == 0)
5814 {
5815 if (*option == '+')
5816 break;
5817 i++;
cristybb503372010-05-27 20:51:26 +00005818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005819 ThrowMogrifyException(OptionError,"MissingArgument",option);
5820 if (IsGeometry(argv[i]) == MagickFalse)
5821 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5822 break;
5823 }
5824 if (LocaleCompare("tint",option+1) == 0)
5825 {
5826 if (*option == '+')
5827 break;
5828 i++;
cristybb503372010-05-27 20:51:26 +00005829 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005830 ThrowMogrifyException(OptionError,"MissingArgument",option);
5831 if (IsGeometry(argv[i]) == MagickFalse)
5832 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5833 break;
5834 }
5835 if (LocaleCompare("transform",option+1) == 0)
5836 break;
5837 if (LocaleCompare("transpose",option+1) == 0)
5838 break;
5839 if (LocaleCompare("transverse",option+1) == 0)
5840 break;
5841 if (LocaleCompare("threshold",option+1) == 0)
5842 {
5843 if (*option == '+')
5844 break;
5845 i++;
cristybb503372010-05-27 20:51:26 +00005846 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005847 ThrowMogrifyException(OptionError,"MissingArgument",option);
5848 if (IsGeometry(argv[i]) == MagickFalse)
5849 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5850 break;
5851 }
5852 if (LocaleCompare("thumbnail",option+1) == 0)
5853 {
5854 if (*option == '+')
5855 break;
5856 i++;
cristybb503372010-05-27 20:51:26 +00005857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005858 ThrowMogrifyException(OptionError,"MissingArgument",option);
5859 if (IsGeometry(argv[i]) == MagickFalse)
5860 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5861 break;
5862 }
5863 if (LocaleCompare("transparent",option+1) == 0)
5864 {
5865 i++;
cristybb503372010-05-27 20:51:26 +00005866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005867 ThrowMogrifyException(OptionError,"MissingArgument",option);
5868 break;
5869 }
5870 if (LocaleCompare("transparent-color",option+1) == 0)
5871 {
5872 if (*option == '+')
5873 break;
5874 i++;
cristybb503372010-05-27 20:51:26 +00005875 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005876 ThrowMogrifyException(OptionError,"MissingArgument",option);
5877 break;
5878 }
5879 if (LocaleCompare("treedepth",option+1) == 0)
5880 {
5881 if (*option == '+')
5882 break;
5883 i++;
cristybb503372010-05-27 20:51:26 +00005884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005885 ThrowMogrifyException(OptionError,"MissingArgument",option);
5886 if (IsGeometry(argv[i]) == MagickFalse)
5887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5888 break;
5889 }
5890 if (LocaleCompare("trim",option+1) == 0)
5891 break;
5892 if (LocaleCompare("type",option+1) == 0)
5893 {
cristybb503372010-05-27 20:51:26 +00005894 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005895 type;
5896
5897 if (*option == '+')
5898 break;
5899 i++;
cristybb503372010-05-27 20:51:26 +00005900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005901 ThrowMogrifyException(OptionError,"MissingArgument",option);
5902 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
5903 if (type < 0)
5904 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5905 argv[i]);
5906 break;
5907 }
5908 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5909 }
5910 case 'u':
5911 {
5912 if (LocaleCompare("undercolor",option+1) == 0)
5913 {
5914 if (*option == '+')
5915 break;
5916 i++;
cristybb503372010-05-27 20:51:26 +00005917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005918 ThrowMogrifyException(OptionError,"MissingArgument",option);
5919 break;
5920 }
5921 if (LocaleCompare("unique-colors",option+1) == 0)
5922 break;
5923 if (LocaleCompare("units",option+1) == 0)
5924 {
cristybb503372010-05-27 20:51:26 +00005925 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005926 units;
5927
5928 if (*option == '+')
5929 break;
5930 i++;
cristybb503372010-05-27 20:51:26 +00005931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
5934 argv[i]);
5935 if (units < 0)
5936 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5937 argv[i]);
5938 break;
5939 }
5940 if (LocaleCompare("unsharp",option+1) == 0)
5941 {
5942 i++;
cristybb503372010-05-27 20:51:26 +00005943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005944 ThrowMogrifyException(OptionError,"MissingArgument",option);
5945 if (IsGeometry(argv[i]) == MagickFalse)
5946 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5947 break;
5948 }
5949 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5950 }
5951 case 'v':
5952 {
5953 if (LocaleCompare("verbose",option+1) == 0)
5954 {
5955 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5956 break;
5957 }
5958 if ((LocaleCompare("version",option+1) == 0) ||
5959 (LocaleCompare("-version",option+1) == 0))
5960 {
5961 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005962 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00005963 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
5964 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005965 break;
5966 }
5967 if (LocaleCompare("view",option+1) == 0)
5968 {
5969 if (*option == '+')
5970 break;
5971 i++;
cristybb503372010-05-27 20:51:26 +00005972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005973 ThrowMogrifyException(OptionError,"MissingArgument",option);
5974 break;
5975 }
5976 if (LocaleCompare("vignette",option+1) == 0)
5977 {
5978 if (*option == '+')
5979 break;
5980 i++;
cristybb503372010-05-27 20:51:26 +00005981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005982 ThrowMogrifyException(OptionError,"MissingArgument",option);
5983 if (IsGeometry(argv[i]) == MagickFalse)
5984 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5985 break;
5986 }
5987 if (LocaleCompare("virtual-pixel",option+1) == 0)
5988 {
cristybb503372010-05-27 20:51:26 +00005989 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005990 method;
5991
5992 if (*option == '+')
5993 break;
5994 i++;
cristybb503372010-05-27 20:51:26 +00005995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005996 ThrowMogrifyException(OptionError,"MissingArgument",option);
5997 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
5998 argv[i]);
5999 if (method < 0)
6000 ThrowMogrifyException(OptionError,
6001 "UnrecognizedVirtualPixelMethod",argv[i]);
6002 break;
6003 }
6004 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6005 }
6006 case 'w':
6007 {
6008 if (LocaleCompare("wave",option+1) == 0)
6009 {
6010 i++;
cristybb503372010-05-27 20:51:26 +00006011 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006012 ThrowMogrifyException(OptionError,"MissingArgument",option);
6013 if (IsGeometry(argv[i]) == MagickFalse)
6014 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6015 break;
6016 }
6017 if (LocaleCompare("weight",option+1) == 0)
6018 {
6019 if (*option == '+')
6020 break;
6021 i++;
cristybb503372010-05-27 20:51:26 +00006022 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006023 ThrowMogrifyException(OptionError,"MissingArgument",option);
6024 break;
6025 }
6026 if (LocaleCompare("white-point",option+1) == 0)
6027 {
6028 if (*option == '+')
6029 break;
6030 i++;
cristybb503372010-05-27 20:51:26 +00006031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006032 ThrowMogrifyException(OptionError,"MissingArgument",option);
6033 if (IsGeometry(argv[i]) == MagickFalse)
6034 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6035 break;
6036 }
6037 if (LocaleCompare("white-threshold",option+1) == 0)
6038 {
6039 if (*option == '+')
6040 break;
6041 i++;
cristybb503372010-05-27 20:51:26 +00006042 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006043 ThrowMogrifyException(OptionError,"MissingArgument",option);
6044 if (IsGeometry(argv[i]) == MagickFalse)
6045 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6046 break;
6047 }
6048 if (LocaleCompare("write",option+1) == 0)
6049 {
6050 i++;
cristybb503372010-05-27 20:51:26 +00006051 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006052 ThrowMogrifyException(OptionError,"MissingArgument",option);
6053 break;
6054 }
6055 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6056 }
6057 case '?':
6058 break;
6059 default:
6060 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6061 }
6062 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6063 MagickFalse : MagickTrue;
6064 if (fire != MagickFalse)
6065 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6066 }
6067 if (k != 0)
6068 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006069 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006070 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6071 DestroyMogrify();
6072 return(status != 0 ? MagickTrue : MagickFalse);
6073}
6074
6075/*
6076%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6077% %
6078% %
6079% %
6080+ M o g r i f y I m a g e I n f o %
6081% %
6082% %
6083% %
6084%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6085%
6086% MogrifyImageInfo() applies image processing settings to the image as
6087% prescribed by command line options.
6088%
6089% The format of the MogrifyImageInfo method is:
6090%
6091% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6092% const char **argv,ExceptionInfo *exception)
6093%
6094% A description of each parameter follows:
6095%
6096% o image_info: the image info..
6097%
6098% o argc: Specifies a pointer to an integer describing the number of
6099% elements in the argument vector.
6100%
6101% o argv: Specifies a pointer to a text array containing the command line
6102% arguments.
6103%
6104% o exception: return any errors or warnings in this structure.
6105%
6106*/
6107WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6108 const int argc,const char **argv,ExceptionInfo *exception)
6109{
6110 const char
6111 *option;
6112
6113 GeometryInfo
6114 geometry_info;
6115
cristybb503372010-05-27 20:51:26 +00006116 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006117 count;
6118
cristybb503372010-05-27 20:51:26 +00006119 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006120 i;
6121
6122 /*
6123 Initialize method variables.
6124 */
6125 assert(image_info != (ImageInfo *) NULL);
6126 assert(image_info->signature == MagickSignature);
6127 if (image_info->debug != MagickFalse)
6128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6129 image_info->filename);
6130 if (argc < 0)
6131 return(MagickTrue);
6132 /*
6133 Set the image settings.
6134 */
cristybb503372010-05-27 20:51:26 +00006135 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006136 {
6137 option=argv[i];
6138 if (IsMagickOption(option) == MagickFalse)
6139 continue;
6140 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6141 0L);
cristycee97112010-05-28 00:44:52 +00006142 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006143 break;
6144 switch (*(option+1))
6145 {
6146 case 'a':
6147 {
6148 if (LocaleCompare("adjoin",option+1) == 0)
6149 {
6150 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6151 break;
6152 }
6153 if (LocaleCompare("antialias",option+1) == 0)
6154 {
6155 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6156 break;
6157 }
6158 if (LocaleCompare("attenuate",option+1) == 0)
6159 {
6160 if (*option == '+')
6161 {
6162 (void) DeleteImageOption(image_info,option+1);
6163 break;
6164 }
6165 (void) SetImageOption(image_info,option+1,argv[i+1]);
6166 break;
6167 }
6168 if (LocaleCompare("authenticate",option+1) == 0)
6169 {
6170 if (*option == '+')
6171 (void) CloneString(&image_info->authenticate,(char *) NULL);
6172 else
6173 (void) CloneString(&image_info->authenticate,argv[i+1]);
6174 break;
6175 }
6176 break;
6177 }
6178 case 'b':
6179 {
6180 if (LocaleCompare("background",option+1) == 0)
6181 {
6182 if (*option == '+')
6183 {
6184 (void) DeleteImageOption(image_info,option+1);
6185 (void) QueryColorDatabase(BackgroundColor,
6186 &image_info->background_color,exception);
6187 break;
6188 }
6189 (void) SetImageOption(image_info,option+1,argv[i+1]);
6190 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6191 exception);
6192 break;
6193 }
6194 if (LocaleCompare("bias",option+1) == 0)
6195 {
6196 if (*option == '+')
6197 {
6198 (void) SetImageOption(image_info,option+1,"0.0");
6199 break;
6200 }
6201 (void) SetImageOption(image_info,option+1,argv[i+1]);
6202 break;
6203 }
6204 if (LocaleCompare("black-point-compensation",option+1) == 0)
6205 {
6206 if (*option == '+')
6207 {
6208 (void) SetImageOption(image_info,option+1,"false");
6209 break;
6210 }
6211 (void) SetImageOption(image_info,option+1,"true");
6212 break;
6213 }
6214 if (LocaleCompare("blue-primary",option+1) == 0)
6215 {
6216 if (*option == '+')
6217 {
6218 (void) SetImageOption(image_info,option+1,"0.0");
6219 break;
6220 }
6221 (void) SetImageOption(image_info,option+1,argv[i+1]);
6222 break;
6223 }
6224 if (LocaleCompare("bordercolor",option+1) == 0)
6225 {
6226 if (*option == '+')
6227 {
6228 (void) DeleteImageOption(image_info,option+1);
6229 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6230 exception);
6231 break;
6232 }
6233 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6234 exception);
6235 (void) SetImageOption(image_info,option+1,argv[i+1]);
6236 break;
6237 }
6238 if (LocaleCompare("box",option+1) == 0)
6239 {
6240 if (*option == '+')
6241 {
6242 (void) SetImageOption(image_info,"undercolor","none");
6243 break;
6244 }
6245 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6246 break;
6247 }
6248 break;
6249 }
6250 case 'c':
6251 {
6252 if (LocaleCompare("cache",option+1) == 0)
6253 {
6254 MagickSizeType
6255 limit;
6256
6257 limit=MagickResourceInfinity;
6258 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006259 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006260 (void) SetMagickResourceLimit(MemoryResource,limit);
6261 (void) SetMagickResourceLimit(MapResource,2*limit);
6262 break;
6263 }
6264 if (LocaleCompare("caption",option+1) == 0)
6265 {
6266 if (*option == '+')
6267 {
6268 (void) DeleteImageOption(image_info,option+1);
6269 break;
6270 }
6271 (void) SetImageOption(image_info,option+1,argv[i+1]);
6272 break;
6273 }
6274 if (LocaleCompare("channel",option+1) == 0)
6275 {
6276 if (*option == '+')
6277 {
6278 image_info->channel=DefaultChannels;
6279 break;
6280 }
6281 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6282 break;
6283 }
6284 if (LocaleCompare("colors",option+1) == 0)
6285 {
cristye27293e2009-12-18 02:53:20 +00006286 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006287 break;
6288 }
6289 if (LocaleCompare("colorspace",option+1) == 0)
6290 {
6291 if (*option == '+')
6292 {
6293 image_info->colorspace=UndefinedColorspace;
6294 (void) SetImageOption(image_info,option+1,"undefined");
6295 break;
6296 }
6297 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6298 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6299 (void) SetImageOption(image_info,option+1,argv[i+1]);
6300 break;
6301 }
6302 if (LocaleCompare("compress",option+1) == 0)
6303 {
6304 if (*option == '+')
6305 {
6306 image_info->compression=UndefinedCompression;
6307 (void) SetImageOption(image_info,option+1,"undefined");
6308 break;
6309 }
6310 image_info->compression=(CompressionType) ParseMagickOption(
6311 MagickCompressOptions,MagickFalse,argv[i+1]);
6312 (void) SetImageOption(image_info,option+1,argv[i+1]);
6313 break;
6314 }
6315 if (LocaleCompare("comment",option+1) == 0)
6316 {
6317 if (*option == '+')
6318 {
6319 (void) DeleteImageOption(image_info,option+1);
6320 break;
6321 }
6322 (void) SetImageOption(image_info,option+1,argv[i+1]);
6323 break;
6324 }
6325 if (LocaleCompare("compose",option+1) == 0)
6326 {
6327 if (*option == '+')
6328 {
6329 (void) SetImageOption(image_info,option+1,"undefined");
6330 break;
6331 }
6332 (void) SetImageOption(image_info,option+1,argv[i+1]);
6333 break;
6334 }
6335 if (LocaleCompare("compress",option+1) == 0)
6336 {
6337 if (*option == '+')
6338 {
6339 image_info->compression=UndefinedCompression;
6340 (void) SetImageOption(image_info,option+1,"undefined");
6341 break;
6342 }
6343 image_info->compression=(CompressionType) ParseMagickOption(
6344 MagickCompressOptions,MagickFalse,argv[i+1]);
6345 (void) SetImageOption(image_info,option+1,argv[i+1]);
6346 break;
6347 }
6348 break;
6349 }
6350 case 'd':
6351 {
6352 if (LocaleCompare("debug",option+1) == 0)
6353 {
6354 if (*option == '+')
6355 (void) SetLogEventMask("none");
6356 else
6357 (void) SetLogEventMask(argv[i+1]);
6358 image_info->debug=IsEventLogging();
6359 break;
6360 }
6361 if (LocaleCompare("define",option+1) == 0)
6362 {
6363 if (*option == '+')
6364 {
6365 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6366 (void) DeleteImageRegistry(argv[i+1]+9);
6367 else
6368 (void) DeleteImageOption(image_info,argv[i+1]);
6369 break;
6370 }
6371 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6372 {
6373 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6374 exception);
6375 break;
6376 }
6377 (void) DefineImageOption(image_info,argv[i+1]);
6378 break;
6379 }
6380 if (LocaleCompare("delay",option+1) == 0)
6381 {
6382 if (*option == '+')
6383 {
6384 (void) SetImageOption(image_info,option+1,"0");
6385 break;
6386 }
6387 (void) SetImageOption(image_info,option+1,argv[i+1]);
6388 break;
6389 }
6390 if (LocaleCompare("density",option+1) == 0)
6391 {
6392 /*
6393 Set image density.
6394 */
6395 if (*option == '+')
6396 {
6397 if (image_info->density != (char *) NULL)
6398 image_info->density=DestroyString(image_info->density);
6399 (void) SetImageOption(image_info,option+1,"72");
6400 break;
6401 }
6402 (void) CloneString(&image_info->density,argv[i+1]);
6403 (void) SetImageOption(image_info,option+1,argv[i+1]);
6404 break;
6405 }
6406 if (LocaleCompare("depth",option+1) == 0)
6407 {
6408 if (*option == '+')
6409 {
6410 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6411 break;
6412 }
cristye27293e2009-12-18 02:53:20 +00006413 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006414 break;
6415 }
cristyc9b12952010-03-28 01:12:28 +00006416 if (LocaleCompare("direction",option+1) == 0)
6417 {
6418 if (*option == '+')
6419 {
6420 (void) SetImageOption(image_info,option+1,"undefined");
6421 break;
6422 }
6423 (void) SetImageOption(image_info,option+1,argv[i+1]);
6424 break;
6425 }
cristy3ed852e2009-09-05 21:47:34 +00006426 if (LocaleCompare("display",option+1) == 0)
6427 {
6428 if (*option == '+')
6429 {
6430 if (image_info->server_name != (char *) NULL)
6431 image_info->server_name=DestroyString(
6432 image_info->server_name);
6433 break;
6434 }
6435 (void) CloneString(&image_info->server_name,argv[i+1]);
6436 break;
6437 }
6438 if (LocaleCompare("dispose",option+1) == 0)
6439 {
6440 if (*option == '+')
6441 {
6442 (void) SetImageOption(image_info,option+1,"undefined");
6443 break;
6444 }
6445 (void) SetImageOption(image_info,option+1,argv[i+1]);
6446 break;
6447 }
6448 if (LocaleCompare("dither",option+1) == 0)
6449 {
6450 if (*option == '+')
6451 {
6452 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006453 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006454 break;
6455 }
6456 (void) SetImageOption(image_info,option+1,argv[i+1]);
6457 image_info->dither=MagickTrue;
6458 break;
6459 }
6460 break;
6461 }
6462 case 'e':
6463 {
6464 if (LocaleCompare("encoding",option+1) == 0)
6465 {
6466 if (*option == '+')
6467 {
6468 (void) SetImageOption(image_info,option+1,"undefined");
6469 break;
6470 }
6471 (void) SetImageOption(image_info,option+1,argv[i+1]);
6472 break;
6473 }
6474 if (LocaleCompare("endian",option+1) == 0)
6475 {
6476 if (*option == '+')
6477 {
6478 image_info->endian=UndefinedEndian;
6479 (void) SetImageOption(image_info,option+1,"undefined");
6480 break;
6481 }
6482 image_info->endian=(EndianType) ParseMagickOption(
6483 MagickEndianOptions,MagickFalse,argv[i+1]);
6484 (void) SetImageOption(image_info,option+1,argv[i+1]);
6485 break;
6486 }
6487 if (LocaleCompare("extract",option+1) == 0)
6488 {
6489 /*
6490 Set image extract geometry.
6491 */
6492 if (*option == '+')
6493 {
6494 if (image_info->extract != (char *) NULL)
6495 image_info->extract=DestroyString(image_info->extract);
6496 break;
6497 }
6498 (void) CloneString(&image_info->extract,argv[i+1]);
6499 break;
6500 }
6501 break;
6502 }
6503 case 'f':
6504 {
6505 if (LocaleCompare("fill",option+1) == 0)
6506 {
6507 if (*option == '+')
6508 {
6509 (void) SetImageOption(image_info,option+1,"none");
6510 break;
6511 }
6512 (void) SetImageOption(image_info,option+1,argv[i+1]);
6513 break;
6514 }
6515 if (LocaleCompare("filter",option+1) == 0)
6516 {
6517 if (*option == '+')
6518 {
6519 (void) SetImageOption(image_info,option+1,"undefined");
6520 break;
6521 }
6522 (void) SetImageOption(image_info,option+1,argv[i+1]);
6523 break;
6524 }
6525 if (LocaleCompare("font",option+1) == 0)
6526 {
6527 if (*option == '+')
6528 {
6529 if (image_info->font != (char *) NULL)
6530 image_info->font=DestroyString(image_info->font);
6531 break;
6532 }
6533 (void) CloneString(&image_info->font,argv[i+1]);
6534 break;
6535 }
6536 if (LocaleCompare("format",option+1) == 0)
6537 {
6538 register const char
6539 *q;
6540
6541 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006542 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006543 image_info->ping=MagickFalse;
6544 (void) SetImageOption(image_info,option+1,argv[i+1]);
6545 break;
6546 }
6547 if (LocaleCompare("fuzz",option+1) == 0)
6548 {
6549 if (*option == '+')
6550 {
6551 image_info->fuzz=0.0;
6552 (void) SetImageOption(image_info,option+1,"0");
6553 break;
6554 }
cristyf2f27272009-12-17 14:48:46 +00006555 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006556 1.0);
6557 (void) SetImageOption(image_info,option+1,argv[i+1]);
6558 break;
6559 }
6560 break;
6561 }
6562 case 'g':
6563 {
6564 if (LocaleCompare("gravity",option+1) == 0)
6565 {
6566 if (*option == '+')
6567 {
6568 (void) SetImageOption(image_info,option+1,"undefined");
6569 break;
6570 }
6571 (void) SetImageOption(image_info,option+1,argv[i+1]);
6572 break;
6573 }
6574 if (LocaleCompare("green-primary",option+1) == 0)
6575 {
6576 if (*option == '+')
6577 {
6578 (void) SetImageOption(image_info,option+1,"0.0");
6579 break;
6580 }
6581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
6584 break;
6585 }
6586 case 'i':
6587 {
6588 if (LocaleCompare("intent",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 (void) SetImageOption(image_info,option+1,"undefined");
6593 break;
6594 }
6595 (void) SetImageOption(image_info,option+1,argv[i+1]);
6596 break;
6597 }
6598 if (LocaleCompare("interlace",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 image_info->interlace=UndefinedInterlace;
6603 (void) SetImageOption(image_info,option+1,"undefined");
6604 break;
6605 }
6606 image_info->interlace=(InterlaceType) ParseMagickOption(
6607 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6608 (void) SetImageOption(image_info,option+1,argv[i+1]);
6609 break;
6610 }
cristyb32b90a2009-09-07 21:45:48 +00006611 if (LocaleCompare("interline-spacing",option+1) == 0)
6612 {
6613 if (*option == '+')
6614 {
6615 (void) SetImageOption(image_info,option+1,"undefined");
6616 break;
6617 }
6618 (void) SetImageOption(image_info,option+1,argv[i+1]);
6619 break;
6620 }
cristy3ed852e2009-09-05 21:47:34 +00006621 if (LocaleCompare("interpolate",option+1) == 0)
6622 {
6623 if (*option == '+')
6624 {
6625 (void) SetImageOption(image_info,option+1,"undefined");
6626 break;
6627 }
6628 (void) SetImageOption(image_info,option+1,argv[i+1]);
6629 break;
6630 }
6631 if (LocaleCompare("interword-spacing",option+1) == 0)
6632 {
6633 if (*option == '+')
6634 {
6635 (void) SetImageOption(image_info,option+1,"undefined");
6636 break;
6637 }
6638 (void) SetImageOption(image_info,option+1,argv[i+1]);
6639 break;
6640 }
6641 break;
6642 }
6643 case 'k':
6644 {
6645 if (LocaleCompare("kerning",option+1) == 0)
6646 {
6647 if (*option == '+')
6648 {
6649 (void) SetImageOption(image_info,option+1,"undefined");
6650 break;
6651 }
6652 (void) SetImageOption(image_info,option+1,argv[i+1]);
6653 break;
6654 }
6655 break;
6656 }
6657 case 'l':
6658 {
6659 if (LocaleCompare("label",option+1) == 0)
6660 {
6661 if (*option == '+')
6662 {
6663 (void) DeleteImageOption(image_info,option+1);
6664 break;
6665 }
6666 (void) SetImageOption(image_info,option+1,argv[i+1]);
6667 break;
6668 }
6669 if (LocaleCompare("limit",option+1) == 0)
6670 {
6671 MagickSizeType
6672 limit;
6673
6674 ResourceType
6675 type;
6676
6677 if (*option == '+')
6678 break;
6679 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6680 MagickFalse,argv[i+1]);
6681 limit=MagickResourceInfinity;
6682 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006683 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006684 (void) SetMagickResourceLimit(type,limit);
6685 break;
6686 }
6687 if (LocaleCompare("list",option+1) == 0)
6688 {
cristybb503372010-05-27 20:51:26 +00006689 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006690 list;
6691
6692 /*
6693 Display configuration list.
6694 */
6695 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6696 switch (list)
6697 {
6698 case MagickCoderOptions:
6699 {
6700 (void) ListCoderInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickColorOptions:
6704 {
6705 (void) ListColorInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickConfigureOptions:
6709 {
6710 (void) ListConfigureInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickDelegateOptions:
6714 {
6715 (void) ListDelegateInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickFontOptions:
6719 {
6720 (void) ListTypeInfo((FILE *) NULL,exception);
6721 break;
6722 }
6723 case MagickFormatOptions:
6724 {
6725 (void) ListMagickInfo((FILE *) NULL,exception);
6726 break;
6727 }
6728 case MagickLocaleOptions:
6729 {
6730 (void) ListLocaleInfo((FILE *) NULL,exception);
6731 break;
6732 }
6733 case MagickLogOptions:
6734 {
6735 (void) ListLogInfo((FILE *) NULL,exception);
6736 break;
6737 }
6738 case MagickMagicOptions:
6739 {
6740 (void) ListMagicInfo((FILE *) NULL,exception);
6741 break;
6742 }
6743 case MagickMimeOptions:
6744 {
6745 (void) ListMimeInfo((FILE *) NULL,exception);
6746 break;
6747 }
6748 case MagickModuleOptions:
6749 {
6750 (void) ListModuleInfo((FILE *) NULL,exception);
6751 break;
6752 }
6753 case MagickPolicyOptions:
6754 {
6755 (void) ListPolicyInfo((FILE *) NULL,exception);
6756 break;
6757 }
6758 case MagickResourceOptions:
6759 {
6760 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6761 break;
6762 }
6763 case MagickThresholdOptions:
6764 {
6765 (void) ListThresholdMaps((FILE *) NULL,exception);
6766 break;
6767 }
6768 default:
6769 {
6770 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
6771 exception);
6772 break;
6773 }
6774 }
cristyaeb2cbc2010-05-07 13:28:58 +00006775 break;
cristy3ed852e2009-09-05 21:47:34 +00006776 }
6777 if (LocaleCompare("log",option+1) == 0)
6778 {
6779 if (*option == '+')
6780 break;
6781 (void) SetLogFormat(argv[i+1]);
6782 break;
6783 }
6784 if (LocaleCompare("loop",option+1) == 0)
6785 {
6786 if (*option == '+')
6787 {
6788 (void) SetImageOption(image_info,option+1,"0");
6789 break;
6790 }
6791 (void) SetImageOption(image_info,option+1,argv[i+1]);
6792 break;
6793 }
6794 break;
6795 }
6796 case 'm':
6797 {
6798 if (LocaleCompare("matte",option+1) == 0)
6799 {
6800 if (*option == '+')
6801 {
6802 (void) SetImageOption(image_info,option+1,"false");
6803 break;
6804 }
6805 (void) SetImageOption(image_info,option+1,"true");
6806 break;
6807 }
6808 if (LocaleCompare("mattecolor",option+1) == 0)
6809 {
6810 if (*option == '+')
6811 {
6812 (void) SetImageOption(image_info,option+1,argv[i+1]);
6813 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6814 exception);
6815 break;
6816 }
6817 (void) SetImageOption(image_info,option+1,argv[i+1]);
6818 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6819 exception);
6820 break;
6821 }
6822 if (LocaleCompare("monitor",option+1) == 0)
6823 {
6824 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6825 (void *) NULL);
6826 break;
6827 }
6828 if (LocaleCompare("monochrome",option+1) == 0)
6829 {
6830 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6831 break;
6832 }
6833 break;
6834 }
6835 case 'o':
6836 {
6837 if (LocaleCompare("orient",option+1) == 0)
6838 {
6839 if (*option == '+')
6840 {
6841 image_info->orientation=UndefinedOrientation;
6842 (void) SetImageOption(image_info,option+1,"undefined");
6843 break;
6844 }
6845 image_info->orientation=(OrientationType) ParseMagickOption(
6846 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006847 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006848 break;
6849 }
6850 }
6851 case 'p':
6852 {
6853 if (LocaleCompare("page",option+1) == 0)
6854 {
6855 char
6856 *canonical_page,
6857 page[MaxTextExtent];
6858
6859 const char
6860 *image_option;
6861
6862 MagickStatusType
6863 flags;
6864
6865 RectangleInfo
6866 geometry;
6867
6868 if (*option == '+')
6869 {
6870 (void) DeleteImageOption(image_info,option+1);
6871 (void) CloneString(&image_info->page,(char *) NULL);
6872 break;
6873 }
6874 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6875 image_option=GetImageOption(image_info,"page");
6876 if (image_option != (const char *) NULL)
6877 flags=ParseAbsoluteGeometry(image_option,&geometry);
6878 canonical_page=GetPageGeometry(argv[i+1]);
6879 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6880 canonical_page=DestroyString(canonical_page);
6881 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006882 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006883 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6884 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006885 (unsigned long) geometry.width,(unsigned long) geometry.height,
6886 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006887 (void) SetImageOption(image_info,option+1,page);
6888 (void) CloneString(&image_info->page,page);
6889 break;
6890 }
6891 if (LocaleCompare("pen",option+1) == 0)
6892 {
6893 if (*option == '+')
6894 {
6895 (void) SetImageOption(image_info,option+1,"none");
6896 break;
6897 }
6898 (void) SetImageOption(image_info,option+1,argv[i+1]);
6899 break;
6900 }
6901 if (LocaleCompare("ping",option+1) == 0)
6902 {
6903 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6904 break;
6905 }
6906 if (LocaleCompare("pointsize",option+1) == 0)
6907 {
6908 if (*option == '+')
6909 geometry_info.rho=0.0;
6910 else
6911 (void) ParseGeometry(argv[i+1],&geometry_info);
6912 image_info->pointsize=geometry_info.rho;
6913 break;
6914 }
cristye7f51092010-01-17 00:39:37 +00006915 if (LocaleCompare("precision",option+1) == 0)
6916 {
cristybf2766a2010-01-17 03:33:23 +00006917 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006918 break;
6919 }
cristy3ed852e2009-09-05 21:47:34 +00006920 if (LocaleCompare("preview",option+1) == 0)
6921 {
6922 /*
6923 Preview image.
6924 */
6925 if (*option == '+')
6926 {
6927 image_info->preview_type=UndefinedPreview;
6928 break;
6929 }
6930 image_info->preview_type=(PreviewType) ParseMagickOption(
6931 MagickPreviewOptions,MagickFalse,argv[i+1]);
6932 break;
6933 }
6934 break;
6935 }
6936 case 'q':
6937 {
6938 if (LocaleCompare("quality",option+1) == 0)
6939 {
6940 /*
6941 Set image compression quality.
6942 */
6943 if (*option == '+')
6944 {
6945 image_info->quality=UndefinedCompressionQuality;
6946 (void) SetImageOption(image_info,option+1,"0");
6947 break;
6948 }
cristye27293e2009-12-18 02:53:20 +00006949 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006950 (void) SetImageOption(image_info,option+1,argv[i+1]);
6951 break;
6952 }
6953 if (LocaleCompare("quiet",option+1) == 0)
6954 {
6955 static WarningHandler
6956 warning_handler = (WarningHandler) NULL;
6957
6958 if (*option == '+')
6959 {
6960 /*
6961 Restore error or warning messages.
6962 */
6963 warning_handler=SetWarningHandler(warning_handler);
6964 break;
6965 }
6966 /*
6967 Suppress error or warning messages.
6968 */
6969 warning_handler=SetWarningHandler((WarningHandler) NULL);
6970 break;
6971 }
6972 break;
6973 }
6974 case 'r':
6975 {
6976 if (LocaleCompare("red-primary",option+1) == 0)
6977 {
6978 if (*option == '+')
6979 {
6980 (void) SetImageOption(image_info,option+1,"0.0");
6981 break;
6982 }
6983 (void) SetImageOption(image_info,option+1,argv[i+1]);
6984 break;
6985 }
6986 break;
6987 }
6988 case 's':
6989 {
6990 if (LocaleCompare("sampling-factor",option+1) == 0)
6991 {
6992 /*
6993 Set image sampling factor.
6994 */
6995 if (*option == '+')
6996 {
6997 if (image_info->sampling_factor != (char *) NULL)
6998 image_info->sampling_factor=DestroyString(
6999 image_info->sampling_factor);
7000 break;
7001 }
7002 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7003 break;
7004 }
7005 if (LocaleCompare("scene",option+1) == 0)
7006 {
7007 /*
7008 Set image scene.
7009 */
7010 if (*option == '+')
7011 {
7012 image_info->scene=0;
7013 (void) SetImageOption(image_info,option+1,"0");
7014 break;
7015 }
cristye27293e2009-12-18 02:53:20 +00007016 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007017 (void) SetImageOption(image_info,option+1,argv[i+1]);
7018 break;
7019 }
7020 if (LocaleCompare("seed",option+1) == 0)
7021 {
cristybb503372010-05-27 20:51:26 +00007022 size_t
cristy3ed852e2009-09-05 21:47:34 +00007023 seed;
7024
7025 if (*option == '+')
7026 {
cristybb503372010-05-27 20:51:26 +00007027 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007028 SeedPseudoRandomGenerator(seed);
7029 break;
7030 }
cristye27293e2009-12-18 02:53:20 +00007031 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007032 SeedPseudoRandomGenerator(seed);
7033 break;
7034 }
7035 if (LocaleCompare("size",option+1) == 0)
7036 {
7037 if (*option == '+')
7038 {
7039 if (image_info->size != (char *) NULL)
7040 image_info->size=DestroyString(image_info->size);
7041 break;
7042 }
7043 (void) CloneString(&image_info->size,argv[i+1]);
7044 break;
7045 }
7046 if (LocaleCompare("stroke",option+1) == 0)
7047 {
7048 if (*option == '+')
7049 {
7050 (void) SetImageOption(image_info,option+1,"none");
7051 break;
7052 }
7053 (void) SetImageOption(image_info,option+1,argv[i+1]);
7054 break;
7055 }
7056 if (LocaleCompare("strokewidth",option+1) == 0)
7057 {
7058 if (*option == '+')
7059 {
7060 (void) SetImageOption(image_info,option+1,"0");
7061 break;
7062 }
7063 (void) SetImageOption(image_info,option+1,argv[i+1]);
7064 break;
7065 }
cristyd9a29192010-10-16 16:49:53 +00007066 if (LocaleCompare("synchronize",option+1) == 0)
7067 {
7068 if (*option == '+')
7069 {
7070 image_info->synchronize=MagickFalse;
7071 break;
7072 }
7073 image_info->synchronize=MagickTrue;
7074 break;
7075 }
cristy3ed852e2009-09-05 21:47:34 +00007076 break;
7077 }
7078 case 't':
7079 {
7080 if (LocaleCompare("taint",option+1) == 0)
7081 {
7082 if (*option == '+')
7083 {
7084 (void) SetImageOption(image_info,option+1,"false");
7085 break;
7086 }
7087 (void) SetImageOption(image_info,option+1,"true");
7088 break;
7089 }
7090 if (LocaleCompare("texture",option+1) == 0)
7091 {
7092 if (*option == '+')
7093 {
7094 if (image_info->texture != (char *) NULL)
7095 image_info->texture=DestroyString(image_info->texture);
7096 break;
7097 }
7098 (void) CloneString(&image_info->texture,argv[i+1]);
7099 break;
7100 }
7101 if (LocaleCompare("tile-offset",option+1) == 0)
7102 {
7103 if (*option == '+')
7104 {
7105 (void) SetImageOption(image_info,option+1,"0");
7106 break;
7107 }
7108 (void) SetImageOption(image_info,option+1,argv[i+1]);
7109 break;
7110 }
7111 if (LocaleCompare("transparent-color",option+1) == 0)
7112 {
7113 if (*option == '+')
7114 {
7115 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7116 (void) SetImageOption(image_info,option+1,"none");
7117 break;
7118 }
7119 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7120 exception);
7121 (void) SetImageOption(image_info,option+1,argv[i+1]);
7122 break;
7123 }
7124 if (LocaleCompare("type",option+1) == 0)
7125 {
7126 if (*option == '+')
7127 {
cristy5f1c1ff2010-12-23 21:38:06 +00007128 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007129 (void) SetImageOption(image_info,option+1,"undefined");
7130 break;
7131 }
7132 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7133 MagickFalse,argv[i+1]);
7134 (void) SetImageOption(image_info,option+1,argv[i+1]);
7135 break;
7136 }
7137 break;
7138 }
7139 case 'u':
7140 {
7141 if (LocaleCompare("undercolor",option+1) == 0)
7142 {
7143 if (*option == '+')
7144 {
7145 (void) DeleteImageOption(image_info,option+1);
7146 break;
7147 }
7148 (void) SetImageOption(image_info,option+1,argv[i+1]);
7149 break;
7150 }
7151 if (LocaleCompare("units",option+1) == 0)
7152 {
7153 if (*option == '+')
7154 {
7155 image_info->units=UndefinedResolution;
7156 (void) SetImageOption(image_info,option+1,"undefined");
7157 break;
7158 }
7159 image_info->units=(ResolutionType) ParseMagickOption(
7160 MagickResolutionOptions,MagickFalse,argv[i+1]);
7161 (void) SetImageOption(image_info,option+1,argv[i+1]);
7162 break;
7163 }
7164 break;
7165 }
7166 case 'v':
7167 {
7168 if (LocaleCompare("verbose",option+1) == 0)
7169 {
7170 if (*option == '+')
7171 {
7172 image_info->verbose=MagickFalse;
7173 break;
7174 }
7175 image_info->verbose=MagickTrue;
7176 image_info->ping=MagickFalse;
7177 break;
7178 }
7179 if (LocaleCompare("view",option+1) == 0)
7180 {
7181 if (*option == '+')
7182 {
7183 if (image_info->view != (char *) NULL)
7184 image_info->view=DestroyString(image_info->view);
7185 break;
7186 }
7187 (void) CloneString(&image_info->view,argv[i+1]);
7188 break;
7189 }
7190 if (LocaleCompare("virtual-pixel",option+1) == 0)
7191 {
7192 if (*option == '+')
7193 {
7194 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7195 (void) SetImageOption(image_info,option+1,"undefined");
7196 break;
7197 }
7198 image_info->virtual_pixel_method=(VirtualPixelMethod)
7199 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7200 argv[i+1]);
7201 (void) SetImageOption(image_info,option+1,argv[i+1]);
7202 break;
7203 }
7204 break;
7205 }
7206 case 'w':
7207 {
7208 if (LocaleCompare("white-point",option+1) == 0)
7209 {
7210 if (*option == '+')
7211 {
7212 (void) SetImageOption(image_info,option+1,"0.0");
7213 break;
7214 }
7215 (void) SetImageOption(image_info,option+1,argv[i+1]);
7216 break;
7217 }
7218 break;
7219 }
7220 default:
7221 break;
7222 }
7223 i+=count;
7224 }
7225 return(MagickTrue);
7226}
7227
7228/*
7229%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7230% %
7231% %
7232% %
7233+ M o g r i f y I m a g e L i s t %
7234% %
7235% %
7236% %
7237%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7238%
7239% MogrifyImageList() applies any command line options that might affect the
7240% entire image list (e.g. -append, -coalesce, etc.).
7241%
7242% The format of the MogrifyImage method is:
7243%
7244% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7245% const char **argv,Image **images,ExceptionInfo *exception)
7246%
7247% A description of each parameter follows:
7248%
7249% o image_info: the image info..
7250%
7251% o argc: Specifies a pointer to an integer describing the number of
7252% elements in the argument vector.
7253%
7254% o argv: Specifies a pointer to a text array containing the command line
7255% arguments.
7256%
anthonye9c27192011-03-27 08:07:06 +00007257% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007258%
7259% o exception: return any errors or warnings in this structure.
7260%
7261*/
7262WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7263 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7264{
7265 ChannelType
7266 channel;
7267
7268 const char
7269 *option;
7270
cristy6b3da3a2010-06-20 02:21:46 +00007271 ImageInfo
7272 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007273
7274 MagickStatusType
7275 status;
7276
7277 QuantizeInfo
7278 *quantize_info;
7279
cristybb503372010-05-27 20:51:26 +00007280 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007281 i;
7282
cristy6b3da3a2010-06-20 02:21:46 +00007283 ssize_t
7284 count,
7285 index;
7286
cristy3ed852e2009-09-05 21:47:34 +00007287 /*
7288 Apply options to the image list.
7289 */
7290 assert(image_info != (ImageInfo *) NULL);
7291 assert(image_info->signature == MagickSignature);
7292 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007293 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007294 assert((*images)->signature == MagickSignature);
7295 if ((*images)->debug != MagickFalse)
7296 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7297 (*images)->filename);
7298 if ((argc <= 0) || (*argv == (char *) NULL))
7299 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007300 mogrify_info=CloneImageInfo(image_info);
7301 quantize_info=AcquireQuantizeInfo(mogrify_info);
7302 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007303 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007304 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007305 {
cristy74fe8f12009-10-03 19:09:01 +00007306 if (*images == (Image *) NULL)
7307 break;
cristy3ed852e2009-09-05 21:47:34 +00007308 option=argv[i];
7309 if (IsMagickOption(option) == MagickFalse)
7310 continue;
7311 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7312 0L);
cristycee97112010-05-28 00:44:52 +00007313 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007314 break;
cristy6b3da3a2010-06-20 02:21:46 +00007315 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007316 switch (*(option+1))
7317 {
7318 case 'a':
7319 {
7320 if (LocaleCompare("affinity",option+1) == 0)
7321 {
cristy6b3da3a2010-06-20 02:21:46 +00007322 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007323 if (*option == '+')
7324 {
7325 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7326 InheritException(exception,&(*images)->exception);
7327 break;
7328 }
7329 i++;
7330 break;
7331 }
7332 if (LocaleCompare("append",option+1) == 0)
7333 {
7334 Image
7335 *append_image;
7336
cristy6b3da3a2010-06-20 02:21:46 +00007337 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007338 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7339 MagickFalse,exception);
7340 if (append_image == (Image *) NULL)
7341 {
7342 status=MagickFalse;
7343 break;
7344 }
7345 *images=DestroyImageList(*images);
7346 *images=append_image;
7347 break;
7348 }
7349 if (LocaleCompare("average",option+1) == 0)
7350 {
7351 Image
7352 *average_image;
7353
cristyd18ae7c2010-03-07 17:39:52 +00007354 /*
7355 Average an image sequence (deprecated).
7356 */
cristy6b3da3a2010-06-20 02:21:46 +00007357 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007358 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7359 exception);
cristy3ed852e2009-09-05 21:47:34 +00007360 if (average_image == (Image *) NULL)
7361 {
7362 status=MagickFalse;
7363 break;
7364 }
7365 *images=DestroyImageList(*images);
7366 *images=average_image;
7367 break;
7368 }
7369 break;
7370 }
7371 case 'c':
7372 {
7373 if (LocaleCompare("channel",option+1) == 0)
7374 {
7375 if (*option == '+')
7376 {
7377 channel=DefaultChannels;
7378 break;
7379 }
7380 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7381 break;
7382 }
7383 if (LocaleCompare("clut",option+1) == 0)
7384 {
7385 Image
7386 *clut_image,
7387 *image;
7388
cristy6b3da3a2010-06-20 02:21:46 +00007389 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007390 image=RemoveFirstImageFromList(images);
7391 clut_image=RemoveFirstImageFromList(images);
7392 if (clut_image == (Image *) NULL)
7393 {
7394 status=MagickFalse;
7395 break;
7396 }
7397 (void) ClutImageChannel(image,channel,clut_image);
7398 clut_image=DestroyImage(clut_image);
7399 InheritException(exception,&image->exception);
7400 *images=DestroyImageList(*images);
7401 *images=image;
7402 break;
7403 }
7404 if (LocaleCompare("coalesce",option+1) == 0)
7405 {
7406 Image
7407 *coalesce_image;
7408
cristy6b3da3a2010-06-20 02:21:46 +00007409 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007410 coalesce_image=CoalesceImages(*images,exception);
7411 if (coalesce_image == (Image *) NULL)
7412 {
7413 status=MagickFalse;
7414 break;
7415 }
7416 *images=DestroyImageList(*images);
7417 *images=coalesce_image;
7418 break;
7419 }
7420 if (LocaleCompare("combine",option+1) == 0)
7421 {
7422 Image
7423 *combine_image;
7424
cristy6b3da3a2010-06-20 02:21:46 +00007425 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007426 combine_image=CombineImages(*images,channel,exception);
7427 if (combine_image == (Image *) NULL)
7428 {
7429 status=MagickFalse;
7430 break;
7431 }
7432 *images=DestroyImageList(*images);
7433 *images=combine_image;
7434 break;
7435 }
7436 if (LocaleCompare("composite",option+1) == 0)
7437 {
7438 Image
7439 *mask_image,
7440 *composite_image,
7441 *image;
7442
7443 RectangleInfo
7444 geometry;
7445
cristy6b3da3a2010-06-20 02:21:46 +00007446 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007447 image=RemoveFirstImageFromList(images);
7448 composite_image=RemoveFirstImageFromList(images);
7449 if (composite_image == (Image *) NULL)
7450 {
7451 status=MagickFalse;
7452 break;
7453 }
7454 (void) TransformImage(&composite_image,(char *) NULL,
7455 composite_image->geometry);
7456 SetGeometry(composite_image,&geometry);
7457 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7458 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7459 &geometry);
7460 mask_image=RemoveFirstImageFromList(images);
7461 if (mask_image != (Image *) NULL)
7462 {
7463 if ((image->compose == DisplaceCompositeOp) ||
7464 (image->compose == DistortCompositeOp))
7465 {
7466 /*
7467 Merge Y displacement into X displacement image.
7468 */
7469 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7470 mask_image,0,0);
7471 mask_image=DestroyImage(mask_image);
7472 }
7473 else
7474 {
7475 /*
7476 Set a blending mask for the composition.
7477 */
anthonya129f702011-04-14 01:08:48 +00007478 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007479 image->mask=mask_image;
7480 (void) NegateImage(image->mask,MagickFalse);
7481 }
7482 }
7483 (void) CompositeImageChannel(image,channel,image->compose,
7484 composite_image,geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007485 if (mask_image != (Image *) NULL)
7486 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007487 composite_image=DestroyImage(composite_image);
7488 InheritException(exception,&image->exception);
7489 *images=DestroyImageList(*images);
7490 *images=image;
7491 break;
7492 }
anthony9f4f0342011-03-28 11:47:22 +00007493#if 0
7494This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007495 if (LocaleCompare("crop",option+1) == 0)
7496 {
7497 MagickStatusType
7498 flags;
7499
7500 RectangleInfo
7501 geometry;
7502
anthonye9c27192011-03-27 08:07:06 +00007503 /*
anthony9f4f0342011-03-28 11:47:22 +00007504 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007505 */
cristy6b3da3a2010-06-20 02:21:46 +00007506 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007507 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7508 if (((geometry.width == 0) && (geometry.height == 0)) ||
7509 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7510 break;
7511 (void) TransformImages(images,argv[i+1],(char *) NULL);
7512 InheritException(exception,&(*images)->exception);
7513 break;
7514 }
anthony9f4f0342011-03-28 11:47:22 +00007515#endif
cristy3ed852e2009-09-05 21:47:34 +00007516 break;
7517 }
7518 case 'd':
7519 {
7520 if (LocaleCompare("deconstruct",option+1) == 0)
7521 {
7522 Image
7523 *deconstruct_image;
7524
cristy6b3da3a2010-06-20 02:21:46 +00007525 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007526 deconstruct_image=DeconstructImages(*images,exception);
7527 if (deconstruct_image == (Image *) NULL)
7528 {
7529 status=MagickFalse;
7530 break;
7531 }
7532 *images=DestroyImageList(*images);
7533 *images=deconstruct_image;
7534 break;
7535 }
7536 if (LocaleCompare("delete",option+1) == 0)
7537 {
7538 if (*option == '+')
7539 DeleteImages(images,"-1",exception);
7540 else
7541 DeleteImages(images,argv[i+1],exception);
7542 break;
7543 }
7544 if (LocaleCompare("dither",option+1) == 0)
7545 {
7546 if (*option == '+')
7547 {
7548 quantize_info->dither=MagickFalse;
7549 break;
7550 }
7551 quantize_info->dither=MagickTrue;
7552 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7553 MagickDitherOptions,MagickFalse,argv[i+1]);
7554 break;
7555 }
cristyecb10ff2011-03-22 13:14:03 +00007556 if (LocaleCompare("duplicate",option+1) == 0)
7557 {
cristy72988482011-03-29 16:34:38 +00007558 Image
7559 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007560
anthony2b6bcae2011-03-23 13:05:34 +00007561 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007562 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7563 else
7564 {
7565 const char
7566 *p;
7567
anthony2b6bcae2011-03-23 13:05:34 +00007568 size_t
7569 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007570
anthony2b6bcae2011-03-23 13:05:34 +00007571 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007572 p=strchr(argv[i+1],',');
7573 if (p == (const char *) NULL)
7574 duplicate_images=DuplicateImages(*images,number_duplicates,
7575 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007576 else
cristy72988482011-03-29 16:34:38 +00007577 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7578 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007579 }
7580 AppendImageToList(images, duplicate_images);
7581 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007582 break;
7583 }
cristy3ed852e2009-09-05 21:47:34 +00007584 break;
7585 }
cristyd18ae7c2010-03-07 17:39:52 +00007586 case 'e':
7587 {
7588 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7589 {
7590 Image
7591 *evaluate_image;
7592
7593 MagickEvaluateOperator
7594 op;
7595
cristy6b3da3a2010-06-20 02:21:46 +00007596 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007597 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7598 MagickFalse,argv[i+1]);
7599 evaluate_image=EvaluateImages(*images,op,exception);
7600 if (evaluate_image == (Image *) NULL)
7601 {
7602 status=MagickFalse;
7603 break;
7604 }
7605 *images=DestroyImageList(*images);
7606 *images=evaluate_image;
7607 break;
7608 }
7609 break;
7610 }
cristy3ed852e2009-09-05 21:47:34 +00007611 case 'f':
7612 {
cristyf0a247f2009-10-04 00:20:03 +00007613 if (LocaleCompare("fft",option+1) == 0)
7614 {
7615 Image
7616 *fourier_image;
7617
7618 /*
7619 Implements the discrete Fourier transform (DFT).
7620 */
cristy6b3da3a2010-06-20 02:21:46 +00007621 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007622 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7623 MagickTrue : MagickFalse,exception);
7624 if (fourier_image == (Image *) NULL)
7625 break;
7626 *images=DestroyImage(*images);
7627 *images=fourier_image;
7628 break;
7629 }
cristy3ed852e2009-09-05 21:47:34 +00007630 if (LocaleCompare("flatten",option+1) == 0)
7631 {
7632 Image
7633 *flatten_image;
7634
cristy6b3da3a2010-06-20 02:21:46 +00007635 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007636 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7637 if (flatten_image == (Image *) NULL)
7638 break;
7639 *images=DestroyImageList(*images);
7640 *images=flatten_image;
7641 break;
7642 }
7643 if (LocaleCompare("fx",option+1) == 0)
7644 {
7645 Image
7646 *fx_image;
7647
cristy6b3da3a2010-06-20 02:21:46 +00007648 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007649 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7650 if (fx_image == (Image *) NULL)
7651 {
7652 status=MagickFalse;
7653 break;
7654 }
7655 *images=DestroyImageList(*images);
7656 *images=fx_image;
7657 break;
7658 }
7659 break;
7660 }
7661 case 'h':
7662 {
7663 if (LocaleCompare("hald-clut",option+1) == 0)
7664 {
7665 Image
7666 *hald_image,
7667 *image;
7668
cristy6b3da3a2010-06-20 02:21:46 +00007669 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007670 image=RemoveFirstImageFromList(images);
7671 hald_image=RemoveFirstImageFromList(images);
7672 if (hald_image == (Image *) NULL)
7673 {
7674 status=MagickFalse;
7675 break;
7676 }
7677 (void) HaldClutImageChannel(image,channel,hald_image);
7678 hald_image=DestroyImage(hald_image);
7679 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007680 if (*images != (Image *) NULL)
7681 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007682 *images=image;
7683 break;
7684 }
7685 break;
7686 }
7687 case 'i':
7688 {
7689 if (LocaleCompare("ift",option+1) == 0)
7690 {
7691 Image
cristy8587f882009-11-13 20:28:49 +00007692 *fourier_image,
7693 *magnitude_image,
7694 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007695
7696 /*
7697 Implements the inverse fourier discrete Fourier transform (DFT).
7698 */
cristy6b3da3a2010-06-20 02:21:46 +00007699 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007700 magnitude_image=RemoveFirstImageFromList(images);
7701 phase_image=RemoveFirstImageFromList(images);
7702 if (phase_image == (Image *) NULL)
7703 {
7704 status=MagickFalse;
7705 break;
7706 }
7707 fourier_image=InverseFourierTransformImage(magnitude_image,
7708 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007709 if (fourier_image == (Image *) NULL)
7710 break;
cristy0aff6ea2009-11-14 01:40:53 +00007711 if (*images != (Image *) NULL)
7712 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007713 *images=fourier_image;
7714 break;
7715 }
7716 if (LocaleCompare("insert",option+1) == 0)
7717 {
7718 Image
7719 *p,
7720 *q;
7721
7722 index=0;
7723 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007724 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007725 p=RemoveLastImageFromList(images);
7726 if (p == (Image *) NULL)
7727 {
7728 (void) ThrowMagickException(exception,GetMagickModule(),
7729 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7730 status=MagickFalse;
7731 break;
7732 }
7733 q=p;
7734 if (index == 0)
7735 PrependImageToList(images,q);
7736 else
cristybb503372010-05-27 20:51:26 +00007737 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007738 AppendImageToList(images,q);
7739 else
7740 {
7741 q=GetImageFromList(*images,index-1);
7742 if (q == (Image *) NULL)
7743 {
7744 (void) ThrowMagickException(exception,GetMagickModule(),
7745 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7746 status=MagickFalse;
7747 break;
7748 }
7749 InsertImageInList(&q,p);
7750 }
7751 *images=GetFirstImageInList(q);
7752 break;
7753 }
7754 break;
7755 }
7756 case 'l':
7757 {
7758 if (LocaleCompare("layers",option+1) == 0)
7759 {
7760 Image
7761 *layers;
7762
7763 ImageLayerMethod
7764 method;
7765
cristy6b3da3a2010-06-20 02:21:46 +00007766 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007767 layers=(Image *) NULL;
7768 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7769 MagickFalse,argv[i+1]);
7770 switch (method)
7771 {
7772 case CoalesceLayer:
7773 {
7774 layers=CoalesceImages(*images,exception);
7775 break;
7776 }
7777 case CompareAnyLayer:
7778 case CompareClearLayer:
7779 case CompareOverlayLayer:
7780 default:
7781 {
7782 layers=CompareImageLayers(*images,method,exception);
7783 break;
7784 }
7785 case MergeLayer:
7786 case FlattenLayer:
7787 case MosaicLayer:
7788 case TrimBoundsLayer:
7789 {
7790 layers=MergeImageLayers(*images,method,exception);
7791 break;
7792 }
7793 case DisposeLayer:
7794 {
7795 layers=DisposeImages(*images,exception);
7796 break;
7797 }
7798 case OptimizeImageLayer:
7799 {
7800 layers=OptimizeImageLayers(*images,exception);
7801 break;
7802 }
7803 case OptimizePlusLayer:
7804 {
7805 layers=OptimizePlusImageLayers(*images,exception);
7806 break;
7807 }
7808 case OptimizeTransLayer:
7809 {
7810 OptimizeImageTransparency(*images,exception);
7811 break;
7812 }
7813 case RemoveDupsLayer:
7814 {
7815 RemoveDuplicateLayers(images,exception);
7816 break;
7817 }
7818 case RemoveZeroLayer:
7819 {
7820 RemoveZeroDelayLayers(images,exception);
7821 break;
7822 }
7823 case OptimizeLayer:
7824 {
7825 /*
7826 General Purpose, GIF Animation Optimizer.
7827 */
7828 layers=CoalesceImages(*images,exception);
7829 if (layers == (Image *) NULL)
7830 {
7831 status=MagickFalse;
7832 break;
7833 }
7834 InheritException(exception,&layers->exception);
7835 *images=DestroyImageList(*images);
7836 *images=layers;
7837 layers=OptimizeImageLayers(*images,exception);
7838 if (layers == (Image *) NULL)
7839 {
7840 status=MagickFalse;
7841 break;
7842 }
7843 InheritException(exception,&layers->exception);
7844 *images=DestroyImageList(*images);
7845 *images=layers;
7846 layers=(Image *) NULL;
7847 OptimizeImageTransparency(*images,exception);
7848 InheritException(exception,&(*images)->exception);
7849 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7850 break;
7851 }
7852 case CompositeLayer:
7853 {
7854 CompositeOperator
7855 compose;
7856
7857 Image
7858 *source;
7859
7860 RectangleInfo
7861 geometry;
7862
7863 /*
7864 Split image sequence at the first 'NULL:' image.
7865 */
7866 source=(*images);
7867 while (source != (Image *) NULL)
7868 {
7869 source=GetNextImageInList(source);
7870 if ((source != (Image *) NULL) &&
7871 (LocaleCompare(source->magick,"NULL") == 0))
7872 break;
7873 }
7874 if (source != (Image *) NULL)
7875 {
7876 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7877 (GetNextImageInList(source) == (Image *) NULL))
7878 source=(Image *) NULL;
7879 else
7880 {
7881 /*
7882 Separate the two lists, junk the null: image.
7883 */
7884 source=SplitImageList(source->previous);
7885 DeleteImageFromList(&source);
7886 }
7887 }
7888 if (source == (Image *) NULL)
7889 {
7890 (void) ThrowMagickException(exception,GetMagickModule(),
7891 OptionError,"MissingNullSeparator","layers Composite");
7892 status=MagickFalse;
7893 break;
7894 }
7895 /*
7896 Adjust offset with gravity and virtual canvas.
7897 */
7898 SetGeometry(*images,&geometry);
7899 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7900 geometry.width=source->page.width != 0 ?
7901 source->page.width : source->columns;
7902 geometry.height=source->page.height != 0 ?
7903 source->page.height : source->rows;
7904 GravityAdjustGeometry((*images)->page.width != 0 ?
7905 (*images)->page.width : (*images)->columns,
7906 (*images)->page.height != 0 ? (*images)->page.height :
7907 (*images)->rows,(*images)->gravity,&geometry);
7908 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007909 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007910 if (option != (const char *) NULL)
7911 compose=(CompositeOperator) ParseMagickOption(
7912 MagickComposeOptions,MagickFalse,option);
7913 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7914 exception);
7915 source=DestroyImageList(source);
7916 break;
7917 }
7918 }
7919 if (layers == (Image *) NULL)
7920 break;
7921 InheritException(exception,&layers->exception);
7922 *images=DestroyImageList(*images);
7923 *images=layers;
7924 break;
7925 }
7926 break;
7927 }
7928 case 'm':
7929 {
7930 if (LocaleCompare("map",option+1) == 0)
7931 {
cristy6b3da3a2010-06-20 02:21:46 +00007932 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007933 if (*option == '+')
7934 {
7935 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7936 InheritException(exception,&(*images)->exception);
7937 break;
7938 }
7939 i++;
7940 break;
7941 }
cristyf40785b2010-03-06 02:27:27 +00007942 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007943 {
7944 Image
cristyf40785b2010-03-06 02:27:27 +00007945 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007946
cristyd18ae7c2010-03-07 17:39:52 +00007947 /*
7948 Maximum image sequence (deprecated).
7949 */
cristy6b3da3a2010-06-20 02:21:46 +00007950 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007951 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007952 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007953 {
7954 status=MagickFalse;
7955 break;
7956 }
7957 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007958 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007959 break;
7960 }
cristyf40785b2010-03-06 02:27:27 +00007961 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007962 {
7963 Image
cristyf40785b2010-03-06 02:27:27 +00007964 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007965
cristyd18ae7c2010-03-07 17:39:52 +00007966 /*
7967 Minimum image sequence (deprecated).
7968 */
cristy6b3da3a2010-06-20 02:21:46 +00007969 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007970 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007971 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007972 {
7973 status=MagickFalse;
7974 break;
7975 }
7976 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007977 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007978 break;
7979 }
cristy3ed852e2009-09-05 21:47:34 +00007980 if (LocaleCompare("morph",option+1) == 0)
7981 {
7982 Image
7983 *morph_image;
7984
cristy6b3da3a2010-06-20 02:21:46 +00007985 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007986 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007987 exception);
7988 if (morph_image == (Image *) NULL)
7989 {
7990 status=MagickFalse;
7991 break;
7992 }
7993 *images=DestroyImageList(*images);
7994 *images=morph_image;
7995 break;
7996 }
7997 if (LocaleCompare("mosaic",option+1) == 0)
7998 {
7999 Image
8000 *mosaic_image;
8001
cristy6b3da3a2010-06-20 02:21:46 +00008002 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008003 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8004 if (mosaic_image == (Image *) NULL)
8005 {
8006 status=MagickFalse;
8007 break;
8008 }
8009 *images=DestroyImageList(*images);
8010 *images=mosaic_image;
8011 break;
8012 }
8013 break;
8014 }
8015 case 'p':
8016 {
8017 if (LocaleCompare("print",option+1) == 0)
8018 {
8019 char
8020 *string;
8021
cristy6b3da3a2010-06-20 02:21:46 +00008022 (void) SyncImagesSettings(mogrify_info,*images);
8023 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008024 if (string == (char *) NULL)
8025 break;
8026 InheritException(exception,&(*images)->exception);
8027 (void) fprintf(stdout,"%s",string);
8028 string=DestroyString(string);
8029 }
8030 if (LocaleCompare("process",option+1) == 0)
8031 {
8032 char
8033 **arguments;
8034
8035 int
8036 j,
8037 number_arguments;
8038
cristy6b3da3a2010-06-20 02:21:46 +00008039 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008040 arguments=StringToArgv(argv[i+1],&number_arguments);
8041 if (arguments == (char **) NULL)
8042 break;
8043 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8044 {
8045 char
8046 breaker,
8047 quote,
8048 *token;
8049
8050 const char
8051 *arguments;
8052
8053 int
8054 next,
8055 status;
8056
8057 size_t
8058 length;
8059
8060 TokenInfo
8061 *token_info;
8062
8063 /*
8064 Support old style syntax, filter="-option arg".
8065 */
8066 length=strlen(argv[i+1]);
8067 token=(char *) NULL;
8068 if (~length >= MaxTextExtent)
8069 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8070 sizeof(*token));
8071 if (token == (char *) NULL)
8072 break;
8073 next=0;
8074 arguments=argv[i+1];
8075 token_info=AcquireTokenInfo();
8076 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8077 "\"",'\0',&breaker,&next,&quote);
8078 token_info=DestroyTokenInfo(token_info);
8079 if (status == 0)
8080 {
8081 const char
8082 *argv;
8083
8084 argv=(&(arguments[next]));
8085 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8086 exception);
8087 }
8088 token=DestroyString(token);
8089 break;
8090 }
cristy91c0da22010-05-02 01:44:07 +00008091 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008092 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8093 number_arguments-2,(const char **) arguments+2,exception);
8094 for (j=0; j < number_arguments; j++)
8095 arguments[j]=DestroyString(arguments[j]);
8096 arguments=(char **) RelinquishMagickMemory(arguments);
8097 break;
8098 }
8099 break;
8100 }
8101 case 'r':
8102 {
8103 if (LocaleCompare("reverse",option+1) == 0)
8104 {
8105 ReverseImageList(images);
8106 InheritException(exception,&(*images)->exception);
8107 break;
8108 }
8109 break;
8110 }
8111 case 's':
8112 {
cristy4285d782011-02-09 20:12:28 +00008113 if (LocaleCompare("smush",option+1) == 0)
8114 {
8115 Image
8116 *smush_image;
8117
8118 ssize_t
8119 offset;
8120
8121 (void) SyncImagesSettings(mogrify_info,*images);
8122 offset=(ssize_t) StringToLong(argv[i+1]);
8123 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8124 MagickFalse,offset,exception);
8125 if (smush_image == (Image *) NULL)
8126 {
8127 status=MagickFalse;
8128 break;
8129 }
8130 *images=DestroyImageList(*images);
8131 *images=smush_image;
8132 break;
8133 }
cristy3ed852e2009-09-05 21:47:34 +00008134 if (LocaleCompare("swap",option+1) == 0)
8135 {
8136 Image
8137 *p,
8138 *q,
8139 *swap;
8140
cristybb503372010-05-27 20:51:26 +00008141 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008142 swap_index;
8143
8144 index=(-1);
8145 swap_index=(-2);
8146 if (*option != '+')
8147 {
8148 GeometryInfo
8149 geometry_info;
8150
8151 MagickStatusType
8152 flags;
8153
8154 swap_index=(-1);
8155 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008156 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008157 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008158 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008159 }
8160 p=GetImageFromList(*images,index);
8161 q=GetImageFromList(*images,swap_index);
8162 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8163 {
8164 (void) ThrowMagickException(exception,GetMagickModule(),
8165 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8166 status=MagickFalse;
8167 break;
8168 }
8169 if (p == q)
8170 break;
8171 swap=CloneImage(p,0,0,MagickTrue,exception);
8172 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8173 ReplaceImageInList(&q,swap);
8174 *images=GetFirstImageInList(q);
8175 break;
8176 }
8177 break;
8178 }
8179 case 'w':
8180 {
8181 if (LocaleCompare("write",option+1) == 0)
8182 {
cristy071dd7b2010-04-09 13:04:54 +00008183 char
cristy06609ee2010-03-17 20:21:27 +00008184 key[MaxTextExtent];
8185
cristy3ed852e2009-09-05 21:47:34 +00008186 Image
8187 *write_images;
8188
8189 ImageInfo
8190 *write_info;
8191
cristy6b3da3a2010-06-20 02:21:46 +00008192 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008193 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8194 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008195 write_images=(*images);
8196 if (*option == '+')
8197 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008198 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008199 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8200 write_info=DestroyImageInfo(write_info);
8201 if (*option == '+')
8202 write_images=DestroyImageList(write_images);
8203 break;
8204 }
8205 break;
8206 }
8207 default:
8208 break;
8209 }
8210 i+=count;
8211 }
8212 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008213 mogrify_info=DestroyImageInfo(mogrify_info);
8214 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008215 return(status != 0 ? MagickTrue : MagickFalse);
8216}
8217
8218/*
8219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8220% %
8221% %
8222% %
8223+ M o g r i f y I m a g e s %
8224% %
8225% %
8226% %
8227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8228%
8229% MogrifyImages() applies image processing options to a sequence of images as
8230% prescribed by command line options.
8231%
8232% The format of the MogrifyImage method is:
8233%
8234% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8235% const MagickBooleanType post,const int argc,const char **argv,
8236% Image **images,Exceptioninfo *exception)
8237%
8238% A description of each parameter follows:
8239%
8240% o image_info: the image info..
8241%
8242% o post: If true, post process image list operators otherwise pre-process.
8243%
8244% o argc: Specifies a pointer to an integer describing the number of
8245% elements in the argument vector.
8246%
8247% o argv: Specifies a pointer to a text array containing the command line
8248% arguments.
8249%
anthonye9c27192011-03-27 08:07:06 +00008250% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008251%
8252% o exception: return any errors or warnings in this structure.
8253%
8254*/
8255WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8256 const MagickBooleanType post,const int argc,const char **argv,
8257 Image **images,ExceptionInfo *exception)
8258{
8259#define MogrifyImageTag "Mogrify/Image"
8260
anthonye9c27192011-03-27 08:07:06 +00008261 MagickStatusType
8262 status;
cristy3ed852e2009-09-05 21:47:34 +00008263
cristy0e9f9c12010-02-11 03:00:47 +00008264 MagickBooleanType
8265 proceed;
8266
anthonye9c27192011-03-27 08:07:06 +00008267 size_t
8268 n;
cristy3ed852e2009-09-05 21:47:34 +00008269
cristybb503372010-05-27 20:51:26 +00008270 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008271 i;
8272
cristy3ed852e2009-09-05 21:47:34 +00008273 assert(image_info != (ImageInfo *) NULL);
8274 assert(image_info->signature == MagickSignature);
8275 if (images == (Image **) NULL)
8276 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008277 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008278 assert((*images)->signature == MagickSignature);
8279 if ((*images)->debug != MagickFalse)
8280 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8281 (*images)->filename);
8282 if ((argc <= 0) || (*argv == (char *) NULL))
8283 return(MagickTrue);
8284 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8285 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008286 status=0;
anthonye9c27192011-03-27 08:07:06 +00008287
8288 /*
8289 Pre-process multi-image sequence operators
8290 */
cristy3ed852e2009-09-05 21:47:34 +00008291 if (post == MagickFalse)
8292 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008293
8294 /*
8295 For each image, process simple single image operators
8296 */
8297 i=0;
8298 n=GetImageListLength(*images);
8299 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008300 {
anthonye9c27192011-03-27 08:07:06 +00008301 status&=MogrifyImage(image_info,argc,argv,images,exception);
8302 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008303 if (proceed == MagickFalse)
8304 break;
anthonye9c27192011-03-27 08:07:06 +00008305 if ( (*images)->next == (Image *) NULL )
8306 break;
8307 *images=(*images)->next;
8308 i++;
cristy3ed852e2009-09-05 21:47:34 +00008309 }
anthonye9c27192011-03-27 08:07:06 +00008310 assert( *images != (Image *) NULL );
8311
8312 /*
8313 Post-process, multi-image sequence operators
8314 */
8315 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008316 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008317 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008318 return(status != 0 ? MagickTrue : MagickFalse);
8319}