blob: 33100c1de827221a1f57f0921c3baebb5b99c165 [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;
anthonyce2716b2011-04-22 09:51:34 +0000685 count=ParseMagickOption(MagickCommandOptions,MagickFalse,option);
686 count=MagickMax(count,0L);
687 count&=NumArgsOption;
cristycee97112010-05-28 00:44:52 +0000688 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000689 break;
cristy6b3da3a2010-06-20 02:21:46 +0000690 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristyd241f442011-03-29 13:50:49 +0000691 mogrify_image=(Image *)NULL;
cristy3ed852e2009-09-05 21:47:34 +0000692 switch (*(option+1))
693 {
694 case 'a':
695 {
696 if (LocaleCompare("adaptive-blur",option+1) == 0)
697 {
cristy3ed852e2009-09-05 21:47:34 +0000698 /*
699 Adaptive blur image.
700 */
cristy6b3da3a2010-06-20 02:21:46 +0000701 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000702 flags=ParseGeometry(argv[i+1],&geometry_info);
703 if ((flags & SigmaValue) == 0)
704 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000705 mogrify_image=AdaptiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +0000706 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000707 break;
708 }
709 if (LocaleCompare("adaptive-resize",option+1) == 0)
710 {
cristy3ed852e2009-09-05 21:47:34 +0000711 /*
712 Adaptive resize image.
713 */
cristy6b3da3a2010-06-20 02:21:46 +0000714 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000715 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +0000716 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +0000717 geometry.height,exception);
cristy3ed852e2009-09-05 21:47:34 +0000718 break;
719 }
720 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
721 {
cristy3ed852e2009-09-05 21:47:34 +0000722 /*
723 Adaptive sharpen image.
724 */
cristy6b3da3a2010-06-20 02:21:46 +0000725 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000726 flags=ParseGeometry(argv[i+1],&geometry_info);
727 if ((flags & SigmaValue) == 0)
728 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000729 mogrify_image=AdaptiveSharpenImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +0000730 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000731 break;
732 }
733 if (LocaleCompare("affine",option+1) == 0)
734 {
735 /*
736 Affine matrix.
737 */
738 if (*option == '+')
739 {
740 GetAffineMatrix(&draw_info->affine);
741 break;
742 }
743 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
744 break;
745 }
746 if (LocaleCompare("alpha",option+1) == 0)
747 {
748 AlphaChannelType
749 alpha_type;
750
cristy6b3da3a2010-06-20 02:21:46 +0000751 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000752 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
753 MagickFalse,argv[i+1]);
754 (void) SetImageAlphaChannel(*image,alpha_type);
755 InheritException(exception,&(*image)->exception);
756 break;
757 }
758 if (LocaleCompare("annotate",option+1) == 0)
759 {
760 char
761 *text,
762 geometry[MaxTextExtent];
763
764 /*
765 Annotate image.
766 */
cristy6b3da3a2010-06-20 02:21:46 +0000767 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000768 SetGeometryInfo(&geometry_info);
769 flags=ParseGeometry(argv[i+1],&geometry_info);
770 if ((flags & SigmaValue) == 0)
771 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000772 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000773 InheritException(exception,&(*image)->exception);
774 if (text == (char *) NULL)
775 break;
776 (void) CloneString(&draw_info->text,text);
777 text=DestroyString(text);
778 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
779 geometry_info.xi,geometry_info.psi);
780 (void) CloneString(&draw_info->geometry,geometry);
781 draw_info->affine.sx=cos(DegreesToRadians(
782 fmod(geometry_info.rho,360.0)));
783 draw_info->affine.rx=sin(DegreesToRadians(
784 fmod(geometry_info.rho,360.0)));
785 draw_info->affine.ry=(-sin(DegreesToRadians(
786 fmod(geometry_info.sigma,360.0))));
787 draw_info->affine.sy=cos(DegreesToRadians(
788 fmod(geometry_info.sigma,360.0)));
789 (void) AnnotateImage(*image,draw_info);
790 InheritException(exception,&(*image)->exception);
791 break;
792 }
793 if (LocaleCompare("antialias",option+1) == 0)
794 {
795 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
796 MagickFalse;
797 draw_info->text_antialias=(*option == '-') ? MagickTrue :
798 MagickFalse;
799 break;
800 }
801 if (LocaleCompare("auto-gamma",option+1) == 0)
802 {
803 /*
804 Auto Adjust Gamma of image based on its mean
805 */
cristy6b3da3a2010-06-20 02:21:46 +0000806 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000807 (void) AutoGammaImageChannel(*image,channel);
808 break;
809 }
810 if (LocaleCompare("auto-level",option+1) == 0)
811 {
812 /*
813 Perfectly Normalize (max/min stretch) the image
814 */
cristy6b3da3a2010-06-20 02:21:46 +0000815 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000816 (void) AutoLevelImageChannel(*image,channel);
817 break;
818 }
819 if (LocaleCompare("auto-orient",option+1) == 0)
820 {
cristy6b3da3a2010-06-20 02:21:46 +0000821 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000822 switch ((*image)->orientation)
823 {
824 case TopRightOrientation:
825 {
cristyd241f442011-03-29 13:50:49 +0000826 mogrify_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000827 break;
828 }
829 case BottomRightOrientation:
830 {
cristyd241f442011-03-29 13:50:49 +0000831 mogrify_image=RotateImage(*image,180.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000832 break;
833 }
834 case BottomLeftOrientation:
835 {
cristyd241f442011-03-29 13:50:49 +0000836 mogrify_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000837 break;
838 }
839 case LeftTopOrientation:
840 {
cristyd241f442011-03-29 13:50:49 +0000841 mogrify_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000842 break;
843 }
844 case RightTopOrientation:
845 {
cristyd241f442011-03-29 13:50:49 +0000846 mogrify_image=RotateImage(*image,90.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000847 break;
848 }
849 case RightBottomOrientation:
850 {
cristyd241f442011-03-29 13:50:49 +0000851 mogrify_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000852 break;
853 }
854 case LeftBottomOrientation:
855 {
cristyd241f442011-03-29 13:50:49 +0000856 mogrify_image=RotateImage(*image,270.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000857 break;
858 }
859 default:
860 break;
861 }
cristyd241f442011-03-29 13:50:49 +0000862 if (mogrify_image != (Image *) NULL)
863 mogrify_image->orientation=TopLeftOrientation;
cristy3ed852e2009-09-05 21:47:34 +0000864 break;
865 }
866 break;
867 }
868 case 'b':
869 {
870 if (LocaleCompare("black-threshold",option+1) == 0)
871 {
872 /*
873 Black threshold image.
874 */
cristy6b3da3a2010-06-20 02:21:46 +0000875 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000876 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
877 exception);
878 InheritException(exception,&(*image)->exception);
879 break;
880 }
881 if (LocaleCompare("blue-shift",option+1) == 0)
882 {
cristy3ed852e2009-09-05 21:47:34 +0000883 /*
884 Blue shift image.
885 */
cristy6b3da3a2010-06-20 02:21:46 +0000886 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000887 geometry_info.rho=1.5;
888 if (*option == '-')
889 flags=ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +0000890 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +0000891 break;
892 }
893 if (LocaleCompare("blur",option+1) == 0)
894 {
cristy3ed852e2009-09-05 21:47:34 +0000895 /*
896 Gaussian blur image.
897 */
cristy6b3da3a2010-06-20 02:21:46 +0000898 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000899 flags=ParseGeometry(argv[i+1],&geometry_info);
900 if ((flags & SigmaValue) == 0)
901 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000902 mogrify_image=BlurImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +0000903 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000904 break;
905 }
906 if (LocaleCompare("border",option+1) == 0)
907 {
cristy3ed852e2009-09-05 21:47:34 +0000908 /*
909 Surround image with a border of solid color.
910 */
cristy6b3da3a2010-06-20 02:21:46 +0000911 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000912 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
913 if ((flags & SigmaValue) == 0)
914 geometry.height=geometry.width;
cristyd241f442011-03-29 13:50:49 +0000915 mogrify_image=BorderImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +0000916 break;
917 }
918 if (LocaleCompare("bordercolor",option+1) == 0)
919 {
920 if (*option == '+')
921 {
922 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
923 exception);
924 break;
925 }
926 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
927 exception);
928 break;
929 }
930 if (LocaleCompare("box",option+1) == 0)
931 {
932 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
933 exception);
934 break;
935 }
cristya28d6b82010-01-11 20:03:47 +0000936 if (LocaleCompare("brightness-contrast",option+1) == 0)
937 {
938 double
939 brightness,
940 contrast;
941
942 GeometryInfo
943 geometry_info;
944
945 MagickStatusType
946 flags;
947
948 /*
949 Brightness / contrast image.
950 */
cristy6b3da3a2010-06-20 02:21:46 +0000951 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000952 flags=ParseGeometry(argv[i+1],&geometry_info);
953 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000954 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000955 if ((flags & SigmaValue) != 0)
956 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000957 (void) BrightnessContrastImageChannel(*image,channel,brightness,
958 contrast);
cristya28d6b82010-01-11 20:03:47 +0000959 InheritException(exception,&(*image)->exception);
960 break;
961 }
cristy3ed852e2009-09-05 21:47:34 +0000962 break;
963 }
964 case 'c':
965 {
966 if (LocaleCompare("cdl",option+1) == 0)
967 {
968 char
969 *color_correction_collection;
970
971 /*
972 Color correct with a color decision list.
973 */
cristy6b3da3a2010-06-20 02:21:46 +0000974 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000975 color_correction_collection=FileToString(argv[i+1],~0,exception);
976 if (color_correction_collection == (char *) NULL)
977 break;
978 (void) ColorDecisionListImage(*image,color_correction_collection);
979 InheritException(exception,&(*image)->exception);
980 break;
981 }
982 if (LocaleCompare("channel",option+1) == 0)
983 {
984 if (*option == '+')
cristy3ed852e2009-09-05 21:47:34 +0000985 channel=DefaultChannels;
anthonye9c27192011-03-27 08:07:06 +0000986 else
987 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +0000988 break;
989 }
990 if (LocaleCompare("charcoal",option+1) == 0)
991 {
cristy3ed852e2009-09-05 21:47:34 +0000992 /*
993 Charcoal image.
994 */
cristy6b3da3a2010-06-20 02:21:46 +0000995 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000996 flags=ParseGeometry(argv[i+1],&geometry_info);
997 if ((flags & SigmaValue) == 0)
998 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000999 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00001000 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001001 break;
1002 }
1003 if (LocaleCompare("chop",option+1) == 0)
1004 {
cristy3ed852e2009-09-05 21:47:34 +00001005 /*
1006 Chop the image.
1007 */
cristy6b3da3a2010-06-20 02:21:46 +00001008 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001009 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00001010 mogrify_image=ChopImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00001011 break;
1012 }
cristy1eb45dd2009-09-25 16:38:06 +00001013 if (LocaleCompare("clamp",option+1) == 0)
1014 {
1015 /*
1016 Clamp image.
1017 */
cristy6b3da3a2010-06-20 02:21:46 +00001018 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001019 (void) ClampImageChannel(*image,channel);
1020 InheritException(exception,&(*image)->exception);
1021 break;
1022 }
cristy3ed852e2009-09-05 21:47:34 +00001023 if (LocaleCompare("clip",option+1) == 0)
1024 {
cristy6b3da3a2010-06-20 02:21:46 +00001025 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001026 if (*option == '+')
1027 {
1028 (void) SetImageClipMask(*image,(Image *) NULL);
1029 InheritException(exception,&(*image)->exception);
1030 break;
1031 }
1032 (void) ClipImage(*image);
1033 InheritException(exception,&(*image)->exception);
1034 break;
1035 }
1036 if (LocaleCompare("clip-mask",option+1) == 0)
1037 {
cristyb0d3bb92010-09-22 14:37:58 +00001038 CacheView
1039 *mask_view;
cristya01cbea2010-11-03 16:33:33 +00001040
cristy3ed852e2009-09-05 21:47:34 +00001041 Image
cristyb0d3bb92010-09-22 14:37:58 +00001042 *mask_image;
cristy3ed852e2009-09-05 21:47:34 +00001043
cristy9d314ff2011-03-09 01:30:28 +00001044 register PixelPacket
1045 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001046
cristybb503372010-05-27 20:51:26 +00001047 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001048 x;
1049
cristy9d314ff2011-03-09 01:30:28 +00001050 ssize_t
1051 y;
cristy3ed852e2009-09-05 21:47:34 +00001052
cristy6b3da3a2010-06-20 02:21:46 +00001053 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001054 if (*option == '+')
1055 {
1056 /*
1057 Remove a mask.
1058 */
1059 (void) SetImageMask(*image,(Image *) NULL);
1060 InheritException(exception,&(*image)->exception);
1061 break;
1062 }
1063 /*
1064 Set the image mask.
anthony77cc4a42011-04-14 02:59:06 +00001065 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
cristy3ed852e2009-09-05 21:47:34 +00001066 */
cristyb0d3bb92010-09-22 14:37:58 +00001067 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1068 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001069 break;
cristyb0d3bb92010-09-22 14:37:58 +00001070 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1071 return(MagickFalse);
1072 mask_view=AcquireCacheView(mask_image);
1073 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001074 {
cristyb0d3bb92010-09-22 14:37:58 +00001075 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1076 exception);
cristy3ed852e2009-09-05 21:47:34 +00001077 if (q == (PixelPacket *) NULL)
1078 break;
cristyb0d3bb92010-09-22 14:37:58 +00001079 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001080 {
cristyb0d3bb92010-09-22 14:37:58 +00001081 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001082 q->opacity=PixelIntensityToQuantum(q);
1083 q->red=q->opacity;
1084 q->green=q->opacity;
1085 q->blue=q->opacity;
1086 q++;
1087 }
cristyb0d3bb92010-09-22 14:37:58 +00001088 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001089 break;
1090 }
cristyb0d3bb92010-09-22 14:37:58 +00001091 mask_view=DestroyCacheView(mask_view);
1092 mask_image->matte=MagickTrue;
1093 (void) SetImageClipMask(*image,mask_image);
1094 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001095 InheritException(exception,&(*image)->exception);
1096 break;
1097 }
1098 if (LocaleCompare("clip-path",option+1) == 0)
1099 {
cristy6b3da3a2010-06-20 02:21:46 +00001100 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001101 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1102 MagickFalse);
1103 InheritException(exception,&(*image)->exception);
1104 break;
1105 }
1106 if (LocaleCompare("colorize",option+1) == 0)
1107 {
cristy3ed852e2009-09-05 21:47:34 +00001108 /*
1109 Colorize the image.
1110 */
cristy6b3da3a2010-06-20 02:21:46 +00001111 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001112 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
cristy3ed852e2009-09-05 21:47:34 +00001113 exception);
cristy3ed852e2009-09-05 21:47:34 +00001114 break;
1115 }
cristye6365592010-04-02 17:31:23 +00001116 if (LocaleCompare("color-matrix",option+1) == 0)
1117 {
cristye6365592010-04-02 17:31:23 +00001118 KernelInfo
1119 *kernel;
1120
cristy6b3da3a2010-06-20 02:21:46 +00001121 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001122 kernel=AcquireKernelInfo(argv[i+1]);
1123 if (kernel == (KernelInfo *) NULL)
1124 break;
cristyd241f442011-03-29 13:50:49 +00001125 mogrify_image=ColorMatrixImage(*image,kernel,exception);
cristye6365592010-04-02 17:31:23 +00001126 kernel=DestroyKernelInfo(kernel);
cristye6365592010-04-02 17:31:23 +00001127 break;
1128 }
cristy3ed852e2009-09-05 21:47:34 +00001129 if (LocaleCompare("colors",option+1) == 0)
1130 {
1131 /*
1132 Reduce the number of colors in the image.
1133 */
cristy6b3da3a2010-06-20 02:21:46 +00001134 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001135 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001136 if (quantize_info->number_colors == 0)
1137 break;
1138 if (((*image)->storage_class == DirectClass) ||
1139 (*image)->colors > quantize_info->number_colors)
1140 (void) QuantizeImage(quantize_info,*image);
1141 else
1142 (void) CompressImageColormap(*image);
1143 InheritException(exception,&(*image)->exception);
1144 break;
1145 }
1146 if (LocaleCompare("colorspace",option+1) == 0)
1147 {
1148 ColorspaceType
1149 colorspace;
1150
cristy6b3da3a2010-06-20 02:21:46 +00001151 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001152 if (*option == '+')
1153 {
1154 (void) TransformImageColorspace(*image,RGBColorspace);
1155 InheritException(exception,&(*image)->exception);
1156 break;
1157 }
1158 colorspace=(ColorspaceType) ParseMagickOption(
1159 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1160 (void) TransformImageColorspace(*image,colorspace);
1161 InheritException(exception,&(*image)->exception);
1162 break;
1163 }
1164 if (LocaleCompare("contrast",option+1) == 0)
1165 {
cristy6b3da3a2010-06-20 02:21:46 +00001166 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001167 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1168 MagickFalse);
1169 InheritException(exception,&(*image)->exception);
1170 break;
1171 }
1172 if (LocaleCompare("contrast-stretch",option+1) == 0)
1173 {
1174 double
1175 black_point,
1176 white_point;
1177
cristy3ed852e2009-09-05 21:47:34 +00001178 MagickStatusType
1179 flags;
1180
1181 /*
1182 Contrast stretch image.
1183 */
cristy6b3da3a2010-06-20 02:21:46 +00001184 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001185 flags=ParseGeometry(argv[i+1],&geometry_info);
1186 black_point=geometry_info.rho;
1187 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1188 black_point;
1189 if ((flags & PercentValue) != 0)
1190 {
1191 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1192 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1193 }
1194 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1195 white_point;
1196 (void) ContrastStretchImageChannel(*image,channel,black_point,
1197 white_point);
1198 InheritException(exception,&(*image)->exception);
1199 break;
1200 }
1201 if (LocaleCompare("convolve",option+1) == 0)
1202 {
cristy36826ab2010-03-06 01:29:30 +00001203 double
1204 gamma;
1205
cristy2be15382010-01-21 02:38:03 +00001206 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001207 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001208
cristybb503372010-05-27 20:51:26 +00001209 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001210 j;
1211
cristy6b3da3a2010-06-20 02:21:46 +00001212 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001213 kernel=AcquireKernelInfo(argv[i+1]);
1214 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001215 break;
cristy36826ab2010-03-06 01:29:30 +00001216 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001217 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001218 gamma+=kernel->values[j];
1219 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001220 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001221 kernel->values[j]*=gamma;
cristyd241f442011-03-29 13:50:49 +00001222 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001223 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001224 break;
1225 }
1226 if (LocaleCompare("crop",option+1) == 0)
1227 {
anthonye9c27192011-03-27 08:07:06 +00001228 /*
1229 Crop a image to a smaller size
anthonye9c27192011-03-27 08:07:06 +00001230 */
cristy6b3da3a2010-06-20 02:21:46 +00001231 (void) SyncImageSettings(mogrify_info,*image);
anthony9f4f0342011-03-28 11:47:22 +00001232#if 0
cristy3ed852e2009-09-05 21:47:34 +00001233 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1234 if (((geometry.width != 0) || (geometry.height != 0)) &&
1235 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1236 break;
anthony9f4f0342011-03-28 11:47:22 +00001237#endif
1238#if 0
cristyd241f442011-03-29 13:50:49 +00001239 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1240 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1241 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1242 InheritException(exception,&mogrify_image->exception);
anthony9f4f0342011-03-28 11:47:22 +00001243#else
cristyd241f442011-03-29 13:50:49 +00001244 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthony9f4f0342011-03-28 11:47:22 +00001245#endif
cristy3ed852e2009-09-05 21:47:34 +00001246 break;
1247 }
1248 if (LocaleCompare("cycle",option+1) == 0)
1249 {
1250 /*
1251 Cycle an image colormap.
1252 */
cristy6b3da3a2010-06-20 02:21:46 +00001253 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001254 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001255 InheritException(exception,&(*image)->exception);
1256 break;
1257 }
1258 break;
1259 }
1260 case 'd':
1261 {
1262 if (LocaleCompare("decipher",option+1) == 0)
1263 {
1264 StringInfo
1265 *passkey;
1266
1267 /*
1268 Decipher pixels.
1269 */
cristy6b3da3a2010-06-20 02:21:46 +00001270 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001271 passkey=FileToStringInfo(argv[i+1],~0,exception);
1272 if (passkey != (StringInfo *) NULL)
1273 {
1274 (void) PasskeyDecipherImage(*image,passkey,exception);
1275 passkey=DestroyStringInfo(passkey);
1276 }
1277 break;
1278 }
1279 if (LocaleCompare("density",option+1) == 0)
1280 {
1281 /*
1282 Set image density.
1283 */
1284 (void) CloneString(&draw_info->density,argv[i+1]);
1285 break;
1286 }
1287 if (LocaleCompare("depth",option+1) == 0)
1288 {
cristy6b3da3a2010-06-20 02:21:46 +00001289 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001290 if (*option == '+')
1291 {
1292 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1293 break;
1294 }
cristye27293e2009-12-18 02:53:20 +00001295 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001296 break;
1297 }
1298 if (LocaleCompare("deskew",option+1) == 0)
1299 {
1300 double
1301 threshold;
1302
cristy3ed852e2009-09-05 21:47:34 +00001303 /*
1304 Straighten the image.
1305 */
cristy6b3da3a2010-06-20 02:21:46 +00001306 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001307 if (*option == '+')
1308 threshold=40.0*QuantumRange/100.0;
1309 else
cristyf2f27272009-12-17 14:48:46 +00001310 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00001311 mogrify_image=DeskewImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00001312 break;
1313 }
1314 if (LocaleCompare("despeckle",option+1) == 0)
1315 {
cristy3ed852e2009-09-05 21:47:34 +00001316 /*
1317 Reduce the speckles within an image.
1318 */
cristy6b3da3a2010-06-20 02:21:46 +00001319 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001320 mogrify_image=DespeckleImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001321 break;
1322 }
1323 if (LocaleCompare("display",option+1) == 0)
1324 {
1325 (void) CloneString(&draw_info->server_name,argv[i+1]);
1326 break;
1327 }
cristy3ed852e2009-09-05 21:47:34 +00001328 if (LocaleCompare("distort",option+1) == 0)
1329 {
1330 char
1331 *args,
1332 token[MaxTextExtent];
1333
1334 const char
1335 *p;
1336
1337 DistortImageMethod
1338 method;
1339
1340 double
1341 *arguments;
1342
cristybb503372010-05-27 20:51:26 +00001343 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001344 x;
1345
cristybb503372010-05-27 20:51:26 +00001346 size_t
cristy3ed852e2009-09-05 21:47:34 +00001347 number_arguments;
1348
1349 /*
1350 Distort image.
1351 */
cristy6b3da3a2010-06-20 02:21:46 +00001352 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001353 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1354 MagickFalse,argv[i+1]);
anthony2029ddc2011-03-30 12:13:27 +00001355 if ( method == ResizeDistortion )
1356 {
1357 /* Special Case - Argument is actually a resize geometry!
1358 ** Convert that to an appropriate distortion argument array.
1359 */
1360 double
1361 resize_args[2];
1362 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1363 exception);
1364 resize_args[0]=(double)geometry.width;
1365 resize_args[1]=(double)geometry.height;
1366 mogrify_image=DistortImage(*image,method,(size_t)2,
1367 resize_args,MagickTrue,exception);
1368 break;
1369 }
cristy6b3da3a2010-06-20 02:21:46 +00001370 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001371 InheritException(exception,&(*image)->exception);
1372 if (args == (char *) NULL)
1373 break;
1374 p=(char *) args;
1375 for (x=0; *p != '\0'; x++)
1376 {
1377 GetMagickToken(p,&p,token);
1378 if (*token == ',')
1379 GetMagickToken(p,&p,token);
1380 }
cristybb503372010-05-27 20:51:26 +00001381 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001382 arguments=(double *) AcquireQuantumMemory(number_arguments,
1383 sizeof(*arguments));
1384 if (arguments == (double *) NULL)
1385 ThrowWandFatalException(ResourceLimitFatalError,
1386 "MemoryAllocationFailed",(*image)->filename);
1387 (void) ResetMagickMemory(arguments,0,number_arguments*
1388 sizeof(*arguments));
1389 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001390 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001391 {
1392 GetMagickToken(p,&p,token);
1393 if (*token == ',')
1394 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001395 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001396 }
1397 args=DestroyString(args);
cristyd241f442011-03-29 13:50:49 +00001398 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
cristy3ed852e2009-09-05 21:47:34 +00001399 (*option == '+') ? MagickTrue : MagickFalse,exception);
1400 arguments=(double *) RelinquishMagickMemory(arguments);
cristy3ed852e2009-09-05 21:47:34 +00001401 break;
1402 }
1403 if (LocaleCompare("dither",option+1) == 0)
1404 {
1405 if (*option == '+')
1406 {
1407 quantize_info->dither=MagickFalse;
1408 break;
1409 }
1410 quantize_info->dither=MagickTrue;
1411 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1412 MagickDitherOptions,MagickFalse,argv[i+1]);
1413 if (quantize_info->dither_method == NoDitherMethod)
1414 quantize_info->dither=MagickFalse;
1415 break;
1416 }
1417 if (LocaleCompare("draw",option+1) == 0)
1418 {
1419 /*
1420 Draw image.
1421 */
cristy6b3da3a2010-06-20 02:21:46 +00001422 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001423 (void) CloneString(&draw_info->primitive,argv[i+1]);
1424 (void) DrawImage(*image,draw_info);
1425 InheritException(exception,&(*image)->exception);
1426 break;
1427 }
1428 break;
1429 }
1430 case 'e':
1431 {
1432 if (LocaleCompare("edge",option+1) == 0)
1433 {
cristy3ed852e2009-09-05 21:47:34 +00001434 /*
1435 Enhance edges in the image.
1436 */
cristy6b3da3a2010-06-20 02:21:46 +00001437 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001438 flags=ParseGeometry(argv[i+1],&geometry_info);
1439 if ((flags & SigmaValue) == 0)
1440 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001441 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001442 break;
1443 }
1444 if (LocaleCompare("emboss",option+1) == 0)
1445 {
cristy3ed852e2009-09-05 21:47:34 +00001446 /*
1447 Gaussian embossen image.
1448 */
cristy6b3da3a2010-06-20 02:21:46 +00001449 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001450 flags=ParseGeometry(argv[i+1],&geometry_info);
1451 if ((flags & SigmaValue) == 0)
1452 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001453 mogrify_image=EmbossImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00001454 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001455 break;
1456 }
1457 if (LocaleCompare("encipher",option+1) == 0)
1458 {
1459 StringInfo
1460 *passkey;
1461
1462 /*
1463 Encipher pixels.
1464 */
cristy6b3da3a2010-06-20 02:21:46 +00001465 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001466 passkey=FileToStringInfo(argv[i+1],~0,exception);
1467 if (passkey != (StringInfo *) NULL)
1468 {
1469 (void) PasskeyEncipherImage(*image,passkey,exception);
1470 passkey=DestroyStringInfo(passkey);
1471 }
1472 break;
1473 }
1474 if (LocaleCompare("encoding",option+1) == 0)
1475 {
1476 (void) CloneString(&draw_info->encoding,argv[i+1]);
1477 break;
1478 }
1479 if (LocaleCompare("enhance",option+1) == 0)
1480 {
cristy3ed852e2009-09-05 21:47:34 +00001481 /*
1482 Enhance image.
1483 */
cristy6b3da3a2010-06-20 02:21:46 +00001484 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001485 mogrify_image=EnhanceImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001486 break;
1487 }
1488 if (LocaleCompare("equalize",option+1) == 0)
1489 {
1490 /*
1491 Equalize image.
1492 */
cristy6b3da3a2010-06-20 02:21:46 +00001493 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001494 (void) EqualizeImageChannel(*image,channel);
1495 InheritException(exception,&(*image)->exception);
1496 break;
1497 }
1498 if (LocaleCompare("evaluate",option+1) == 0)
1499 {
1500 double
1501 constant;
1502
1503 MagickEvaluateOperator
1504 op;
1505
cristy6b3da3a2010-06-20 02:21:46 +00001506 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001507 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1508 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001509 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001510 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1511 break;
1512 }
1513 if (LocaleCompare("extent",option+1) == 0)
1514 {
cristy3ed852e2009-09-05 21:47:34 +00001515 /*
1516 Set the image extent.
1517 */
cristy6b3da3a2010-06-20 02:21:46 +00001518 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001519 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001520 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001521 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001522 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001523 geometry.height=(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00001524 mogrify_image=ExtentImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00001525 break;
1526 }
1527 break;
1528 }
1529 case 'f':
1530 {
1531 if (LocaleCompare("family",option+1) == 0)
1532 {
1533 if (*option == '+')
1534 {
1535 if (draw_info->family != (char *) NULL)
1536 draw_info->family=DestroyString(draw_info->family);
1537 break;
1538 }
1539 (void) CloneString(&draw_info->family,argv[i+1]);
1540 break;
1541 }
cristy0fe961c2010-01-30 03:09:54 +00001542 if (LocaleCompare("features",option+1) == 0)
1543 {
1544 if (*option == '+')
1545 {
1546 (void) DeleteImageArtifact(*image,"identify:features");
1547 break;
1548 }
1549 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1550 break;
1551 }
cristy3ed852e2009-09-05 21:47:34 +00001552 if (LocaleCompare("fill",option+1) == 0)
1553 {
1554 ExceptionInfo
1555 *sans;
1556
1557 GetMagickPixelPacket(*image,&fill);
1558 if (*option == '+')
1559 {
1560 (void) QueryMagickColor("none",&fill,exception);
1561 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1562 if (draw_info->fill_pattern != (Image *) NULL)
1563 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1564 break;
1565 }
1566 sans=AcquireExceptionInfo();
1567 (void) QueryMagickColor(argv[i+1],&fill,sans);
1568 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1569 sans=DestroyExceptionInfo(sans);
1570 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001571 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001572 exception);
1573 break;
1574 }
1575 if (LocaleCompare("flip",option+1) == 0)
1576 {
cristy3ed852e2009-09-05 21:47:34 +00001577 /*
1578 Flip image scanlines.
1579 */
cristy6b3da3a2010-06-20 02:21:46 +00001580 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001581 mogrify_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001582 break;
1583 }
1584 if (LocaleCompare("flop",option+1) == 0)
1585 {
cristy3ed852e2009-09-05 21:47:34 +00001586 /*
1587 Flop image scanlines.
1588 */
cristy6b3da3a2010-06-20 02:21:46 +00001589 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001590 mogrify_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001591 break;
1592 }
1593 if (LocaleCompare("floodfill",option+1) == 0)
1594 {
1595 MagickPixelPacket
1596 target;
1597
1598 /*
1599 Floodfill image.
1600 */
cristy6b3da3a2010-06-20 02:21:46 +00001601 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001602 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1603 (void) QueryMagickColor(argv[i+2],&target,exception);
1604 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1605 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1606 InheritException(exception,&(*image)->exception);
1607 break;
1608 }
1609 if (LocaleCompare("font",option+1) == 0)
1610 {
1611 if (*option == '+')
1612 {
1613 if (draw_info->font != (char *) NULL)
1614 draw_info->font=DestroyString(draw_info->font);
1615 break;
1616 }
1617 (void) CloneString(&draw_info->font,argv[i+1]);
1618 break;
1619 }
1620 if (LocaleCompare("format",option+1) == 0)
1621 {
1622 format=argv[i+1];
1623 break;
1624 }
1625 if (LocaleCompare("frame",option+1) == 0)
1626 {
1627 FrameInfo
1628 frame_info;
1629
cristy3ed852e2009-09-05 21:47:34 +00001630 /*
1631 Surround image with an ornamental border.
1632 */
cristy6b3da3a2010-06-20 02:21:46 +00001633 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001634 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1635 frame_info.width=geometry.width;
1636 frame_info.height=geometry.height;
1637 if ((flags & HeightValue) == 0)
1638 frame_info.height=geometry.width;
1639 frame_info.outer_bevel=geometry.x;
1640 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001641 frame_info.x=(ssize_t) frame_info.width;
1642 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001643 frame_info.width=(*image)->columns+2*frame_info.width;
1644 frame_info.height=(*image)->rows+2*frame_info.height;
cristyd241f442011-03-29 13:50:49 +00001645 mogrify_image=FrameImage(*image,&frame_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00001646 break;
1647 }
1648 if (LocaleCompare("function",option+1) == 0)
1649 {
1650 char
1651 *arguments,
1652 token[MaxTextExtent];
1653
1654 const char
1655 *p;
1656
1657 double
1658 *parameters;
1659
1660 MagickFunction
1661 function;
1662
cristybb503372010-05-27 20:51:26 +00001663 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001664 x;
1665
cristybb503372010-05-27 20:51:26 +00001666 size_t
cristy3ed852e2009-09-05 21:47:34 +00001667 number_parameters;
1668
1669 /*
1670 Function Modify Image Values
1671 */
cristy6b3da3a2010-06-20 02:21:46 +00001672 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001673 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1674 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001675 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001676 InheritException(exception,&(*image)->exception);
1677 if (arguments == (char *) NULL)
1678 break;
1679 p=(char *) arguments;
1680 for (x=0; *p != '\0'; x++)
1681 {
1682 GetMagickToken(p,&p,token);
1683 if (*token == ',')
1684 GetMagickToken(p,&p,token);
1685 }
cristybb503372010-05-27 20:51:26 +00001686 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001687 parameters=(double *) AcquireQuantumMemory(number_parameters,
1688 sizeof(*parameters));
1689 if (parameters == (double *) NULL)
1690 ThrowWandFatalException(ResourceLimitFatalError,
1691 "MemoryAllocationFailed",(*image)->filename);
1692 (void) ResetMagickMemory(parameters,0,number_parameters*
1693 sizeof(*parameters));
1694 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001695 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001696 {
1697 GetMagickToken(p,&p,token);
1698 if (*token == ',')
1699 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001700 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001701 }
1702 arguments=DestroyString(arguments);
1703 (void) FunctionImageChannel(*image,channel,function,
1704 number_parameters,parameters,exception);
1705 parameters=(double *) RelinquishMagickMemory(parameters);
1706 break;
1707 }
1708 break;
1709 }
1710 case 'g':
1711 {
1712 if (LocaleCompare("gamma",option+1) == 0)
1713 {
1714 /*
1715 Gamma image.
1716 */
cristy6b3da3a2010-06-20 02:21:46 +00001717 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001718 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001719 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001720 else
1721 {
1722 if (strchr(argv[i+1],',') != (char *) NULL)
1723 (void) GammaImage(*image,argv[i+1]);
1724 else
cristya5447be2010-01-11 00:20:51 +00001725 (void) GammaImageChannel(*image,channel,
1726 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001727 InheritException(exception,&(*image)->exception);
1728 }
1729 break;
1730 }
1731 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1732 (LocaleCompare("gaussian",option+1) == 0))
1733 {
cristy3ed852e2009-09-05 21:47:34 +00001734 /*
1735 Gaussian blur image.
1736 */
cristy6b3da3a2010-06-20 02:21:46 +00001737 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001738 flags=ParseGeometry(argv[i+1],&geometry_info);
1739 if ((flags & SigmaValue) == 0)
1740 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001741 mogrify_image=GaussianBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00001742 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001743 break;
1744 }
1745 if (LocaleCompare("geometry",option+1) == 0)
1746 {
anthonye9c27192011-03-27 08:07:06 +00001747 /*
1748 Record Image offset, Resize last image.
1749 */
cristy6b3da3a2010-06-20 02:21:46 +00001750 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001751 if (*option == '+')
1752 {
1753 if ((*image)->geometry != (char *) NULL)
1754 (*image)->geometry=DestroyString((*image)->geometry);
1755 break;
1756 }
1757 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1758 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1759 (void) CloneString(&(*image)->geometry,argv[i+1]);
1760 else
cristyd241f442011-03-29 13:50:49 +00001761 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
anthonye9c27192011-03-27 08:07:06 +00001762 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00001763 break;
1764 }
1765 if (LocaleCompare("gravity",option+1) == 0)
1766 {
1767 if (*option == '+')
1768 {
1769 draw_info->gravity=UndefinedGravity;
1770 break;
1771 }
1772 draw_info->gravity=(GravityType) ParseMagickOption(
1773 MagickGravityOptions,MagickFalse,argv[i+1]);
1774 break;
1775 }
1776 break;
1777 }
1778 case 'h':
1779 {
1780 if (LocaleCompare("highlight-color",option+1) == 0)
1781 {
1782 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1783 break;
1784 }
1785 break;
1786 }
1787 case 'i':
1788 {
1789 if (LocaleCompare("identify",option+1) == 0)
1790 {
1791 char
1792 *text;
1793
cristy6b3da3a2010-06-20 02:21:46 +00001794 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001795 if (format == (char *) NULL)
1796 {
cristy6b3da3a2010-06-20 02:21:46 +00001797 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001798 InheritException(exception,&(*image)->exception);
1799 break;
1800 }
cristy6b3da3a2010-06-20 02:21:46 +00001801 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001802 InheritException(exception,&(*image)->exception);
1803 if (text == (char *) NULL)
1804 break;
1805 (void) fputs(text,stdout);
1806 (void) fputc('\n',stdout);
1807 text=DestroyString(text);
1808 break;
1809 }
1810 if (LocaleCompare("implode",option+1) == 0)
1811 {
cristy3ed852e2009-09-05 21:47:34 +00001812 /*
1813 Implode image.
1814 */
cristy6b3da3a2010-06-20 02:21:46 +00001815 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001816 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00001817 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001818 break;
1819 }
cristyb32b90a2009-09-07 21:45:48 +00001820 if (LocaleCompare("interline-spacing",option+1) == 0)
1821 {
1822 if (*option == '+')
1823 (void) ParseGeometry("0",&geometry_info);
1824 else
1825 (void) ParseGeometry(argv[i+1],&geometry_info);
1826 draw_info->interline_spacing=geometry_info.rho;
1827 break;
1828 }
cristy3ed852e2009-09-05 21:47:34 +00001829 if (LocaleCompare("interword-spacing",option+1) == 0)
1830 {
1831 if (*option == '+')
1832 (void) ParseGeometry("0",&geometry_info);
1833 else
1834 (void) ParseGeometry(argv[i+1],&geometry_info);
1835 draw_info->interword_spacing=geometry_info.rho;
1836 break;
1837 }
1838 break;
1839 }
1840 case 'k':
1841 {
1842 if (LocaleCompare("kerning",option+1) == 0)
1843 {
1844 if (*option == '+')
1845 (void) ParseGeometry("0",&geometry_info);
1846 else
1847 (void) ParseGeometry(argv[i+1],&geometry_info);
1848 draw_info->kerning=geometry_info.rho;
1849 break;
1850 }
1851 break;
1852 }
1853 case 'l':
1854 {
1855 if (LocaleCompare("lat",option+1) == 0)
1856 {
cristy3ed852e2009-09-05 21:47:34 +00001857 /*
1858 Local adaptive threshold image.
1859 */
cristy6b3da3a2010-06-20 02:21:46 +00001860 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001861 flags=ParseGeometry(argv[i+1],&geometry_info);
1862 if ((flags & PercentValue) != 0)
1863 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00001864 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1865 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1866 geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001867 break;
1868 }
1869 if (LocaleCompare("level",option+1) == 0)
1870 {
cristy3ed852e2009-09-05 21:47:34 +00001871 MagickRealType
1872 black_point,
1873 gamma,
1874 white_point;
1875
1876 MagickStatusType
1877 flags;
1878
1879 /*
1880 Parse levels.
1881 */
cristy6b3da3a2010-06-20 02:21:46 +00001882 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001883 flags=ParseGeometry(argv[i+1],&geometry_info);
1884 black_point=geometry_info.rho;
1885 white_point=(MagickRealType) QuantumRange;
1886 if ((flags & SigmaValue) != 0)
1887 white_point=geometry_info.sigma;
1888 gamma=1.0;
1889 if ((flags & XiValue) != 0)
1890 gamma=geometry_info.xi;
1891 if ((flags & PercentValue) != 0)
1892 {
1893 black_point*=(MagickRealType) (QuantumRange/100.0);
1894 white_point*=(MagickRealType) (QuantumRange/100.0);
1895 }
1896 if ((flags & SigmaValue) == 0)
1897 white_point=(MagickRealType) QuantumRange-black_point;
1898 if ((*option == '+') || ((flags & AspectValue) != 0))
1899 (void) LevelizeImageChannel(*image,channel,black_point,
1900 white_point,gamma);
1901 else
1902 (void) LevelImageChannel(*image,channel,black_point,white_point,
1903 gamma);
1904 InheritException(exception,&(*image)->exception);
1905 break;
1906 }
1907 if (LocaleCompare("level-colors",option+1) == 0)
1908 {
1909 char
1910 token[MaxTextExtent];
1911
1912 const char
1913 *p;
1914
1915 MagickPixelPacket
1916 black_point,
1917 white_point;
1918
1919 p=(const char *) argv[i+1];
1920 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00001921 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001922 (void) QueryMagickColor(token,&black_point,exception);
1923 else
cristyee0f8d72009-09-19 00:58:29 +00001924 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001925 if (isalpha((int) token[0]) || (token[0] == '#'))
1926 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00001927 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00001928 white_point=black_point; /* set everything to that color */
1929 else
1930 {
cristyee0f8d72009-09-19 00:58:29 +00001931 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
anthonye9c27192011-03-27 08:07:06 +00001932 GetMagickToken(p,&p,token); /* Get white point color. */
cristyee0f8d72009-09-19 00:58:29 +00001933 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001934 (void) QueryMagickColor(token,&white_point,exception);
1935 else
cristyee0f8d72009-09-19 00:58:29 +00001936 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001937 }
cristy74fe8f12009-10-03 19:09:01 +00001938 (void) LevelColorsImageChannel(*image,channel,&black_point,
1939 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001940 break;
1941 }
1942 if (LocaleCompare("linear-stretch",option+1) == 0)
1943 {
1944 double
1945 black_point,
1946 white_point;
1947
cristy3ed852e2009-09-05 21:47:34 +00001948 MagickStatusType
1949 flags;
1950
cristy6b3da3a2010-06-20 02:21:46 +00001951 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001952 flags=ParseGeometry(argv[i+1],&geometry_info);
1953 black_point=geometry_info.rho;
1954 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1955 if ((flags & SigmaValue) != 0)
1956 white_point=geometry_info.sigma;
1957 if ((flags & PercentValue) != 0)
1958 {
1959 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1960 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1961 }
1962 if ((flags & SigmaValue) == 0)
1963 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1964 black_point;
1965 (void) LinearStretchImage(*image,black_point,white_point);
1966 InheritException(exception,&(*image)->exception);
1967 break;
1968 }
1969 if (LocaleCompare("linewidth",option+1) == 0)
1970 {
cristyf2f27272009-12-17 14:48:46 +00001971 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001972 break;
1973 }
1974 if (LocaleCompare("liquid-rescale",option+1) == 0)
1975 {
cristy3ed852e2009-09-05 21:47:34 +00001976 /*
1977 Liquid rescale image.
1978 */
cristy6b3da3a2010-06-20 02:21:46 +00001979 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001980 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1981 if ((flags & XValue) == 0)
1982 geometry.x=1;
1983 if ((flags & YValue) == 0)
1984 geometry.y=0;
cristyd241f442011-03-29 13:50:49 +00001985 mogrify_image=LiquidRescaleImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +00001986 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00001987 break;
1988 }
1989 if (LocaleCompare("lowlight-color",option+1) == 0)
1990 {
1991 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1992 break;
1993 }
1994 break;
1995 }
1996 case 'm':
1997 {
1998 if (LocaleCompare("map",option+1) == 0)
1999 {
2000 Image
2001 *remap_image;
2002
2003 /*
2004 Transform image colors to match this set of colors.
2005 */
cristy6b3da3a2010-06-20 02:21:46 +00002006 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002007 if (*option == '+')
2008 break;
cristy6b3da3a2010-06-20 02:21:46 +00002009 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002010 if (remap_image == (Image *) NULL)
2011 break;
2012 (void) RemapImage(quantize_info,*image,remap_image);
2013 InheritException(exception,&(*image)->exception);
2014 remap_image=DestroyImage(remap_image);
2015 break;
2016 }
2017 if (LocaleCompare("mask",option+1) == 0)
2018 {
2019 Image
2020 *mask;
2021
cristy6b3da3a2010-06-20 02:21:46 +00002022 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002023 if (*option == '+')
2024 {
2025 /*
2026 Remove a mask.
2027 */
2028 (void) SetImageMask(*image,(Image *) NULL);
2029 InheritException(exception,&(*image)->exception);
2030 break;
2031 }
2032 /*
2033 Set the image mask.
2034 */
cristy6b3da3a2010-06-20 02:21:46 +00002035 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002036 if (mask == (Image *) NULL)
2037 break;
2038 (void) SetImageMask(*image,mask);
2039 mask=DestroyImage(mask);
2040 InheritException(exception,&(*image)->exception);
2041 break;
2042 }
2043 if (LocaleCompare("matte",option+1) == 0)
2044 {
2045 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2046 SetAlphaChannel : DeactivateAlphaChannel );
2047 InheritException(exception,&(*image)->exception);
2048 break;
2049 }
2050 if (LocaleCompare("median",option+1) == 0)
2051 {
cristy3ed852e2009-09-05 21:47:34 +00002052 /*
2053 Median filter image.
2054 */
cristy6b3da3a2010-06-20 02:21:46 +00002055 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002056 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002057 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
cristy95c38342011-03-18 22:39:51 +00002058 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002059 break;
2060 }
cristy69ec32d2011-02-27 23:57:09 +00002061 if (LocaleCompare("mode",option+1) == 0)
2062 {
cristy69ec32d2011-02-27 23:57:09 +00002063 /*
2064 Mode image.
2065 */
2066 (void) SyncImageSettings(mogrify_info,*image);
2067 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002068 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
cristy95c38342011-03-18 22:39:51 +00002069 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy69ec32d2011-02-27 23:57:09 +00002070 break;
2071 }
cristy3ed852e2009-09-05 21:47:34 +00002072 if (LocaleCompare("modulate",option+1) == 0)
2073 {
cristy6b3da3a2010-06-20 02:21:46 +00002074 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002075 (void) ModulateImage(*image,argv[i+1]);
2076 InheritException(exception,&(*image)->exception);
2077 break;
2078 }
2079 if (LocaleCompare("monitor",option+1) == 0)
2080 {
cristy7d34ef22010-03-25 01:11:22 +00002081 if (*option == '+')
2082 {
2083 (void) SetImageProgressMonitor(*image,
2084 (MagickProgressMonitor) NULL,(void *) NULL);
2085 break;
2086 }
cristy3ed852e2009-09-05 21:47:34 +00002087 (void) SetImageProgressMonitor(*image,MonitorProgress,
2088 (void *) NULL);
2089 break;
2090 }
2091 if (LocaleCompare("monochrome",option+1) == 0)
2092 {
cristy6b3da3a2010-06-20 02:21:46 +00002093 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002094 (void) SetImageType(*image,BilevelType);
2095 InheritException(exception,&(*image)->exception);
2096 break;
2097 }
anthony29188a82010-01-22 10:12:34 +00002098 if (LocaleCompare("morphology",option+1) == 0)
2099 {
anthony29188a82010-01-22 10:12:34 +00002100 char
2101 token[MaxTextExtent];
2102
2103 const char
2104 *p;
2105
cristye96405a2010-05-19 02:24:31 +00002106 KernelInfo
2107 *kernel;
2108
cristye96405a2010-05-19 02:24:31 +00002109 MorphologyMethod
2110 method;
2111
cristy9d314ff2011-03-09 01:30:28 +00002112 ssize_t
2113 iterations;
2114
anthony29188a82010-01-22 10:12:34 +00002115 /*
2116 Morphological Image Operation
2117 */
cristy6b3da3a2010-06-20 02:21:46 +00002118 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002119 p=argv[i+1];
2120 GetMagickToken(p,&p,token);
2121 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002122 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002123 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002124 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002125 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002126 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002127 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002128 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002129 kernel=AcquireKernelInfo(argv[i+2]);
2130 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002131 {
2132 (void) ThrowMagickException(exception,GetMagickModule(),
2133 OptionError,"UnabletoParseKernel","morphology");
2134 status=MagickFalse;
2135 break;
2136 }
cristyd241f442011-03-29 13:50:49 +00002137 mogrify_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002138 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002139 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002140 break;
2141 }
cristy3ed852e2009-09-05 21:47:34 +00002142 if (LocaleCompare("motion-blur",option+1) == 0)
2143 {
cristy3ed852e2009-09-05 21:47:34 +00002144 /*
2145 Motion blur image.
2146 */
cristy6b3da3a2010-06-20 02:21:46 +00002147 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002148 flags=ParseGeometry(argv[i+1],&geometry_info);
2149 if ((flags & SigmaValue) == 0)
2150 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002151 mogrify_image=MotionBlurImageChannel(*image,channel,
2152 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002153 break;
2154 }
2155 break;
2156 }
2157 case 'n':
2158 {
2159 if (LocaleCompare("negate",option+1) == 0)
2160 {
cristy6b3da3a2010-06-20 02:21:46 +00002161 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002162 (void) NegateImageChannel(*image,channel,*option == '+' ?
2163 MagickTrue : MagickFalse);
2164 InheritException(exception,&(*image)->exception);
2165 break;
2166 }
2167 if (LocaleCompare("noise",option+1) == 0)
2168 {
cristy6b3da3a2010-06-20 02:21:46 +00002169 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002170 if (*option == '-')
2171 {
2172 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002173 mogrify_image=StatisticImageChannel(*image,channel,
cristy95c38342011-03-18 22:39:51 +00002174 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2175 geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002176 }
2177 else
2178 {
2179 NoiseType
2180 noise;
2181
2182 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2183 MagickFalse,argv[i+1]);
cristyd241f442011-03-29 13:50:49 +00002184 mogrify_image=AddNoiseImageChannel(*image,channel,noise,
cristy3ed852e2009-09-05 21:47:34 +00002185 exception);
2186 }
cristy3ed852e2009-09-05 21:47:34 +00002187 break;
2188 }
2189 if (LocaleCompare("normalize",option+1) == 0)
2190 {
cristy6b3da3a2010-06-20 02:21:46 +00002191 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002192 (void) NormalizeImageChannel(*image,channel);
2193 InheritException(exception,&(*image)->exception);
2194 break;
2195 }
2196 break;
2197 }
2198 case 'o':
2199 {
2200 if (LocaleCompare("opaque",option+1) == 0)
2201 {
2202 MagickPixelPacket
2203 target;
2204
cristy6b3da3a2010-06-20 02:21:46 +00002205 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002206 (void) QueryMagickColor(argv[i+1],&target,exception);
2207 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2208 *option == '-' ? MagickFalse : MagickTrue);
2209 break;
2210 }
2211 if (LocaleCompare("ordered-dither",option+1) == 0)
2212 {
cristy6b3da3a2010-06-20 02:21:46 +00002213 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002214 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2215 exception);
2216 break;
2217 }
2218 break;
2219 }
2220 case 'p':
2221 {
2222 if (LocaleCompare("paint",option+1) == 0)
2223 {
2224 Image
2225 *paint_image;
2226
2227 /*
2228 Oil paint image.
2229 */
cristy6b3da3a2010-06-20 02:21:46 +00002230 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002231 (void) ParseGeometry(argv[i+1],&geometry_info);
2232 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2233 if (paint_image == (Image *) NULL)
2234 break;
2235 *image=DestroyImage(*image);
2236 *image=paint_image;
2237 break;
2238 }
2239 if (LocaleCompare("pen",option+1) == 0)
2240 {
2241 if (*option == '+')
2242 {
2243 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2244 break;
2245 }
2246 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2247 break;
2248 }
2249 if (LocaleCompare("pointsize",option+1) == 0)
2250 {
2251 if (*option == '+')
2252 (void) ParseGeometry("12",&geometry_info);
2253 else
2254 (void) ParseGeometry(argv[i+1],&geometry_info);
2255 draw_info->pointsize=geometry_info.rho;
2256 break;
2257 }
2258 if (LocaleCompare("polaroid",option+1) == 0)
2259 {
2260 double
2261 angle;
2262
cristy3ed852e2009-09-05 21:47:34 +00002263 RandomInfo
2264 *random_info;
2265
2266 /*
2267 Simulate a Polaroid picture.
2268 */
cristy6b3da3a2010-06-20 02:21:46 +00002269 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002270 random_info=AcquireRandomInfo();
2271 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2272 random_info=DestroyRandomInfo(random_info);
2273 if (*option == '-')
2274 {
2275 SetGeometryInfo(&geometry_info);
2276 flags=ParseGeometry(argv[i+1],&geometry_info);
2277 angle=geometry_info.rho;
2278 }
cristyd241f442011-03-29 13:50:49 +00002279 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
cristy3ed852e2009-09-05 21:47:34 +00002280 break;
2281 }
2282 if (LocaleCompare("posterize",option+1) == 0)
2283 {
2284 /*
2285 Posterize image.
2286 */
cristy6b3da3a2010-06-20 02:21:46 +00002287 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002288 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002289 quantize_info->dither);
2290 InheritException(exception,&(*image)->exception);
2291 break;
2292 }
2293 if (LocaleCompare("preview",option+1) == 0)
2294 {
cristy3ed852e2009-09-05 21:47:34 +00002295 PreviewType
2296 preview_type;
2297
2298 /*
2299 Preview image.
2300 */
cristy6b3da3a2010-06-20 02:21:46 +00002301 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002302 if (*option == '+')
2303 preview_type=UndefinedPreview;
2304 else
2305 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2306 MagickFalse,argv[i+1]);
cristyd241f442011-03-29 13:50:49 +00002307 mogrify_image=PreviewImage(*image,preview_type,exception);
cristy3ed852e2009-09-05 21:47:34 +00002308 break;
2309 }
2310 if (LocaleCompare("profile",option+1) == 0)
2311 {
2312 const char
2313 *name;
2314
2315 const StringInfo
2316 *profile;
2317
2318 Image
2319 *profile_image;
2320
2321 ImageInfo
2322 *profile_info;
2323
cristy6b3da3a2010-06-20 02:21:46 +00002324 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002325 if (*option == '+')
2326 {
2327 /*
2328 Remove a profile from the image.
2329 */
2330 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2331 NULL,0,MagickTrue);
2332 InheritException(exception,&(*image)->exception);
2333 break;
2334 }
2335 /*
2336 Associate a profile with the image.
2337 */
cristy6b3da3a2010-06-20 02:21:46 +00002338 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002339 profile=GetImageProfile(*image,"iptc");
2340 if (profile != (StringInfo *) NULL)
2341 profile_info->profile=(void *) CloneStringInfo(profile);
2342 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2343 profile_info=DestroyImageInfo(profile_info);
2344 if (profile_image == (Image *) NULL)
2345 {
cristy3ed852e2009-09-05 21:47:34 +00002346 StringInfo
2347 *profile;
2348
cristy6b3da3a2010-06-20 02:21:46 +00002349 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002350 (void) CopyMagickString(profile_info->filename,argv[i+1],
2351 MaxTextExtent);
2352 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002353 if (profile != (StringInfo *) NULL)
2354 {
cristy071dd7b2010-04-09 13:04:54 +00002355 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002356 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002357 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002358 profile=DestroyStringInfo(profile);
2359 }
cristy071dd7b2010-04-09 13:04:54 +00002360 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002361 break;
2362 }
2363 ResetImageProfileIterator(profile_image);
2364 name=GetNextImageProfile(profile_image);
2365 while (name != (const char *) NULL)
2366 {
2367 profile=GetImageProfile(profile_image,name);
2368 if (profile != (StringInfo *) NULL)
2369 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002370 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002371 name=GetNextImageProfile(profile_image);
2372 }
2373 profile_image=DestroyImage(profile_image);
2374 break;
2375 }
2376 break;
2377 }
2378 case 'q':
2379 {
2380 if (LocaleCompare("quantize",option+1) == 0)
2381 {
2382 if (*option == '+')
2383 {
2384 quantize_info->colorspace=UndefinedColorspace;
2385 break;
2386 }
2387 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2388 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2389 break;
2390 }
2391 break;
2392 }
2393 case 'r':
2394 {
2395 if (LocaleCompare("radial-blur",option+1) == 0)
2396 {
cristy3ed852e2009-09-05 21:47:34 +00002397 /*
2398 Radial blur image.
2399 */
cristy6b3da3a2010-06-20 02:21:46 +00002400 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002401 mogrify_image=RadialBlurImageChannel(*image,channel,
cristya5447be2010-01-11 00:20:51 +00002402 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002403 break;
2404 }
2405 if (LocaleCompare("raise",option+1) == 0)
2406 {
2407 /*
2408 Surround image with a raise of solid color.
2409 */
2410 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2411 if ((flags & SigmaValue) == 0)
2412 geometry.height=geometry.width;
2413 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2414 MagickFalse);
2415 InheritException(exception,&(*image)->exception);
2416 break;
2417 }
2418 if (LocaleCompare("random-threshold",option+1) == 0)
2419 {
2420 /*
2421 Threshold image.
2422 */
cristy6b3da3a2010-06-20 02:21:46 +00002423 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002424 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2425 exception);
2426 break;
2427 }
2428 if (LocaleCompare("recolor",option+1) == 0)
2429 {
cristyf055ae42010-04-02 23:01:38 +00002430 KernelInfo
2431 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002432
cristy6b3da3a2010-06-20 02:21:46 +00002433 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002434 kernel=AcquireKernelInfo(argv[i+1]);
2435 if (kernel == (KernelInfo *) NULL)
2436 break;
cristyd241f442011-03-29 13:50:49 +00002437 mogrify_image=ColorMatrixImage(*image,kernel,exception);
cristyf055ae42010-04-02 23:01:38 +00002438 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00002439 break;
2440 }
2441 if (LocaleCompare("region",option+1) == 0)
2442 {
cristy6b3da3a2010-06-20 02:21:46 +00002443 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002444 if (region_image != (Image *) NULL)
2445 {
2446 /*
2447 Composite region.
2448 */
anthonya129f702011-04-14 01:08:48 +00002449 (void) CompositeImage(region_image,region_image->matte !=
2450 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2451 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00002452 InheritException(exception,&region_image->exception);
2453 *image=DestroyImage(*image);
2454 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00002455 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002456 }
2457 if (*option == '+')
anthonye9c27192011-03-27 08:07:06 +00002458 break;
cristy3ed852e2009-09-05 21:47:34 +00002459 /*
2460 Apply transformations to a selected region of the image.
2461 */
2462 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2463 exception);
cristyd241f442011-03-29 13:50:49 +00002464 mogrify_image=CropImage(*image,&region_geometry,exception);
2465 if (mogrify_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002466 break;
2467 region_image=(*image);
cristyd241f442011-03-29 13:50:49 +00002468 *image=mogrify_image;
2469 mogrify_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002470 break;
2471 }
2472 if (LocaleCompare("render",option+1) == 0)
2473 {
cristy6b3da3a2010-06-20 02:21:46 +00002474 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002475 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2476 break;
2477 }
2478 if (LocaleCompare("remap",option+1) == 0)
2479 {
2480 Image
2481 *remap_image;
2482
2483 /*
2484 Transform image colors to match this set of colors.
2485 */
cristy6b3da3a2010-06-20 02:21:46 +00002486 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002487 if (*option == '+')
2488 break;
cristy6b3da3a2010-06-20 02:21:46 +00002489 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002490 if (remap_image == (Image *) NULL)
2491 break;
2492 (void) RemapImage(quantize_info,*image,remap_image);
2493 InheritException(exception,&(*image)->exception);
2494 remap_image=DestroyImage(remap_image);
2495 break;
2496 }
2497 if (LocaleCompare("repage",option+1) == 0)
2498 {
2499 if (*option == '+')
2500 {
2501 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2502 break;
2503 }
2504 (void) ResetImagePage(*image,argv[i+1]);
2505 InheritException(exception,&(*image)->exception);
2506 break;
2507 }
2508 if (LocaleCompare("resample",option+1) == 0)
2509 {
cristy3ed852e2009-09-05 21:47:34 +00002510 /*
2511 Resample image.
2512 */
cristy6b3da3a2010-06-20 02:21:46 +00002513 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002514 flags=ParseGeometry(argv[i+1],&geometry_info);
2515 if ((flags & SigmaValue) == 0)
2516 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002517 mogrify_image=ResampleImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002518 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002519 break;
2520 }
2521 if (LocaleCompare("resize",option+1) == 0)
2522 {
cristy3ed852e2009-09-05 21:47:34 +00002523 /*
2524 Resize image.
2525 */
cristy6b3da3a2010-06-20 02:21:46 +00002526 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002527 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002528 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002529 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002530 break;
2531 }
cristy3ed852e2009-09-05 21:47:34 +00002532 if (LocaleCompare("roll",option+1) == 0)
2533 {
cristy3ed852e2009-09-05 21:47:34 +00002534 /*
2535 Roll image.
2536 */
cristy6b3da3a2010-06-20 02:21:46 +00002537 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002538 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002539 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00002540 break;
2541 }
2542 if (LocaleCompare("rotate",option+1) == 0)
2543 {
2544 char
2545 *geometry;
2546
cristy3ed852e2009-09-05 21:47:34 +00002547 /*
2548 Check for conditional image rotation.
2549 */
cristy6b3da3a2010-06-20 02:21:46 +00002550 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002551 if (strchr(argv[i+1],'>') != (char *) NULL)
2552 if ((*image)->columns <= (*image)->rows)
2553 break;
2554 if (strchr(argv[i+1],'<') != (char *) NULL)
2555 if ((*image)->columns >= (*image)->rows)
2556 break;
2557 /*
2558 Rotate image.
2559 */
2560 geometry=ConstantString(argv[i+1]);
2561 (void) SubstituteString(&geometry,">","");
2562 (void) SubstituteString(&geometry,"<","");
2563 (void) ParseGeometry(geometry,&geometry_info);
2564 geometry=DestroyString(geometry);
cristyd241f442011-03-29 13:50:49 +00002565 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002566 break;
2567 }
2568 break;
2569 }
2570 case 's':
2571 {
2572 if (LocaleCompare("sample",option+1) == 0)
2573 {
cristy3ed852e2009-09-05 21:47:34 +00002574 /*
2575 Sample image with pixel replication.
2576 */
cristy6b3da3a2010-06-20 02:21:46 +00002577 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002578 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002579 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002580 exception);
cristy3ed852e2009-09-05 21:47:34 +00002581 break;
2582 }
2583 if (LocaleCompare("scale",option+1) == 0)
2584 {
cristy3ed852e2009-09-05 21:47:34 +00002585 /*
2586 Resize image.
2587 */
cristy6b3da3a2010-06-20 02:21:46 +00002588 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002589 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002590 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002591 exception);
cristy3ed852e2009-09-05 21:47:34 +00002592 break;
2593 }
2594 if (LocaleCompare("selective-blur",option+1) == 0)
2595 {
cristy3ed852e2009-09-05 21:47:34 +00002596 /*
2597 Selectively blur pixels within a contrast threshold.
2598 */
cristy6b3da3a2010-06-20 02:21:46 +00002599 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002600 flags=ParseGeometry(argv[i+1],&geometry_info);
2601 if ((flags & PercentValue) != 0)
2602 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00002603 mogrify_image=SelectiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00002604 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002605 break;
2606 }
2607 if (LocaleCompare("separate",option+1) == 0)
2608 {
cristy3ed852e2009-09-05 21:47:34 +00002609 /*
2610 Break channels into separate images.
anthonye9c27192011-03-27 08:07:06 +00002611 WARNING: This can generate multiple images!
cristy3ed852e2009-09-05 21:47:34 +00002612 */
cristy6b3da3a2010-06-20 02:21:46 +00002613 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002614 mogrify_image=SeparateImages(*image,channel,exception);
cristy3ed852e2009-09-05 21:47:34 +00002615 break;
2616 }
2617 if (LocaleCompare("sepia-tone",option+1) == 0)
2618 {
2619 double
2620 threshold;
2621
cristy3ed852e2009-09-05 21:47:34 +00002622 /*
2623 Sepia-tone image.
2624 */
cristy6b3da3a2010-06-20 02:21:46 +00002625 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002626 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00002627 mogrify_image=SepiaToneImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00002628 break;
2629 }
2630 if (LocaleCompare("segment",option+1) == 0)
2631 {
2632 /*
2633 Segment image.
2634 */
cristy6b3da3a2010-06-20 02:21:46 +00002635 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002636 flags=ParseGeometry(argv[i+1],&geometry_info);
2637 if ((flags & SigmaValue) == 0)
2638 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002639 (void) SegmentImage(*image,(*image)->colorspace,
2640 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002641 InheritException(exception,&(*image)->exception);
2642 break;
2643 }
2644 if (LocaleCompare("set",option+1) == 0)
2645 {
cristy6d9a1292010-05-31 14:17:06 +00002646 char
2647 *value;
2648
cristy3ed852e2009-09-05 21:47:34 +00002649 /*
2650 Set image option.
2651 */
cristy6d9a1292010-05-31 14:17:06 +00002652 if (*option == '+')
2653 {
2654 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2655 (void) DeleteImageRegistry(argv[i+1]+9);
2656 else
2657 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002658 {
cristy6b3da3a2010-06-20 02:21:46 +00002659 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002660 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2661 }
cristy6d9a1292010-05-31 14:17:06 +00002662 else
2663 (void) DeleteImageProperty(*image,argv[i+1]);
2664 break;
2665 }
cristy6b3da3a2010-06-20 02:21:46 +00002666 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002667 if (value == (char *) NULL)
2668 break;
cristy3ed852e2009-09-05 21:47:34 +00002669 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002670 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2671 exception);
cristy3ed852e2009-09-05 21:47:34 +00002672 else
2673 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002674 {
cristy7f02ba12010-09-21 12:39:28 +00002675 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002676 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002677 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2678 }
cristy3ed852e2009-09-05 21:47:34 +00002679 else
cristy6d9a1292010-05-31 14:17:06 +00002680 (void) SetImageProperty(*image,argv[i+1],value);
2681 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002682 break;
2683 }
2684 if (LocaleCompare("shade",option+1) == 0)
2685 {
cristy3ed852e2009-09-05 21:47:34 +00002686 /*
2687 Shade image.
2688 */
cristy6b3da3a2010-06-20 02:21:46 +00002689 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002690 flags=ParseGeometry(argv[i+1],&geometry_info);
2691 if ((flags & SigmaValue) == 0)
2692 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002693 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
cristy3ed852e2009-09-05 21:47:34 +00002694 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002695 break;
2696 }
2697 if (LocaleCompare("shadow",option+1) == 0)
2698 {
cristy3ed852e2009-09-05 21:47:34 +00002699 /*
2700 Shadow image.
2701 */
cristy6b3da3a2010-06-20 02:21:46 +00002702 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002703 flags=ParseGeometry(argv[i+1],&geometry_info);
2704 if ((flags & SigmaValue) == 0)
2705 geometry_info.sigma=1.0;
2706 if ((flags & XiValue) == 0)
2707 geometry_info.xi=4.0;
2708 if ((flags & PsiValue) == 0)
2709 geometry_info.psi=4.0;
cristyd241f442011-03-29 13:50:49 +00002710 mogrify_image=ShadowImage(*image,geometry_info.rho,
2711 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2712 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002713 break;
2714 }
2715 if (LocaleCompare("sharpen",option+1) == 0)
2716 {
cristy3ed852e2009-09-05 21:47:34 +00002717 /*
2718 Sharpen image.
2719 */
cristy6b3da3a2010-06-20 02:21:46 +00002720 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002721 flags=ParseGeometry(argv[i+1],&geometry_info);
2722 if ((flags & SigmaValue) == 0)
2723 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002724 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002725 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002726 break;
2727 }
2728 if (LocaleCompare("shave",option+1) == 0)
2729 {
cristy3ed852e2009-09-05 21:47:34 +00002730 /*
2731 Shave the image edges.
2732 */
cristy6b3da3a2010-06-20 02:21:46 +00002733 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002734 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002735 mogrify_image=ShaveImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002736 break;
2737 }
2738 if (LocaleCompare("shear",option+1) == 0)
2739 {
cristy3ed852e2009-09-05 21:47:34 +00002740 /*
2741 Shear image.
2742 */
cristy6b3da3a2010-06-20 02:21:46 +00002743 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002744 flags=ParseGeometry(argv[i+1],&geometry_info);
2745 if ((flags & SigmaValue) == 0)
2746 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002747 mogrify_image=ShearImage(*image,geometry_info.rho,
2748 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002749 break;
2750 }
2751 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2752 {
2753 /*
2754 Sigmoidal non-linearity contrast control.
2755 */
cristy6b3da3a2010-06-20 02:21:46 +00002756 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002757 flags=ParseGeometry(argv[i+1],&geometry_info);
2758 if ((flags & SigmaValue) == 0)
2759 geometry_info.sigma=(double) QuantumRange/2.0;
2760 if ((flags & PercentValue) != 0)
2761 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2762 100.0;
2763 (void) SigmoidalContrastImageChannel(*image,channel,
2764 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2765 geometry_info.sigma);
2766 InheritException(exception,&(*image)->exception);
2767 break;
2768 }
2769 if (LocaleCompare("sketch",option+1) == 0)
2770 {
cristy3ed852e2009-09-05 21:47:34 +00002771 /*
2772 Sketch image.
2773 */
cristy6b3da3a2010-06-20 02:21:46 +00002774 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002775 flags=ParseGeometry(argv[i+1],&geometry_info);
2776 if ((flags & SigmaValue) == 0)
2777 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002778 mogrify_image=SketchImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002779 geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002780 break;
2781 }
2782 if (LocaleCompare("solarize",option+1) == 0)
2783 {
2784 double
2785 threshold;
2786
cristy6b3da3a2010-06-20 02:21:46 +00002787 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002788 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002789 (void) SolarizeImage(*image,threshold);
2790 InheritException(exception,&(*image)->exception);
2791 break;
2792 }
2793 if (LocaleCompare("sparse-color",option+1) == 0)
2794 {
cristy3ed852e2009-09-05 21:47:34 +00002795 SparseColorMethod
2796 method;
2797
2798 char
2799 *arguments;
2800
2801 /*
2802 Sparse Color Interpolated Gradient
2803 */
cristy6b3da3a2010-06-20 02:21:46 +00002804 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002805 method=(SparseColorMethod) ParseMagickOption(
2806 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00002807 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00002808 InheritException(exception,&(*image)->exception);
2809 if (arguments == (char *) NULL)
2810 break;
cristyd241f442011-03-29 13:50:49 +00002811 mogrify_image=SparseColorOption(*image,channel,method,arguments,
cristy3ed852e2009-09-05 21:47:34 +00002812 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2813 arguments=DestroyString(arguments);
cristy3ed852e2009-09-05 21:47:34 +00002814 break;
2815 }
2816 if (LocaleCompare("splice",option+1) == 0)
2817 {
cristy3ed852e2009-09-05 21:47:34 +00002818 /*
2819 Splice a solid color into the image.
2820 */
cristy6b3da3a2010-06-20 02:21:46 +00002821 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002822 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002823 mogrify_image=SpliceImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002824 break;
2825 }
2826 if (LocaleCompare("spread",option+1) == 0)
2827 {
cristy3ed852e2009-09-05 21:47:34 +00002828 /*
2829 Spread an image.
2830 */
cristy6b3da3a2010-06-20 02:21:46 +00002831 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002832 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002833 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002834 break;
2835 }
cristy0834d642011-03-18 18:26:08 +00002836 if (LocaleCompare("statistic",option+1) == 0)
2837 {
cristy0834d642011-03-18 18:26:08 +00002838 StatisticType
2839 type;
2840
2841 (void) SyncImageSettings(mogrify_info,*image);
2842 type=(StatisticType) ParseMagickOption(MagickStatisticOptions,
2843 MagickFalse,argv[i+1]);
2844 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002845 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2846 geometry_info.rho,(size_t) geometry_info.sigma,exception);
cristy0834d642011-03-18 18:26:08 +00002847 break;
2848 }
cristy3ed852e2009-09-05 21:47:34 +00002849 if (LocaleCompare("stretch",option+1) == 0)
2850 {
2851 if (*option == '+')
2852 {
2853 draw_info->stretch=UndefinedStretch;
2854 break;
2855 }
2856 draw_info->stretch=(StretchType) ParseMagickOption(
2857 MagickStretchOptions,MagickFalse,argv[i+1]);
2858 break;
2859 }
2860 if (LocaleCompare("strip",option+1) == 0)
2861 {
2862 /*
2863 Strip image of profiles and comments.
2864 */
cristy6b3da3a2010-06-20 02:21:46 +00002865 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00002866 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00002867 InheritException(exception,&(*image)->exception);
2868 break;
2869 }
2870 if (LocaleCompare("stroke",option+1) == 0)
2871 {
2872 ExceptionInfo
2873 *sans;
2874
2875 if (*option == '+')
2876 {
2877 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2878 if (draw_info->stroke_pattern != (Image *) NULL)
2879 draw_info->stroke_pattern=DestroyImage(
2880 draw_info->stroke_pattern);
2881 break;
2882 }
2883 sans=AcquireExceptionInfo();
2884 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2885 sans=DestroyExceptionInfo(sans);
2886 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00002887 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002888 exception);
2889 break;
2890 }
2891 if (LocaleCompare("strokewidth",option+1) == 0)
2892 {
cristyf2f27272009-12-17 14:48:46 +00002893 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002894 break;
2895 }
2896 if (LocaleCompare("style",option+1) == 0)
2897 {
2898 if (*option == '+')
2899 {
2900 draw_info->style=UndefinedStyle;
2901 break;
2902 }
2903 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
2904 MagickFalse,argv[i+1]);
2905 break;
2906 }
2907 if (LocaleCompare("swirl",option+1) == 0)
2908 {
cristy3ed852e2009-09-05 21:47:34 +00002909 /*
2910 Swirl image.
2911 */
cristy6b3da3a2010-06-20 02:21:46 +00002912 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002913 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002914 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002915 break;
2916 }
2917 break;
2918 }
2919 case 't':
2920 {
2921 if (LocaleCompare("threshold",option+1) == 0)
2922 {
2923 double
2924 threshold;
2925
2926 /*
2927 Threshold image.
2928 */
cristy6b3da3a2010-06-20 02:21:46 +00002929 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002930 if (*option == '+')
2931 threshold=(double) QuantumRange/2.5;
2932 else
cristyf2f27272009-12-17 14:48:46 +00002933 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002934 (void) BilevelImageChannel(*image,channel,threshold);
2935 InheritException(exception,&(*image)->exception);
2936 break;
2937 }
2938 if (LocaleCompare("thumbnail",option+1) == 0)
2939 {
cristy3ed852e2009-09-05 21:47:34 +00002940 /*
2941 Thumbnail image.
2942 */
cristy6b3da3a2010-06-20 02:21:46 +00002943 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002944 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002945 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2946 exception);
cristy3ed852e2009-09-05 21:47:34 +00002947 break;
2948 }
2949 if (LocaleCompare("tile",option+1) == 0)
2950 {
2951 if (*option == '+')
2952 {
2953 if (draw_info->fill_pattern != (Image *) NULL)
2954 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2955 break;
2956 }
cristy6b3da3a2010-06-20 02:21:46 +00002957 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002958 exception);
2959 break;
2960 }
2961 if (LocaleCompare("tint",option+1) == 0)
2962 {
cristy3ed852e2009-09-05 21:47:34 +00002963 /*
2964 Tint the image.
2965 */
cristy6b3da3a2010-06-20 02:21:46 +00002966 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002967 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
cristy3ed852e2009-09-05 21:47:34 +00002968 break;
2969 }
2970 if (LocaleCompare("transform",option+1) == 0)
2971 {
cristy3ed852e2009-09-05 21:47:34 +00002972 /*
2973 Affine transform image.
2974 */
cristy6b3da3a2010-06-20 02:21:46 +00002975 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002976 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
cristy3ed852e2009-09-05 21:47:34 +00002977 exception);
cristy3ed852e2009-09-05 21:47:34 +00002978 break;
2979 }
2980 if (LocaleCompare("transparent",option+1) == 0)
2981 {
2982 MagickPixelPacket
2983 target;
2984
cristy6b3da3a2010-06-20 02:21:46 +00002985 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002986 (void) QueryMagickColor(argv[i+1],&target,exception);
2987 (void) TransparentPaintImage(*image,&target,(Quantum)
2988 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
2989 InheritException(exception,&(*image)->exception);
2990 break;
2991 }
2992 if (LocaleCompare("transpose",option+1) == 0)
2993 {
cristy3ed852e2009-09-05 21:47:34 +00002994 /*
2995 Transpose image scanlines.
2996 */
cristy6b3da3a2010-06-20 02:21:46 +00002997 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002998 mogrify_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002999 break;
3000 }
3001 if (LocaleCompare("transverse",option+1) == 0)
3002 {
cristy3ed852e2009-09-05 21:47:34 +00003003 /*
3004 Transverse image scanlines.
3005 */
cristy6b3da3a2010-06-20 02:21:46 +00003006 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003007 mogrify_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003008 break;
3009 }
3010 if (LocaleCompare("treedepth",option+1) == 0)
3011 {
cristye27293e2009-12-18 02:53:20 +00003012 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003013 break;
3014 }
3015 if (LocaleCompare("trim",option+1) == 0)
3016 {
cristy3ed852e2009-09-05 21:47:34 +00003017 /*
3018 Trim image.
3019 */
cristy6b3da3a2010-06-20 02:21:46 +00003020 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003021 mogrify_image=TrimImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003022 break;
3023 }
3024 if (LocaleCompare("type",option+1) == 0)
3025 {
3026 ImageType
3027 type;
3028
cristy6b3da3a2010-06-20 02:21:46 +00003029 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003030 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003031 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003032 else
3033 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3034 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003035 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003036 (void) SetImageType(*image,type);
3037 InheritException(exception,&(*image)->exception);
3038 break;
3039 }
3040 break;
3041 }
3042 case 'u':
3043 {
3044 if (LocaleCompare("undercolor",option+1) == 0)
3045 {
3046 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3047 exception);
3048 break;
3049 }
cristy045bd902010-01-30 18:56:24 +00003050 if (LocaleCompare("unique",option+1) == 0)
3051 {
3052 if (*option == '+')
3053 {
cristy83fae872010-04-22 15:04:16 +00003054 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003055 break;
3056 }
cristy83fae872010-04-22 15:04:16 +00003057 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003058 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003059 break;
3060 }
cristy3ed852e2009-09-05 21:47:34 +00003061 if (LocaleCompare("unique-colors",option+1) == 0)
3062 {
cristy3ed852e2009-09-05 21:47:34 +00003063 /*
3064 Unique image colors.
3065 */
cristy6b3da3a2010-06-20 02:21:46 +00003066 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003067 mogrify_image=UniqueImageColors(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003068 break;
3069 }
3070 if (LocaleCompare("unsharp",option+1) == 0)
3071 {
cristy3ed852e2009-09-05 21:47:34 +00003072 /*
3073 Unsharp mask image.
3074 */
cristy6b3da3a2010-06-20 02:21:46 +00003075 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003076 flags=ParseGeometry(argv[i+1],&geometry_info);
3077 if ((flags & SigmaValue) == 0)
3078 geometry_info.sigma=1.0;
3079 if ((flags & XiValue) == 0)
3080 geometry_info.xi=1.0;
3081 if ((flags & PsiValue) == 0)
3082 geometry_info.psi=0.05;
cristyd241f442011-03-29 13:50:49 +00003083 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3084 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3085 geometry_info.psi,exception);
cristy3ed852e2009-09-05 21:47:34 +00003086 break;
3087 }
3088 break;
3089 }
3090 case 'v':
3091 {
3092 if (LocaleCompare("verbose",option+1) == 0)
3093 {
3094 (void) SetImageArtifact(*image,option+1,
3095 *option == '+' ? "false" : "true");
3096 break;
3097 }
3098 if (LocaleCompare("vignette",option+1) == 0)
3099 {
cristy3ed852e2009-09-05 21:47:34 +00003100 /*
3101 Vignette image.
3102 */
cristy6b3da3a2010-06-20 02:21:46 +00003103 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003104 flags=ParseGeometry(argv[i+1],&geometry_info);
3105 if ((flags & SigmaValue) == 0)
3106 geometry_info.sigma=1.0;
3107 if ((flags & XiValue) == 0)
3108 geometry_info.xi=0.1*(*image)->columns;
3109 if ((flags & PsiValue) == 0)
3110 geometry_info.psi=0.1*(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00003111 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003112 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003113 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003114 break;
3115 }
3116 if (LocaleCompare("virtual-pixel",option+1) == 0)
3117 {
3118 if (*option == '+')
3119 {
3120 (void) SetImageVirtualPixelMethod(*image,
3121 UndefinedVirtualPixelMethod);
3122 break;
3123 }
3124 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3125 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3126 argv[i+1]));
3127 break;
3128 }
3129 break;
3130 }
3131 case 'w':
3132 {
3133 if (LocaleCompare("wave",option+1) == 0)
3134 {
cristy3ed852e2009-09-05 21:47:34 +00003135 /*
3136 Wave image.
3137 */
cristy6b3da3a2010-06-20 02:21:46 +00003138 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003139 flags=ParseGeometry(argv[i+1],&geometry_info);
3140 if ((flags & SigmaValue) == 0)
3141 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00003142 mogrify_image=WaveImage(*image,geometry_info.rho,
3143 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00003144 break;
3145 }
3146 if (LocaleCompare("weight",option+1) == 0)
3147 {
cristye27293e2009-12-18 02:53:20 +00003148 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003149 if (LocaleCompare(argv[i+1],"all") == 0)
3150 draw_info->weight=0;
3151 if (LocaleCompare(argv[i+1],"bold") == 0)
3152 draw_info->weight=700;
3153 if (LocaleCompare(argv[i+1],"bolder") == 0)
3154 if (draw_info->weight <= 800)
3155 draw_info->weight+=100;
3156 if (LocaleCompare(argv[i+1],"lighter") == 0)
3157 if (draw_info->weight >= 100)
3158 draw_info->weight-=100;
3159 if (LocaleCompare(argv[i+1],"normal") == 0)
3160 draw_info->weight=400;
3161 break;
3162 }
3163 if (LocaleCompare("white-threshold",option+1) == 0)
3164 {
3165 /*
3166 White threshold image.
3167 */
cristy6b3da3a2010-06-20 02:21:46 +00003168 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003169 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3170 exception);
3171 InheritException(exception,&(*image)->exception);
3172 break;
3173 }
3174 break;
3175 }
3176 default:
3177 break;
3178 }
anthonye9c27192011-03-27 08:07:06 +00003179 /*
3180 Replace current image with any image that was generated
3181 */
cristyd241f442011-03-29 13:50:49 +00003182 if (mogrify_image != (Image *) NULL)
3183 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003184 i+=count;
3185 }
3186 if (region_image != (Image *) NULL)
3187 {
3188 /*
3189 Composite transformed region onto image.
3190 */
cristy6b3da3a2010-06-20 02:21:46 +00003191 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003192 (void) CompositeImage(region_image,region_image->matte !=
3193 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
anthonye9c27192011-03-27 08:07:06 +00003194 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003195 InheritException(exception,&region_image->exception);
3196 *image=DestroyImage(*image);
3197 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003198 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003199 }
3200 /*
3201 Free resources.
3202 */
3203 quantize_info=DestroyQuantizeInfo(quantize_info);
3204 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003205 mogrify_info=DestroyImageInfo(mogrify_info);
cristy72988482011-03-29 16:34:38 +00003206 status=(*image)->exception.severity == UndefinedException ? 1 : 0;
3207 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003208}
3209
3210/*
3211%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3212% %
3213% %
3214% %
cristy5063d812010-10-19 16:28:10 +00003215+ 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 +00003216% %
3217% %
3218% %
3219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3220%
3221% MogrifyImageCommand() transforms an image or a sequence of images. These
3222% transforms include image scaling, image rotation, color reduction, and
3223% others. The transmogrified image overwrites the original image.
3224%
3225% The format of the MogrifyImageCommand method is:
3226%
3227% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3228% const char **argv,char **metadata,ExceptionInfo *exception)
3229%
3230% A description of each parameter follows:
3231%
3232% o image_info: the image info.
3233%
3234% o argc: the number of elements in the argument vector.
3235%
3236% o argv: A text array containing the command line arguments.
3237%
3238% o metadata: any metadata is returned here.
3239%
3240% o exception: return any errors or warnings in this structure.
3241%
3242*/
3243
3244static MagickBooleanType MogrifyUsage(void)
3245{
3246 static const char
3247 *miscellaneous[]=
3248 {
3249 "-debug events display copious debugging information",
3250 "-help print program options",
3251 "-list type print a list of supported option arguments",
3252 "-log format format of debugging information",
3253 "-version print version information",
3254 (char *) NULL
3255 },
3256 *operators[]=
3257 {
3258 "-adaptive-blur geometry",
3259 " adaptively blur pixels; decrease effect near edges",
3260 "-adaptive-resize geometry",
3261 " adaptively resize image using 'mesh' interpolation",
3262 "-adaptive-sharpen geometry",
3263 " adaptively sharpen pixels; increase effect near edges",
3264 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3265 " transparent, extract, background, or shape",
3266 "-annotate geometry text",
3267 " annotate the image with text",
3268 "-auto-gamma automagically adjust gamma level of image",
3269 "-auto-level automagically adjust color levels of image",
3270 "-auto-orient automagically orient (rotate) image",
3271 "-bench iterations measure performance",
3272 "-black-threshold value",
3273 " force all pixels below the threshold into black",
3274 "-blue-shift simulate a scene at nighttime in the moonlight",
3275 "-blur geometry reduce image noise and reduce detail levels",
3276 "-border geometry surround image with a border of color",
3277 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003278 "-brightness-contrast geometry",
3279 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-cdl filename color correct with a color decision list",
3281 "-charcoal radius simulate a charcoal drawing",
3282 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003283 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003284 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003285 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003286 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003287 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003288 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003289 "-contrast enhance or reduce the image contrast",
3290 "-contrast-stretch geometry",
3291 " improve contrast by `stretching' the intensity range",
3292 "-convolve coefficients",
3293 " apply a convolution kernel to the image",
3294 "-cycle amount cycle the image colormap",
3295 "-decipher filename convert cipher pixels to plain pixels",
3296 "-deskew threshold straighten an image",
3297 "-despeckle reduce the speckles within an image",
3298 "-distort method args",
3299 " distort images according to given method ad args",
3300 "-draw string annotate the image with a graphic primitive",
3301 "-edge radius apply a filter to detect edges in the image",
3302 "-encipher filename convert plain pixels to cipher pixels",
3303 "-emboss radius emboss an image",
3304 "-enhance apply a digital filter to enhance a noisy image",
3305 "-equalize perform histogram equalization to an image",
3306 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003307 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003308 "-extent geometry set the image size",
3309 "-extract geometry extract area from image",
3310 "-fft implements the discrete Fourier transform (DFT)",
3311 "-flip flip image vertically",
3312 "-floodfill geometry color",
3313 " floodfill the image with color",
3314 "-flop flop image horizontally",
3315 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003316 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003317 " apply function over image values",
3318 "-gamma value level of gamma correction",
3319 "-gaussian-blur geometry",
3320 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003321 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003322 "-identify identify the format and characteristics of the image",
3323 "-ift implements the inverse discrete Fourier transform (DFT)",
3324 "-implode amount implode image pixels about the center",
3325 "-lat geometry local adaptive thresholding",
3326 "-layers method optimize, merge, or compare image layers",
3327 "-level value adjust the level of image contrast",
3328 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003329 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003330 "-linear-stretch geometry",
3331 " improve contrast by `stretching with saturation'",
3332 "-liquid-rescale geometry",
3333 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003334 "-median geometry apply a median filter to the image",
3335 "-mode geometry make each pixel the 'predominate color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003336 "-modulate value vary the brightness, saturation, and hue",
3337 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003338 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003339 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003340 "-motion-blur geometry",
3341 " simulate motion blur",
3342 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003343 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003344 "-normalize transform image to span the full range of colors",
3345 "-opaque color change this color to the fill color",
3346 "-ordered-dither NxN",
3347 " add a noise pattern to the image with specific",
3348 " amplitudes",
3349 "-paint radius simulate an oil painting",
3350 "-polaroid angle simulate a Polaroid picture",
3351 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003352 "-profile filename add, delete, or apply an image profile",
3353 "-quantize colorspace reduce colors in this colorspace",
3354 "-radial-blur angle radial blur the image",
3355 "-raise value lighten/darken image edges to create a 3-D effect",
3356 "-random-threshold low,high",
3357 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003358 "-region geometry apply options to a portion of the image",
3359 "-render render vector graphics",
3360 "-repage geometry size and location of an image canvas",
3361 "-resample geometry change the resolution of an image",
3362 "-resize geometry resize the image",
3363 "-roll geometry roll an image vertically or horizontally",
3364 "-rotate degrees apply Paeth rotation to the image",
3365 "-sample geometry scale image with pixel sampling",
3366 "-scale geometry scale the image",
3367 "-segment values segment an image",
3368 "-selective-blur geometry",
3369 " selectively blur pixels within a contrast threshold",
3370 "-sepia-tone threshold",
3371 " simulate a sepia-toned photo",
3372 "-set property value set an image property",
3373 "-shade degrees shade the image using a distant light source",
3374 "-shadow geometry simulate an image shadow",
3375 "-sharpen geometry sharpen the image",
3376 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003377 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003378 "-sigmoidal-contrast geometry",
3379 " increase the contrast without saturating highlights or shadows",
3380 "-sketch geometry simulate a pencil sketch",
3381 "-solarize threshold negate all pixels above the threshold level",
3382 "-sparse-color method args",
3383 " fill in a image based on a few color points",
3384 "-splice geometry splice the background color into the image",
3385 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003386 "-statistic type radius",
3387 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003388 "-strip strip image of all profiles and comments",
3389 "-swirl degrees swirl image pixels about the center",
3390 "-threshold value threshold the image",
3391 "-thumbnail geometry create a thumbnail of the image",
3392 "-tile filename tile image when filling a graphic primitive",
3393 "-tint value tint the image with the fill color",
3394 "-transform affine transform image",
3395 "-transparent color make this color transparent within the image",
3396 "-transpose flip image vertically and rotate 90 degrees",
3397 "-transverse flop image horizontally and rotate 270 degrees",
3398 "-trim trim image edges",
3399 "-type type image type",
3400 "-unique-colors discard all but one of any pixel color",
3401 "-unsharp geometry sharpen the image",
3402 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003403 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003404 "-white-threshold value",
3405 " force all pixels above the threshold into white",
3406 (char *) NULL
3407 },
3408 *sequence_operators[]=
3409 {
cristy4285d782011-02-09 20:12:28 +00003410 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003411 "-clut apply a color lookup table to the image",
3412 "-coalesce merge a sequence of images",
3413 "-combine combine a sequence of images",
3414 "-composite composite image",
3415 "-crop geometry cut out a rectangular region of the image",
3416 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003417 "-evaluate-sequence operator",
3418 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003419 "-flatten flatten a sequence of images",
3420 "-fx expression apply mathematical expression to an image channel(s)",
3421 "-hald-clut apply a Hald color lookup table to the image",
3422 "-morph value morph an image sequence",
3423 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003424 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003425 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003426 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003427 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003428 "-write filename write images to this file",
3429 (char *) NULL
3430 },
3431 *settings[]=
3432 {
3433 "-adjoin join images into a single multi-image file",
3434 "-affine matrix affine transform matrix",
3435 "-alpha option activate, deactivate, reset, or set the alpha channel",
3436 "-antialias remove pixel-aliasing",
3437 "-authenticate password",
3438 " decipher image with this password",
3439 "-attenuate value lessen (or intensify) when adding noise to an image",
3440 "-background color background color",
3441 "-bias value add bias when convolving an image",
3442 "-black-point-compensation",
3443 " use black point compensation",
3444 "-blue-primary point chromaticity blue primary point",
3445 "-bordercolor color border color",
3446 "-caption string assign a caption to an image",
3447 "-channel type apply option to select image channels",
3448 "-colors value preferred number of colors in the image",
3449 "-colorspace type alternate image colorspace",
3450 "-comment string annotate image with comment",
3451 "-compose operator set image composite operator",
3452 "-compress type type of pixel compression when writing the image",
3453 "-define format:option",
3454 " define one or more image format options",
3455 "-delay value display the next image after pausing",
3456 "-density geometry horizontal and vertical density of the image",
3457 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003458 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003459 "-display server get image or font from this X server",
3460 "-dispose method layer disposal method",
3461 "-dither method apply error diffusion to image",
3462 "-encoding type text encoding type",
3463 "-endian type endianness (MSB or LSB) of the image",
3464 "-family name render text with this font family",
3465 "-fill color color to use when filling a graphic primitive",
3466 "-filter type use this filter when resizing an image",
3467 "-font name render text with this font",
3468 "-format \"string\" output formatted image characteristics",
3469 "-fuzz distance colors within this distance are considered equal",
3470 "-gravity type horizontal and vertical text placement",
3471 "-green-primary point chromaticity green primary point",
3472 "-intent type type of rendering intent when managing the image color",
3473 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003474 "-interline-spacing value",
3475 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003476 "-interpolate method pixel color interpolation method",
3477 "-interword-spacing value",
3478 " set the space between two words",
3479 "-kerning value set the space between two letters",
3480 "-label string assign a label to an image",
3481 "-limit type value pixel cache resource limit",
3482 "-loop iterations add Netscape loop extension to your GIF animation",
3483 "-mask filename associate a mask with the image",
3484 "-mattecolor color frame color",
3485 "-monitor monitor progress",
3486 "-orient type image orientation",
3487 "-page geometry size and location of an image canvas (setting)",
3488 "-ping efficiently determine image attributes",
3489 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003490 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003491 "-preview type image preview type",
3492 "-quality value JPEG/MIFF/PNG compression level",
3493 "-quiet suppress all warning messages",
3494 "-red-primary point chromaticity red primary point",
3495 "-regard-warnings pay attention to warning messages",
3496 "-remap filename transform image colors to match this set of colors",
3497 "-respect-parentheses settings remain in effect until parenthesis boundary",
3498 "-sampling-factor geometry",
3499 " horizontal and vertical sampling factor",
3500 "-scene value image scene number",
3501 "-seed value seed a new sequence of pseudo-random numbers",
3502 "-size geometry width and height of image",
3503 "-stretch type render text with this font stretch",
3504 "-stroke color graphic primitive stroke color",
3505 "-strokewidth value graphic primitive stroke width",
3506 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003507 "-synchronize synchronize image to storage device",
3508 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003509 "-texture filename name of texture to tile onto the image background",
3510 "-tile-offset geometry",
3511 " tile offset",
3512 "-treedepth value color tree depth",
3513 "-transparent-color color",
3514 " transparent color",
3515 "-undercolor color annotation bounding box color",
3516 "-units type the units of image resolution",
3517 "-verbose print detailed information about the image",
3518 "-view FlashPix viewing transforms",
3519 "-virtual-pixel method",
3520 " virtual pixel access method",
3521 "-weight type render text with this font weight",
3522 "-white-point point chromaticity white point",
3523 (char *) NULL
3524 },
3525 *stack_operators[]=
3526 {
anthonyb69c4b32011-03-23 04:37:44 +00003527 "-delete indexes delete the image from the image sequence",
3528 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003529 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003530 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003531 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003532 "-swap indexes swap two images in the image sequence",
3533 (char *) NULL
3534 };
3535
3536 const char
3537 **p;
3538
cristybb503372010-05-27 20:51:26 +00003539 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003540 (void) printf("Copyright: %s\n",GetMagickCopyright());
3541 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003542 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3543 GetClientName());
3544 (void) printf("\nImage Settings:\n");
3545 for (p=settings; *p != (char *) NULL; p++)
3546 (void) printf(" %s\n",*p);
3547 (void) printf("\nImage Operators:\n");
3548 for (p=operators; *p != (char *) NULL; p++)
3549 (void) printf(" %s\n",*p);
3550 (void) printf("\nImage Sequence Operators:\n");
3551 for (p=sequence_operators; *p != (char *) NULL; p++)
3552 (void) printf(" %s\n",*p);
3553 (void) printf("\nImage Stack Operators:\n");
3554 for (p=stack_operators; *p != (char *) NULL; p++)
3555 (void) printf(" %s\n",*p);
3556 (void) printf("\nMiscellaneous Options:\n");
3557 for (p=miscellaneous; *p != (char *) NULL; p++)
3558 (void) printf(" %s\n",*p);
3559 (void) printf(
3560 "\nBy default, the image format of `file' is determined by its magic\n");
3561 (void) printf(
3562 "number. To specify a particular image format, precede the filename\n");
3563 (void) printf(
3564 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3565 (void) printf(
3566 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3567 (void) printf("'-' for standard input or output.\n");
3568 return(MagickFalse);
3569}
3570
3571WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3572 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3573{
3574#define DestroyMogrify() \
3575{ \
3576 if (format != (char *) NULL) \
3577 format=DestroyString(format); \
3578 if (path != (char *) NULL) \
3579 path=DestroyString(path); \
3580 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003581 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003582 argv[i]=DestroyString(argv[i]); \
3583 argv=(char **) RelinquishMagickMemory(argv); \
3584}
3585#define ThrowMogrifyException(asperity,tag,option) \
3586{ \
3587 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3588 option); \
3589 DestroyMogrify(); \
3590 return(MagickFalse); \
3591}
3592#define ThrowMogrifyInvalidArgumentException(option,argument) \
3593{ \
3594 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3595 "InvalidArgument","`%s': %s",argument,option); \
3596 DestroyMogrify(); \
3597 return(MagickFalse); \
3598}
3599
3600 char
3601 *format,
3602 *option,
3603 *path;
3604
3605 Image
3606 *image;
3607
3608 ImageStack
3609 image_stack[MaxImageStackDepth+1];
3610
cristy3ed852e2009-09-05 21:47:34 +00003611 MagickBooleanType
3612 global_colormap;
3613
3614 MagickBooleanType
3615 fire,
cristyebbcfea2011-02-25 02:43:54 +00003616 pend,
3617 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003618
3619 MagickStatusType
3620 status;
3621
cristyebbcfea2011-02-25 02:43:54 +00003622 register ssize_t
3623 i;
3624
3625 ssize_t
3626 j,
3627 k;
3628
cristy3ed852e2009-09-05 21:47:34 +00003629 /*
3630 Set defaults.
3631 */
3632 assert(image_info != (ImageInfo *) NULL);
3633 assert(image_info->signature == MagickSignature);
3634 if (image_info->debug != MagickFalse)
3635 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3636 assert(exception != (ExceptionInfo *) NULL);
3637 if (argc == 2)
3638 {
3639 option=argv[1];
3640 if ((LocaleCompare("version",option+1) == 0) ||
3641 (LocaleCompare("-version",option+1) == 0))
3642 {
3643 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003644 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003645 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
3646 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003647 return(MagickFalse);
3648 }
3649 }
3650 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003651 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003652 format=(char *) NULL;
3653 path=(char *) NULL;
3654 global_colormap=MagickFalse;
3655 k=0;
3656 j=1;
3657 NewImageStack();
3658 option=(char *) NULL;
3659 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003660 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003661 status=MagickTrue;
3662 /*
3663 Parse command line.
3664 */
3665 ReadCommandlLine(argc,&argv);
3666 status=ExpandFilenames(&argc,&argv);
3667 if (status == MagickFalse)
3668 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3669 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003670 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003671 {
3672 option=argv[i];
3673 if (LocaleCompare(option,"(") == 0)
3674 {
3675 FireImageStack(MagickFalse,MagickTrue,pend);
3676 if (k == MaxImageStackDepth)
3677 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3678 option);
3679 PushImageStack();
3680 continue;
3681 }
3682 if (LocaleCompare(option,")") == 0)
3683 {
3684 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3685 if (k == 0)
3686 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3687 PopImageStack();
3688 continue;
3689 }
3690 if (IsMagickOption(option) == MagickFalse)
3691 {
3692 char
3693 backup_filename[MaxTextExtent],
3694 *filename;
3695
3696 Image
3697 *images;
3698
3699 /*
3700 Option is a file name: begin by reading image from specified file.
3701 */
3702 FireImageStack(MagickFalse,MagickFalse,pend);
3703 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003704 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003705 filename=argv[++i];
3706 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3707 images=ReadImages(image_info,exception);
3708 status&=(images != (Image *) NULL) &&
3709 (exception->severity < ErrorException);
3710 if (images == (Image *) NULL)
3711 continue;
cristydaa76602010-06-30 13:05:11 +00003712 if (format != (char *) NULL)
3713 (void) CopyMagickString(images->filename,images->magick_filename,
3714 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003715 if (path != (char *) NULL)
3716 {
3717 GetPathComponent(option,TailPath,filename);
3718 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
3719 path,*DirectorySeparator,filename);
3720 }
3721 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003722 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003723 AppendImageStack(images);
3724 FinalizeImageSettings(image_info,image,MagickFalse);
3725 if (global_colormap != MagickFalse)
3726 {
3727 QuantizeInfo
3728 *quantize_info;
3729
3730 quantize_info=AcquireQuantizeInfo(image_info);
3731 (void) RemapImages(quantize_info,images,(Image *) NULL);
3732 quantize_info=DestroyQuantizeInfo(quantize_info);
3733 }
3734 *backup_filename='\0';
3735 if ((LocaleCompare(image->filename,"-") != 0) &&
3736 (IsPathWritable(image->filename) != MagickFalse))
3737 {
cristybb503372010-05-27 20:51:26 +00003738 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003739 i;
3740
3741 /*
3742 Rename image file as backup.
3743 */
3744 (void) CopyMagickString(backup_filename,image->filename,
3745 MaxTextExtent);
3746 for (i=0; i < 6; i++)
3747 {
3748 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3749 if (IsPathAccessible(backup_filename) == MagickFalse)
3750 break;
3751 }
3752 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3753 (rename(image->filename,backup_filename) != 0))
3754 *backup_filename='\0';
3755 }
3756 /*
3757 Write transmogrified image to disk.
3758 */
3759 image_info->synchronize=MagickTrue;
3760 status&=WriteImages(image_info,image,image->filename,exception);
3761 if ((status == MagickFalse) && (*backup_filename != '\0'))
3762 (void) remove(backup_filename);
3763 RemoveAllImageStack();
3764 continue;
3765 }
3766 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3767 switch (*(option+1))
3768 {
3769 case 'a':
3770 {
3771 if (LocaleCompare("adaptive-blur",option+1) == 0)
3772 {
3773 i++;
cristybb503372010-05-27 20:51:26 +00003774 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003775 ThrowMogrifyException(OptionError,"MissingArgument",option);
3776 if (IsGeometry(argv[i]) == MagickFalse)
3777 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3778 break;
3779 }
3780 if (LocaleCompare("adaptive-resize",option+1) == 0)
3781 {
3782 i++;
cristybb503372010-05-27 20:51:26 +00003783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003784 ThrowMogrifyException(OptionError,"MissingArgument",option);
3785 if (IsGeometry(argv[i]) == MagickFalse)
3786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3787 break;
3788 }
3789 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3790 {
3791 i++;
cristybb503372010-05-27 20:51:26 +00003792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003793 ThrowMogrifyException(OptionError,"MissingArgument",option);
3794 if (IsGeometry(argv[i]) == MagickFalse)
3795 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3796 break;
3797 }
3798 if (LocaleCompare("affine",option+1) == 0)
3799 {
3800 if (*option == '+')
3801 break;
3802 i++;
cristybb503372010-05-27 20:51:26 +00003803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003804 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003805 break;
3806 }
3807 if (LocaleCompare("alpha",option+1) == 0)
3808 {
cristybb503372010-05-27 20:51:26 +00003809 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003810 type;
3811
3812 if (*option == '+')
3813 break;
3814 i++;
cristybb503372010-05-27 20:51:26 +00003815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003816 ThrowMogrifyException(OptionError,"MissingArgument",option);
3817 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
3818 if (type < 0)
3819 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3820 argv[i]);
3821 break;
3822 }
3823 if (LocaleCompare("annotate",option+1) == 0)
3824 {
3825 if (*option == '+')
3826 break;
3827 i++;
cristybb503372010-05-27 20:51:26 +00003828 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003829 ThrowMogrifyException(OptionError,"MissingArgument",option);
3830 if (IsGeometry(argv[i]) == MagickFalse)
3831 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003833 ThrowMogrifyException(OptionError,"MissingArgument",option);
3834 i++;
3835 break;
3836 }
3837 if (LocaleCompare("antialias",option+1) == 0)
3838 break;
3839 if (LocaleCompare("append",option+1) == 0)
3840 break;
3841 if (LocaleCompare("attenuate",option+1) == 0)
3842 {
3843 if (*option == '+')
3844 break;
3845 i++;
cristybb503372010-05-27 20:51:26 +00003846 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003847 ThrowMogrifyException(OptionError,"MissingArgument",option);
3848 if (IsGeometry(argv[i]) == MagickFalse)
3849 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3850 break;
3851 }
3852 if (LocaleCompare("authenticate",option+1) == 0)
3853 {
3854 if (*option == '+')
3855 break;
3856 i++;
cristybb503372010-05-27 20:51:26 +00003857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003858 ThrowMogrifyException(OptionError,"MissingArgument",option);
3859 break;
3860 }
3861 if (LocaleCompare("auto-gamma",option+1) == 0)
3862 break;
3863 if (LocaleCompare("auto-level",option+1) == 0)
3864 break;
3865 if (LocaleCompare("auto-orient",option+1) == 0)
3866 break;
3867 if (LocaleCompare("average",option+1) == 0)
3868 break;
3869 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3870 }
3871 case 'b':
3872 {
3873 if (LocaleCompare("background",option+1) == 0)
3874 {
3875 if (*option == '+')
3876 break;
3877 i++;
cristybb503372010-05-27 20:51:26 +00003878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003879 ThrowMogrifyException(OptionError,"MissingArgument",option);
3880 break;
3881 }
3882 if (LocaleCompare("bias",option+1) == 0)
3883 {
3884 if (*option == '+')
3885 break;
3886 i++;
cristybb503372010-05-27 20:51:26 +00003887 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003888 ThrowMogrifyException(OptionError,"MissingArgument",option);
3889 if (IsGeometry(argv[i]) == MagickFalse)
3890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3891 break;
3892 }
3893 if (LocaleCompare("black-point-compensation",option+1) == 0)
3894 break;
3895 if (LocaleCompare("black-threshold",option+1) == 0)
3896 {
3897 if (*option == '+')
3898 break;
3899 i++;
cristybb503372010-05-27 20:51:26 +00003900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003901 ThrowMogrifyException(OptionError,"MissingArgument",option);
3902 if (IsGeometry(argv[i]) == MagickFalse)
3903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3904 break;
3905 }
3906 if (LocaleCompare("blue-primary",option+1) == 0)
3907 {
3908 if (*option == '+')
3909 break;
3910 i++;
cristybb503372010-05-27 20:51:26 +00003911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003912 ThrowMogrifyException(OptionError,"MissingArgument",option);
3913 if (IsGeometry(argv[i]) == MagickFalse)
3914 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3915 break;
3916 }
3917 if (LocaleCompare("blue-shift",option+1) == 0)
3918 {
3919 i++;
cristybb503372010-05-27 20:51:26 +00003920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003921 ThrowMogrifyException(OptionError,"MissingArgument",option);
3922 if (IsGeometry(argv[i]) == MagickFalse)
3923 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3924 break;
3925 }
3926 if (LocaleCompare("blur",option+1) == 0)
3927 {
3928 i++;
cristybb503372010-05-27 20:51:26 +00003929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003930 ThrowMogrifyException(OptionError,"MissingArgument",option);
3931 if (IsGeometry(argv[i]) == MagickFalse)
3932 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3933 break;
3934 }
3935 if (LocaleCompare("border",option+1) == 0)
3936 {
3937 if (*option == '+')
3938 break;
3939 i++;
cristybb503372010-05-27 20:51:26 +00003940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003941 ThrowMogrifyException(OptionError,"MissingArgument",option);
3942 if (IsGeometry(argv[i]) == MagickFalse)
3943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3944 break;
3945 }
3946 if (LocaleCompare("bordercolor",option+1) == 0)
3947 {
3948 if (*option == '+')
3949 break;
3950 i++;
cristybb503372010-05-27 20:51:26 +00003951 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003952 ThrowMogrifyException(OptionError,"MissingArgument",option);
3953 break;
3954 }
3955 if (LocaleCompare("box",option+1) == 0)
3956 {
3957 if (*option == '+')
3958 break;
3959 i++;
cristybb503372010-05-27 20:51:26 +00003960 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003961 ThrowMogrifyException(OptionError,"MissingArgument",option);
3962 break;
3963 }
cristya28d6b82010-01-11 20:03:47 +00003964 if (LocaleCompare("brightness-contrast",option+1) == 0)
3965 {
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 if (IsGeometry(argv[i]) == MagickFalse)
3970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3971 break;
3972 }
cristy3ed852e2009-09-05 21:47:34 +00003973 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3974 }
3975 case 'c':
3976 {
3977 if (LocaleCompare("cache",option+1) == 0)
3978 {
3979 if (*option == '+')
3980 break;
3981 i++;
cristybb503372010-05-27 20:51:26 +00003982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003983 ThrowMogrifyException(OptionError,"MissingArgument",option);
3984 if (IsGeometry(argv[i]) == MagickFalse)
3985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3986 break;
3987 }
3988 if (LocaleCompare("caption",option+1) == 0)
3989 {
3990 if (*option == '+')
3991 break;
3992 i++;
cristybb503372010-05-27 20:51:26 +00003993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003994 ThrowMogrifyException(OptionError,"MissingArgument",option);
3995 break;
3996 }
3997 if (LocaleCompare("channel",option+1) == 0)
3998 {
cristybb503372010-05-27 20:51:26 +00003999 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004000 channel;
4001
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 channel=ParseChannelOption(argv[i]);
4008 if (channel < 0)
4009 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4010 argv[i]);
4011 break;
4012 }
4013 if (LocaleCompare("cdl",option+1) == 0)
4014 {
4015 if (*option == '+')
4016 break;
4017 i++;
cristybb503372010-05-27 20:51:26 +00004018 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004019 ThrowMogrifyException(OptionError,"MissingArgument",option);
4020 break;
4021 }
4022 if (LocaleCompare("charcoal",option+1) == 0)
4023 {
4024 if (*option == '+')
4025 break;
4026 i++;
cristybb503372010-05-27 20:51:26 +00004027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004028 ThrowMogrifyException(OptionError,"MissingArgument",option);
4029 if (IsGeometry(argv[i]) == MagickFalse)
4030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4031 break;
4032 }
4033 if (LocaleCompare("chop",option+1) == 0)
4034 {
4035 if (*option == '+')
4036 break;
4037 i++;
cristybb503372010-05-27 20:51:26 +00004038 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004039 ThrowMogrifyException(OptionError,"MissingArgument",option);
4040 if (IsGeometry(argv[i]) == MagickFalse)
4041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4042 break;
4043 }
cristy1eb45dd2009-09-25 16:38:06 +00004044 if (LocaleCompare("clamp",option+1) == 0)
4045 break;
4046 if (LocaleCompare("clip",option+1) == 0)
4047 break;
cristy3ed852e2009-09-05 21:47:34 +00004048 if (LocaleCompare("clip-mask",option+1) == 0)
4049 {
4050 if (*option == '+')
4051 break;
4052 i++;
cristybb503372010-05-27 20:51:26 +00004053 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004054 ThrowMogrifyException(OptionError,"MissingArgument",option);
4055 break;
4056 }
4057 if (LocaleCompare("clut",option+1) == 0)
4058 break;
4059 if (LocaleCompare("coalesce",option+1) == 0)
4060 break;
4061 if (LocaleCompare("colorize",option+1) == 0)
4062 {
4063 if (*option == '+')
4064 break;
4065 i++;
cristybb503372010-05-27 20:51:26 +00004066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004067 ThrowMogrifyException(OptionError,"MissingArgument",option);
4068 if (IsGeometry(argv[i]) == MagickFalse)
4069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4070 break;
4071 }
cristye6365592010-04-02 17:31:23 +00004072 if (LocaleCompare("color-matrix",option+1) == 0)
4073 {
cristyb6bd4ad2010-08-08 01:12:27 +00004074 KernelInfo
4075 *kernel_info;
4076
cristye6365592010-04-02 17:31:23 +00004077 if (*option == '+')
4078 break;
4079 i++;
cristybb503372010-05-27 20:51:26 +00004080 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004081 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004082 kernel_info=AcquireKernelInfo(argv[i]);
4083 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004084 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004085 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004086 break;
4087 }
cristy3ed852e2009-09-05 21:47:34 +00004088 if (LocaleCompare("colors",option+1) == 0)
4089 {
4090 if (*option == '+')
4091 break;
4092 i++;
cristybb503372010-05-27 20:51:26 +00004093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004094 ThrowMogrifyException(OptionError,"MissingArgument",option);
4095 if (IsGeometry(argv[i]) == MagickFalse)
4096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4097 break;
4098 }
4099 if (LocaleCompare("colorspace",option+1) == 0)
4100 {
cristybb503372010-05-27 20:51:26 +00004101 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004102 colorspace;
4103
4104 if (*option == '+')
4105 break;
4106 i++;
cristybb503372010-05-27 20:51:26 +00004107 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004108 ThrowMogrifyException(OptionError,"MissingArgument",option);
4109 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4110 argv[i]);
4111 if (colorspace < 0)
4112 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4113 argv[i]);
4114 break;
4115 }
4116 if (LocaleCompare("combine",option+1) == 0)
4117 break;
4118 if (LocaleCompare("comment",option+1) == 0)
4119 {
4120 if (*option == '+')
4121 break;
4122 i++;
cristybb503372010-05-27 20:51:26 +00004123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004124 ThrowMogrifyException(OptionError,"MissingArgument",option);
4125 break;
4126 }
4127 if (LocaleCompare("composite",option+1) == 0)
4128 break;
4129 if (LocaleCompare("compress",option+1) == 0)
4130 {
cristybb503372010-05-27 20:51:26 +00004131 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004132 compress;
4133
4134 if (*option == '+')
4135 break;
4136 i++;
cristybb503372010-05-27 20:51:26 +00004137 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004138 ThrowMogrifyException(OptionError,"MissingArgument",option);
4139 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4140 argv[i]);
4141 if (compress < 0)
4142 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4143 argv[i]);
4144 break;
4145 }
cristy22879752009-10-25 23:55:40 +00004146 if (LocaleCompare("concurrent",option+1) == 0)
4147 break;
cristy3ed852e2009-09-05 21:47:34 +00004148 if (LocaleCompare("contrast",option+1) == 0)
4149 break;
4150 if (LocaleCompare("contrast-stretch",option+1) == 0)
4151 {
4152 i++;
cristybb503372010-05-27 20:51:26 +00004153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004154 ThrowMogrifyException(OptionError,"MissingArgument",option);
4155 if (IsGeometry(argv[i]) == MagickFalse)
4156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4157 break;
4158 }
4159 if (LocaleCompare("convolve",option+1) == 0)
4160 {
cristyb6bd4ad2010-08-08 01:12:27 +00004161 KernelInfo
4162 *kernel_info;
4163
cristy3ed852e2009-09-05 21:47:34 +00004164 if (*option == '+')
4165 break;
4166 i++;
cristybb503372010-05-27 20:51:26 +00004167 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004168 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004169 kernel_info=AcquireKernelInfo(argv[i]);
4170 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004171 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004172 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004173 break;
4174 }
4175 if (LocaleCompare("crop",option+1) == 0)
4176 {
4177 if (*option == '+')
4178 break;
4179 i++;
cristybb503372010-05-27 20:51:26 +00004180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004181 ThrowMogrifyException(OptionError,"MissingArgument",option);
4182 if (IsGeometry(argv[i]) == MagickFalse)
4183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4184 break;
4185 }
4186 if (LocaleCompare("cycle",option+1) == 0)
4187 {
4188 if (*option == '+')
4189 break;
4190 i++;
cristybb503372010-05-27 20:51:26 +00004191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004192 ThrowMogrifyException(OptionError,"MissingArgument",option);
4193 if (IsGeometry(argv[i]) == MagickFalse)
4194 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4195 break;
4196 }
4197 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4198 }
4199 case 'd':
4200 {
4201 if (LocaleCompare("decipher",option+1) == 0)
4202 {
4203 if (*option == '+')
4204 break;
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
4208 break;
4209 }
4210 if (LocaleCompare("deconstruct",option+1) == 0)
4211 break;
4212 if (LocaleCompare("debug",option+1) == 0)
4213 {
cristybb503372010-05-27 20:51:26 +00004214 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004215 event;
4216
4217 if (*option == '+')
4218 break;
4219 i++;
cristybb503372010-05-27 20:51:26 +00004220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004221 ThrowMogrifyException(OptionError,"MissingArgument",option);
4222 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4223 if (event < 0)
4224 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4225 argv[i]);
4226 (void) SetLogEventMask(argv[i]);
4227 break;
4228 }
4229 if (LocaleCompare("define",option+1) == 0)
4230 {
4231 i++;
cristybb503372010-05-27 20:51:26 +00004232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004233 ThrowMogrifyException(OptionError,"MissingArgument",option);
4234 if (*option == '+')
4235 {
4236 const char
4237 *define;
4238
4239 define=GetImageOption(image_info,argv[i]);
4240 if (define == (const char *) NULL)
4241 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4242 break;
4243 }
4244 break;
4245 }
4246 if (LocaleCompare("delay",option+1) == 0)
4247 {
4248 if (*option == '+')
4249 break;
4250 i++;
cristybb503372010-05-27 20:51:26 +00004251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004252 ThrowMogrifyException(OptionError,"MissingArgument",option);
4253 if (IsGeometry(argv[i]) == MagickFalse)
4254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4255 break;
4256 }
cristyecb10ff2011-03-22 13:14:03 +00004257 if (LocaleCompare("delete",option+1) == 0)
4258 {
4259 if (*option == '+')
4260 break;
4261 i++;
4262 if (i == (ssize_t) (argc-1))
4263 ThrowMogrifyException(OptionError,"MissingArgument",option);
4264 if (IsGeometry(argv[i]) == MagickFalse)
4265 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4266 break;
4267 }
cristy3ed852e2009-09-05 21:47:34 +00004268 if (LocaleCompare("density",option+1) == 0)
4269 {
4270 if (*option == '+')
4271 break;
4272 i++;
cristybb503372010-05-27 20:51:26 +00004273 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004274 ThrowMogrifyException(OptionError,"MissingArgument",option);
4275 if (IsGeometry(argv[i]) == MagickFalse)
4276 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4277 break;
4278 }
4279 if (LocaleCompare("depth",option+1) == 0)
4280 {
4281 if (*option == '+')
4282 break;
4283 i++;
cristybb503372010-05-27 20:51:26 +00004284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004285 ThrowMogrifyException(OptionError,"MissingArgument",option);
4286 if (IsGeometry(argv[i]) == MagickFalse)
4287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4288 break;
4289 }
4290 if (LocaleCompare("deskew",option+1) == 0)
4291 {
4292 if (*option == '+')
4293 break;
4294 i++;
cristybb503372010-05-27 20:51:26 +00004295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004296 ThrowMogrifyException(OptionError,"MissingArgument",option);
4297 if (IsGeometry(argv[i]) == MagickFalse)
4298 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4299 break;
4300 }
4301 if (LocaleCompare("despeckle",option+1) == 0)
4302 break;
4303 if (LocaleCompare("dft",option+1) == 0)
4304 break;
cristyc9b12952010-03-28 01:12:28 +00004305 if (LocaleCompare("direction",option+1) == 0)
4306 {
cristybb503372010-05-27 20:51:26 +00004307 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004308 direction;
4309
4310 if (*option == '+')
4311 break;
4312 i++;
cristybb503372010-05-27 20:51:26 +00004313 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004314 ThrowMogrifyException(OptionError,"MissingArgument",option);
4315 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4316 argv[i]);
4317 if (direction < 0)
4318 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4319 argv[i]);
4320 break;
4321 }
cristy3ed852e2009-09-05 21:47:34 +00004322 if (LocaleCompare("display",option+1) == 0)
4323 {
4324 if (*option == '+')
4325 break;
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
4329 break;
4330 }
4331 if (LocaleCompare("dispose",option+1) == 0)
4332 {
cristybb503372010-05-27 20:51:26 +00004333 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004334 dispose;
4335
4336 if (*option == '+')
4337 break;
4338 i++;
cristybb503372010-05-27 20:51:26 +00004339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004340 ThrowMogrifyException(OptionError,"MissingArgument",option);
4341 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4342 if (dispose < 0)
4343 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4344 argv[i]);
4345 break;
4346 }
4347 if (LocaleCompare("distort",option+1) == 0)
4348 {
cristybb503372010-05-27 20:51:26 +00004349 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004350 op;
4351
4352 i++;
cristybb503372010-05-27 20:51:26 +00004353 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004354 ThrowMogrifyException(OptionError,"MissingArgument",option);
4355 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4356 if (op < 0)
4357 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4358 argv[i]);
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
4362 break;
4363 }
4364 if (LocaleCompare("dither",option+1) == 0)
4365 {
cristybb503372010-05-27 20:51:26 +00004366 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004367 method;
4368
4369 if (*option == '+')
4370 break;
4371 i++;
cristybb503372010-05-27 20:51:26 +00004372 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004373 ThrowMogrifyException(OptionError,"MissingArgument",option);
4374 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4375 if (method < 0)
4376 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4377 argv[i]);
4378 break;
4379 }
4380 if (LocaleCompare("draw",option+1) == 0)
4381 {
4382 if (*option == '+')
4383 break;
4384 i++;
cristybb503372010-05-27 20:51:26 +00004385 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004386 ThrowMogrifyException(OptionError,"MissingArgument",option);
4387 break;
4388 }
cristyecb10ff2011-03-22 13:14:03 +00004389 if (LocaleCompare("duplicate",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
4394 if (i == (ssize_t) (argc-1))
4395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 if (IsGeometry(argv[i]) == MagickFalse)
4397 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4398 break;
4399 }
cristy22879752009-10-25 23:55:40 +00004400 if (LocaleCompare("duration",option+1) == 0)
4401 {
4402 if (*option == '+')
4403 break;
4404 i++;
cristybb503372010-05-27 20:51:26 +00004405 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004406 ThrowMogrifyException(OptionError,"MissingArgument",option);
4407 if (IsGeometry(argv[i]) == MagickFalse)
4408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4409 break;
4410 }
cristy3ed852e2009-09-05 21:47:34 +00004411 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4412 }
4413 case 'e':
4414 {
4415 if (LocaleCompare("edge",option+1) == 0)
4416 {
4417 if (*option == '+')
4418 break;
4419 i++;
cristybb503372010-05-27 20:51:26 +00004420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004421 ThrowMogrifyException(OptionError,"MissingArgument",option);
4422 if (IsGeometry(argv[i]) == MagickFalse)
4423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4424 break;
4425 }
4426 if (LocaleCompare("emboss",option+1) == 0)
4427 {
4428 if (*option == '+')
4429 break;
4430 i++;
cristybb503372010-05-27 20:51:26 +00004431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004432 ThrowMogrifyException(OptionError,"MissingArgument",option);
4433 if (IsGeometry(argv[i]) == MagickFalse)
4434 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4435 break;
4436 }
4437 if (LocaleCompare("encipher",option+1) == 0)
4438 {
4439 if (*option == '+')
4440 break;
4441 i++;
cristybb503372010-05-27 20:51:26 +00004442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"MissingArgument",option);
4444 break;
4445 }
4446 if (LocaleCompare("encoding",option+1) == 0)
4447 {
4448 if (*option == '+')
4449 break;
4450 i++;
cristybb503372010-05-27 20:51:26 +00004451 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004452 ThrowMogrifyException(OptionError,"MissingArgument",option);
4453 break;
4454 }
4455 if (LocaleCompare("endian",option+1) == 0)
4456 {
cristybb503372010-05-27 20:51:26 +00004457 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004458 endian;
4459
4460 if (*option == '+')
4461 break;
4462 i++;
cristybb503372010-05-27 20:51:26 +00004463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004464 ThrowMogrifyException(OptionError,"MissingArgument",option);
4465 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4466 if (endian < 0)
4467 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4468 argv[i]);
4469 break;
4470 }
4471 if (LocaleCompare("enhance",option+1) == 0)
4472 break;
4473 if (LocaleCompare("equalize",option+1) == 0)
4474 break;
4475 if (LocaleCompare("evaluate",option+1) == 0)
4476 {
cristybb503372010-05-27 20:51:26 +00004477 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004478 op;
4479
4480 if (*option == '+')
4481 break;
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4486 if (op < 0)
4487 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4488 argv[i]);
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 if (IsGeometry(argv[i]) == MagickFalse)
4493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4494 break;
4495 }
cristyd18ae7c2010-03-07 17:39:52 +00004496 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4497 {
cristybb503372010-05-27 20:51:26 +00004498 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004499 op;
4500
4501 if (*option == '+')
4502 break;
4503 i++;
cristybb503372010-05-27 20:51:26 +00004504 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004505 ThrowMogrifyException(OptionError,"MissingArgument",option);
4506 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4507 if (op < 0)
4508 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4509 argv[i]);
4510 break;
4511 }
cristy3ed852e2009-09-05 21:47:34 +00004512 if (LocaleCompare("extent",option+1) == 0)
4513 {
4514 if (*option == '+')
4515 break;
4516 i++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
4519 if (IsGeometry(argv[i]) == MagickFalse)
4520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4521 break;
4522 }
4523 if (LocaleCompare("extract",option+1) == 0)
4524 {
4525 if (*option == '+')
4526 break;
4527 i++;
cristybb503372010-05-27 20:51:26 +00004528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004529 ThrowMogrifyException(OptionError,"MissingArgument",option);
4530 if (IsGeometry(argv[i]) == MagickFalse)
4531 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4532 break;
4533 }
4534 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4535 }
4536 case 'f':
4537 {
4538 if (LocaleCompare("family",option+1) == 0)
4539 {
4540 if (*option == '+')
4541 break;
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
4545 break;
4546 }
4547 if (LocaleCompare("fill",option+1) == 0)
4548 {
4549 if (*option == '+')
4550 break;
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 break;
4555 }
4556 if (LocaleCompare("filter",option+1) == 0)
4557 {
cristybb503372010-05-27 20:51:26 +00004558 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004559 filter;
4560
4561 if (*option == '+')
4562 break;
4563 i++;
cristybb503372010-05-27 20:51:26 +00004564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004565 ThrowMogrifyException(OptionError,"MissingArgument",option);
4566 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4567 if (filter < 0)
4568 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4569 argv[i]);
4570 break;
4571 }
4572 if (LocaleCompare("flatten",option+1) == 0)
4573 break;
4574 if (LocaleCompare("flip",option+1) == 0)
4575 break;
4576 if (LocaleCompare("flop",option+1) == 0)
4577 break;
4578 if (LocaleCompare("floodfill",option+1) == 0)
4579 {
4580 if (*option == '+')
4581 break;
4582 i++;
cristybb503372010-05-27 20:51:26 +00004583 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004584 ThrowMogrifyException(OptionError,"MissingArgument",option);
4585 if (IsGeometry(argv[i]) == MagickFalse)
4586 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4587 i++;
cristybb503372010-05-27 20:51:26 +00004588 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004589 ThrowMogrifyException(OptionError,"MissingArgument",option);
4590 break;
4591 }
4592 if (LocaleCompare("font",option+1) == 0)
4593 {
4594 if (*option == '+')
4595 break;
4596 i++;
cristybb503372010-05-27 20:51:26 +00004597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004598 ThrowMogrifyException(OptionError,"MissingArgument",option);
4599 break;
4600 }
4601 if (LocaleCompare("format",option+1) == 0)
4602 {
4603 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4604 (void) CloneString(&format,(char *) NULL);
4605 if (*option == '+')
4606 break;
4607 i++;
cristybb503372010-05-27 20:51:26 +00004608 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004609 ThrowMogrifyException(OptionError,"MissingArgument",option);
4610 (void) CloneString(&format,argv[i]);
4611 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4612 (void) ConcatenateMagickString(image_info->filename,":",
4613 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004614 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004615 if (*image_info->magick == '\0')
4616 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4617 format);
4618 break;
4619 }
4620 if (LocaleCompare("frame",option+1) == 0)
4621 {
4622 if (*option == '+')
4623 break;
4624 i++;
cristybb503372010-05-27 20:51:26 +00004625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004626 ThrowMogrifyException(OptionError,"MissingArgument",option);
4627 if (IsGeometry(argv[i]) == MagickFalse)
4628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4629 break;
4630 }
4631 if (LocaleCompare("function",option+1) == 0)
4632 {
cristybb503372010-05-27 20:51:26 +00004633 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004634 op;
4635
4636 if (*option == '+')
4637 break;
4638 i++;
cristybb503372010-05-27 20:51:26 +00004639 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004640 ThrowMogrifyException(OptionError,"MissingArgument",option);
4641 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4642 if (op < 0)
4643 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4644 i++;
cristybb503372010-05-27 20:51:26 +00004645 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004646 ThrowMogrifyException(OptionError,"MissingArgument",option);
4647 break;
4648 }
4649 if (LocaleCompare("fuzz",option+1) == 0)
4650 {
4651 if (*option == '+')
4652 break;
4653 i++;
cristybb503372010-05-27 20:51:26 +00004654 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004655 ThrowMogrifyException(OptionError,"MissingArgument",option);
4656 if (IsGeometry(argv[i]) == MagickFalse)
4657 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4658 break;
4659 }
4660 if (LocaleCompare("fx",option+1) == 0)
4661 {
4662 if (*option == '+')
4663 break;
4664 i++;
cristybb503372010-05-27 20:51:26 +00004665 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004666 ThrowMogrifyException(OptionError,"MissingArgument",option);
4667 break;
4668 }
4669 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4670 }
4671 case 'g':
4672 {
4673 if (LocaleCompare("gamma",option+1) == 0)
4674 {
4675 i++;
cristybb503372010-05-27 20:51:26 +00004676 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004677 ThrowMogrifyException(OptionError,"MissingArgument",option);
4678 if (IsGeometry(argv[i]) == MagickFalse)
4679 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4680 break;
4681 }
4682 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4683 (LocaleCompare("gaussian",option+1) == 0))
4684 {
4685 i++;
cristybb503372010-05-27 20:51:26 +00004686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004687 ThrowMogrifyException(OptionError,"MissingArgument",option);
4688 if (IsGeometry(argv[i]) == MagickFalse)
4689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4690 break;
4691 }
4692 if (LocaleCompare("geometry",option+1) == 0)
4693 {
4694 if (*option == '+')
4695 break;
4696 i++;
cristybb503372010-05-27 20:51:26 +00004697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004698 ThrowMogrifyException(OptionError,"MissingArgument",option);
4699 if (IsGeometry(argv[i]) == MagickFalse)
4700 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4701 break;
4702 }
4703 if (LocaleCompare("gravity",option+1) == 0)
4704 {
cristybb503372010-05-27 20:51:26 +00004705 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004706 gravity;
4707
4708 if (*option == '+')
4709 break;
4710 i++;
cristybb503372010-05-27 20:51:26 +00004711 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004712 ThrowMogrifyException(OptionError,"MissingArgument",option);
4713 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
4714 if (gravity < 0)
4715 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4716 argv[i]);
4717 break;
4718 }
4719 if (LocaleCompare("green-primary",option+1) == 0)
4720 {
4721 if (*option == '+')
4722 break;
4723 i++;
cristybb503372010-05-27 20:51:26 +00004724 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004725 ThrowMogrifyException(OptionError,"MissingArgument",option);
4726 if (IsGeometry(argv[i]) == MagickFalse)
4727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4728 break;
4729 }
4730 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4731 }
4732 case 'h':
4733 {
4734 if (LocaleCompare("hald-clut",option+1) == 0)
4735 break;
4736 if ((LocaleCompare("help",option+1) == 0) ||
4737 (LocaleCompare("-help",option+1) == 0))
4738 return(MogrifyUsage());
4739 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4740 }
4741 case 'i':
4742 {
4743 if (LocaleCompare("identify",option+1) == 0)
4744 break;
4745 if (LocaleCompare("idft",option+1) == 0)
4746 break;
4747 if (LocaleCompare("implode",option+1) == 0)
4748 {
4749 if (*option == '+')
4750 break;
4751 i++;
cristybb503372010-05-27 20:51:26 +00004752 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004753 ThrowMogrifyException(OptionError,"MissingArgument",option);
4754 if (IsGeometry(argv[i]) == MagickFalse)
4755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4756 break;
4757 }
4758 if (LocaleCompare("intent",option+1) == 0)
4759 {
cristybb503372010-05-27 20:51:26 +00004760 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004761 intent;
4762
4763 if (*option == '+')
4764 break;
4765 i++;
cristybb503372010-05-27 20:51:26 +00004766 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004767 ThrowMogrifyException(OptionError,"MissingArgument",option);
4768 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
4769 if (intent < 0)
4770 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4771 argv[i]);
4772 break;
4773 }
4774 if (LocaleCompare("interlace",option+1) == 0)
4775 {
cristybb503372010-05-27 20:51:26 +00004776 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004777 interlace;
4778
4779 if (*option == '+')
4780 break;
4781 i++;
cristybb503372010-05-27 20:51:26 +00004782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004783 ThrowMogrifyException(OptionError,"MissingArgument",option);
4784 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
4785 argv[i]);
4786 if (interlace < 0)
4787 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4788 argv[i]);
4789 break;
4790 }
cristyb32b90a2009-09-07 21:45:48 +00004791 if (LocaleCompare("interline-spacing",option+1) == 0)
4792 {
4793 if (*option == '+')
4794 break;
4795 i++;
cristybb503372010-05-27 20:51:26 +00004796 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004797 ThrowMogrifyException(OptionError,"MissingArgument",option);
4798 if (IsGeometry(argv[i]) == MagickFalse)
4799 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4800 break;
4801 }
cristy3ed852e2009-09-05 21:47:34 +00004802 if (LocaleCompare("interpolate",option+1) == 0)
4803 {
cristybb503372010-05-27 20:51:26 +00004804 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004805 interpolate;
4806
4807 if (*option == '+')
4808 break;
4809 i++;
cristybb503372010-05-27 20:51:26 +00004810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004811 ThrowMogrifyException(OptionError,"MissingArgument",option);
4812 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
4813 argv[i]);
4814 if (interpolate < 0)
4815 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4816 argv[i]);
4817 break;
4818 }
4819 if (LocaleCompare("interword-spacing",option+1) == 0)
4820 {
4821 if (*option == '+')
4822 break;
4823 i++;
cristybb503372010-05-27 20:51:26 +00004824 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004825 ThrowMogrifyException(OptionError,"MissingArgument",option);
4826 if (IsGeometry(argv[i]) == MagickFalse)
4827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4828 break;
4829 }
4830 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4831 }
4832 case 'k':
4833 {
4834 if (LocaleCompare("kerning",option+1) == 0)
4835 {
4836 if (*option == '+')
4837 break;
4838 i++;
cristybb503372010-05-27 20:51:26 +00004839 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004840 ThrowMogrifyException(OptionError,"MissingArgument",option);
4841 if (IsGeometry(argv[i]) == MagickFalse)
4842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4843 break;
4844 }
4845 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4846 }
4847 case 'l':
4848 {
4849 if (LocaleCompare("label",option+1) == 0)
4850 {
4851 if (*option == '+')
4852 break;
4853 i++;
cristybb503372010-05-27 20:51:26 +00004854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004855 ThrowMogrifyException(OptionError,"MissingArgument",option);
4856 break;
4857 }
4858 if (LocaleCompare("lat",option+1) == 0)
4859 {
4860 if (*option == '+')
4861 break;
4862 i++;
cristybb503372010-05-27 20:51:26 +00004863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004864 ThrowMogrifyException(OptionError,"MissingArgument",option);
4865 if (IsGeometry(argv[i]) == MagickFalse)
4866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4867 }
4868 if (LocaleCompare("layers",option+1) == 0)
4869 {
cristybb503372010-05-27 20:51:26 +00004870 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004871 type;
4872
4873 if (*option == '+')
4874 break;
4875 i++;
cristybb503372010-05-27 20:51:26 +00004876 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004877 ThrowMogrifyException(OptionError,"MissingArgument",option);
4878 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
4879 if (type < 0)
4880 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4881 argv[i]);
4882 break;
4883 }
4884 if (LocaleCompare("level",option+1) == 0)
4885 {
4886 i++;
cristybb503372010-05-27 20:51:26 +00004887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004888 ThrowMogrifyException(OptionError,"MissingArgument",option);
4889 if (IsGeometry(argv[i]) == MagickFalse)
4890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4891 break;
4892 }
4893 if (LocaleCompare("level-colors",option+1) == 0)
4894 {
4895 i++;
cristybb503372010-05-27 20:51:26 +00004896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004897 ThrowMogrifyException(OptionError,"MissingArgument",option);
4898 break;
4899 }
4900 if (LocaleCompare("linewidth",option+1) == 0)
4901 {
4902 if (*option == '+')
4903 break;
4904 i++;
cristybb503372010-05-27 20:51:26 +00004905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004906 ThrowMogrifyException(OptionError,"MissingArgument",option);
4907 if (IsGeometry(argv[i]) == MagickFalse)
4908 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4909 break;
4910 }
4911 if (LocaleCompare("limit",option+1) == 0)
4912 {
4913 char
4914 *p;
4915
4916 double
4917 value;
4918
cristybb503372010-05-27 20:51:26 +00004919 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004920 resource;
4921
4922 if (*option == '+')
4923 break;
4924 i++;
cristybb503372010-05-27 20:51:26 +00004925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004926 ThrowMogrifyException(OptionError,"MissingArgument",option);
4927 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
4928 argv[i]);
4929 if (resource < 0)
4930 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4931 argv[i]);
4932 i++;
cristybb503372010-05-27 20:51:26 +00004933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004934 ThrowMogrifyException(OptionError,"MissingArgument",option);
4935 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004936 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004937 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4938 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4939 break;
4940 }
4941 if (LocaleCompare("liquid-rescale",option+1) == 0)
4942 {
4943 i++;
cristybb503372010-05-27 20:51:26 +00004944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004945 ThrowMogrifyException(OptionError,"MissingArgument",option);
4946 if (IsGeometry(argv[i]) == MagickFalse)
4947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4948 break;
4949 }
4950 if (LocaleCompare("list",option+1) == 0)
4951 {
cristybb503372010-05-27 20:51:26 +00004952 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004953 list;
4954
4955 if (*option == '+')
4956 break;
4957 i++;
cristybb503372010-05-27 20:51:26 +00004958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004959 ThrowMogrifyException(OptionError,"MissingArgument",option);
4960 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
4961 if (list < 0)
4962 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004963 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004964 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004965 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004966 }
4967 if (LocaleCompare("log",option+1) == 0)
4968 {
4969 if (*option == '+')
4970 break;
4971 i++;
cristybb503372010-05-27 20:51:26 +00004972 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004973 (strchr(argv[i],'%') == (char *) NULL))
4974 ThrowMogrifyException(OptionError,"MissingArgument",option);
4975 break;
4976 }
4977 if (LocaleCompare("loop",option+1) == 0)
4978 {
4979 if (*option == '+')
4980 break;
4981 i++;
cristybb503372010-05-27 20:51:26 +00004982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004983 ThrowMogrifyException(OptionError,"MissingArgument",option);
4984 if (IsGeometry(argv[i]) == MagickFalse)
4985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4986 break;
4987 }
4988 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4989 }
4990 case 'm':
4991 {
4992 if (LocaleCompare("map",option+1) == 0)
4993 {
4994 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4995 if (*option == '+')
4996 break;
4997 i++;
cristybb503372010-05-27 20:51:26 +00004998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004999 ThrowMogrifyException(OptionError,"MissingArgument",option);
5000 break;
5001 }
5002 if (LocaleCompare("mask",option+1) == 0)
5003 {
5004 if (*option == '+')
5005 break;
5006 i++;
cristybb503372010-05-27 20:51:26 +00005007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005008 ThrowMogrifyException(OptionError,"MissingArgument",option);
5009 break;
5010 }
5011 if (LocaleCompare("matte",option+1) == 0)
5012 break;
5013 if (LocaleCompare("mattecolor",option+1) == 0)
5014 {
5015 if (*option == '+')
5016 break;
5017 i++;
cristybb503372010-05-27 20:51:26 +00005018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005019 ThrowMogrifyException(OptionError,"MissingArgument",option);
5020 break;
5021 }
cristyf40785b2010-03-06 02:27:27 +00005022 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005023 break;
cristyf40785b2010-03-06 02:27:27 +00005024 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005025 break;
cristy3ed852e2009-09-05 21:47:34 +00005026 if (LocaleCompare("modulate",option+1) == 0)
5027 {
5028 if (*option == '+')
5029 break;
5030 i++;
cristybb503372010-05-27 20:51:26 +00005031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005032 ThrowMogrifyException(OptionError,"MissingArgument",option);
5033 if (IsGeometry(argv[i]) == MagickFalse)
5034 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5035 break;
5036 }
5037 if (LocaleCompare("median",option+1) == 0)
5038 {
5039 if (*option == '+')
5040 break;
5041 i++;
cristybb503372010-05-27 20:51:26 +00005042 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005043 ThrowMogrifyException(OptionError,"MissingArgument",option);
5044 if (IsGeometry(argv[i]) == MagickFalse)
5045 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5046 break;
5047 }
cristy69ec32d2011-02-27 23:57:09 +00005048 if (LocaleCompare("mode",option+1) == 0)
5049 {
5050 if (*option == '+')
5051 break;
5052 i++;
5053 if (i == (ssize_t) argc)
5054 ThrowMogrifyException(OptionError,"MissingArgument",option);
5055 if (IsGeometry(argv[i]) == MagickFalse)
5056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5057 break;
5058 }
cristy3ed852e2009-09-05 21:47:34 +00005059 if (LocaleCompare("monitor",option+1) == 0)
5060 break;
5061 if (LocaleCompare("monochrome",option+1) == 0)
5062 break;
5063 if (LocaleCompare("morph",option+1) == 0)
5064 {
5065 if (*option == '+')
5066 break;
5067 i++;
cristybb503372010-05-27 20:51:26 +00005068 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005069 ThrowMogrifyException(OptionError,"MissingArgument",option);
5070 if (IsGeometry(argv[i]) == MagickFalse)
5071 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5072 break;
5073 }
anthony29188a82010-01-22 10:12:34 +00005074 if (LocaleCompare("morphology",option+1) == 0)
5075 {
anthony29188a82010-01-22 10:12:34 +00005076 char
5077 token[MaxTextExtent];
5078
cristyb6bd4ad2010-08-08 01:12:27 +00005079 KernelInfo
5080 *kernel_info;
5081
5082 ssize_t
5083 op;
5084
anthony29188a82010-01-22 10:12:34 +00005085 i++;
cristybb503372010-05-27 20:51:26 +00005086 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005087 ThrowMogrifyException(OptionError,"MissingArgument",option);
5088 GetMagickToken(argv[i],NULL,token);
5089 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5090 if (op < 0)
5091 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005092 token);
anthony29188a82010-01-22 10:12:34 +00005093 i++;
cristybb503372010-05-27 20:51:26 +00005094 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005095 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005096 kernel_info=AcquireKernelInfo(argv[i]);
5097 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005098 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005099 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005100 break;
5101 }
cristy3ed852e2009-09-05 21:47:34 +00005102 if (LocaleCompare("mosaic",option+1) == 0)
5103 break;
5104 if (LocaleCompare("motion-blur",option+1) == 0)
5105 {
5106 if (*option == '+')
5107 break;
5108 i++;
cristybb503372010-05-27 20:51:26 +00005109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005110 ThrowMogrifyException(OptionError,"MissingArgument",option);
5111 if (IsGeometry(argv[i]) == MagickFalse)
5112 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5113 break;
5114 }
5115 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5116 }
5117 case 'n':
5118 {
5119 if (LocaleCompare("negate",option+1) == 0)
5120 break;
5121 if (LocaleCompare("noise",option+1) == 0)
5122 {
5123 i++;
cristybb503372010-05-27 20:51:26 +00005124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005125 ThrowMogrifyException(OptionError,"MissingArgument",option);
5126 if (*option == '+')
5127 {
cristybb503372010-05-27 20:51:26 +00005128 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005129 noise;
5130
5131 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5132 if (noise < 0)
5133 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5134 argv[i]);
5135 break;
5136 }
5137 if (IsGeometry(argv[i]) == MagickFalse)
5138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5139 break;
5140 }
5141 if (LocaleCompare("noop",option+1) == 0)
5142 break;
5143 if (LocaleCompare("normalize",option+1) == 0)
5144 break;
5145 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5146 }
5147 case 'o':
5148 {
5149 if (LocaleCompare("opaque",option+1) == 0)
5150 {
cristy3ed852e2009-09-05 21:47:34 +00005151 i++;
cristybb503372010-05-27 20:51:26 +00005152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005153 ThrowMogrifyException(OptionError,"MissingArgument",option);
5154 break;
5155 }
5156 if (LocaleCompare("ordered-dither",option+1) == 0)
5157 {
5158 if (*option == '+')
5159 break;
5160 i++;
cristybb503372010-05-27 20:51:26 +00005161 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005162 ThrowMogrifyException(OptionError,"MissingArgument",option);
5163 break;
5164 }
5165 if (LocaleCompare("orient",option+1) == 0)
5166 {
cristybb503372010-05-27 20:51:26 +00005167 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005168 orientation;
5169
5170 orientation=UndefinedOrientation;
5171 if (*option == '+')
5172 break;
5173 i++;
cristybb503372010-05-27 20:51:26 +00005174 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005175 ThrowMogrifyException(OptionError,"MissingArgument",option);
5176 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5177 argv[i]);
5178 if (orientation < 0)
5179 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5180 argv[i]);
5181 break;
5182 }
5183 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5184 }
5185 case 'p':
5186 {
5187 if (LocaleCompare("page",option+1) == 0)
5188 {
5189 if (*option == '+')
5190 break;
5191 i++;
cristybb503372010-05-27 20:51:26 +00005192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005193 ThrowMogrifyException(OptionError,"MissingArgument",option);
5194 break;
5195 }
5196 if (LocaleCompare("paint",option+1) == 0)
5197 {
5198 if (*option == '+')
5199 break;
5200 i++;
cristybb503372010-05-27 20:51:26 +00005201 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005202 ThrowMogrifyException(OptionError,"MissingArgument",option);
5203 if (IsGeometry(argv[i]) == MagickFalse)
5204 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5205 break;
5206 }
5207 if (LocaleCompare("path",option+1) == 0)
5208 {
5209 (void) CloneString(&path,(char *) NULL);
5210 if (*option == '+')
5211 break;
5212 i++;
cristybb503372010-05-27 20:51:26 +00005213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005214 ThrowMogrifyException(OptionError,"MissingArgument",option);
5215 (void) CloneString(&path,argv[i]);
5216 break;
5217 }
5218 if (LocaleCompare("pointsize",option+1) == 0)
5219 {
5220 if (*option == '+')
5221 break;
5222 i++;
cristybb503372010-05-27 20:51:26 +00005223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005224 ThrowMogrifyException(OptionError,"MissingArgument",option);
5225 if (IsGeometry(argv[i]) == MagickFalse)
5226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5227 break;
5228 }
5229 if (LocaleCompare("polaroid",option+1) == 0)
5230 {
5231 if (*option == '+')
5232 break;
5233 i++;
cristybb503372010-05-27 20:51:26 +00005234 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005235 ThrowMogrifyException(OptionError,"MissingArgument",option);
5236 if (IsGeometry(argv[i]) == MagickFalse)
5237 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5238 break;
5239 }
5240 if (LocaleCompare("posterize",option+1) == 0)
5241 {
5242 if (*option == '+')
5243 break;
5244 i++;
cristybb503372010-05-27 20:51:26 +00005245 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005246 ThrowMogrifyException(OptionError,"MissingArgument",option);
5247 if (IsGeometry(argv[i]) == MagickFalse)
5248 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5249 break;
5250 }
cristye7f51092010-01-17 00:39:37 +00005251 if (LocaleCompare("precision",option+1) == 0)
5252 {
5253 if (*option == '+')
5254 break;
5255 i++;
cristybb503372010-05-27 20:51:26 +00005256 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005257 ThrowMogrifyException(OptionError,"MissingArgument",option);
5258 if (IsGeometry(argv[i]) == MagickFalse)
5259 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5260 break;
5261 }
cristy3ed852e2009-09-05 21:47:34 +00005262 if (LocaleCompare("print",option+1) == 0)
5263 {
5264 if (*option == '+')
5265 break;
5266 i++;
cristybb503372010-05-27 20:51:26 +00005267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005268 ThrowMogrifyException(OptionError,"MissingArgument",option);
5269 break;
5270 }
5271 if (LocaleCompare("process",option+1) == 0)
5272 {
5273 if (*option == '+')
5274 break;
5275 i++;
cristybb503372010-05-27 20:51:26 +00005276 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005277 ThrowMogrifyException(OptionError,"MissingArgument",option);
5278 break;
5279 }
5280 if (LocaleCompare("profile",option+1) == 0)
5281 {
5282 i++;
cristybb503372010-05-27 20:51:26 +00005283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005284 ThrowMogrifyException(OptionError,"MissingArgument",option);
5285 break;
5286 }
5287 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5288 }
5289 case 'q':
5290 {
5291 if (LocaleCompare("quality",option+1) == 0)
5292 {
5293 if (*option == '+')
5294 break;
5295 i++;
cristybb503372010-05-27 20:51:26 +00005296 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005297 ThrowMogrifyException(OptionError,"MissingArgument",option);
5298 if (IsGeometry(argv[i]) == MagickFalse)
5299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5300 break;
5301 }
5302 if (LocaleCompare("quantize",option+1) == 0)
5303 {
cristybb503372010-05-27 20:51:26 +00005304 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005305 colorspace;
5306
5307 if (*option == '+')
5308 break;
5309 i++;
cristybb503372010-05-27 20:51:26 +00005310 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005311 ThrowMogrifyException(OptionError,"MissingArgument",option);
5312 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5313 argv[i]);
5314 if (colorspace < 0)
5315 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5316 argv[i]);
5317 break;
5318 }
5319 if (LocaleCompare("quiet",option+1) == 0)
5320 break;
5321 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5322 }
5323 case 'r':
5324 {
5325 if (LocaleCompare("radial-blur",option+1) == 0)
5326 {
5327 i++;
cristybb503372010-05-27 20:51:26 +00005328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005329 ThrowMogrifyException(OptionError,"MissingArgument",option);
5330 if (IsGeometry(argv[i]) == MagickFalse)
5331 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5332 break;
5333 }
5334 if (LocaleCompare("raise",option+1) == 0)
5335 {
5336 i++;
cristybb503372010-05-27 20:51:26 +00005337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005338 ThrowMogrifyException(OptionError,"MissingArgument",option);
5339 if (IsGeometry(argv[i]) == MagickFalse)
5340 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5341 break;
5342 }
5343 if (LocaleCompare("random-threshold",option+1) == 0)
5344 {
5345 if (*option == '+')
5346 break;
5347 i++;
cristybb503372010-05-27 20:51:26 +00005348 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005349 ThrowMogrifyException(OptionError,"MissingArgument",option);
5350 if (IsGeometry(argv[i]) == MagickFalse)
5351 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5352 break;
5353 }
cristye6365592010-04-02 17:31:23 +00005354 if (LocaleCompare("recolor",option+1) == 0)
5355 {
5356 if (*option == '+')
5357 break;
5358 i++;
cristybb503372010-05-27 20:51:26 +00005359 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005360 ThrowMogrifyException(OptionError,"MissingArgument",option);
5361 if (IsGeometry(argv[i]) == MagickFalse)
5362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5363 break;
5364 }
cristy3ed852e2009-09-05 21:47:34 +00005365 if (LocaleCompare("red-primary",option+1) == 0)
5366 {
5367 if (*option == '+')
5368 break;
5369 i++;
cristybb503372010-05-27 20:51:26 +00005370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005371 ThrowMogrifyException(OptionError,"MissingArgument",option);
5372 if (IsGeometry(argv[i]) == MagickFalse)
5373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5374 }
cristy9f2083a2010-04-22 19:48:05 +00005375 if (LocaleCompare("regard-warnings",option+1) == 0)
5376 break;
cristy3ed852e2009-09-05 21:47:34 +00005377 if (LocaleCompare("region",option+1) == 0)
5378 {
5379 if (*option == '+')
5380 break;
5381 i++;
cristybb503372010-05-27 20:51:26 +00005382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005383 ThrowMogrifyException(OptionError,"MissingArgument",option);
5384 if (IsGeometry(argv[i]) == MagickFalse)
5385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5386 break;
5387 }
cristyf0c78232010-03-15 12:53:40 +00005388 if (LocaleCompare("remap",option+1) == 0)
5389 {
5390 if (*option == '+')
5391 break;
5392 i++;
cristybb503372010-05-27 20:51:26 +00005393 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005394 ThrowMogrifyException(OptionError,"MissingArgument",option);
5395 break;
5396 }
cristy3ed852e2009-09-05 21:47:34 +00005397 if (LocaleCompare("render",option+1) == 0)
5398 break;
5399 if (LocaleCompare("repage",option+1) == 0)
5400 {
5401 if (*option == '+')
5402 break;
5403 i++;
cristybb503372010-05-27 20:51:26 +00005404 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005405 ThrowMogrifyException(OptionError,"MissingArgument",option);
5406 if (IsGeometry(argv[i]) == MagickFalse)
5407 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5408 break;
5409 }
5410 if (LocaleCompare("resample",option+1) == 0)
5411 {
5412 if (*option == '+')
5413 break;
5414 i++;
cristybb503372010-05-27 20:51:26 +00005415 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005416 ThrowMogrifyException(OptionError,"MissingArgument",option);
5417 if (IsGeometry(argv[i]) == MagickFalse)
5418 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5419 break;
5420 }
5421 if (LocaleCompare("resize",option+1) == 0)
5422 {
5423 if (*option == '+')
5424 break;
5425 i++;
cristybb503372010-05-27 20:51:26 +00005426 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005427 ThrowMogrifyException(OptionError,"MissingArgument",option);
5428 if (IsGeometry(argv[i]) == MagickFalse)
5429 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5430 break;
5431 }
cristyebbcfea2011-02-25 02:43:54 +00005432 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5433 {
5434 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5435 break;
5436 }
cristy3ed852e2009-09-05 21:47:34 +00005437 if (LocaleCompare("reverse",option+1) == 0)
5438 break;
5439 if (LocaleCompare("roll",option+1) == 0)
5440 {
5441 if (*option == '+')
5442 break;
5443 i++;
cristybb503372010-05-27 20:51:26 +00005444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005445 ThrowMogrifyException(OptionError,"MissingArgument",option);
5446 if (IsGeometry(argv[i]) == MagickFalse)
5447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5448 break;
5449 }
5450 if (LocaleCompare("rotate",option+1) == 0)
5451 {
5452 i++;
cristybb503372010-05-27 20:51:26 +00005453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005454 ThrowMogrifyException(OptionError,"MissingArgument",option);
5455 if (IsGeometry(argv[i]) == MagickFalse)
5456 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5457 break;
5458 }
5459 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5460 }
5461 case 's':
5462 {
5463 if (LocaleCompare("sample",option+1) == 0)
5464 {
5465 if (*option == '+')
5466 break;
5467 i++;
cristybb503372010-05-27 20:51:26 +00005468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005469 ThrowMogrifyException(OptionError,"MissingArgument",option);
5470 if (IsGeometry(argv[i]) == MagickFalse)
5471 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5472 break;
5473 }
5474 if (LocaleCompare("sampling-factor",option+1) == 0)
5475 {
5476 if (*option == '+')
5477 break;
5478 i++;
cristybb503372010-05-27 20:51:26 +00005479 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005480 ThrowMogrifyException(OptionError,"MissingArgument",option);
5481 if (IsGeometry(argv[i]) == MagickFalse)
5482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5483 break;
5484 }
5485 if (LocaleCompare("scale",option+1) == 0)
5486 {
5487 if (*option == '+')
5488 break;
5489 i++;
cristybb503372010-05-27 20:51:26 +00005490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005491 ThrowMogrifyException(OptionError,"MissingArgument",option);
5492 if (IsGeometry(argv[i]) == MagickFalse)
5493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5494 break;
5495 }
5496 if (LocaleCompare("scene",option+1) == 0)
5497 {
5498 if (*option == '+')
5499 break;
5500 i++;
cristybb503372010-05-27 20:51:26 +00005501 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005502 ThrowMogrifyException(OptionError,"MissingArgument",option);
5503 if (IsGeometry(argv[i]) == MagickFalse)
5504 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5505 break;
5506 }
5507 if (LocaleCompare("seed",option+1) == 0)
5508 {
5509 if (*option == '+')
5510 break;
5511 i++;
cristybb503372010-05-27 20:51:26 +00005512 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005513 ThrowMogrifyException(OptionError,"MissingArgument",option);
5514 if (IsGeometry(argv[i]) == MagickFalse)
5515 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5516 break;
5517 }
5518 if (LocaleCompare("segment",option+1) == 0)
5519 {
5520 if (*option == '+')
5521 break;
5522 i++;
cristybb503372010-05-27 20:51:26 +00005523 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005524 ThrowMogrifyException(OptionError,"MissingArgument",option);
5525 if (IsGeometry(argv[i]) == MagickFalse)
5526 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5527 break;
5528 }
5529 if (LocaleCompare("selective-blur",option+1) == 0)
5530 {
5531 i++;
cristybb503372010-05-27 20:51:26 +00005532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005533 ThrowMogrifyException(OptionError,"MissingArgument",option);
5534 if (IsGeometry(argv[i]) == MagickFalse)
5535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5536 break;
5537 }
5538 if (LocaleCompare("separate",option+1) == 0)
5539 break;
5540 if (LocaleCompare("sepia-tone",option+1) == 0)
5541 {
5542 if (*option == '+')
5543 break;
5544 i++;
cristybb503372010-05-27 20:51:26 +00005545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 if (IsGeometry(argv[i]) == MagickFalse)
5548 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5549 break;
5550 }
5551 if (LocaleCompare("set",option+1) == 0)
5552 {
5553 i++;
cristybb503372010-05-27 20:51:26 +00005554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 if (*option == '+')
5557 break;
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 break;
5562 }
5563 if (LocaleCompare("shade",option+1) == 0)
5564 {
5565 i++;
cristybb503372010-05-27 20:51:26 +00005566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005567 ThrowMogrifyException(OptionError,"MissingArgument",option);
5568 if (IsGeometry(argv[i]) == MagickFalse)
5569 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5570 break;
5571 }
5572 if (LocaleCompare("shadow",option+1) == 0)
5573 {
5574 if (*option == '+')
5575 break;
5576 i++;
cristybb503372010-05-27 20:51:26 +00005577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005578 ThrowMogrifyException(OptionError,"MissingArgument",option);
5579 if (IsGeometry(argv[i]) == MagickFalse)
5580 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5581 break;
5582 }
5583 if (LocaleCompare("sharpen",option+1) == 0)
5584 {
5585 i++;
cristybb503372010-05-27 20:51:26 +00005586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 if (IsGeometry(argv[i]) == MagickFalse)
5589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5590 break;
5591 }
5592 if (LocaleCompare("shave",option+1) == 0)
5593 {
5594 if (*option == '+')
5595 break;
5596 i++;
cristybb503372010-05-27 20:51:26 +00005597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005598 ThrowMogrifyException(OptionError,"MissingArgument",option);
5599 if (IsGeometry(argv[i]) == MagickFalse)
5600 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5601 break;
5602 }
5603 if (LocaleCompare("shear",option+1) == 0)
5604 {
5605 i++;
cristybb503372010-05-27 20:51:26 +00005606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 if (IsGeometry(argv[i]) == MagickFalse)
5609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5610 break;
5611 }
5612 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5613 {
5614 i++;
cristybb503372010-05-27 20:51:26 +00005615 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005616 ThrowMogrifyException(OptionError,"MissingArgument",option);
5617 if (IsGeometry(argv[i]) == MagickFalse)
5618 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5619 break;
5620 }
5621 if (LocaleCompare("size",option+1) == 0)
5622 {
5623 if (*option == '+')
5624 break;
5625 i++;
cristybb503372010-05-27 20:51:26 +00005626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005627 ThrowMogrifyException(OptionError,"MissingArgument",option);
5628 if (IsGeometry(argv[i]) == MagickFalse)
5629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5630 break;
5631 }
5632 if (LocaleCompare("sketch",option+1) == 0)
5633 {
5634 if (*option == '+')
5635 break;
5636 i++;
cristybb503372010-05-27 20:51:26 +00005637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005638 ThrowMogrifyException(OptionError,"MissingArgument",option);
5639 if (IsGeometry(argv[i]) == MagickFalse)
5640 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5641 break;
5642 }
cristy4285d782011-02-09 20:12:28 +00005643 if (LocaleCompare("smush",option+1) == 0)
5644 {
cristy4285d782011-02-09 20:12:28 +00005645 i++;
5646 if (i == (ssize_t) argc)
5647 ThrowMogrifyException(OptionError,"MissingArgument",option);
5648 if (IsGeometry(argv[i]) == MagickFalse)
5649 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005650 i++;
5651 break;
5652 }
cristy3ed852e2009-09-05 21:47:34 +00005653 if (LocaleCompare("solarize",option+1) == 0)
5654 {
5655 if (*option == '+')
5656 break;
5657 i++;
cristybb503372010-05-27 20:51:26 +00005658 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005659 ThrowMogrifyException(OptionError,"MissingArgument",option);
5660 if (IsGeometry(argv[i]) == MagickFalse)
5661 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5662 break;
5663 }
5664 if (LocaleCompare("sparse-color",option+1) == 0)
5665 {
cristybb503372010-05-27 20:51:26 +00005666 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005667 op;
5668
5669 i++;
cristybb503372010-05-27 20:51:26 +00005670 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005671 ThrowMogrifyException(OptionError,"MissingArgument",option);
5672 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5673 if (op < 0)
5674 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5675 argv[i]);
5676 i++;
cristybb503372010-05-27 20:51:26 +00005677 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005678 ThrowMogrifyException(OptionError,"MissingArgument",option);
5679 break;
5680 }
5681 if (LocaleCompare("spread",option+1) == 0)
5682 {
5683 if (*option == '+')
5684 break;
5685 i++;
cristybb503372010-05-27 20:51:26 +00005686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005687 ThrowMogrifyException(OptionError,"MissingArgument",option);
5688 if (IsGeometry(argv[i]) == MagickFalse)
5689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5690 break;
5691 }
cristy0834d642011-03-18 18:26:08 +00005692 if (LocaleCompare("statistic",option+1) == 0)
5693 {
5694 ssize_t
5695 op;
5696
5697 if (*option == '+')
5698 break;
5699 i++;
5700 if (i == (ssize_t) argc)
5701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 op=ParseMagickOption(MagickStatisticOptions,MagickFalse,argv[i]);
5703 if (op < 0)
5704 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5705 argv[i]);
5706 i++;
5707 if (i == (ssize_t) (argc-1))
5708 ThrowMogrifyException(OptionError,"MissingArgument",option);
5709 if (IsGeometry(argv[i]) == MagickFalse)
5710 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5711 break;
5712 }
cristy3ed852e2009-09-05 21:47:34 +00005713 if (LocaleCompare("stretch",option+1) == 0)
5714 {
cristybb503372010-05-27 20:51:26 +00005715 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005716 stretch;
5717
5718 if (*option == '+')
5719 break;
5720 i++;
cristybb503372010-05-27 20:51:26 +00005721 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005722 ThrowMogrifyException(OptionError,"MissingArgument",option);
5723 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
5724 if (stretch < 0)
5725 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5726 argv[i]);
5727 break;
5728 }
5729 if (LocaleCompare("strip",option+1) == 0)
5730 break;
5731 if (LocaleCompare("stroke",option+1) == 0)
5732 {
5733 if (*option == '+')
5734 break;
5735 i++;
cristybb503372010-05-27 20:51:26 +00005736 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005737 ThrowMogrifyException(OptionError,"MissingArgument",option);
5738 break;
5739 }
5740 if (LocaleCompare("strokewidth",option+1) == 0)
5741 {
5742 if (*option == '+')
5743 break;
5744 i++;
cristybb503372010-05-27 20:51:26 +00005745 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005746 ThrowMogrifyException(OptionError,"MissingArgument",option);
5747 if (IsGeometry(argv[i]) == MagickFalse)
5748 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5749 break;
5750 }
5751 if (LocaleCompare("style",option+1) == 0)
5752 {
cristybb503372010-05-27 20:51:26 +00005753 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005754 style;
5755
5756 if (*option == '+')
5757 break;
5758 i++;
cristybb503372010-05-27 20:51:26 +00005759 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005760 ThrowMogrifyException(OptionError,"MissingArgument",option);
5761 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
5762 if (style < 0)
5763 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5764 argv[i]);
5765 break;
5766 }
cristyecb10ff2011-03-22 13:14:03 +00005767 if (LocaleCompare("swap",option+1) == 0)
5768 {
5769 if (*option == '+')
5770 break;
5771 i++;
5772 if (i == (ssize_t) (argc-1))
5773 ThrowMogrifyException(OptionError,"MissingArgument",option);
5774 if (IsGeometry(argv[i]) == MagickFalse)
5775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5776 break;
5777 }
cristy3ed852e2009-09-05 21:47:34 +00005778 if (LocaleCompare("swirl",option+1) == 0)
5779 {
5780 if (*option == '+')
5781 break;
5782 i++;
cristybb503372010-05-27 20:51:26 +00005783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 if (IsGeometry(argv[i]) == MagickFalse)
5786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5787 break;
5788 }
cristyd9a29192010-10-16 16:49:53 +00005789 if (LocaleCompare("synchronize",option+1) == 0)
5790 break;
cristy3ed852e2009-09-05 21:47:34 +00005791 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5792 }
5793 case 't':
5794 {
5795 if (LocaleCompare("taint",option+1) == 0)
5796 break;
5797 if (LocaleCompare("texture",option+1) == 0)
5798 {
5799 if (*option == '+')
5800 break;
5801 i++;
cristybb503372010-05-27 20:51:26 +00005802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005803 ThrowMogrifyException(OptionError,"MissingArgument",option);
5804 break;
5805 }
5806 if (LocaleCompare("tile",option+1) == 0)
5807 {
5808 if (*option == '+')
5809 break;
5810 i++;
cristybb503372010-05-27 20:51:26 +00005811 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005812 ThrowMogrifyException(OptionError,"MissingArgument",option);
5813 break;
5814 }
5815 if (LocaleCompare("tile-offset",option+1) == 0)
5816 {
5817 if (*option == '+')
5818 break;
5819 i++;
cristybb503372010-05-27 20:51:26 +00005820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005821 ThrowMogrifyException(OptionError,"MissingArgument",option);
5822 if (IsGeometry(argv[i]) == MagickFalse)
5823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5824 break;
5825 }
5826 if (LocaleCompare("tint",option+1) == 0)
5827 {
5828 if (*option == '+')
5829 break;
5830 i++;
cristybb503372010-05-27 20:51:26 +00005831 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005832 ThrowMogrifyException(OptionError,"MissingArgument",option);
5833 if (IsGeometry(argv[i]) == MagickFalse)
5834 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5835 break;
5836 }
5837 if (LocaleCompare("transform",option+1) == 0)
5838 break;
5839 if (LocaleCompare("transpose",option+1) == 0)
5840 break;
5841 if (LocaleCompare("transverse",option+1) == 0)
5842 break;
5843 if (LocaleCompare("threshold",option+1) == 0)
5844 {
5845 if (*option == '+')
5846 break;
5847 i++;
cristybb503372010-05-27 20:51:26 +00005848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005849 ThrowMogrifyException(OptionError,"MissingArgument",option);
5850 if (IsGeometry(argv[i]) == MagickFalse)
5851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5852 break;
5853 }
5854 if (LocaleCompare("thumbnail",option+1) == 0)
5855 {
5856 if (*option == '+')
5857 break;
5858 i++;
cristybb503372010-05-27 20:51:26 +00005859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005860 ThrowMogrifyException(OptionError,"MissingArgument",option);
5861 if (IsGeometry(argv[i]) == MagickFalse)
5862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5863 break;
5864 }
5865 if (LocaleCompare("transparent",option+1) == 0)
5866 {
5867 i++;
cristybb503372010-05-27 20:51:26 +00005868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005869 ThrowMogrifyException(OptionError,"MissingArgument",option);
5870 break;
5871 }
5872 if (LocaleCompare("transparent-color",option+1) == 0)
5873 {
5874 if (*option == '+')
5875 break;
5876 i++;
cristybb503372010-05-27 20:51:26 +00005877 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005878 ThrowMogrifyException(OptionError,"MissingArgument",option);
5879 break;
5880 }
5881 if (LocaleCompare("treedepth",option+1) == 0)
5882 {
5883 if (*option == '+')
5884 break;
5885 i++;
cristybb503372010-05-27 20:51:26 +00005886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005887 ThrowMogrifyException(OptionError,"MissingArgument",option);
5888 if (IsGeometry(argv[i]) == MagickFalse)
5889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5890 break;
5891 }
5892 if (LocaleCompare("trim",option+1) == 0)
5893 break;
5894 if (LocaleCompare("type",option+1) == 0)
5895 {
cristybb503372010-05-27 20:51:26 +00005896 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005897 type;
5898
5899 if (*option == '+')
5900 break;
5901 i++;
cristybb503372010-05-27 20:51:26 +00005902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005903 ThrowMogrifyException(OptionError,"MissingArgument",option);
5904 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
5905 if (type < 0)
5906 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5907 argv[i]);
5908 break;
5909 }
5910 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5911 }
5912 case 'u':
5913 {
5914 if (LocaleCompare("undercolor",option+1) == 0)
5915 {
5916 if (*option == '+')
5917 break;
5918 i++;
cristybb503372010-05-27 20:51:26 +00005919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005920 ThrowMogrifyException(OptionError,"MissingArgument",option);
5921 break;
5922 }
5923 if (LocaleCompare("unique-colors",option+1) == 0)
5924 break;
5925 if (LocaleCompare("units",option+1) == 0)
5926 {
cristybb503372010-05-27 20:51:26 +00005927 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005928 units;
5929
5930 if (*option == '+')
5931 break;
5932 i++;
cristybb503372010-05-27 20:51:26 +00005933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005934 ThrowMogrifyException(OptionError,"MissingArgument",option);
5935 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
5936 argv[i]);
5937 if (units < 0)
5938 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5939 argv[i]);
5940 break;
5941 }
5942 if (LocaleCompare("unsharp",option+1) == 0)
5943 {
5944 i++;
cristybb503372010-05-27 20:51:26 +00005945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005946 ThrowMogrifyException(OptionError,"MissingArgument",option);
5947 if (IsGeometry(argv[i]) == MagickFalse)
5948 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5949 break;
5950 }
5951 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5952 }
5953 case 'v':
5954 {
5955 if (LocaleCompare("verbose",option+1) == 0)
5956 {
5957 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5958 break;
5959 }
5960 if ((LocaleCompare("version",option+1) == 0) ||
5961 (LocaleCompare("-version",option+1) == 0))
5962 {
5963 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005964 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00005965 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
5966 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005967 break;
5968 }
5969 if (LocaleCompare("view",option+1) == 0)
5970 {
5971 if (*option == '+')
5972 break;
5973 i++;
cristybb503372010-05-27 20:51:26 +00005974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005975 ThrowMogrifyException(OptionError,"MissingArgument",option);
5976 break;
5977 }
5978 if (LocaleCompare("vignette",option+1) == 0)
5979 {
5980 if (*option == '+')
5981 break;
5982 i++;
cristybb503372010-05-27 20:51:26 +00005983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005984 ThrowMogrifyException(OptionError,"MissingArgument",option);
5985 if (IsGeometry(argv[i]) == MagickFalse)
5986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5987 break;
5988 }
5989 if (LocaleCompare("virtual-pixel",option+1) == 0)
5990 {
cristybb503372010-05-27 20:51:26 +00005991 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005992 method;
5993
5994 if (*option == '+')
5995 break;
5996 i++;
cristybb503372010-05-27 20:51:26 +00005997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005998 ThrowMogrifyException(OptionError,"MissingArgument",option);
5999 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6000 argv[i]);
6001 if (method < 0)
6002 ThrowMogrifyException(OptionError,
6003 "UnrecognizedVirtualPixelMethod",argv[i]);
6004 break;
6005 }
6006 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6007 }
6008 case 'w':
6009 {
6010 if (LocaleCompare("wave",option+1) == 0)
6011 {
6012 i++;
cristybb503372010-05-27 20:51:26 +00006013 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006014 ThrowMogrifyException(OptionError,"MissingArgument",option);
6015 if (IsGeometry(argv[i]) == MagickFalse)
6016 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6017 break;
6018 }
6019 if (LocaleCompare("weight",option+1) == 0)
6020 {
6021 if (*option == '+')
6022 break;
6023 i++;
cristybb503372010-05-27 20:51:26 +00006024 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006025 ThrowMogrifyException(OptionError,"MissingArgument",option);
6026 break;
6027 }
6028 if (LocaleCompare("white-point",option+1) == 0)
6029 {
6030 if (*option == '+')
6031 break;
6032 i++;
cristybb503372010-05-27 20:51:26 +00006033 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006034 ThrowMogrifyException(OptionError,"MissingArgument",option);
6035 if (IsGeometry(argv[i]) == MagickFalse)
6036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6037 break;
6038 }
6039 if (LocaleCompare("white-threshold",option+1) == 0)
6040 {
6041 if (*option == '+')
6042 break;
6043 i++;
cristybb503372010-05-27 20:51:26 +00006044 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006045 ThrowMogrifyException(OptionError,"MissingArgument",option);
6046 if (IsGeometry(argv[i]) == MagickFalse)
6047 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6048 break;
6049 }
6050 if (LocaleCompare("write",option+1) == 0)
6051 {
6052 i++;
cristybb503372010-05-27 20:51:26 +00006053 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006054 ThrowMogrifyException(OptionError,"MissingArgument",option);
6055 break;
6056 }
6057 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6058 }
6059 case '?':
6060 break;
6061 default:
6062 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6063 }
anthonyce2716b2011-04-22 09:51:34 +00006064 fire=(ParseMagickOption(MagickCommandOptions,MagickFalse,option)
6065 &FireOption) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006066 if (fire != MagickFalse)
6067 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6068 }
6069 if (k != 0)
6070 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006071 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006072 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6073 DestroyMogrify();
6074 return(status != 0 ? MagickTrue : MagickFalse);
6075}
6076
6077/*
6078%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6079% %
6080% %
6081% %
6082+ M o g r i f y I m a g e I n f o %
6083% %
6084% %
6085% %
6086%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6087%
6088% MogrifyImageInfo() applies image processing settings to the image as
6089% prescribed by command line options.
6090%
6091% The format of the MogrifyImageInfo method is:
6092%
6093% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6094% const char **argv,ExceptionInfo *exception)
6095%
6096% A description of each parameter follows:
6097%
6098% o image_info: the image info..
6099%
6100% o argc: Specifies a pointer to an integer describing the number of
6101% elements in the argument vector.
6102%
6103% o argv: Specifies a pointer to a text array containing the command line
6104% arguments.
6105%
6106% o exception: return any errors or warnings in this structure.
6107%
6108*/
6109WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6110 const int argc,const char **argv,ExceptionInfo *exception)
6111{
6112 const char
6113 *option;
6114
6115 GeometryInfo
6116 geometry_info;
6117
cristybb503372010-05-27 20:51:26 +00006118 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006119 count;
6120
cristybb503372010-05-27 20:51:26 +00006121 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006122 i;
6123
6124 /*
6125 Initialize method variables.
6126 */
6127 assert(image_info != (ImageInfo *) NULL);
6128 assert(image_info->signature == MagickSignature);
6129 if (image_info->debug != MagickFalse)
6130 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6131 image_info->filename);
6132 if (argc < 0)
6133 return(MagickTrue);
6134 /*
6135 Set the image settings.
6136 */
cristybb503372010-05-27 20:51:26 +00006137 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006138 {
6139 option=argv[i];
6140 if (IsMagickOption(option) == MagickFalse)
6141 continue;
anthonyce2716b2011-04-22 09:51:34 +00006142 count=ParseMagickOption(MagickCommandOptions,MagickFalse,option);
6143 count=MagickMax(count,0L);
6144 count&=NumArgsOption;
cristycee97112010-05-28 00:44:52 +00006145 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006146 break;
6147 switch (*(option+1))
6148 {
6149 case 'a':
6150 {
6151 if (LocaleCompare("adjoin",option+1) == 0)
6152 {
6153 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6154 break;
6155 }
6156 if (LocaleCompare("antialias",option+1) == 0)
6157 {
6158 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6159 break;
6160 }
6161 if (LocaleCompare("attenuate",option+1) == 0)
6162 {
6163 if (*option == '+')
6164 {
6165 (void) DeleteImageOption(image_info,option+1);
6166 break;
6167 }
6168 (void) SetImageOption(image_info,option+1,argv[i+1]);
6169 break;
6170 }
6171 if (LocaleCompare("authenticate",option+1) == 0)
6172 {
6173 if (*option == '+')
6174 (void) CloneString(&image_info->authenticate,(char *) NULL);
6175 else
6176 (void) CloneString(&image_info->authenticate,argv[i+1]);
6177 break;
6178 }
6179 break;
6180 }
6181 case 'b':
6182 {
6183 if (LocaleCompare("background",option+1) == 0)
6184 {
6185 if (*option == '+')
6186 {
6187 (void) DeleteImageOption(image_info,option+1);
6188 (void) QueryColorDatabase(BackgroundColor,
6189 &image_info->background_color,exception);
6190 break;
6191 }
6192 (void) SetImageOption(image_info,option+1,argv[i+1]);
6193 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6194 exception);
6195 break;
6196 }
6197 if (LocaleCompare("bias",option+1) == 0)
6198 {
6199 if (*option == '+')
6200 {
6201 (void) SetImageOption(image_info,option+1,"0.0");
6202 break;
6203 }
6204 (void) SetImageOption(image_info,option+1,argv[i+1]);
6205 break;
6206 }
6207 if (LocaleCompare("black-point-compensation",option+1) == 0)
6208 {
6209 if (*option == '+')
6210 {
6211 (void) SetImageOption(image_info,option+1,"false");
6212 break;
6213 }
6214 (void) SetImageOption(image_info,option+1,"true");
6215 break;
6216 }
6217 if (LocaleCompare("blue-primary",option+1) == 0)
6218 {
6219 if (*option == '+')
6220 {
6221 (void) SetImageOption(image_info,option+1,"0.0");
6222 break;
6223 }
6224 (void) SetImageOption(image_info,option+1,argv[i+1]);
6225 break;
6226 }
6227 if (LocaleCompare("bordercolor",option+1) == 0)
6228 {
6229 if (*option == '+')
6230 {
6231 (void) DeleteImageOption(image_info,option+1);
6232 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6233 exception);
6234 break;
6235 }
6236 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6237 exception);
6238 (void) SetImageOption(image_info,option+1,argv[i+1]);
6239 break;
6240 }
6241 if (LocaleCompare("box",option+1) == 0)
6242 {
6243 if (*option == '+')
6244 {
6245 (void) SetImageOption(image_info,"undercolor","none");
6246 break;
6247 }
6248 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6249 break;
6250 }
6251 break;
6252 }
6253 case 'c':
6254 {
6255 if (LocaleCompare("cache",option+1) == 0)
6256 {
6257 MagickSizeType
6258 limit;
6259
6260 limit=MagickResourceInfinity;
6261 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006262 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006263 (void) SetMagickResourceLimit(MemoryResource,limit);
6264 (void) SetMagickResourceLimit(MapResource,2*limit);
6265 break;
6266 }
6267 if (LocaleCompare("caption",option+1) == 0)
6268 {
6269 if (*option == '+')
6270 {
6271 (void) DeleteImageOption(image_info,option+1);
6272 break;
6273 }
6274 (void) SetImageOption(image_info,option+1,argv[i+1]);
6275 break;
6276 }
6277 if (LocaleCompare("channel",option+1) == 0)
6278 {
6279 if (*option == '+')
6280 {
6281 image_info->channel=DefaultChannels;
6282 break;
6283 }
6284 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6285 break;
6286 }
6287 if (LocaleCompare("colors",option+1) == 0)
6288 {
cristye27293e2009-12-18 02:53:20 +00006289 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006290 break;
6291 }
6292 if (LocaleCompare("colorspace",option+1) == 0)
6293 {
6294 if (*option == '+')
6295 {
6296 image_info->colorspace=UndefinedColorspace;
6297 (void) SetImageOption(image_info,option+1,"undefined");
6298 break;
6299 }
6300 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6301 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6302 (void) SetImageOption(image_info,option+1,argv[i+1]);
6303 break;
6304 }
6305 if (LocaleCompare("compress",option+1) == 0)
6306 {
6307 if (*option == '+')
6308 {
6309 image_info->compression=UndefinedCompression;
6310 (void) SetImageOption(image_info,option+1,"undefined");
6311 break;
6312 }
6313 image_info->compression=(CompressionType) ParseMagickOption(
6314 MagickCompressOptions,MagickFalse,argv[i+1]);
6315 (void) SetImageOption(image_info,option+1,argv[i+1]);
6316 break;
6317 }
6318 if (LocaleCompare("comment",option+1) == 0)
6319 {
6320 if (*option == '+')
6321 {
6322 (void) DeleteImageOption(image_info,option+1);
6323 break;
6324 }
6325 (void) SetImageOption(image_info,option+1,argv[i+1]);
6326 break;
6327 }
6328 if (LocaleCompare("compose",option+1) == 0)
6329 {
6330 if (*option == '+')
6331 {
6332 (void) SetImageOption(image_info,option+1,"undefined");
6333 break;
6334 }
6335 (void) SetImageOption(image_info,option+1,argv[i+1]);
6336 break;
6337 }
6338 if (LocaleCompare("compress",option+1) == 0)
6339 {
6340 if (*option == '+')
6341 {
6342 image_info->compression=UndefinedCompression;
6343 (void) SetImageOption(image_info,option+1,"undefined");
6344 break;
6345 }
6346 image_info->compression=(CompressionType) ParseMagickOption(
6347 MagickCompressOptions,MagickFalse,argv[i+1]);
6348 (void) SetImageOption(image_info,option+1,argv[i+1]);
6349 break;
6350 }
6351 break;
6352 }
6353 case 'd':
6354 {
6355 if (LocaleCompare("debug",option+1) == 0)
6356 {
6357 if (*option == '+')
6358 (void) SetLogEventMask("none");
6359 else
6360 (void) SetLogEventMask(argv[i+1]);
6361 image_info->debug=IsEventLogging();
6362 break;
6363 }
6364 if (LocaleCompare("define",option+1) == 0)
6365 {
6366 if (*option == '+')
6367 {
6368 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6369 (void) DeleteImageRegistry(argv[i+1]+9);
6370 else
6371 (void) DeleteImageOption(image_info,argv[i+1]);
6372 break;
6373 }
6374 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6375 {
6376 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6377 exception);
6378 break;
6379 }
6380 (void) DefineImageOption(image_info,argv[i+1]);
6381 break;
6382 }
6383 if (LocaleCompare("delay",option+1) == 0)
6384 {
6385 if (*option == '+')
6386 {
6387 (void) SetImageOption(image_info,option+1,"0");
6388 break;
6389 }
6390 (void) SetImageOption(image_info,option+1,argv[i+1]);
6391 break;
6392 }
6393 if (LocaleCompare("density",option+1) == 0)
6394 {
6395 /*
6396 Set image density.
6397 */
6398 if (*option == '+')
6399 {
6400 if (image_info->density != (char *) NULL)
6401 image_info->density=DestroyString(image_info->density);
6402 (void) SetImageOption(image_info,option+1,"72");
6403 break;
6404 }
6405 (void) CloneString(&image_info->density,argv[i+1]);
6406 (void) SetImageOption(image_info,option+1,argv[i+1]);
6407 break;
6408 }
6409 if (LocaleCompare("depth",option+1) == 0)
6410 {
6411 if (*option == '+')
6412 {
6413 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6414 break;
6415 }
cristye27293e2009-12-18 02:53:20 +00006416 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006417 break;
6418 }
cristyc9b12952010-03-28 01:12:28 +00006419 if (LocaleCompare("direction",option+1) == 0)
6420 {
6421 if (*option == '+')
6422 {
6423 (void) SetImageOption(image_info,option+1,"undefined");
6424 break;
6425 }
6426 (void) SetImageOption(image_info,option+1,argv[i+1]);
6427 break;
6428 }
cristy3ed852e2009-09-05 21:47:34 +00006429 if (LocaleCompare("display",option+1) == 0)
6430 {
6431 if (*option == '+')
6432 {
6433 if (image_info->server_name != (char *) NULL)
6434 image_info->server_name=DestroyString(
6435 image_info->server_name);
6436 break;
6437 }
6438 (void) CloneString(&image_info->server_name,argv[i+1]);
6439 break;
6440 }
6441 if (LocaleCompare("dispose",option+1) == 0)
6442 {
6443 if (*option == '+')
6444 {
6445 (void) SetImageOption(image_info,option+1,"undefined");
6446 break;
6447 }
6448 (void) SetImageOption(image_info,option+1,argv[i+1]);
6449 break;
6450 }
6451 if (LocaleCompare("dither",option+1) == 0)
6452 {
6453 if (*option == '+')
6454 {
6455 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006456 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006457 break;
6458 }
6459 (void) SetImageOption(image_info,option+1,argv[i+1]);
6460 image_info->dither=MagickTrue;
6461 break;
6462 }
6463 break;
6464 }
6465 case 'e':
6466 {
6467 if (LocaleCompare("encoding",option+1) == 0)
6468 {
6469 if (*option == '+')
6470 {
6471 (void) SetImageOption(image_info,option+1,"undefined");
6472 break;
6473 }
6474 (void) SetImageOption(image_info,option+1,argv[i+1]);
6475 break;
6476 }
6477 if (LocaleCompare("endian",option+1) == 0)
6478 {
6479 if (*option == '+')
6480 {
6481 image_info->endian=UndefinedEndian;
6482 (void) SetImageOption(image_info,option+1,"undefined");
6483 break;
6484 }
6485 image_info->endian=(EndianType) ParseMagickOption(
6486 MagickEndianOptions,MagickFalse,argv[i+1]);
6487 (void) SetImageOption(image_info,option+1,argv[i+1]);
6488 break;
6489 }
6490 if (LocaleCompare("extract",option+1) == 0)
6491 {
6492 /*
6493 Set image extract geometry.
6494 */
6495 if (*option == '+')
6496 {
6497 if (image_info->extract != (char *) NULL)
6498 image_info->extract=DestroyString(image_info->extract);
6499 break;
6500 }
6501 (void) CloneString(&image_info->extract,argv[i+1]);
6502 break;
6503 }
6504 break;
6505 }
6506 case 'f':
6507 {
6508 if (LocaleCompare("fill",option+1) == 0)
6509 {
6510 if (*option == '+')
6511 {
6512 (void) SetImageOption(image_info,option+1,"none");
6513 break;
6514 }
6515 (void) SetImageOption(image_info,option+1,argv[i+1]);
6516 break;
6517 }
6518 if (LocaleCompare("filter",option+1) == 0)
6519 {
6520 if (*option == '+')
6521 {
6522 (void) SetImageOption(image_info,option+1,"undefined");
6523 break;
6524 }
6525 (void) SetImageOption(image_info,option+1,argv[i+1]);
6526 break;
6527 }
6528 if (LocaleCompare("font",option+1) == 0)
6529 {
6530 if (*option == '+')
6531 {
6532 if (image_info->font != (char *) NULL)
6533 image_info->font=DestroyString(image_info->font);
6534 break;
6535 }
6536 (void) CloneString(&image_info->font,argv[i+1]);
6537 break;
6538 }
6539 if (LocaleCompare("format",option+1) == 0)
6540 {
6541 register const char
6542 *q;
6543
6544 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006545 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006546 image_info->ping=MagickFalse;
6547 (void) SetImageOption(image_info,option+1,argv[i+1]);
6548 break;
6549 }
6550 if (LocaleCompare("fuzz",option+1) == 0)
6551 {
6552 if (*option == '+')
6553 {
6554 image_info->fuzz=0.0;
6555 (void) SetImageOption(image_info,option+1,"0");
6556 break;
6557 }
cristyf2f27272009-12-17 14:48:46 +00006558 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006559 1.0);
6560 (void) SetImageOption(image_info,option+1,argv[i+1]);
6561 break;
6562 }
6563 break;
6564 }
6565 case 'g':
6566 {
6567 if (LocaleCompare("gravity",option+1) == 0)
6568 {
6569 if (*option == '+')
6570 {
6571 (void) SetImageOption(image_info,option+1,"undefined");
6572 break;
6573 }
6574 (void) SetImageOption(image_info,option+1,argv[i+1]);
6575 break;
6576 }
6577 if (LocaleCompare("green-primary",option+1) == 0)
6578 {
6579 if (*option == '+')
6580 {
6581 (void) SetImageOption(image_info,option+1,"0.0");
6582 break;
6583 }
6584 (void) SetImageOption(image_info,option+1,argv[i+1]);
6585 break;
6586 }
6587 break;
6588 }
6589 case 'i':
6590 {
6591 if (LocaleCompare("intent",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 (void) SetImageOption(image_info,option+1,"undefined");
6596 break;
6597 }
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
6601 if (LocaleCompare("interlace",option+1) == 0)
6602 {
6603 if (*option == '+')
6604 {
6605 image_info->interlace=UndefinedInterlace;
6606 (void) SetImageOption(image_info,option+1,"undefined");
6607 break;
6608 }
6609 image_info->interlace=(InterlaceType) ParseMagickOption(
6610 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6611 (void) SetImageOption(image_info,option+1,argv[i+1]);
6612 break;
6613 }
cristyb32b90a2009-09-07 21:45:48 +00006614 if (LocaleCompare("interline-spacing",option+1) == 0)
6615 {
6616 if (*option == '+')
6617 {
6618 (void) SetImageOption(image_info,option+1,"undefined");
6619 break;
6620 }
6621 (void) SetImageOption(image_info,option+1,argv[i+1]);
6622 break;
6623 }
cristy3ed852e2009-09-05 21:47:34 +00006624 if (LocaleCompare("interpolate",option+1) == 0)
6625 {
6626 if (*option == '+')
6627 {
6628 (void) SetImageOption(image_info,option+1,"undefined");
6629 break;
6630 }
6631 (void) SetImageOption(image_info,option+1,argv[i+1]);
6632 break;
6633 }
6634 if (LocaleCompare("interword-spacing",option+1) == 0)
6635 {
6636 if (*option == '+')
6637 {
6638 (void) SetImageOption(image_info,option+1,"undefined");
6639 break;
6640 }
6641 (void) SetImageOption(image_info,option+1,argv[i+1]);
6642 break;
6643 }
6644 break;
6645 }
6646 case 'k':
6647 {
6648 if (LocaleCompare("kerning",option+1) == 0)
6649 {
6650 if (*option == '+')
6651 {
6652 (void) SetImageOption(image_info,option+1,"undefined");
6653 break;
6654 }
6655 (void) SetImageOption(image_info,option+1,argv[i+1]);
6656 break;
6657 }
6658 break;
6659 }
6660 case 'l':
6661 {
6662 if (LocaleCompare("label",option+1) == 0)
6663 {
6664 if (*option == '+')
6665 {
6666 (void) DeleteImageOption(image_info,option+1);
6667 break;
6668 }
6669 (void) SetImageOption(image_info,option+1,argv[i+1]);
6670 break;
6671 }
6672 if (LocaleCompare("limit",option+1) == 0)
6673 {
6674 MagickSizeType
6675 limit;
6676
6677 ResourceType
6678 type;
6679
6680 if (*option == '+')
6681 break;
6682 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6683 MagickFalse,argv[i+1]);
6684 limit=MagickResourceInfinity;
6685 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006686 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006687 (void) SetMagickResourceLimit(type,limit);
6688 break;
6689 }
6690 if (LocaleCompare("list",option+1) == 0)
6691 {
cristybb503372010-05-27 20:51:26 +00006692 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006693 list;
6694
6695 /*
6696 Display configuration list.
6697 */
6698 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6699 switch (list)
6700 {
6701 case MagickCoderOptions:
6702 {
6703 (void) ListCoderInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickColorOptions:
6707 {
6708 (void) ListColorInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickConfigureOptions:
6712 {
6713 (void) ListConfigureInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickDelegateOptions:
6717 {
6718 (void) ListDelegateInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickFontOptions:
6722 {
6723 (void) ListTypeInfo((FILE *) NULL,exception);
6724 break;
6725 }
6726 case MagickFormatOptions:
6727 {
6728 (void) ListMagickInfo((FILE *) NULL,exception);
6729 break;
6730 }
6731 case MagickLocaleOptions:
6732 {
6733 (void) ListLocaleInfo((FILE *) NULL,exception);
6734 break;
6735 }
6736 case MagickLogOptions:
6737 {
6738 (void) ListLogInfo((FILE *) NULL,exception);
6739 break;
6740 }
6741 case MagickMagicOptions:
6742 {
6743 (void) ListMagicInfo((FILE *) NULL,exception);
6744 break;
6745 }
6746 case MagickMimeOptions:
6747 {
6748 (void) ListMimeInfo((FILE *) NULL,exception);
6749 break;
6750 }
6751 case MagickModuleOptions:
6752 {
6753 (void) ListModuleInfo((FILE *) NULL,exception);
6754 break;
6755 }
6756 case MagickPolicyOptions:
6757 {
6758 (void) ListPolicyInfo((FILE *) NULL,exception);
6759 break;
6760 }
6761 case MagickResourceOptions:
6762 {
6763 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6764 break;
6765 }
6766 case MagickThresholdOptions:
6767 {
6768 (void) ListThresholdMaps((FILE *) NULL,exception);
6769 break;
6770 }
6771 default:
6772 {
6773 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
6774 exception);
6775 break;
6776 }
6777 }
cristyaeb2cbc2010-05-07 13:28:58 +00006778 break;
cristy3ed852e2009-09-05 21:47:34 +00006779 }
6780 if (LocaleCompare("log",option+1) == 0)
6781 {
6782 if (*option == '+')
6783 break;
6784 (void) SetLogFormat(argv[i+1]);
6785 break;
6786 }
6787 if (LocaleCompare("loop",option+1) == 0)
6788 {
6789 if (*option == '+')
6790 {
6791 (void) SetImageOption(image_info,option+1,"0");
6792 break;
6793 }
6794 (void) SetImageOption(image_info,option+1,argv[i+1]);
6795 break;
6796 }
6797 break;
6798 }
6799 case 'm':
6800 {
6801 if (LocaleCompare("matte",option+1) == 0)
6802 {
6803 if (*option == '+')
6804 {
6805 (void) SetImageOption(image_info,option+1,"false");
6806 break;
6807 }
6808 (void) SetImageOption(image_info,option+1,"true");
6809 break;
6810 }
6811 if (LocaleCompare("mattecolor",option+1) == 0)
6812 {
6813 if (*option == '+')
6814 {
6815 (void) SetImageOption(image_info,option+1,argv[i+1]);
6816 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6817 exception);
6818 break;
6819 }
6820 (void) SetImageOption(image_info,option+1,argv[i+1]);
6821 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6822 exception);
6823 break;
6824 }
6825 if (LocaleCompare("monitor",option+1) == 0)
6826 {
6827 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6828 (void *) NULL);
6829 break;
6830 }
6831 if (LocaleCompare("monochrome",option+1) == 0)
6832 {
6833 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6834 break;
6835 }
6836 break;
6837 }
6838 case 'o':
6839 {
6840 if (LocaleCompare("orient",option+1) == 0)
6841 {
6842 if (*option == '+')
6843 {
6844 image_info->orientation=UndefinedOrientation;
6845 (void) SetImageOption(image_info,option+1,"undefined");
6846 break;
6847 }
6848 image_info->orientation=(OrientationType) ParseMagickOption(
6849 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006850 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006851 break;
6852 }
6853 }
6854 case 'p':
6855 {
6856 if (LocaleCompare("page",option+1) == 0)
6857 {
6858 char
6859 *canonical_page,
6860 page[MaxTextExtent];
6861
6862 const char
6863 *image_option;
6864
6865 MagickStatusType
6866 flags;
6867
6868 RectangleInfo
6869 geometry;
6870
6871 if (*option == '+')
6872 {
6873 (void) DeleteImageOption(image_info,option+1);
6874 (void) CloneString(&image_info->page,(char *) NULL);
6875 break;
6876 }
6877 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6878 image_option=GetImageOption(image_info,"page");
6879 if (image_option != (const char *) NULL)
6880 flags=ParseAbsoluteGeometry(image_option,&geometry);
6881 canonical_page=GetPageGeometry(argv[i+1]);
6882 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6883 canonical_page=DestroyString(canonical_page);
6884 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006885 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006886 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6887 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006888 (unsigned long) geometry.width,(unsigned long) geometry.height,
6889 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006890 (void) SetImageOption(image_info,option+1,page);
6891 (void) CloneString(&image_info->page,page);
6892 break;
6893 }
6894 if (LocaleCompare("pen",option+1) == 0)
6895 {
6896 if (*option == '+')
6897 {
6898 (void) SetImageOption(image_info,option+1,"none");
6899 break;
6900 }
6901 (void) SetImageOption(image_info,option+1,argv[i+1]);
6902 break;
6903 }
6904 if (LocaleCompare("ping",option+1) == 0)
6905 {
6906 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6907 break;
6908 }
6909 if (LocaleCompare("pointsize",option+1) == 0)
6910 {
6911 if (*option == '+')
6912 geometry_info.rho=0.0;
6913 else
6914 (void) ParseGeometry(argv[i+1],&geometry_info);
6915 image_info->pointsize=geometry_info.rho;
6916 break;
6917 }
cristye7f51092010-01-17 00:39:37 +00006918 if (LocaleCompare("precision",option+1) == 0)
6919 {
cristybf2766a2010-01-17 03:33:23 +00006920 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006921 break;
6922 }
cristy3ed852e2009-09-05 21:47:34 +00006923 if (LocaleCompare("preview",option+1) == 0)
6924 {
6925 /*
6926 Preview image.
6927 */
6928 if (*option == '+')
6929 {
6930 image_info->preview_type=UndefinedPreview;
6931 break;
6932 }
6933 image_info->preview_type=(PreviewType) ParseMagickOption(
6934 MagickPreviewOptions,MagickFalse,argv[i+1]);
6935 break;
6936 }
6937 break;
6938 }
6939 case 'q':
6940 {
6941 if (LocaleCompare("quality",option+1) == 0)
6942 {
6943 /*
6944 Set image compression quality.
6945 */
6946 if (*option == '+')
6947 {
6948 image_info->quality=UndefinedCompressionQuality;
6949 (void) SetImageOption(image_info,option+1,"0");
6950 break;
6951 }
cristye27293e2009-12-18 02:53:20 +00006952 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006953 (void) SetImageOption(image_info,option+1,argv[i+1]);
6954 break;
6955 }
6956 if (LocaleCompare("quiet",option+1) == 0)
6957 {
6958 static WarningHandler
6959 warning_handler = (WarningHandler) NULL;
6960
6961 if (*option == '+')
6962 {
6963 /*
6964 Restore error or warning messages.
6965 */
6966 warning_handler=SetWarningHandler(warning_handler);
6967 break;
6968 }
6969 /*
6970 Suppress error or warning messages.
6971 */
6972 warning_handler=SetWarningHandler((WarningHandler) NULL);
6973 break;
6974 }
6975 break;
6976 }
6977 case 'r':
6978 {
6979 if (LocaleCompare("red-primary",option+1) == 0)
6980 {
6981 if (*option == '+')
6982 {
6983 (void) SetImageOption(image_info,option+1,"0.0");
6984 break;
6985 }
6986 (void) SetImageOption(image_info,option+1,argv[i+1]);
6987 break;
6988 }
6989 break;
6990 }
6991 case 's':
6992 {
6993 if (LocaleCompare("sampling-factor",option+1) == 0)
6994 {
6995 /*
6996 Set image sampling factor.
6997 */
6998 if (*option == '+')
6999 {
7000 if (image_info->sampling_factor != (char *) NULL)
7001 image_info->sampling_factor=DestroyString(
7002 image_info->sampling_factor);
7003 break;
7004 }
7005 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7006 break;
7007 }
7008 if (LocaleCompare("scene",option+1) == 0)
7009 {
7010 /*
7011 Set image scene.
7012 */
7013 if (*option == '+')
7014 {
7015 image_info->scene=0;
7016 (void) SetImageOption(image_info,option+1,"0");
7017 break;
7018 }
cristye27293e2009-12-18 02:53:20 +00007019 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007020 (void) SetImageOption(image_info,option+1,argv[i+1]);
7021 break;
7022 }
7023 if (LocaleCompare("seed",option+1) == 0)
7024 {
cristybb503372010-05-27 20:51:26 +00007025 size_t
cristy3ed852e2009-09-05 21:47:34 +00007026 seed;
7027
7028 if (*option == '+')
7029 {
cristybb503372010-05-27 20:51:26 +00007030 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007031 SeedPseudoRandomGenerator(seed);
7032 break;
7033 }
cristye27293e2009-12-18 02:53:20 +00007034 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007035 SeedPseudoRandomGenerator(seed);
7036 break;
7037 }
7038 if (LocaleCompare("size",option+1) == 0)
7039 {
7040 if (*option == '+')
7041 {
7042 if (image_info->size != (char *) NULL)
7043 image_info->size=DestroyString(image_info->size);
7044 break;
7045 }
7046 (void) CloneString(&image_info->size,argv[i+1]);
7047 break;
7048 }
7049 if (LocaleCompare("stroke",option+1) == 0)
7050 {
7051 if (*option == '+')
7052 {
7053 (void) SetImageOption(image_info,option+1,"none");
7054 break;
7055 }
7056 (void) SetImageOption(image_info,option+1,argv[i+1]);
7057 break;
7058 }
7059 if (LocaleCompare("strokewidth",option+1) == 0)
7060 {
7061 if (*option == '+')
7062 {
7063 (void) SetImageOption(image_info,option+1,"0");
7064 break;
7065 }
7066 (void) SetImageOption(image_info,option+1,argv[i+1]);
7067 break;
7068 }
cristyd9a29192010-10-16 16:49:53 +00007069 if (LocaleCompare("synchronize",option+1) == 0)
7070 {
7071 if (*option == '+')
7072 {
7073 image_info->synchronize=MagickFalse;
7074 break;
7075 }
7076 image_info->synchronize=MagickTrue;
7077 break;
7078 }
cristy3ed852e2009-09-05 21:47:34 +00007079 break;
7080 }
7081 case 't':
7082 {
7083 if (LocaleCompare("taint",option+1) == 0)
7084 {
7085 if (*option == '+')
7086 {
7087 (void) SetImageOption(image_info,option+1,"false");
7088 break;
7089 }
7090 (void) SetImageOption(image_info,option+1,"true");
7091 break;
7092 }
7093 if (LocaleCompare("texture",option+1) == 0)
7094 {
7095 if (*option == '+')
7096 {
7097 if (image_info->texture != (char *) NULL)
7098 image_info->texture=DestroyString(image_info->texture);
7099 break;
7100 }
7101 (void) CloneString(&image_info->texture,argv[i+1]);
7102 break;
7103 }
7104 if (LocaleCompare("tile-offset",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
7108 (void) SetImageOption(image_info,option+1,"0");
7109 break;
7110 }
7111 (void) SetImageOption(image_info,option+1,argv[i+1]);
7112 break;
7113 }
7114 if (LocaleCompare("transparent-color",option+1) == 0)
7115 {
7116 if (*option == '+')
7117 {
7118 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7119 (void) SetImageOption(image_info,option+1,"none");
7120 break;
7121 }
7122 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7123 exception);
7124 (void) SetImageOption(image_info,option+1,argv[i+1]);
7125 break;
7126 }
7127 if (LocaleCompare("type",option+1) == 0)
7128 {
7129 if (*option == '+')
7130 {
cristy5f1c1ff2010-12-23 21:38:06 +00007131 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007132 (void) SetImageOption(image_info,option+1,"undefined");
7133 break;
7134 }
7135 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7136 MagickFalse,argv[i+1]);
7137 (void) SetImageOption(image_info,option+1,argv[i+1]);
7138 break;
7139 }
7140 break;
7141 }
7142 case 'u':
7143 {
7144 if (LocaleCompare("undercolor",option+1) == 0)
7145 {
7146 if (*option == '+')
7147 {
7148 (void) DeleteImageOption(image_info,option+1);
7149 break;
7150 }
7151 (void) SetImageOption(image_info,option+1,argv[i+1]);
7152 break;
7153 }
7154 if (LocaleCompare("units",option+1) == 0)
7155 {
7156 if (*option == '+')
7157 {
7158 image_info->units=UndefinedResolution;
7159 (void) SetImageOption(image_info,option+1,"undefined");
7160 break;
7161 }
7162 image_info->units=(ResolutionType) ParseMagickOption(
7163 MagickResolutionOptions,MagickFalse,argv[i+1]);
7164 (void) SetImageOption(image_info,option+1,argv[i+1]);
7165 break;
7166 }
7167 break;
7168 }
7169 case 'v':
7170 {
7171 if (LocaleCompare("verbose",option+1) == 0)
7172 {
7173 if (*option == '+')
7174 {
7175 image_info->verbose=MagickFalse;
7176 break;
7177 }
7178 image_info->verbose=MagickTrue;
7179 image_info->ping=MagickFalse;
7180 break;
7181 }
7182 if (LocaleCompare("view",option+1) == 0)
7183 {
7184 if (*option == '+')
7185 {
7186 if (image_info->view != (char *) NULL)
7187 image_info->view=DestroyString(image_info->view);
7188 break;
7189 }
7190 (void) CloneString(&image_info->view,argv[i+1]);
7191 break;
7192 }
7193 if (LocaleCompare("virtual-pixel",option+1) == 0)
7194 {
7195 if (*option == '+')
7196 {
7197 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7198 (void) SetImageOption(image_info,option+1,"undefined");
7199 break;
7200 }
7201 image_info->virtual_pixel_method=(VirtualPixelMethod)
7202 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7203 argv[i+1]);
7204 (void) SetImageOption(image_info,option+1,argv[i+1]);
7205 break;
7206 }
7207 break;
7208 }
7209 case 'w':
7210 {
7211 if (LocaleCompare("white-point",option+1) == 0)
7212 {
7213 if (*option == '+')
7214 {
7215 (void) SetImageOption(image_info,option+1,"0.0");
7216 break;
7217 }
7218 (void) SetImageOption(image_info,option+1,argv[i+1]);
7219 break;
7220 }
7221 break;
7222 }
7223 default:
7224 break;
7225 }
7226 i+=count;
7227 }
7228 return(MagickTrue);
7229}
7230
7231/*
7232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7233% %
7234% %
7235% %
7236+ M o g r i f y I m a g e L i s t %
7237% %
7238% %
7239% %
7240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7241%
7242% MogrifyImageList() applies any command line options that might affect the
7243% entire image list (e.g. -append, -coalesce, etc.).
7244%
7245% The format of the MogrifyImage method is:
7246%
7247% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7248% const char **argv,Image **images,ExceptionInfo *exception)
7249%
7250% A description of each parameter follows:
7251%
7252% o image_info: the image info..
7253%
7254% o argc: Specifies a pointer to an integer describing the number of
7255% elements in the argument vector.
7256%
7257% o argv: Specifies a pointer to a text array containing the command line
7258% arguments.
7259%
anthonye9c27192011-03-27 08:07:06 +00007260% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007261%
7262% o exception: return any errors or warnings in this structure.
7263%
7264*/
7265WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7266 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7267{
7268 ChannelType
7269 channel;
7270
7271 const char
7272 *option;
7273
cristy6b3da3a2010-06-20 02:21:46 +00007274 ImageInfo
7275 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007276
7277 MagickStatusType
7278 status;
7279
7280 QuantizeInfo
7281 *quantize_info;
7282
cristybb503372010-05-27 20:51:26 +00007283 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007284 i;
7285
cristy6b3da3a2010-06-20 02:21:46 +00007286 ssize_t
7287 count,
7288 index;
7289
cristy3ed852e2009-09-05 21:47:34 +00007290 /*
7291 Apply options to the image list.
7292 */
7293 assert(image_info != (ImageInfo *) NULL);
7294 assert(image_info->signature == MagickSignature);
7295 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007296 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007297 assert((*images)->signature == MagickSignature);
7298 if ((*images)->debug != MagickFalse)
7299 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7300 (*images)->filename);
7301 if ((argc <= 0) || (*argv == (char *) NULL))
7302 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007303 mogrify_info=CloneImageInfo(image_info);
7304 quantize_info=AcquireQuantizeInfo(mogrify_info);
7305 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007306 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007307 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007308 {
cristy74fe8f12009-10-03 19:09:01 +00007309 if (*images == (Image *) NULL)
7310 break;
cristy3ed852e2009-09-05 21:47:34 +00007311 option=argv[i];
7312 if (IsMagickOption(option) == MagickFalse)
7313 continue;
anthonyce2716b2011-04-22 09:51:34 +00007314 count=ParseMagickOption(MagickCommandOptions,MagickFalse,option);
7315 count=MagickMax(count,0L);
7316 count&=NumArgsOption;
cristycee97112010-05-28 00:44:52 +00007317 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007318 break;
cristy6b3da3a2010-06-20 02:21:46 +00007319 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007320 switch (*(option+1))
7321 {
7322 case 'a':
7323 {
7324 if (LocaleCompare("affinity",option+1) == 0)
7325 {
cristy6b3da3a2010-06-20 02:21:46 +00007326 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007327 if (*option == '+')
7328 {
7329 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7330 InheritException(exception,&(*images)->exception);
7331 break;
7332 }
7333 i++;
7334 break;
7335 }
7336 if (LocaleCompare("append",option+1) == 0)
7337 {
7338 Image
7339 *append_image;
7340
cristy6b3da3a2010-06-20 02:21:46 +00007341 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007342 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7343 MagickFalse,exception);
7344 if (append_image == (Image *) NULL)
7345 {
7346 status=MagickFalse;
7347 break;
7348 }
7349 *images=DestroyImageList(*images);
7350 *images=append_image;
7351 break;
7352 }
7353 if (LocaleCompare("average",option+1) == 0)
7354 {
7355 Image
7356 *average_image;
7357
cristyd18ae7c2010-03-07 17:39:52 +00007358 /*
7359 Average an image sequence (deprecated).
7360 */
cristy6b3da3a2010-06-20 02:21:46 +00007361 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007362 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7363 exception);
cristy3ed852e2009-09-05 21:47:34 +00007364 if (average_image == (Image *) NULL)
7365 {
7366 status=MagickFalse;
7367 break;
7368 }
7369 *images=DestroyImageList(*images);
7370 *images=average_image;
7371 break;
7372 }
7373 break;
7374 }
7375 case 'c':
7376 {
7377 if (LocaleCompare("channel",option+1) == 0)
7378 {
7379 if (*option == '+')
7380 {
7381 channel=DefaultChannels;
7382 break;
7383 }
7384 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7385 break;
7386 }
7387 if (LocaleCompare("clut",option+1) == 0)
7388 {
7389 Image
7390 *clut_image,
7391 *image;
7392
cristy6b3da3a2010-06-20 02:21:46 +00007393 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007394 image=RemoveFirstImageFromList(images);
7395 clut_image=RemoveFirstImageFromList(images);
7396 if (clut_image == (Image *) NULL)
7397 {
7398 status=MagickFalse;
7399 break;
7400 }
7401 (void) ClutImageChannel(image,channel,clut_image);
7402 clut_image=DestroyImage(clut_image);
7403 InheritException(exception,&image->exception);
7404 *images=DestroyImageList(*images);
7405 *images=image;
7406 break;
7407 }
7408 if (LocaleCompare("coalesce",option+1) == 0)
7409 {
7410 Image
7411 *coalesce_image;
7412
cristy6b3da3a2010-06-20 02:21:46 +00007413 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007414 coalesce_image=CoalesceImages(*images,exception);
7415 if (coalesce_image == (Image *) NULL)
7416 {
7417 status=MagickFalse;
7418 break;
7419 }
7420 *images=DestroyImageList(*images);
7421 *images=coalesce_image;
7422 break;
7423 }
7424 if (LocaleCompare("combine",option+1) == 0)
7425 {
7426 Image
7427 *combine_image;
7428
cristy6b3da3a2010-06-20 02:21:46 +00007429 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007430 combine_image=CombineImages(*images,channel,exception);
7431 if (combine_image == (Image *) NULL)
7432 {
7433 status=MagickFalse;
7434 break;
7435 }
7436 *images=DestroyImageList(*images);
7437 *images=combine_image;
7438 break;
7439 }
7440 if (LocaleCompare("composite",option+1) == 0)
7441 {
7442 Image
7443 *mask_image,
7444 *composite_image,
7445 *image;
7446
7447 RectangleInfo
7448 geometry;
7449
cristy6b3da3a2010-06-20 02:21:46 +00007450 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007451 image=RemoveFirstImageFromList(images);
7452 composite_image=RemoveFirstImageFromList(images);
7453 if (composite_image == (Image *) NULL)
7454 {
7455 status=MagickFalse;
7456 break;
7457 }
7458 (void) TransformImage(&composite_image,(char *) NULL,
7459 composite_image->geometry);
7460 SetGeometry(composite_image,&geometry);
7461 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7462 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7463 &geometry);
7464 mask_image=RemoveFirstImageFromList(images);
7465 if (mask_image != (Image *) NULL)
7466 {
7467 if ((image->compose == DisplaceCompositeOp) ||
7468 (image->compose == DistortCompositeOp))
7469 {
7470 /*
7471 Merge Y displacement into X displacement image.
7472 */
7473 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7474 mask_image,0,0);
7475 mask_image=DestroyImage(mask_image);
7476 }
7477 else
7478 {
7479 /*
7480 Set a blending mask for the composition.
7481 */
anthonya129f702011-04-14 01:08:48 +00007482 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007483 image->mask=mask_image;
7484 (void) NegateImage(image->mask,MagickFalse);
7485 }
7486 }
7487 (void) CompositeImageChannel(image,channel,image->compose,
7488 composite_image,geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007489 if (mask_image != (Image *) NULL)
7490 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007491 composite_image=DestroyImage(composite_image);
7492 InheritException(exception,&image->exception);
7493 *images=DestroyImageList(*images);
7494 *images=image;
7495 break;
7496 }
anthony9f4f0342011-03-28 11:47:22 +00007497#if 0
7498This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007499 if (LocaleCompare("crop",option+1) == 0)
7500 {
7501 MagickStatusType
7502 flags;
7503
7504 RectangleInfo
7505 geometry;
7506
anthonye9c27192011-03-27 08:07:06 +00007507 /*
anthony9f4f0342011-03-28 11:47:22 +00007508 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007509 */
cristy6b3da3a2010-06-20 02:21:46 +00007510 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007511 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7512 if (((geometry.width == 0) && (geometry.height == 0)) ||
7513 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7514 break;
7515 (void) TransformImages(images,argv[i+1],(char *) NULL);
7516 InheritException(exception,&(*images)->exception);
7517 break;
7518 }
anthony9f4f0342011-03-28 11:47:22 +00007519#endif
cristy3ed852e2009-09-05 21:47:34 +00007520 break;
7521 }
7522 case 'd':
7523 {
7524 if (LocaleCompare("deconstruct",option+1) == 0)
7525 {
7526 Image
7527 *deconstruct_image;
7528
cristy6b3da3a2010-06-20 02:21:46 +00007529 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007530 deconstruct_image=DeconstructImages(*images,exception);
7531 if (deconstruct_image == (Image *) NULL)
7532 {
7533 status=MagickFalse;
7534 break;
7535 }
7536 *images=DestroyImageList(*images);
7537 *images=deconstruct_image;
7538 break;
7539 }
7540 if (LocaleCompare("delete",option+1) == 0)
7541 {
7542 if (*option == '+')
7543 DeleteImages(images,"-1",exception);
7544 else
7545 DeleteImages(images,argv[i+1],exception);
7546 break;
7547 }
7548 if (LocaleCompare("dither",option+1) == 0)
7549 {
7550 if (*option == '+')
7551 {
7552 quantize_info->dither=MagickFalse;
7553 break;
7554 }
7555 quantize_info->dither=MagickTrue;
7556 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7557 MagickDitherOptions,MagickFalse,argv[i+1]);
7558 break;
7559 }
cristyecb10ff2011-03-22 13:14:03 +00007560 if (LocaleCompare("duplicate",option+1) == 0)
7561 {
cristy72988482011-03-29 16:34:38 +00007562 Image
7563 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007564
anthony2b6bcae2011-03-23 13:05:34 +00007565 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007566 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7567 else
7568 {
7569 const char
7570 *p;
7571
anthony2b6bcae2011-03-23 13:05:34 +00007572 size_t
7573 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007574
anthony2b6bcae2011-03-23 13:05:34 +00007575 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007576 p=strchr(argv[i+1],',');
7577 if (p == (const char *) NULL)
7578 duplicate_images=DuplicateImages(*images,number_duplicates,
7579 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007580 else
cristy72988482011-03-29 16:34:38 +00007581 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7582 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007583 }
7584 AppendImageToList(images, duplicate_images);
7585 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007586 break;
7587 }
cristy3ed852e2009-09-05 21:47:34 +00007588 break;
7589 }
cristyd18ae7c2010-03-07 17:39:52 +00007590 case 'e':
7591 {
7592 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7593 {
7594 Image
7595 *evaluate_image;
7596
7597 MagickEvaluateOperator
7598 op;
7599
cristy6b3da3a2010-06-20 02:21:46 +00007600 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007601 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7602 MagickFalse,argv[i+1]);
7603 evaluate_image=EvaluateImages(*images,op,exception);
7604 if (evaluate_image == (Image *) NULL)
7605 {
7606 status=MagickFalse;
7607 break;
7608 }
7609 *images=DestroyImageList(*images);
7610 *images=evaluate_image;
7611 break;
7612 }
7613 break;
7614 }
cristy3ed852e2009-09-05 21:47:34 +00007615 case 'f':
7616 {
cristyf0a247f2009-10-04 00:20:03 +00007617 if (LocaleCompare("fft",option+1) == 0)
7618 {
7619 Image
7620 *fourier_image;
7621
7622 /*
7623 Implements the discrete Fourier transform (DFT).
7624 */
cristy6b3da3a2010-06-20 02:21:46 +00007625 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007626 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7627 MagickTrue : MagickFalse,exception);
7628 if (fourier_image == (Image *) NULL)
7629 break;
7630 *images=DestroyImage(*images);
7631 *images=fourier_image;
7632 break;
7633 }
cristy3ed852e2009-09-05 21:47:34 +00007634 if (LocaleCompare("flatten",option+1) == 0)
7635 {
7636 Image
7637 *flatten_image;
7638
cristy6b3da3a2010-06-20 02:21:46 +00007639 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007640 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7641 if (flatten_image == (Image *) NULL)
7642 break;
7643 *images=DestroyImageList(*images);
7644 *images=flatten_image;
7645 break;
7646 }
7647 if (LocaleCompare("fx",option+1) == 0)
7648 {
7649 Image
7650 *fx_image;
7651
cristy6b3da3a2010-06-20 02:21:46 +00007652 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007653 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7654 if (fx_image == (Image *) NULL)
7655 {
7656 status=MagickFalse;
7657 break;
7658 }
7659 *images=DestroyImageList(*images);
7660 *images=fx_image;
7661 break;
7662 }
7663 break;
7664 }
7665 case 'h':
7666 {
7667 if (LocaleCompare("hald-clut",option+1) == 0)
7668 {
7669 Image
7670 *hald_image,
7671 *image;
7672
cristy6b3da3a2010-06-20 02:21:46 +00007673 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007674 image=RemoveFirstImageFromList(images);
7675 hald_image=RemoveFirstImageFromList(images);
7676 if (hald_image == (Image *) NULL)
7677 {
7678 status=MagickFalse;
7679 break;
7680 }
7681 (void) HaldClutImageChannel(image,channel,hald_image);
7682 hald_image=DestroyImage(hald_image);
7683 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007684 if (*images != (Image *) NULL)
7685 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007686 *images=image;
7687 break;
7688 }
7689 break;
7690 }
7691 case 'i':
7692 {
7693 if (LocaleCompare("ift",option+1) == 0)
7694 {
7695 Image
cristy8587f882009-11-13 20:28:49 +00007696 *fourier_image,
7697 *magnitude_image,
7698 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007699
7700 /*
7701 Implements the inverse fourier discrete Fourier transform (DFT).
7702 */
cristy6b3da3a2010-06-20 02:21:46 +00007703 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007704 magnitude_image=RemoveFirstImageFromList(images);
7705 phase_image=RemoveFirstImageFromList(images);
7706 if (phase_image == (Image *) NULL)
7707 {
7708 status=MagickFalse;
7709 break;
7710 }
7711 fourier_image=InverseFourierTransformImage(magnitude_image,
7712 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007713 if (fourier_image == (Image *) NULL)
7714 break;
cristy0aff6ea2009-11-14 01:40:53 +00007715 if (*images != (Image *) NULL)
7716 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007717 *images=fourier_image;
7718 break;
7719 }
7720 if (LocaleCompare("insert",option+1) == 0)
7721 {
7722 Image
7723 *p,
7724 *q;
7725
7726 index=0;
7727 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007728 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007729 p=RemoveLastImageFromList(images);
7730 if (p == (Image *) NULL)
7731 {
7732 (void) ThrowMagickException(exception,GetMagickModule(),
7733 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7734 status=MagickFalse;
7735 break;
7736 }
7737 q=p;
7738 if (index == 0)
7739 PrependImageToList(images,q);
7740 else
cristybb503372010-05-27 20:51:26 +00007741 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007742 AppendImageToList(images,q);
7743 else
7744 {
7745 q=GetImageFromList(*images,index-1);
7746 if (q == (Image *) NULL)
7747 {
7748 (void) ThrowMagickException(exception,GetMagickModule(),
7749 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7750 status=MagickFalse;
7751 break;
7752 }
7753 InsertImageInList(&q,p);
7754 }
7755 *images=GetFirstImageInList(q);
7756 break;
7757 }
7758 break;
7759 }
7760 case 'l':
7761 {
7762 if (LocaleCompare("layers",option+1) == 0)
7763 {
7764 Image
7765 *layers;
7766
7767 ImageLayerMethod
7768 method;
7769
cristy6b3da3a2010-06-20 02:21:46 +00007770 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007771 layers=(Image *) NULL;
7772 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7773 MagickFalse,argv[i+1]);
7774 switch (method)
7775 {
7776 case CoalesceLayer:
7777 {
7778 layers=CoalesceImages(*images,exception);
7779 break;
7780 }
7781 case CompareAnyLayer:
7782 case CompareClearLayer:
7783 case CompareOverlayLayer:
7784 default:
7785 {
7786 layers=CompareImageLayers(*images,method,exception);
7787 break;
7788 }
7789 case MergeLayer:
7790 case FlattenLayer:
7791 case MosaicLayer:
7792 case TrimBoundsLayer:
7793 {
7794 layers=MergeImageLayers(*images,method,exception);
7795 break;
7796 }
7797 case DisposeLayer:
7798 {
7799 layers=DisposeImages(*images,exception);
7800 break;
7801 }
7802 case OptimizeImageLayer:
7803 {
7804 layers=OptimizeImageLayers(*images,exception);
7805 break;
7806 }
7807 case OptimizePlusLayer:
7808 {
7809 layers=OptimizePlusImageLayers(*images,exception);
7810 break;
7811 }
7812 case OptimizeTransLayer:
7813 {
7814 OptimizeImageTransparency(*images,exception);
7815 break;
7816 }
7817 case RemoveDupsLayer:
7818 {
7819 RemoveDuplicateLayers(images,exception);
7820 break;
7821 }
7822 case RemoveZeroLayer:
7823 {
7824 RemoveZeroDelayLayers(images,exception);
7825 break;
7826 }
7827 case OptimizeLayer:
7828 {
7829 /*
7830 General Purpose, GIF Animation Optimizer.
7831 */
7832 layers=CoalesceImages(*images,exception);
7833 if (layers == (Image *) NULL)
7834 {
7835 status=MagickFalse;
7836 break;
7837 }
7838 InheritException(exception,&layers->exception);
7839 *images=DestroyImageList(*images);
7840 *images=layers;
7841 layers=OptimizeImageLayers(*images,exception);
7842 if (layers == (Image *) NULL)
7843 {
7844 status=MagickFalse;
7845 break;
7846 }
7847 InheritException(exception,&layers->exception);
7848 *images=DestroyImageList(*images);
7849 *images=layers;
7850 layers=(Image *) NULL;
7851 OptimizeImageTransparency(*images,exception);
7852 InheritException(exception,&(*images)->exception);
7853 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7854 break;
7855 }
7856 case CompositeLayer:
7857 {
7858 CompositeOperator
7859 compose;
7860
7861 Image
7862 *source;
7863
7864 RectangleInfo
7865 geometry;
7866
7867 /*
7868 Split image sequence at the first 'NULL:' image.
7869 */
7870 source=(*images);
7871 while (source != (Image *) NULL)
7872 {
7873 source=GetNextImageInList(source);
7874 if ((source != (Image *) NULL) &&
7875 (LocaleCompare(source->magick,"NULL") == 0))
7876 break;
7877 }
7878 if (source != (Image *) NULL)
7879 {
7880 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7881 (GetNextImageInList(source) == (Image *) NULL))
7882 source=(Image *) NULL;
7883 else
7884 {
7885 /*
7886 Separate the two lists, junk the null: image.
7887 */
7888 source=SplitImageList(source->previous);
7889 DeleteImageFromList(&source);
7890 }
7891 }
7892 if (source == (Image *) NULL)
7893 {
7894 (void) ThrowMagickException(exception,GetMagickModule(),
7895 OptionError,"MissingNullSeparator","layers Composite");
7896 status=MagickFalse;
7897 break;
7898 }
7899 /*
7900 Adjust offset with gravity and virtual canvas.
7901 */
7902 SetGeometry(*images,&geometry);
7903 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7904 geometry.width=source->page.width != 0 ?
7905 source->page.width : source->columns;
7906 geometry.height=source->page.height != 0 ?
7907 source->page.height : source->rows;
7908 GravityAdjustGeometry((*images)->page.width != 0 ?
7909 (*images)->page.width : (*images)->columns,
7910 (*images)->page.height != 0 ? (*images)->page.height :
7911 (*images)->rows,(*images)->gravity,&geometry);
7912 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007913 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007914 if (option != (const char *) NULL)
7915 compose=(CompositeOperator) ParseMagickOption(
7916 MagickComposeOptions,MagickFalse,option);
7917 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7918 exception);
7919 source=DestroyImageList(source);
7920 break;
7921 }
7922 }
7923 if (layers == (Image *) NULL)
7924 break;
7925 InheritException(exception,&layers->exception);
7926 *images=DestroyImageList(*images);
7927 *images=layers;
7928 break;
7929 }
7930 break;
7931 }
7932 case 'm':
7933 {
7934 if (LocaleCompare("map",option+1) == 0)
7935 {
cristy6b3da3a2010-06-20 02:21:46 +00007936 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007937 if (*option == '+')
7938 {
7939 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7940 InheritException(exception,&(*images)->exception);
7941 break;
7942 }
7943 i++;
7944 break;
7945 }
cristyf40785b2010-03-06 02:27:27 +00007946 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007947 {
7948 Image
cristyf40785b2010-03-06 02:27:27 +00007949 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007950
cristyd18ae7c2010-03-07 17:39:52 +00007951 /*
7952 Maximum image sequence (deprecated).
7953 */
cristy6b3da3a2010-06-20 02:21:46 +00007954 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007955 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007956 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007957 {
7958 status=MagickFalse;
7959 break;
7960 }
7961 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007962 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007963 break;
7964 }
cristyf40785b2010-03-06 02:27:27 +00007965 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007966 {
7967 Image
cristyf40785b2010-03-06 02:27:27 +00007968 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007969
cristyd18ae7c2010-03-07 17:39:52 +00007970 /*
7971 Minimum image sequence (deprecated).
7972 */
cristy6b3da3a2010-06-20 02:21:46 +00007973 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007974 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007975 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007976 {
7977 status=MagickFalse;
7978 break;
7979 }
7980 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007981 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007982 break;
7983 }
cristy3ed852e2009-09-05 21:47:34 +00007984 if (LocaleCompare("morph",option+1) == 0)
7985 {
7986 Image
7987 *morph_image;
7988
cristy6b3da3a2010-06-20 02:21:46 +00007989 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007990 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007991 exception);
7992 if (morph_image == (Image *) NULL)
7993 {
7994 status=MagickFalse;
7995 break;
7996 }
7997 *images=DestroyImageList(*images);
7998 *images=morph_image;
7999 break;
8000 }
8001 if (LocaleCompare("mosaic",option+1) == 0)
8002 {
8003 Image
8004 *mosaic_image;
8005
cristy6b3da3a2010-06-20 02:21:46 +00008006 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008007 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8008 if (mosaic_image == (Image *) NULL)
8009 {
8010 status=MagickFalse;
8011 break;
8012 }
8013 *images=DestroyImageList(*images);
8014 *images=mosaic_image;
8015 break;
8016 }
8017 break;
8018 }
8019 case 'p':
8020 {
8021 if (LocaleCompare("print",option+1) == 0)
8022 {
8023 char
8024 *string;
8025
cristy6b3da3a2010-06-20 02:21:46 +00008026 (void) SyncImagesSettings(mogrify_info,*images);
8027 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008028 if (string == (char *) NULL)
8029 break;
8030 InheritException(exception,&(*images)->exception);
8031 (void) fprintf(stdout,"%s",string);
8032 string=DestroyString(string);
8033 }
8034 if (LocaleCompare("process",option+1) == 0)
8035 {
8036 char
8037 **arguments;
8038
8039 int
8040 j,
8041 number_arguments;
8042
cristy6b3da3a2010-06-20 02:21:46 +00008043 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008044 arguments=StringToArgv(argv[i+1],&number_arguments);
8045 if (arguments == (char **) NULL)
8046 break;
8047 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8048 {
8049 char
8050 breaker,
8051 quote,
8052 *token;
8053
8054 const char
8055 *arguments;
8056
8057 int
8058 next,
8059 status;
8060
8061 size_t
8062 length;
8063
8064 TokenInfo
8065 *token_info;
8066
8067 /*
8068 Support old style syntax, filter="-option arg".
8069 */
8070 length=strlen(argv[i+1]);
8071 token=(char *) NULL;
8072 if (~length >= MaxTextExtent)
8073 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8074 sizeof(*token));
8075 if (token == (char *) NULL)
8076 break;
8077 next=0;
8078 arguments=argv[i+1];
8079 token_info=AcquireTokenInfo();
8080 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8081 "\"",'\0',&breaker,&next,&quote);
8082 token_info=DestroyTokenInfo(token_info);
8083 if (status == 0)
8084 {
8085 const char
8086 *argv;
8087
8088 argv=(&(arguments[next]));
8089 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8090 exception);
8091 }
8092 token=DestroyString(token);
8093 break;
8094 }
cristy91c0da22010-05-02 01:44:07 +00008095 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008096 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8097 number_arguments-2,(const char **) arguments+2,exception);
8098 for (j=0; j < number_arguments; j++)
8099 arguments[j]=DestroyString(arguments[j]);
8100 arguments=(char **) RelinquishMagickMemory(arguments);
8101 break;
8102 }
8103 break;
8104 }
8105 case 'r':
8106 {
8107 if (LocaleCompare("reverse",option+1) == 0)
8108 {
8109 ReverseImageList(images);
8110 InheritException(exception,&(*images)->exception);
8111 break;
8112 }
8113 break;
8114 }
8115 case 's':
8116 {
cristy4285d782011-02-09 20:12:28 +00008117 if (LocaleCompare("smush",option+1) == 0)
8118 {
8119 Image
8120 *smush_image;
8121
8122 ssize_t
8123 offset;
8124
8125 (void) SyncImagesSettings(mogrify_info,*images);
8126 offset=(ssize_t) StringToLong(argv[i+1]);
8127 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8128 MagickFalse,offset,exception);
8129 if (smush_image == (Image *) NULL)
8130 {
8131 status=MagickFalse;
8132 break;
8133 }
8134 *images=DestroyImageList(*images);
8135 *images=smush_image;
8136 break;
8137 }
cristy3ed852e2009-09-05 21:47:34 +00008138 if (LocaleCompare("swap",option+1) == 0)
8139 {
8140 Image
8141 *p,
8142 *q,
8143 *swap;
8144
cristybb503372010-05-27 20:51:26 +00008145 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008146 swap_index;
8147
8148 index=(-1);
8149 swap_index=(-2);
8150 if (*option != '+')
8151 {
8152 GeometryInfo
8153 geometry_info;
8154
8155 MagickStatusType
8156 flags;
8157
8158 swap_index=(-1);
8159 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008160 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008161 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008162 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008163 }
8164 p=GetImageFromList(*images,index);
8165 q=GetImageFromList(*images,swap_index);
8166 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8167 {
8168 (void) ThrowMagickException(exception,GetMagickModule(),
8169 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8170 status=MagickFalse;
8171 break;
8172 }
8173 if (p == q)
8174 break;
8175 swap=CloneImage(p,0,0,MagickTrue,exception);
8176 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8177 ReplaceImageInList(&q,swap);
8178 *images=GetFirstImageInList(q);
8179 break;
8180 }
8181 break;
8182 }
8183 case 'w':
8184 {
8185 if (LocaleCompare("write",option+1) == 0)
8186 {
cristy071dd7b2010-04-09 13:04:54 +00008187 char
cristy06609ee2010-03-17 20:21:27 +00008188 key[MaxTextExtent];
8189
cristy3ed852e2009-09-05 21:47:34 +00008190 Image
8191 *write_images;
8192
8193 ImageInfo
8194 *write_info;
8195
cristy6b3da3a2010-06-20 02:21:46 +00008196 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008197 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8198 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008199 write_images=(*images);
8200 if (*option == '+')
8201 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008202 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008203 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8204 write_info=DestroyImageInfo(write_info);
8205 if (*option == '+')
8206 write_images=DestroyImageList(write_images);
8207 break;
8208 }
8209 break;
8210 }
8211 default:
8212 break;
8213 }
8214 i+=count;
8215 }
8216 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008217 mogrify_info=DestroyImageInfo(mogrify_info);
8218 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008219 return(status != 0 ? MagickTrue : MagickFalse);
8220}
8221
8222/*
8223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8224% %
8225% %
8226% %
8227+ M o g r i f y I m a g e s %
8228% %
8229% %
8230% %
8231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8232%
8233% MogrifyImages() applies image processing options to a sequence of images as
8234% prescribed by command line options.
8235%
8236% The format of the MogrifyImage method is:
8237%
8238% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8239% const MagickBooleanType post,const int argc,const char **argv,
8240% Image **images,Exceptioninfo *exception)
8241%
8242% A description of each parameter follows:
8243%
8244% o image_info: the image info..
8245%
8246% o post: If true, post process image list operators otherwise pre-process.
8247%
8248% o argc: Specifies a pointer to an integer describing the number of
8249% elements in the argument vector.
8250%
8251% o argv: Specifies a pointer to a text array containing the command line
8252% arguments.
8253%
anthonye9c27192011-03-27 08:07:06 +00008254% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008255%
8256% o exception: return any errors or warnings in this structure.
8257%
8258*/
8259WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8260 const MagickBooleanType post,const int argc,const char **argv,
8261 Image **images,ExceptionInfo *exception)
8262{
8263#define MogrifyImageTag "Mogrify/Image"
8264
anthonye9c27192011-03-27 08:07:06 +00008265 MagickStatusType
8266 status;
cristy3ed852e2009-09-05 21:47:34 +00008267
cristy0e9f9c12010-02-11 03:00:47 +00008268 MagickBooleanType
8269 proceed;
8270
anthonye9c27192011-03-27 08:07:06 +00008271 size_t
8272 n;
cristy3ed852e2009-09-05 21:47:34 +00008273
cristybb503372010-05-27 20:51:26 +00008274 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008275 i;
8276
cristy3ed852e2009-09-05 21:47:34 +00008277 assert(image_info != (ImageInfo *) NULL);
8278 assert(image_info->signature == MagickSignature);
8279 if (images == (Image **) NULL)
8280 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008281 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008282 assert((*images)->signature == MagickSignature);
8283 if ((*images)->debug != MagickFalse)
8284 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8285 (*images)->filename);
8286 if ((argc <= 0) || (*argv == (char *) NULL))
8287 return(MagickTrue);
8288 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8289 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008290 status=0;
anthonye9c27192011-03-27 08:07:06 +00008291
anthonyce2716b2011-04-22 09:51:34 +00008292#if 0
8293fprintf(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,post?"post":"pre");
8294#endif
8295
anthonye9c27192011-03-27 08:07:06 +00008296 /*
8297 Pre-process multi-image sequence operators
8298 */
cristy3ed852e2009-09-05 21:47:34 +00008299 if (post == MagickFalse)
8300 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008301
8302 /*
8303 For each image, process simple single image operators
8304 */
8305 i=0;
8306 n=GetImageListLength(*images);
8307 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008308 {
anthonyce2716b2011-04-22 09:51:34 +00008309#if 0
8310fprintf(stderr, "mogrify %ld of %ld\n",
8311 (long)GetImageIndexInList(*images),(long)GetImageListLength(*images));
8312#endif
anthonye9c27192011-03-27 08:07:06 +00008313 status&=MogrifyImage(image_info,argc,argv,images,exception);
8314 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008315 if (proceed == MagickFalse)
8316 break;
anthonye9c27192011-03-27 08:07:06 +00008317 if ( (*images)->next == (Image *) NULL )
8318 break;
8319 *images=(*images)->next;
8320 i++;
cristy3ed852e2009-09-05 21:47:34 +00008321 }
anthonye9c27192011-03-27 08:07:06 +00008322 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008323#if 0
8324fprintf(stderr, "mogrify end %ld of %ld\n",
8325 (long)GetImageIndexInList(*images),(long)GetImageListLength(*images));
8326#endif
anthonye9c27192011-03-27 08:07:06 +00008327
8328 /*
8329 Post-process, multi-image sequence operators
8330 */
8331 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008332 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008333 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008334 return(status != 0 ? MagickTrue : MagickFalse);
8335}