blob: 646f2accdcd4469cb34abd2d5bd6d1e814f4586c [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
47#include "wand/studio.h"
48#include "wand/MagickWand.h"
49#include "wand/mogrify-private.h"
cristy0e9f9c12010-02-11 03:00:47 +000050#include "magick/monitor-private.h"
cristy3980b0d2009-10-25 14:37:13 +000051#include "magick/thread-private.h"
cristyf2f27272009-12-17 14:48:46 +000052#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define UndefinedCompressionQuality 0UL
58
59/*
60 Constant declaration.
61*/
62static const char
cristy7138c592009-09-08 13:58:52 +000063 BackgroundColor[] = "#fff", /* white */
64 BorderColor[] = "#dfdfdf", /* gray */
65 MatteColor[] = "#bdbdbd"; /* gray */
cristy3ed852e2009-09-05 21:47:34 +000066
67/*
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
cristy5063d812010-10-19 16:28:10 +000072% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000073% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78% MagickCommandGenesis() applies image processing options to an image as
79% prescribed by command line options.
80%
81% The format of the MagickCommandGenesis method is:
82%
83% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000084% MagickCommand command,int argc,char **argv,char **metadata,
85% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000086%
87% A description of each parameter follows:
88%
89% o image_info: the image info.
90%
cristy5063d812010-10-19 16:28:10 +000091% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
92% MogrifyImageCommand, CompositeImageCommand, CompareImageCommand,
93% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
94% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000095%
96% o argc: Specifies a pointer to an integer describing the number of
97% elements in the argument vector.
98%
99% o argv: Specifies a pointer to a text array containing the command line
100% arguments.
101%
cristy5063d812010-10-19 16:28:10 +0000102% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000103%
104% o exception: return any errors or warnings in this structure.
105%
106*/
107WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
108 MagickCommand command,int argc,char **argv,char **metadata,
109 ExceptionInfo *exception)
110{
111 char
112 *option;
113
114 double
115 duration,
116 elapsed_time,
117 user_time;
118
cristy3980b0d2009-10-25 14:37:13 +0000119 MagickBooleanType
120 concurrent,
121 regard_warnings,
122 status;
123
cristybb503372010-05-27 20:51:26 +0000124 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000125 i;
126
127 TimerInfo
128 *timer;
129
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristy3980b0d2009-10-25 14:37:13 +0000131 iterations;
132
cristyd0a94fa2010-03-12 14:18:11 +0000133 (void) setlocale(LC_ALL,"");
134 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000135 concurrent=MagickFalse;
136 duration=(-1.0);
137 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000138 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000139 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000140 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000141 {
142 option=argv[i];
143 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
144 continue;
145 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000146 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000147 if (LocaleCompare("concurrent",option+1) == 0)
148 concurrent=MagickTrue;
149 if (LocaleCompare("debug",option+1) == 0)
150 (void) SetLogEventMask(argv[++i]);
151 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000152 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000153 if (LocaleCompare("regard-warnings",option+1) == 0)
154 regard_warnings=MagickTrue;
155 }
156 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000157 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000158 {
cristybb503372010-05-27 20:51:26 +0000159 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000160 {
cristy33557d72009-11-06 00:54:33 +0000161 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000162 continue;
163 if (duration > 0)
164 {
165 if (GetElapsedTime(timer) > duration)
166 continue;
167 (void) ContinueTimer(timer);
168 }
169 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000170 if (exception->severity != UndefinedException)
171 {
172 if ((exception->severity > ErrorException) ||
173 (regard_warnings != MagickFalse))
174 status=MagickTrue;
175 CatchException(exception);
176 }
cristy3d1a5512009-10-25 21:23:27 +0000177 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000178 {
179 (void) fputs(*metadata,stdout);
180 (void) fputc('\n',stdout);
181 *metadata=DestroyString(*metadata);
182 }
183 }
184 }
cristyceae09d2009-10-28 17:18:47 +0000185 else
186 {
187 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000188#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000189 # pragma omp parallel for shared(status)
190#endif
cristybb503372010-05-27 20:51:26 +0000191 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000192 {
cristy33557d72009-11-06 00:54:33 +0000193 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000194 continue;
195 if (duration > 0)
196 {
197 if (GetElapsedTime(timer) > duration)
198 continue;
199 (void) ContinueTimer(timer);
200 }
201 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000202#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000203 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000204#endif
205 {
206 if (exception->severity != UndefinedException)
207 {
208 if ((exception->severity > ErrorException) ||
209 (regard_warnings != MagickFalse))
210 status=MagickTrue;
211 CatchException(exception);
212 }
213 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
214 {
215 (void) fputs(*metadata,stdout);
216 (void) fputc('\n',stdout);
217 *metadata=DestroyString(*metadata);
218 }
219 }
220 }
221 }
cristy3980b0d2009-10-25 14:37:13 +0000222 if (iterations > 1)
223 {
224 elapsed_time=GetElapsedTime(timer);
225 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000226 (void) fprintf(stderr,
cristye8c25f92010-06-03 00:53:06 +0000227 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
228 iterations,1.0*iterations/elapsed_time,user_time,(double)
229 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
230 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000231 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000232 }
233 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000234 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000235}
236
237/*
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239% %
240% %
241% %
cristy3ed852e2009-09-05 21:47:34 +0000242+ M o g r i f y I m a g e %
243% %
244% %
245% %
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247%
anthonye9c27192011-03-27 08:07:06 +0000248% MogrifyImage() applies simple single image processing options to a single
249% image. That image however may be part of a longer list of images.
250%
251% The image in the list may be modified in three different ways...
252%
253% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
254% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
255% * replace by a list of images (only the -separate option!)
256%
257% In each case the result is returned into the list, and a pointer to the
258% modified image (last image added if replaced by a list of images) is
259% returned.
260%
261% ASIDE: The -crop is present but restricted to non-tile single image crops
262%
263% This means if all the images are being processed (such as by
264% MogrifyImages(), next image to be processed will be as per the pointer
265% (*image)->next. Also the image list may grow as a result of some specific
266% operations but as images are never merged or deleted, it will never shrink
267% in length. Typically the list will remain the same length.
268%
269% WARNING: As the image pointed to may be replaced, the first image in the
270% list may also change. GetFirstImageInList() should be used by caller if
271% they wish return the Image pointer to the first image in list.
272%
cristy3ed852e2009-09-05 21:47:34 +0000273%
274% The format of the MogrifyImage method is:
275%
276% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
277% const char **argv,Image **image)
278%
279% A description of each parameter follows:
280%
281% o image_info: the image info..
282%
283% o argc: Specifies a pointer to an integer describing the number of
284% elements in the argument vector.
285%
286% o argv: Specifies a pointer to a text array containing the command line
287% arguments.
288%
289% o image: the image.
290%
291% o exception: return any errors or warnings in this structure.
292%
293*/
294
anthonye9c27192011-03-27 08:07:06 +0000295/*
296** GetImageCache() will read an image into a image cache if not already
297** present then return the image that is in the cache under that filename.
298*/
cristy3ed852e2009-09-05 21:47:34 +0000299static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
300 ExceptionInfo *exception)
301{
302 char
303 key[MaxTextExtent];
304
305 ExceptionInfo
306 *sans_exception;
307
308 Image
309 *image;
310
311 ImageInfo
312 *read_info;
313
314 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
315 sans_exception=AcquireExceptionInfo();
316 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
317 sans_exception=DestroyExceptionInfo(sans_exception);
318 if (image != (Image *) NULL)
319 return(image);
320 read_info=CloneImageInfo(image_info);
321 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
322 image=ReadImage(read_info,exception);
323 read_info=DestroyImageInfo(read_info);
324 if (image != (Image *) NULL)
325 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
326 return(image);
327}
328
cristy3ed852e2009-09-05 21:47:34 +0000329static MagickBooleanType IsPathWritable(const char *path)
330{
331 if (IsPathAccessible(path) == MagickFalse)
332 return(MagickFalse);
333 if (access(path,W_OK) != 0)
334 return(MagickFalse);
335 return(MagickTrue);
336}
337
cristybb503372010-05-27 20:51:26 +0000338static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000339{
340 if (x > y)
341 return(x);
342 return(y);
343}
344
345static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000346 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000347 void *wand_unused(client_data))
348{
349 char
350 message[MaxTextExtent],
351 tag[MaxTextExtent];
352
353 const char
354 *locale_message;
355
356 register char
357 *p;
358
cristyb32b90a2009-09-07 21:45:48 +0000359 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000360 return(MagickTrue);
361 (void) CopyMagickMemory(tag,text,MaxTextExtent);
362 p=strrchr(tag,'/');
363 if (p != (char *) NULL)
364 *p='\0';
365 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
366 locale_message=GetLocaleMessage(message);
367 if (locale_message == message)
368 locale_message=tag;
369 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000370 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
cristyf2faecf2010-05-28 19:19:36 +0000371 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000372 else
cristyb32b90a2009-09-07 21:45:48 +0000373 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
cristyf2faecf2010-05-28 19:19:36 +0000374 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
cristyb32b90a2009-09-07 21:45:48 +0000375 (100L*offset/(extent-1)));
376 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000377 (void) fprintf(stderr,"\n");
378 (void) fflush(stderr);
379 return(MagickTrue);
380}
381
anthonye9c27192011-03-27 08:07:06 +0000382/*
383** SparseColorOption() parse the complex -sparse-color argument into an
384** an array of floating point values than call SparseColorImage().
385** Argument is a complex mix of floating-point pixel coodinates, and color
386** specifications (or direct floating point numbers). The number of floats
387** needed to represent a color varies depending on teh current channel
388** setting.
389*/
cristy3ed852e2009-09-05 21:47:34 +0000390static Image *SparseColorOption(const Image *image,const ChannelType channel,
391 const SparseColorMethod method,const char *arguments,
392 const MagickBooleanType color_from_image,ExceptionInfo *exception)
393{
394 ChannelType
395 channels;
396
397 char
398 token[MaxTextExtent];
399
400 const char
401 *p;
402
403 double
404 *sparse_arguments;
405
cristybb503372010-05-27 20:51:26 +0000406 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000407 x;
408
cristybb503372010-05-27 20:51:26 +0000409 size_t
cristy3ed852e2009-09-05 21:47:34 +0000410 number_arguments;
411
cristybb503372010-05-27 20:51:26 +0000412 size_t
cristy3ed852e2009-09-05 21:47:34 +0000413 number_colors;
414
415 Image
416 *sparse_image;
417
418 MagickPixelPacket
419 color;
420
421 MagickBooleanType
422 error;
423
424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
433 channels=channel;
434 if (image->colorspace != CMYKColorspace)
435 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
436 if (image->matte == MagickFalse)
437 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
438 number_colors=0;
439 if ((channels & RedChannel) != 0)
440 number_colors++;
441 if ((channels & GreenChannel) != 0)
442 number_colors++;
443 if ((channels & BlueChannel) != 0)
444 number_colors++;
445 if ((channels & IndexChannel) != 0)
446 number_colors++;
447 if ((channels & OpacityChannel) != 0)
448 number_colors++;
anthony1e4df872011-03-19 14:10:59 +0000449
cristy3ed852e2009-09-05 21:47:34 +0000450 /*
451 Read string, to determine number of arguments needed,
452 */
453 p=arguments;
454 x=0;
455 while( *p != '\0' )
456 {
457 GetMagickToken(p,&p,token);
458 if ( token[0] == ',' ) continue;
459 if ( isalpha((int) token[0]) || token[0] == '#' ) {
460 if ( color_from_image ) {
461 (void) ThrowMagickException(exception,GetMagickModule(),
462 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
463 "Color arg given, when colors are coming from image");
464 return( (Image *)NULL);
465 }
466 x += number_colors; /* color argument */
467 }
468 else {
469 x++; /* floating point argument */
470 }
471 }
472 error=MagickTrue;
473 if ( color_from_image ) {
474 /* just the control points are being given */
475 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
476 number_arguments=(x/2)*(2+number_colors);
477 }
478 else {
479 /* control points and color values */
480 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
481 number_arguments=x;
482 }
483 if ( error ) {
484 (void) ThrowMagickException(exception,GetMagickModule(),
485 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
486 "Invalid number of Arguments");
487 return( (Image *)NULL);
488 }
489
490 /* Allocate and fill in the floating point arguments */
491 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
492 sizeof(*sparse_arguments));
493 if (sparse_arguments == (double *) NULL) {
494 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
495 "MemoryAllocationFailed","%s","SparseColorOption");
496 return( (Image *)NULL);
497 }
498 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
499 sizeof(*sparse_arguments));
500 p=arguments;
501 x=0;
502 while( *p != '\0' && x < number_arguments ) {
503 /* X coordinate */
504 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
505 if ( token[0] == '\0' ) break;
506 if ( isalpha((int) token[0]) || token[0] == '#' ) {
507 (void) ThrowMagickException(exception,GetMagickModule(),
508 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
509 "Color found, instead of X-coord");
510 error = MagickTrue;
511 break;
512 }
cristyf2f27272009-12-17 14:48:46 +0000513 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000514 /* Y coordinate */
515 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
516 if ( token[0] == '\0' ) break;
517 if ( isalpha((int) token[0]) || token[0] == '#' ) {
518 (void) ThrowMagickException(exception,GetMagickModule(),
519 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
520 "Color found, instead of Y-coord");
521 error = MagickTrue;
522 break;
523 }
cristyf2f27272009-12-17 14:48:46 +0000524 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000525 /* color values for this control point */
526#if 0
527 if ( (color_from_image ) {
528 /* get color from image */
529 /* HOW??? */
530 }
531 else
532#endif
533 {
534 /* color name or function given in string argument */
535 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
536 if ( token[0] == '\0' ) break;
537 if ( isalpha((int) token[0]) || token[0] == '#' ) {
538 /* Color string given */
539 (void) QueryMagickColor(token,&color,exception);
540 if ( channels & RedChannel )
541 sparse_arguments[x++] = QuantumScale*color.red;
542 if ( channels & GreenChannel )
543 sparse_arguments[x++] = QuantumScale*color.green;
544 if ( channels & BlueChannel )
545 sparse_arguments[x++] = QuantumScale*color.blue;
546 if ( channels & IndexChannel )
547 sparse_arguments[x++] = QuantumScale*color.index;
548 if ( channels & OpacityChannel )
549 sparse_arguments[x++] = QuantumScale*color.opacity;
550 }
551 else {
cristy3ed852e2009-09-05 21:47:34 +0000552 /* Colors given as a set of floating point values - experimental */
553 /* NB: token contains the first floating point value to use! */
554 if ( channels & RedChannel ) {
555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristy0f19e682009-12-17 14:55:51 +0000558 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000559 token[0] = ','; /* used this token - get another */
560 }
561 if ( channels & GreenChannel ) {
562 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
563 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
564 break;
cristy0f19e682009-12-17 14:55:51 +0000565 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000566 token[0] = ','; /* used this token - get another */
567 }
568 if ( channels & BlueChannel ) {
569 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
570 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
571 break;
cristy0f19e682009-12-17 14:55:51 +0000572 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000573 token[0] = ','; /* used this token - get another */
574 }
575 if ( channels & IndexChannel ) {
576 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
577 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
578 break;
cristy0f19e682009-12-17 14:55:51 +0000579 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000580 token[0] = ','; /* used this token - get another */
581 }
582 if ( channels & OpacityChannel ) {
583 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
584 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
585 break;
cristy0f19e682009-12-17 14:55:51 +0000586 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000587 token[0] = ','; /* used this token - get another */
588 }
cristy3ed852e2009-09-05 21:47:34 +0000589 }
590 }
591 }
592 if ( number_arguments != x && !error ) {
593 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
594 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
595 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
596 return( (Image *)NULL);
597 }
598 if ( error )
599 return( (Image *)NULL);
600
601 /* Call the Interpolation function with the parsed arguments */
602 sparse_image=SparseColorImage(image,channels,method,number_arguments,
603 sparse_arguments,exception);
604 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
605 return( sparse_image );
606}
607
608WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
609 const char **argv,Image **image,ExceptionInfo *exception)
610{
611 ChannelType
612 channel;
613
614 const char
615 *format,
616 *option;
617
618 DrawInfo
619 *draw_info;
620
621 GeometryInfo
622 geometry_info;
623
624 Image
625 *region_image;
626
cristy6b3da3a2010-06-20 02:21:46 +0000627 ImageInfo
628 *mogrify_info;
629
cristyebbcfea2011-02-25 02:43:54 +0000630 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000631 status;
632
633 MagickPixelPacket
634 fill;
635
636 MagickStatusType
637 flags;
638
639 QuantizeInfo
640 *quantize_info;
641
642 RectangleInfo
643 geometry,
644 region_geometry;
645
cristybb503372010-05-27 20:51:26 +0000646 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000647 i;
648
649 /*
650 Initialize method variables.
651 */
652 assert(image_info != (const ImageInfo *) NULL);
653 assert(image_info->signature == MagickSignature);
654 assert(image != (Image **) NULL);
655 assert((*image)->signature == MagickSignature);
656 if ((*image)->debug != MagickFalse)
657 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
658 if (argc < 0)
659 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000660 mogrify_info=CloneImageInfo(image_info);
661 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
662 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +0000663 SetGeometryInfo(&geometry_info);
664 GetMagickPixelPacket(*image,&fill);
665 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
666 &fill);
cristy6b3da3a2010-06-20 02:21:46 +0000667 channel=mogrify_info->channel;
668 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000669 SetGeometry(*image,&region_geometry);
670 region_image=NewImageList();
671 /*
672 Transmogrify the image.
673 */
cristybb503372010-05-27 20:51:26 +0000674 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000675 {
anthonye9c27192011-03-27 08:07:06 +0000676 Image
cristyd241f442011-03-29 13:50:49 +0000677 *mogrify_image;
anthonye9c27192011-03-27 08:07:06 +0000678
679 ssize_t
680 count;
681
cristy3ed852e2009-09-05 21:47:34 +0000682 option=argv[i];
683 if (IsMagickOption(option) == MagickFalse)
684 continue;
685 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
686 0L);
cristycee97112010-05-28 00:44:52 +0000687 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000688 break;
cristy6b3da3a2010-06-20 02:21:46 +0000689 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristyd241f442011-03-29 13:50:49 +0000690 mogrify_image=(Image *)NULL;
cristy3ed852e2009-09-05 21:47:34 +0000691 switch (*(option+1))
692 {
693 case 'a':
694 {
695 if (LocaleCompare("adaptive-blur",option+1) == 0)
696 {
cristy3ed852e2009-09-05 21:47:34 +0000697 /*
698 Adaptive blur image.
699 */
cristy6b3da3a2010-06-20 02:21:46 +0000700 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000701 flags=ParseGeometry(argv[i+1],&geometry_info);
702 if ((flags & SigmaValue) == 0)
703 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000704 mogrify_image=AdaptiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +0000705 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000706 break;
707 }
708 if (LocaleCompare("adaptive-resize",option+1) == 0)
709 {
cristy3ed852e2009-09-05 21:47:34 +0000710 /*
711 Adaptive resize image.
712 */
cristy6b3da3a2010-06-20 02:21:46 +0000713 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000714 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +0000715 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +0000716 geometry.height,exception);
cristy3ed852e2009-09-05 21:47:34 +0000717 break;
718 }
719 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
720 {
cristy3ed852e2009-09-05 21:47:34 +0000721 /*
722 Adaptive sharpen image.
723 */
cristy6b3da3a2010-06-20 02:21:46 +0000724 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000725 flags=ParseGeometry(argv[i+1],&geometry_info);
726 if ((flags & SigmaValue) == 0)
727 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000728 mogrify_image=AdaptiveSharpenImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +0000729 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000730 break;
731 }
732 if (LocaleCompare("affine",option+1) == 0)
733 {
734 /*
735 Affine matrix.
736 */
737 if (*option == '+')
738 {
739 GetAffineMatrix(&draw_info->affine);
740 break;
741 }
742 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
743 break;
744 }
745 if (LocaleCompare("alpha",option+1) == 0)
746 {
747 AlphaChannelType
748 alpha_type;
749
cristy6b3da3a2010-06-20 02:21:46 +0000750 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000751 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
752 MagickFalse,argv[i+1]);
753 (void) SetImageAlphaChannel(*image,alpha_type);
754 InheritException(exception,&(*image)->exception);
755 break;
756 }
757 if (LocaleCompare("annotate",option+1) == 0)
758 {
759 char
760 *text,
761 geometry[MaxTextExtent];
762
763 /*
764 Annotate image.
765 */
cristy6b3da3a2010-06-20 02:21:46 +0000766 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000767 SetGeometryInfo(&geometry_info);
768 flags=ParseGeometry(argv[i+1],&geometry_info);
769 if ((flags & SigmaValue) == 0)
770 geometry_info.sigma=geometry_info.rho;
cristy6b3da3a2010-06-20 02:21:46 +0000771 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +0000772 InheritException(exception,&(*image)->exception);
773 if (text == (char *) NULL)
774 break;
775 (void) CloneString(&draw_info->text,text);
776 text=DestroyString(text);
777 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
778 geometry_info.xi,geometry_info.psi);
779 (void) CloneString(&draw_info->geometry,geometry);
780 draw_info->affine.sx=cos(DegreesToRadians(
781 fmod(geometry_info.rho,360.0)));
782 draw_info->affine.rx=sin(DegreesToRadians(
783 fmod(geometry_info.rho,360.0)));
784 draw_info->affine.ry=(-sin(DegreesToRadians(
785 fmod(geometry_info.sigma,360.0))));
786 draw_info->affine.sy=cos(DegreesToRadians(
787 fmod(geometry_info.sigma,360.0)));
788 (void) AnnotateImage(*image,draw_info);
789 InheritException(exception,&(*image)->exception);
790 break;
791 }
792 if (LocaleCompare("antialias",option+1) == 0)
793 {
794 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
795 MagickFalse;
796 draw_info->text_antialias=(*option == '-') ? MagickTrue :
797 MagickFalse;
798 break;
799 }
800 if (LocaleCompare("auto-gamma",option+1) == 0)
801 {
802 /*
803 Auto Adjust Gamma of image based on its mean
804 */
cristy6b3da3a2010-06-20 02:21:46 +0000805 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000806 (void) AutoGammaImageChannel(*image,channel);
807 break;
808 }
809 if (LocaleCompare("auto-level",option+1) == 0)
810 {
811 /*
812 Perfectly Normalize (max/min stretch) the image
813 */
cristy6b3da3a2010-06-20 02:21:46 +0000814 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000815 (void) AutoLevelImageChannel(*image,channel);
816 break;
817 }
818 if (LocaleCompare("auto-orient",option+1) == 0)
819 {
cristy6b3da3a2010-06-20 02:21:46 +0000820 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000821 switch ((*image)->orientation)
822 {
823 case TopRightOrientation:
824 {
cristyd241f442011-03-29 13:50:49 +0000825 mogrify_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000826 break;
827 }
828 case BottomRightOrientation:
829 {
cristyd241f442011-03-29 13:50:49 +0000830 mogrify_image=RotateImage(*image,180.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000831 break;
832 }
833 case BottomLeftOrientation:
834 {
cristyd241f442011-03-29 13:50:49 +0000835 mogrify_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000836 break;
837 }
838 case LeftTopOrientation:
839 {
cristyd241f442011-03-29 13:50:49 +0000840 mogrify_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000841 break;
842 }
843 case RightTopOrientation:
844 {
cristyd241f442011-03-29 13:50:49 +0000845 mogrify_image=RotateImage(*image,90.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000846 break;
847 }
848 case RightBottomOrientation:
849 {
cristyd241f442011-03-29 13:50:49 +0000850 mogrify_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000851 break;
852 }
853 case LeftBottomOrientation:
854 {
cristyd241f442011-03-29 13:50:49 +0000855 mogrify_image=RotateImage(*image,270.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000856 break;
857 }
858 default:
859 break;
860 }
cristyd241f442011-03-29 13:50:49 +0000861 if (mogrify_image != (Image *) NULL)
862 mogrify_image->orientation=TopLeftOrientation;
cristy3ed852e2009-09-05 21:47:34 +0000863 break;
864 }
865 break;
866 }
867 case 'b':
868 {
869 if (LocaleCompare("black-threshold",option+1) == 0)
870 {
871 /*
872 Black threshold image.
873 */
cristy6b3da3a2010-06-20 02:21:46 +0000874 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000875 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
876 exception);
877 InheritException(exception,&(*image)->exception);
878 break;
879 }
880 if (LocaleCompare("blue-shift",option+1) == 0)
881 {
cristy3ed852e2009-09-05 21:47:34 +0000882 /*
883 Blue shift image.
884 */
cristy6b3da3a2010-06-20 02:21:46 +0000885 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000886 geometry_info.rho=1.5;
887 if (*option == '-')
888 flags=ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +0000889 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +0000890 break;
891 }
892 if (LocaleCompare("blur",option+1) == 0)
893 {
cristy3ed852e2009-09-05 21:47:34 +0000894 /*
895 Gaussian blur image.
896 */
cristy6b3da3a2010-06-20 02:21:46 +0000897 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000898 flags=ParseGeometry(argv[i+1],&geometry_info);
899 if ((flags & SigmaValue) == 0)
900 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000901 mogrify_image=BlurImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +0000902 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000903 break;
904 }
905 if (LocaleCompare("border",option+1) == 0)
906 {
cristy3ed852e2009-09-05 21:47:34 +0000907 /*
908 Surround image with a border of solid color.
909 */
cristy6b3da3a2010-06-20 02:21:46 +0000910 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000911 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
912 if ((flags & SigmaValue) == 0)
913 geometry.height=geometry.width;
cristyd241f442011-03-29 13:50:49 +0000914 mogrify_image=BorderImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +0000915 break;
916 }
917 if (LocaleCompare("bordercolor",option+1) == 0)
918 {
919 if (*option == '+')
920 {
921 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
922 exception);
923 break;
924 }
925 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
926 exception);
927 break;
928 }
929 if (LocaleCompare("box",option+1) == 0)
930 {
931 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
932 exception);
933 break;
934 }
cristya28d6b82010-01-11 20:03:47 +0000935 if (LocaleCompare("brightness-contrast",option+1) == 0)
936 {
937 double
938 brightness,
939 contrast;
940
941 GeometryInfo
942 geometry_info;
943
944 MagickStatusType
945 flags;
946
947 /*
948 Brightness / contrast image.
949 */
cristy6b3da3a2010-06-20 02:21:46 +0000950 (void) SyncImageSettings(mogrify_info,*image);
cristya28d6b82010-01-11 20:03:47 +0000951 flags=ParseGeometry(argv[i+1],&geometry_info);
952 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000953 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000954 if ((flags & SigmaValue) != 0)
955 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000956 (void) BrightnessContrastImageChannel(*image,channel,brightness,
957 contrast);
cristya28d6b82010-01-11 20:03:47 +0000958 InheritException(exception,&(*image)->exception);
959 break;
960 }
cristy3ed852e2009-09-05 21:47:34 +0000961 break;
962 }
963 case 'c':
964 {
965 if (LocaleCompare("cdl",option+1) == 0)
966 {
967 char
968 *color_correction_collection;
969
970 /*
971 Color correct with a color decision list.
972 */
cristy6b3da3a2010-06-20 02:21:46 +0000973 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000974 color_correction_collection=FileToString(argv[i+1],~0,exception);
975 if (color_correction_collection == (char *) NULL)
976 break;
977 (void) ColorDecisionListImage(*image,color_correction_collection);
978 InheritException(exception,&(*image)->exception);
979 break;
980 }
981 if (LocaleCompare("channel",option+1) == 0)
982 {
983 if (*option == '+')
cristy3ed852e2009-09-05 21:47:34 +0000984 channel=DefaultChannels;
anthonye9c27192011-03-27 08:07:06 +0000985 else
986 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +0000987 break;
988 }
989 if (LocaleCompare("charcoal",option+1) == 0)
990 {
cristy3ed852e2009-09-05 21:47:34 +0000991 /*
992 Charcoal image.
993 */
cristy6b3da3a2010-06-20 02:21:46 +0000994 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +0000995 flags=ParseGeometry(argv[i+1],&geometry_info);
996 if ((flags & SigmaValue) == 0)
997 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +0000998 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +0000999 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001000 break;
1001 }
1002 if (LocaleCompare("chop",option+1) == 0)
1003 {
cristy3ed852e2009-09-05 21:47:34 +00001004 /*
1005 Chop the image.
1006 */
cristy6b3da3a2010-06-20 02:21:46 +00001007 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001008 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00001009 mogrify_image=ChopImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00001010 break;
1011 }
cristy1eb45dd2009-09-25 16:38:06 +00001012 if (LocaleCompare("clamp",option+1) == 0)
1013 {
1014 /*
1015 Clamp image.
1016 */
cristy6b3da3a2010-06-20 02:21:46 +00001017 (void) SyncImageSettings(mogrify_info,*image);
cristy1eb45dd2009-09-25 16:38:06 +00001018 (void) ClampImageChannel(*image,channel);
1019 InheritException(exception,&(*image)->exception);
1020 break;
1021 }
cristy3ed852e2009-09-05 21:47:34 +00001022 if (LocaleCompare("clip",option+1) == 0)
1023 {
cristy6b3da3a2010-06-20 02:21:46 +00001024 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001025 if (*option == '+')
1026 {
1027 (void) SetImageClipMask(*image,(Image *) NULL);
1028 InheritException(exception,&(*image)->exception);
1029 break;
1030 }
1031 (void) ClipImage(*image);
1032 InheritException(exception,&(*image)->exception);
1033 break;
1034 }
1035 if (LocaleCompare("clip-mask",option+1) == 0)
1036 {
cristyb0d3bb92010-09-22 14:37:58 +00001037 CacheView
1038 *mask_view;
cristya01cbea2010-11-03 16:33:33 +00001039
cristy3ed852e2009-09-05 21:47:34 +00001040 Image
cristyb0d3bb92010-09-22 14:37:58 +00001041 *mask_image;
cristy3ed852e2009-09-05 21:47:34 +00001042
cristy9d314ff2011-03-09 01:30:28 +00001043 register PixelPacket
1044 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001045
cristybb503372010-05-27 20:51:26 +00001046 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001047 x;
1048
cristy9d314ff2011-03-09 01:30:28 +00001049 ssize_t
1050 y;
cristy3ed852e2009-09-05 21:47:34 +00001051
cristy6b3da3a2010-06-20 02:21:46 +00001052 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001053 if (*option == '+')
1054 {
1055 /*
1056 Remove a mask.
1057 */
1058 (void) SetImageMask(*image,(Image *) NULL);
1059 InheritException(exception,&(*image)->exception);
1060 break;
1061 }
1062 /*
1063 Set the image mask.
1064 */
cristyb0d3bb92010-09-22 14:37:58 +00001065 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1066 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001067 break;
cristyb0d3bb92010-09-22 14:37:58 +00001068 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1069 return(MagickFalse);
1070 mask_view=AcquireCacheView(mask_image);
1071 for (y=0; y < (ssize_t) mask_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001072 {
cristyb0d3bb92010-09-22 14:37:58 +00001073 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1074 exception);
cristy3ed852e2009-09-05 21:47:34 +00001075 if (q == (PixelPacket *) NULL)
1076 break;
cristyb0d3bb92010-09-22 14:37:58 +00001077 for (x=0; x < (ssize_t) mask_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001078 {
cristyb0d3bb92010-09-22 14:37:58 +00001079 if (mask_image->matte == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001080 q->opacity=PixelIntensityToQuantum(q);
1081 q->red=q->opacity;
1082 q->green=q->opacity;
1083 q->blue=q->opacity;
1084 q++;
1085 }
cristyb0d3bb92010-09-22 14:37:58 +00001086 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001087 break;
1088 }
cristyb0d3bb92010-09-22 14:37:58 +00001089 mask_view=DestroyCacheView(mask_view);
1090 mask_image->matte=MagickTrue;
1091 (void) SetImageClipMask(*image,mask_image);
1092 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001093 InheritException(exception,&(*image)->exception);
1094 break;
1095 }
1096 if (LocaleCompare("clip-path",option+1) == 0)
1097 {
cristy6b3da3a2010-06-20 02:21:46 +00001098 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001099 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1100 MagickFalse);
1101 InheritException(exception,&(*image)->exception);
1102 break;
1103 }
1104 if (LocaleCompare("colorize",option+1) == 0)
1105 {
cristy3ed852e2009-09-05 21:47:34 +00001106 /*
1107 Colorize the image.
1108 */
cristy6b3da3a2010-06-20 02:21:46 +00001109 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001110 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
cristy3ed852e2009-09-05 21:47:34 +00001111 exception);
cristy3ed852e2009-09-05 21:47:34 +00001112 break;
1113 }
cristye6365592010-04-02 17:31:23 +00001114 if (LocaleCompare("color-matrix",option+1) == 0)
1115 {
cristye6365592010-04-02 17:31:23 +00001116 KernelInfo
1117 *kernel;
1118
cristy6b3da3a2010-06-20 02:21:46 +00001119 (void) SyncImageSettings(mogrify_info,*image);
cristye6365592010-04-02 17:31:23 +00001120 kernel=AcquireKernelInfo(argv[i+1]);
1121 if (kernel == (KernelInfo *) NULL)
1122 break;
cristyd241f442011-03-29 13:50:49 +00001123 mogrify_image=ColorMatrixImage(*image,kernel,exception);
cristye6365592010-04-02 17:31:23 +00001124 kernel=DestroyKernelInfo(kernel);
cristye6365592010-04-02 17:31:23 +00001125 break;
1126 }
cristy3ed852e2009-09-05 21:47:34 +00001127 if (LocaleCompare("colors",option+1) == 0)
1128 {
1129 /*
1130 Reduce the number of colors in the image.
1131 */
cristy6b3da3a2010-06-20 02:21:46 +00001132 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00001133 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001134 if (quantize_info->number_colors == 0)
1135 break;
1136 if (((*image)->storage_class == DirectClass) ||
1137 (*image)->colors > quantize_info->number_colors)
1138 (void) QuantizeImage(quantize_info,*image);
1139 else
1140 (void) CompressImageColormap(*image);
1141 InheritException(exception,&(*image)->exception);
1142 break;
1143 }
1144 if (LocaleCompare("colorspace",option+1) == 0)
1145 {
1146 ColorspaceType
1147 colorspace;
1148
cristy6b3da3a2010-06-20 02:21:46 +00001149 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001150 if (*option == '+')
1151 {
1152 (void) TransformImageColorspace(*image,RGBColorspace);
1153 InheritException(exception,&(*image)->exception);
1154 break;
1155 }
1156 colorspace=(ColorspaceType) ParseMagickOption(
1157 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1158 (void) TransformImageColorspace(*image,colorspace);
1159 InheritException(exception,&(*image)->exception);
1160 break;
1161 }
1162 if (LocaleCompare("contrast",option+1) == 0)
1163 {
cristy6b3da3a2010-06-20 02:21:46 +00001164 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001165 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1166 MagickFalse);
1167 InheritException(exception,&(*image)->exception);
1168 break;
1169 }
1170 if (LocaleCompare("contrast-stretch",option+1) == 0)
1171 {
1172 double
1173 black_point,
1174 white_point;
1175
cristy3ed852e2009-09-05 21:47:34 +00001176 MagickStatusType
1177 flags;
1178
1179 /*
1180 Contrast stretch image.
1181 */
cristy6b3da3a2010-06-20 02:21:46 +00001182 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001183 flags=ParseGeometry(argv[i+1],&geometry_info);
1184 black_point=geometry_info.rho;
1185 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1186 black_point;
1187 if ((flags & PercentValue) != 0)
1188 {
1189 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1190 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1191 }
1192 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1193 white_point;
1194 (void) ContrastStretchImageChannel(*image,channel,black_point,
1195 white_point);
1196 InheritException(exception,&(*image)->exception);
1197 break;
1198 }
1199 if (LocaleCompare("convolve",option+1) == 0)
1200 {
cristy36826ab2010-03-06 01:29:30 +00001201 double
1202 gamma;
1203
cristy2be15382010-01-21 02:38:03 +00001204 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001205 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001206
cristybb503372010-05-27 20:51:26 +00001207 register ssize_t
cristy36826ab2010-03-06 01:29:30 +00001208 j;
1209
cristy6b3da3a2010-06-20 02:21:46 +00001210 (void) SyncImageSettings(mogrify_info,*image);
cristy2be15382010-01-21 02:38:03 +00001211 kernel=AcquireKernelInfo(argv[i+1]);
1212 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001213 break;
cristy36826ab2010-03-06 01:29:30 +00001214 gamma=0.0;
cristybb503372010-05-27 20:51:26 +00001215 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001216 gamma+=kernel->values[j];
1217 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristybb503372010-05-27 20:51:26 +00001218 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001219 kernel->values[j]*=gamma;
cristyd241f442011-03-29 13:50:49 +00001220 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001221 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001222 break;
1223 }
1224 if (LocaleCompare("crop",option+1) == 0)
1225 {
anthonye9c27192011-03-27 08:07:06 +00001226 /*
1227 Crop a image to a smaller size
anthonye9c27192011-03-27 08:07:06 +00001228 */
cristy6b3da3a2010-06-20 02:21:46 +00001229 (void) SyncImageSettings(mogrify_info,*image);
anthony9f4f0342011-03-28 11:47:22 +00001230#if 0
cristy3ed852e2009-09-05 21:47:34 +00001231 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1232 if (((geometry.width != 0) || (geometry.height != 0)) &&
1233 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1234 break;
anthony9f4f0342011-03-28 11:47:22 +00001235#endif
1236#if 0
cristyd241f442011-03-29 13:50:49 +00001237 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1238 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1239 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1240 InheritException(exception,&mogrify_image->exception);
anthony9f4f0342011-03-28 11:47:22 +00001241#else
cristyd241f442011-03-29 13:50:49 +00001242 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthony9f4f0342011-03-28 11:47:22 +00001243#endif
cristy3ed852e2009-09-05 21:47:34 +00001244 break;
1245 }
1246 if (LocaleCompare("cycle",option+1) == 0)
1247 {
1248 /*
1249 Cycle an image colormap.
1250 */
cristy6b3da3a2010-06-20 02:21:46 +00001251 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001252 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001253 InheritException(exception,&(*image)->exception);
1254 break;
1255 }
1256 break;
1257 }
1258 case 'd':
1259 {
1260 if (LocaleCompare("decipher",option+1) == 0)
1261 {
1262 StringInfo
1263 *passkey;
1264
1265 /*
1266 Decipher pixels.
1267 */
cristy6b3da3a2010-06-20 02:21:46 +00001268 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001269 passkey=FileToStringInfo(argv[i+1],~0,exception);
1270 if (passkey != (StringInfo *) NULL)
1271 {
1272 (void) PasskeyDecipherImage(*image,passkey,exception);
1273 passkey=DestroyStringInfo(passkey);
1274 }
1275 break;
1276 }
1277 if (LocaleCompare("density",option+1) == 0)
1278 {
1279 /*
1280 Set image density.
1281 */
1282 (void) CloneString(&draw_info->density,argv[i+1]);
1283 break;
1284 }
1285 if (LocaleCompare("depth",option+1) == 0)
1286 {
cristy6b3da3a2010-06-20 02:21:46 +00001287 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001288 if (*option == '+')
1289 {
1290 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1291 break;
1292 }
cristye27293e2009-12-18 02:53:20 +00001293 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001294 break;
1295 }
1296 if (LocaleCompare("deskew",option+1) == 0)
1297 {
1298 double
1299 threshold;
1300
cristy3ed852e2009-09-05 21:47:34 +00001301 /*
1302 Straighten the image.
1303 */
cristy6b3da3a2010-06-20 02:21:46 +00001304 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001305 if (*option == '+')
1306 threshold=40.0*QuantumRange/100.0;
1307 else
cristyf2f27272009-12-17 14:48:46 +00001308 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00001309 mogrify_image=DeskewImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00001310 break;
1311 }
1312 if (LocaleCompare("despeckle",option+1) == 0)
1313 {
cristy3ed852e2009-09-05 21:47:34 +00001314 /*
1315 Reduce the speckles within an image.
1316 */
cristy6b3da3a2010-06-20 02:21:46 +00001317 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001318 mogrify_image=DespeckleImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001319 break;
1320 }
1321 if (LocaleCompare("display",option+1) == 0)
1322 {
1323 (void) CloneString(&draw_info->server_name,argv[i+1]);
1324 break;
1325 }
cristy3ed852e2009-09-05 21:47:34 +00001326 if (LocaleCompare("distort",option+1) == 0)
1327 {
1328 char
1329 *args,
1330 token[MaxTextExtent];
1331
1332 const char
1333 *p;
1334
1335 DistortImageMethod
1336 method;
1337
1338 double
1339 *arguments;
1340
cristybb503372010-05-27 20:51:26 +00001341 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001342 x;
1343
cristybb503372010-05-27 20:51:26 +00001344 size_t
cristy3ed852e2009-09-05 21:47:34 +00001345 number_arguments;
1346
1347 /*
1348 Distort image.
1349 */
cristy6b3da3a2010-06-20 02:21:46 +00001350 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001351 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1352 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001353 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001354 InheritException(exception,&(*image)->exception);
1355 if (args == (char *) NULL)
1356 break;
1357 p=(char *) args;
1358 for (x=0; *p != '\0'; x++)
1359 {
1360 GetMagickToken(p,&p,token);
1361 if (*token == ',')
1362 GetMagickToken(p,&p,token);
1363 }
cristybb503372010-05-27 20:51:26 +00001364 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001365 arguments=(double *) AcquireQuantumMemory(number_arguments,
1366 sizeof(*arguments));
1367 if (arguments == (double *) NULL)
1368 ThrowWandFatalException(ResourceLimitFatalError,
1369 "MemoryAllocationFailed",(*image)->filename);
1370 (void) ResetMagickMemory(arguments,0,number_arguments*
1371 sizeof(*arguments));
1372 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001373 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001374 {
1375 GetMagickToken(p,&p,token);
1376 if (*token == ',')
1377 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001378 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001379 }
1380 args=DestroyString(args);
cristyd241f442011-03-29 13:50:49 +00001381 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
cristy3ed852e2009-09-05 21:47:34 +00001382 (*option == '+') ? MagickTrue : MagickFalse,exception);
1383 arguments=(double *) RelinquishMagickMemory(arguments);
cristy3ed852e2009-09-05 21:47:34 +00001384 break;
1385 }
1386 if (LocaleCompare("dither",option+1) == 0)
1387 {
1388 if (*option == '+')
1389 {
1390 quantize_info->dither=MagickFalse;
1391 break;
1392 }
1393 quantize_info->dither=MagickTrue;
1394 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1395 MagickDitherOptions,MagickFalse,argv[i+1]);
1396 if (quantize_info->dither_method == NoDitherMethod)
1397 quantize_info->dither=MagickFalse;
1398 break;
1399 }
1400 if (LocaleCompare("draw",option+1) == 0)
1401 {
1402 /*
1403 Draw image.
1404 */
cristy6b3da3a2010-06-20 02:21:46 +00001405 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001406 (void) CloneString(&draw_info->primitive,argv[i+1]);
1407 (void) DrawImage(*image,draw_info);
1408 InheritException(exception,&(*image)->exception);
1409 break;
1410 }
1411 break;
1412 }
1413 case 'e':
1414 {
1415 if (LocaleCompare("edge",option+1) == 0)
1416 {
cristy3ed852e2009-09-05 21:47:34 +00001417 /*
1418 Enhance edges in the image.
1419 */
cristy6b3da3a2010-06-20 02:21:46 +00001420 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001421 flags=ParseGeometry(argv[i+1],&geometry_info);
1422 if ((flags & SigmaValue) == 0)
1423 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001424 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001425 break;
1426 }
1427 if (LocaleCompare("emboss",option+1) == 0)
1428 {
cristy3ed852e2009-09-05 21:47:34 +00001429 /*
1430 Gaussian embossen image.
1431 */
cristy6b3da3a2010-06-20 02:21:46 +00001432 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001433 flags=ParseGeometry(argv[i+1],&geometry_info);
1434 if ((flags & SigmaValue) == 0)
1435 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001436 mogrify_image=EmbossImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00001437 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001438 break;
1439 }
1440 if (LocaleCompare("encipher",option+1) == 0)
1441 {
1442 StringInfo
1443 *passkey;
1444
1445 /*
1446 Encipher pixels.
1447 */
cristy6b3da3a2010-06-20 02:21:46 +00001448 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001449 passkey=FileToStringInfo(argv[i+1],~0,exception);
1450 if (passkey != (StringInfo *) NULL)
1451 {
1452 (void) PasskeyEncipherImage(*image,passkey,exception);
1453 passkey=DestroyStringInfo(passkey);
1454 }
1455 break;
1456 }
1457 if (LocaleCompare("encoding",option+1) == 0)
1458 {
1459 (void) CloneString(&draw_info->encoding,argv[i+1]);
1460 break;
1461 }
1462 if (LocaleCompare("enhance",option+1) == 0)
1463 {
cristy3ed852e2009-09-05 21:47:34 +00001464 /*
1465 Enhance image.
1466 */
cristy6b3da3a2010-06-20 02:21:46 +00001467 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001468 mogrify_image=EnhanceImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001469 break;
1470 }
1471 if (LocaleCompare("equalize",option+1) == 0)
1472 {
1473 /*
1474 Equalize image.
1475 */
cristy6b3da3a2010-06-20 02:21:46 +00001476 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001477 (void) EqualizeImageChannel(*image,channel);
1478 InheritException(exception,&(*image)->exception);
1479 break;
1480 }
1481 if (LocaleCompare("evaluate",option+1) == 0)
1482 {
1483 double
1484 constant;
1485
1486 MagickEvaluateOperator
1487 op;
1488
cristy6b3da3a2010-06-20 02:21:46 +00001489 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001490 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1491 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001492 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001493 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1494 break;
1495 }
1496 if (LocaleCompare("extent",option+1) == 0)
1497 {
cristy3ed852e2009-09-05 21:47:34 +00001498 /*
1499 Set the image extent.
1500 */
cristy6b3da3a2010-06-20 02:21:46 +00001501 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001502 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001503 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001504 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001505 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001506 geometry.height=(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00001507 mogrify_image=ExtentImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00001508 break;
1509 }
1510 break;
1511 }
1512 case 'f':
1513 {
1514 if (LocaleCompare("family",option+1) == 0)
1515 {
1516 if (*option == '+')
1517 {
1518 if (draw_info->family != (char *) NULL)
1519 draw_info->family=DestroyString(draw_info->family);
1520 break;
1521 }
1522 (void) CloneString(&draw_info->family,argv[i+1]);
1523 break;
1524 }
cristy0fe961c2010-01-30 03:09:54 +00001525 if (LocaleCompare("features",option+1) == 0)
1526 {
1527 if (*option == '+')
1528 {
1529 (void) DeleteImageArtifact(*image,"identify:features");
1530 break;
1531 }
1532 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1533 break;
1534 }
cristy3ed852e2009-09-05 21:47:34 +00001535 if (LocaleCompare("fill",option+1) == 0)
1536 {
1537 ExceptionInfo
1538 *sans;
1539
1540 GetMagickPixelPacket(*image,&fill);
1541 if (*option == '+')
1542 {
1543 (void) QueryMagickColor("none",&fill,exception);
1544 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1545 if (draw_info->fill_pattern != (Image *) NULL)
1546 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1547 break;
1548 }
1549 sans=AcquireExceptionInfo();
1550 (void) QueryMagickColor(argv[i+1],&fill,sans);
1551 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1552 sans=DestroyExceptionInfo(sans);
1553 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001554 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001555 exception);
1556 break;
1557 }
1558 if (LocaleCompare("flip",option+1) == 0)
1559 {
cristy3ed852e2009-09-05 21:47:34 +00001560 /*
1561 Flip image scanlines.
1562 */
cristy6b3da3a2010-06-20 02:21:46 +00001563 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001564 mogrify_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001565 break;
1566 }
1567 if (LocaleCompare("flop",option+1) == 0)
1568 {
cristy3ed852e2009-09-05 21:47:34 +00001569 /*
1570 Flop image scanlines.
1571 */
cristy6b3da3a2010-06-20 02:21:46 +00001572 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00001573 mogrify_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001574 break;
1575 }
1576 if (LocaleCompare("floodfill",option+1) == 0)
1577 {
1578 MagickPixelPacket
1579 target;
1580
1581 /*
1582 Floodfill image.
1583 */
cristy6b3da3a2010-06-20 02:21:46 +00001584 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001585 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1586 (void) QueryMagickColor(argv[i+2],&target,exception);
1587 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1588 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1589 InheritException(exception,&(*image)->exception);
1590 break;
1591 }
1592 if (LocaleCompare("font",option+1) == 0)
1593 {
1594 if (*option == '+')
1595 {
1596 if (draw_info->font != (char *) NULL)
1597 draw_info->font=DestroyString(draw_info->font);
1598 break;
1599 }
1600 (void) CloneString(&draw_info->font,argv[i+1]);
1601 break;
1602 }
1603 if (LocaleCompare("format",option+1) == 0)
1604 {
1605 format=argv[i+1];
1606 break;
1607 }
1608 if (LocaleCompare("frame",option+1) == 0)
1609 {
1610 FrameInfo
1611 frame_info;
1612
cristy3ed852e2009-09-05 21:47:34 +00001613 /*
1614 Surround image with an ornamental border.
1615 */
cristy6b3da3a2010-06-20 02:21:46 +00001616 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001617 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1618 frame_info.width=geometry.width;
1619 frame_info.height=geometry.height;
1620 if ((flags & HeightValue) == 0)
1621 frame_info.height=geometry.width;
1622 frame_info.outer_bevel=geometry.x;
1623 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001624 frame_info.x=(ssize_t) frame_info.width;
1625 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001626 frame_info.width=(*image)->columns+2*frame_info.width;
1627 frame_info.height=(*image)->rows+2*frame_info.height;
cristyd241f442011-03-29 13:50:49 +00001628 mogrify_image=FrameImage(*image,&frame_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00001629 break;
1630 }
1631 if (LocaleCompare("function",option+1) == 0)
1632 {
1633 char
1634 *arguments,
1635 token[MaxTextExtent];
1636
1637 const char
1638 *p;
1639
1640 double
1641 *parameters;
1642
1643 MagickFunction
1644 function;
1645
cristybb503372010-05-27 20:51:26 +00001646 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001647 x;
1648
cristybb503372010-05-27 20:51:26 +00001649 size_t
cristy3ed852e2009-09-05 21:47:34 +00001650 number_parameters;
1651
1652 /*
1653 Function Modify Image Values
1654 */
cristy6b3da3a2010-06-20 02:21:46 +00001655 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001656 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1657 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001658 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001659 InheritException(exception,&(*image)->exception);
1660 if (arguments == (char *) NULL)
1661 break;
1662 p=(char *) arguments;
1663 for (x=0; *p != '\0'; x++)
1664 {
1665 GetMagickToken(p,&p,token);
1666 if (*token == ',')
1667 GetMagickToken(p,&p,token);
1668 }
cristybb503372010-05-27 20:51:26 +00001669 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001670 parameters=(double *) AcquireQuantumMemory(number_parameters,
1671 sizeof(*parameters));
1672 if (parameters == (double *) NULL)
1673 ThrowWandFatalException(ResourceLimitFatalError,
1674 "MemoryAllocationFailed",(*image)->filename);
1675 (void) ResetMagickMemory(parameters,0,number_parameters*
1676 sizeof(*parameters));
1677 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001678 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001679 {
1680 GetMagickToken(p,&p,token);
1681 if (*token == ',')
1682 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001683 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001684 }
1685 arguments=DestroyString(arguments);
1686 (void) FunctionImageChannel(*image,channel,function,
1687 number_parameters,parameters,exception);
1688 parameters=(double *) RelinquishMagickMemory(parameters);
1689 break;
1690 }
1691 break;
1692 }
1693 case 'g':
1694 {
1695 if (LocaleCompare("gamma",option+1) == 0)
1696 {
1697 /*
1698 Gamma image.
1699 */
cristy6b3da3a2010-06-20 02:21:46 +00001700 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001701 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001702 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001703 else
1704 {
1705 if (strchr(argv[i+1],',') != (char *) NULL)
1706 (void) GammaImage(*image,argv[i+1]);
1707 else
cristya5447be2010-01-11 00:20:51 +00001708 (void) GammaImageChannel(*image,channel,
1709 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001710 InheritException(exception,&(*image)->exception);
1711 }
1712 break;
1713 }
1714 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1715 (LocaleCompare("gaussian",option+1) == 0))
1716 {
cristy3ed852e2009-09-05 21:47:34 +00001717 /*
1718 Gaussian blur image.
1719 */
cristy6b3da3a2010-06-20 02:21:46 +00001720 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001721 flags=ParseGeometry(argv[i+1],&geometry_info);
1722 if ((flags & SigmaValue) == 0)
1723 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00001724 mogrify_image=GaussianBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00001725 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001726 break;
1727 }
1728 if (LocaleCompare("geometry",option+1) == 0)
1729 {
anthonye9c27192011-03-27 08:07:06 +00001730 /*
1731 Record Image offset, Resize last image.
1732 */
cristy6b3da3a2010-06-20 02:21:46 +00001733 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001734 if (*option == '+')
1735 {
1736 if ((*image)->geometry != (char *) NULL)
1737 (*image)->geometry=DestroyString((*image)->geometry);
1738 break;
1739 }
1740 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1741 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1742 (void) CloneString(&(*image)->geometry,argv[i+1]);
1743 else
cristyd241f442011-03-29 13:50:49 +00001744 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
anthonye9c27192011-03-27 08:07:06 +00001745 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00001746 break;
1747 }
1748 if (LocaleCompare("gravity",option+1) == 0)
1749 {
1750 if (*option == '+')
1751 {
1752 draw_info->gravity=UndefinedGravity;
1753 break;
1754 }
1755 draw_info->gravity=(GravityType) ParseMagickOption(
1756 MagickGravityOptions,MagickFalse,argv[i+1]);
1757 break;
1758 }
1759 break;
1760 }
1761 case 'h':
1762 {
1763 if (LocaleCompare("highlight-color",option+1) == 0)
1764 {
1765 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1766 break;
1767 }
1768 break;
1769 }
1770 case 'i':
1771 {
1772 if (LocaleCompare("identify",option+1) == 0)
1773 {
1774 char
1775 *text;
1776
cristy6b3da3a2010-06-20 02:21:46 +00001777 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001778 if (format == (char *) NULL)
1779 {
cristy6b3da3a2010-06-20 02:21:46 +00001780 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001781 InheritException(exception,&(*image)->exception);
1782 break;
1783 }
cristy6b3da3a2010-06-20 02:21:46 +00001784 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001785 InheritException(exception,&(*image)->exception);
1786 if (text == (char *) NULL)
1787 break;
1788 (void) fputs(text,stdout);
1789 (void) fputc('\n',stdout);
1790 text=DestroyString(text);
1791 break;
1792 }
1793 if (LocaleCompare("implode",option+1) == 0)
1794 {
cristy3ed852e2009-09-05 21:47:34 +00001795 /*
1796 Implode image.
1797 */
cristy6b3da3a2010-06-20 02:21:46 +00001798 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001799 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00001800 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001801 break;
1802 }
cristyb32b90a2009-09-07 21:45:48 +00001803 if (LocaleCompare("interline-spacing",option+1) == 0)
1804 {
1805 if (*option == '+')
1806 (void) ParseGeometry("0",&geometry_info);
1807 else
1808 (void) ParseGeometry(argv[i+1],&geometry_info);
1809 draw_info->interline_spacing=geometry_info.rho;
1810 break;
1811 }
cristy3ed852e2009-09-05 21:47:34 +00001812 if (LocaleCompare("interword-spacing",option+1) == 0)
1813 {
1814 if (*option == '+')
1815 (void) ParseGeometry("0",&geometry_info);
1816 else
1817 (void) ParseGeometry(argv[i+1],&geometry_info);
1818 draw_info->interword_spacing=geometry_info.rho;
1819 break;
1820 }
1821 break;
1822 }
1823 case 'k':
1824 {
1825 if (LocaleCompare("kerning",option+1) == 0)
1826 {
1827 if (*option == '+')
1828 (void) ParseGeometry("0",&geometry_info);
1829 else
1830 (void) ParseGeometry(argv[i+1],&geometry_info);
1831 draw_info->kerning=geometry_info.rho;
1832 break;
1833 }
1834 break;
1835 }
1836 case 'l':
1837 {
1838 if (LocaleCompare("lat",option+1) == 0)
1839 {
cristy3ed852e2009-09-05 21:47:34 +00001840 /*
1841 Local adaptive threshold image.
1842 */
cristy6b3da3a2010-06-20 02:21:46 +00001843 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001844 flags=ParseGeometry(argv[i+1],&geometry_info);
1845 if ((flags & PercentValue) != 0)
1846 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00001847 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1848 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1849 geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001850 break;
1851 }
1852 if (LocaleCompare("level",option+1) == 0)
1853 {
cristy3ed852e2009-09-05 21:47:34 +00001854 MagickRealType
1855 black_point,
1856 gamma,
1857 white_point;
1858
1859 MagickStatusType
1860 flags;
1861
1862 /*
1863 Parse levels.
1864 */
cristy6b3da3a2010-06-20 02:21:46 +00001865 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001866 flags=ParseGeometry(argv[i+1],&geometry_info);
1867 black_point=geometry_info.rho;
1868 white_point=(MagickRealType) QuantumRange;
1869 if ((flags & SigmaValue) != 0)
1870 white_point=geometry_info.sigma;
1871 gamma=1.0;
1872 if ((flags & XiValue) != 0)
1873 gamma=geometry_info.xi;
1874 if ((flags & PercentValue) != 0)
1875 {
1876 black_point*=(MagickRealType) (QuantumRange/100.0);
1877 white_point*=(MagickRealType) (QuantumRange/100.0);
1878 }
1879 if ((flags & SigmaValue) == 0)
1880 white_point=(MagickRealType) QuantumRange-black_point;
1881 if ((*option == '+') || ((flags & AspectValue) != 0))
1882 (void) LevelizeImageChannel(*image,channel,black_point,
1883 white_point,gamma);
1884 else
1885 (void) LevelImageChannel(*image,channel,black_point,white_point,
1886 gamma);
1887 InheritException(exception,&(*image)->exception);
1888 break;
1889 }
1890 if (LocaleCompare("level-colors",option+1) == 0)
1891 {
1892 char
1893 token[MaxTextExtent];
1894
1895 const char
1896 *p;
1897
1898 MagickPixelPacket
1899 black_point,
1900 white_point;
1901
1902 p=(const char *) argv[i+1];
1903 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00001904 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001905 (void) QueryMagickColor(token,&black_point,exception);
1906 else
cristyee0f8d72009-09-19 00:58:29 +00001907 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001908 if (isalpha((int) token[0]) || (token[0] == '#'))
1909 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00001910 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00001911 white_point=black_point; /* set everything to that color */
1912 else
1913 {
cristyee0f8d72009-09-19 00:58:29 +00001914 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
anthonye9c27192011-03-27 08:07:06 +00001915 GetMagickToken(p,&p,token); /* Get white point color. */
cristyee0f8d72009-09-19 00:58:29 +00001916 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001917 (void) QueryMagickColor(token,&white_point,exception);
1918 else
cristyee0f8d72009-09-19 00:58:29 +00001919 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001920 }
cristy74fe8f12009-10-03 19:09:01 +00001921 (void) LevelColorsImageChannel(*image,channel,&black_point,
1922 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001923 break;
1924 }
1925 if (LocaleCompare("linear-stretch",option+1) == 0)
1926 {
1927 double
1928 black_point,
1929 white_point;
1930
cristy3ed852e2009-09-05 21:47:34 +00001931 MagickStatusType
1932 flags;
1933
cristy6b3da3a2010-06-20 02:21:46 +00001934 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001935 flags=ParseGeometry(argv[i+1],&geometry_info);
1936 black_point=geometry_info.rho;
1937 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1938 if ((flags & SigmaValue) != 0)
1939 white_point=geometry_info.sigma;
1940 if ((flags & PercentValue) != 0)
1941 {
1942 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1943 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1944 }
1945 if ((flags & SigmaValue) == 0)
1946 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1947 black_point;
1948 (void) LinearStretchImage(*image,black_point,white_point);
1949 InheritException(exception,&(*image)->exception);
1950 break;
1951 }
1952 if (LocaleCompare("linewidth",option+1) == 0)
1953 {
cristyf2f27272009-12-17 14:48:46 +00001954 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001955 break;
1956 }
1957 if (LocaleCompare("liquid-rescale",option+1) == 0)
1958 {
cristy3ed852e2009-09-05 21:47:34 +00001959 /*
1960 Liquid rescale image.
1961 */
cristy6b3da3a2010-06-20 02:21:46 +00001962 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001963 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1964 if ((flags & XValue) == 0)
1965 geometry.x=1;
1966 if ((flags & YValue) == 0)
1967 geometry.y=0;
cristyd241f442011-03-29 13:50:49 +00001968 mogrify_image=LiquidRescaleImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +00001969 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00001970 break;
1971 }
1972 if (LocaleCompare("lowlight-color",option+1) == 0)
1973 {
1974 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1975 break;
1976 }
1977 break;
1978 }
1979 case 'm':
1980 {
1981 if (LocaleCompare("map",option+1) == 0)
1982 {
1983 Image
1984 *remap_image;
1985
1986 /*
1987 Transform image colors to match this set of colors.
1988 */
cristy6b3da3a2010-06-20 02:21:46 +00001989 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001990 if (*option == '+')
1991 break;
cristy6b3da3a2010-06-20 02:21:46 +00001992 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00001993 if (remap_image == (Image *) NULL)
1994 break;
1995 (void) RemapImage(quantize_info,*image,remap_image);
1996 InheritException(exception,&(*image)->exception);
1997 remap_image=DestroyImage(remap_image);
1998 break;
1999 }
2000 if (LocaleCompare("mask",option+1) == 0)
2001 {
2002 Image
2003 *mask;
2004
cristy6b3da3a2010-06-20 02:21:46 +00002005 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002006 if (*option == '+')
2007 {
2008 /*
2009 Remove a mask.
2010 */
2011 (void) SetImageMask(*image,(Image *) NULL);
2012 InheritException(exception,&(*image)->exception);
2013 break;
2014 }
2015 /*
2016 Set the image mask.
2017 */
cristy6b3da3a2010-06-20 02:21:46 +00002018 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002019 if (mask == (Image *) NULL)
2020 break;
2021 (void) SetImageMask(*image,mask);
2022 mask=DestroyImage(mask);
2023 InheritException(exception,&(*image)->exception);
2024 break;
2025 }
2026 if (LocaleCompare("matte",option+1) == 0)
2027 {
2028 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2029 SetAlphaChannel : DeactivateAlphaChannel );
2030 InheritException(exception,&(*image)->exception);
2031 break;
2032 }
2033 if (LocaleCompare("median",option+1) == 0)
2034 {
cristy3ed852e2009-09-05 21:47:34 +00002035 /*
2036 Median filter image.
2037 */
cristy6b3da3a2010-06-20 02:21:46 +00002038 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002039 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002040 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
cristy95c38342011-03-18 22:39:51 +00002041 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002042 break;
2043 }
cristy69ec32d2011-02-27 23:57:09 +00002044 if (LocaleCompare("mode",option+1) == 0)
2045 {
cristy69ec32d2011-02-27 23:57:09 +00002046 /*
2047 Mode image.
2048 */
2049 (void) SyncImageSettings(mogrify_info,*image);
2050 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002051 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
cristy95c38342011-03-18 22:39:51 +00002052 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy69ec32d2011-02-27 23:57:09 +00002053 break;
2054 }
cristy3ed852e2009-09-05 21:47:34 +00002055 if (LocaleCompare("modulate",option+1) == 0)
2056 {
cristy6b3da3a2010-06-20 02:21:46 +00002057 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002058 (void) ModulateImage(*image,argv[i+1]);
2059 InheritException(exception,&(*image)->exception);
2060 break;
2061 }
2062 if (LocaleCompare("monitor",option+1) == 0)
2063 {
cristy7d34ef22010-03-25 01:11:22 +00002064 if (*option == '+')
2065 {
2066 (void) SetImageProgressMonitor(*image,
2067 (MagickProgressMonitor) NULL,(void *) NULL);
2068 break;
2069 }
cristy3ed852e2009-09-05 21:47:34 +00002070 (void) SetImageProgressMonitor(*image,MonitorProgress,
2071 (void *) NULL);
2072 break;
2073 }
2074 if (LocaleCompare("monochrome",option+1) == 0)
2075 {
cristy6b3da3a2010-06-20 02:21:46 +00002076 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002077 (void) SetImageType(*image,BilevelType);
2078 InheritException(exception,&(*image)->exception);
2079 break;
2080 }
anthony29188a82010-01-22 10:12:34 +00002081 if (LocaleCompare("morphology",option+1) == 0)
2082 {
anthony29188a82010-01-22 10:12:34 +00002083 char
2084 token[MaxTextExtent];
2085
2086 const char
2087 *p;
2088
cristye96405a2010-05-19 02:24:31 +00002089 KernelInfo
2090 *kernel;
2091
cristye96405a2010-05-19 02:24:31 +00002092 MorphologyMethod
2093 method;
2094
cristy9d314ff2011-03-09 01:30:28 +00002095 ssize_t
2096 iterations;
2097
anthony29188a82010-01-22 10:12:34 +00002098 /*
2099 Morphological Image Operation
2100 */
cristy6b3da3a2010-06-20 02:21:46 +00002101 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002102 p=argv[i+1];
2103 GetMagickToken(p,&p,token);
2104 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002105 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002106 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002107 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002108 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002109 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002110 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002111 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002112 kernel=AcquireKernelInfo(argv[i+2]);
2113 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002114 {
2115 (void) ThrowMagickException(exception,GetMagickModule(),
2116 OptionError,"UnabletoParseKernel","morphology");
2117 status=MagickFalse;
2118 break;
2119 }
cristyd241f442011-03-29 13:50:49 +00002120 mogrify_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002121 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002122 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002123 break;
2124 }
cristy3ed852e2009-09-05 21:47:34 +00002125 if (LocaleCompare("motion-blur",option+1) == 0)
2126 {
cristy3ed852e2009-09-05 21:47:34 +00002127 /*
2128 Motion blur image.
2129 */
cristy6b3da3a2010-06-20 02:21:46 +00002130 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002131 flags=ParseGeometry(argv[i+1],&geometry_info);
2132 if ((flags & SigmaValue) == 0)
2133 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002134 mogrify_image=MotionBlurImageChannel(*image,channel,
2135 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002136 break;
2137 }
2138 break;
2139 }
2140 case 'n':
2141 {
2142 if (LocaleCompare("negate",option+1) == 0)
2143 {
cristy6b3da3a2010-06-20 02:21:46 +00002144 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002145 (void) NegateImageChannel(*image,channel,*option == '+' ?
2146 MagickTrue : MagickFalse);
2147 InheritException(exception,&(*image)->exception);
2148 break;
2149 }
2150 if (LocaleCompare("noise",option+1) == 0)
2151 {
cristy6b3da3a2010-06-20 02:21:46 +00002152 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002153 if (*option == '-')
2154 {
2155 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002156 mogrify_image=StatisticImageChannel(*image,channel,
cristy95c38342011-03-18 22:39:51 +00002157 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2158 geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002159 }
2160 else
2161 {
2162 NoiseType
2163 noise;
2164
2165 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2166 MagickFalse,argv[i+1]);
cristyd241f442011-03-29 13:50:49 +00002167 mogrify_image=AddNoiseImageChannel(*image,channel,noise,
cristy3ed852e2009-09-05 21:47:34 +00002168 exception);
2169 }
cristy3ed852e2009-09-05 21:47:34 +00002170 break;
2171 }
2172 if (LocaleCompare("normalize",option+1) == 0)
2173 {
cristy6b3da3a2010-06-20 02:21:46 +00002174 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002175 (void) NormalizeImageChannel(*image,channel);
2176 InheritException(exception,&(*image)->exception);
2177 break;
2178 }
2179 break;
2180 }
2181 case 'o':
2182 {
2183 if (LocaleCompare("opaque",option+1) == 0)
2184 {
2185 MagickPixelPacket
2186 target;
2187
cristy6b3da3a2010-06-20 02:21:46 +00002188 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002189 (void) QueryMagickColor(argv[i+1],&target,exception);
2190 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2191 *option == '-' ? MagickFalse : MagickTrue);
2192 break;
2193 }
2194 if (LocaleCompare("ordered-dither",option+1) == 0)
2195 {
cristy6b3da3a2010-06-20 02:21:46 +00002196 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002197 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2198 exception);
2199 break;
2200 }
2201 break;
2202 }
2203 case 'p':
2204 {
2205 if (LocaleCompare("paint",option+1) == 0)
2206 {
2207 Image
2208 *paint_image;
2209
2210 /*
2211 Oil paint image.
2212 */
cristy6b3da3a2010-06-20 02:21:46 +00002213 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002214 (void) ParseGeometry(argv[i+1],&geometry_info);
2215 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2216 if (paint_image == (Image *) NULL)
2217 break;
2218 *image=DestroyImage(*image);
2219 *image=paint_image;
2220 break;
2221 }
2222 if (LocaleCompare("pen",option+1) == 0)
2223 {
2224 if (*option == '+')
2225 {
2226 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2227 break;
2228 }
2229 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2230 break;
2231 }
2232 if (LocaleCompare("pointsize",option+1) == 0)
2233 {
2234 if (*option == '+')
2235 (void) ParseGeometry("12",&geometry_info);
2236 else
2237 (void) ParseGeometry(argv[i+1],&geometry_info);
2238 draw_info->pointsize=geometry_info.rho;
2239 break;
2240 }
2241 if (LocaleCompare("polaroid",option+1) == 0)
2242 {
2243 double
2244 angle;
2245
cristy3ed852e2009-09-05 21:47:34 +00002246 RandomInfo
2247 *random_info;
2248
2249 /*
2250 Simulate a Polaroid picture.
2251 */
cristy6b3da3a2010-06-20 02:21:46 +00002252 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002253 random_info=AcquireRandomInfo();
2254 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2255 random_info=DestroyRandomInfo(random_info);
2256 if (*option == '-')
2257 {
2258 SetGeometryInfo(&geometry_info);
2259 flags=ParseGeometry(argv[i+1],&geometry_info);
2260 angle=geometry_info.rho;
2261 }
cristyd241f442011-03-29 13:50:49 +00002262 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
cristy3ed852e2009-09-05 21:47:34 +00002263 break;
2264 }
2265 if (LocaleCompare("posterize",option+1) == 0)
2266 {
2267 /*
2268 Posterize image.
2269 */
cristy6b3da3a2010-06-20 02:21:46 +00002270 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002271 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002272 quantize_info->dither);
2273 InheritException(exception,&(*image)->exception);
2274 break;
2275 }
2276 if (LocaleCompare("preview",option+1) == 0)
2277 {
cristy3ed852e2009-09-05 21:47:34 +00002278 PreviewType
2279 preview_type;
2280
2281 /*
2282 Preview image.
2283 */
cristy6b3da3a2010-06-20 02:21:46 +00002284 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002285 if (*option == '+')
2286 preview_type=UndefinedPreview;
2287 else
2288 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2289 MagickFalse,argv[i+1]);
cristyd241f442011-03-29 13:50:49 +00002290 mogrify_image=PreviewImage(*image,preview_type,exception);
cristy3ed852e2009-09-05 21:47:34 +00002291 break;
2292 }
2293 if (LocaleCompare("profile",option+1) == 0)
2294 {
2295 const char
2296 *name;
2297
2298 const StringInfo
2299 *profile;
2300
2301 Image
2302 *profile_image;
2303
2304 ImageInfo
2305 *profile_info;
2306
cristy6b3da3a2010-06-20 02:21:46 +00002307 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002308 if (*option == '+')
2309 {
2310 /*
2311 Remove a profile from the image.
2312 */
2313 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2314 NULL,0,MagickTrue);
2315 InheritException(exception,&(*image)->exception);
2316 break;
2317 }
2318 /*
2319 Associate a profile with the image.
2320 */
cristy6b3da3a2010-06-20 02:21:46 +00002321 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002322 profile=GetImageProfile(*image,"iptc");
2323 if (profile != (StringInfo *) NULL)
2324 profile_info->profile=(void *) CloneStringInfo(profile);
2325 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2326 profile_info=DestroyImageInfo(profile_info);
2327 if (profile_image == (Image *) NULL)
2328 {
cristy3ed852e2009-09-05 21:47:34 +00002329 StringInfo
2330 *profile;
2331
cristy6b3da3a2010-06-20 02:21:46 +00002332 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002333 (void) CopyMagickString(profile_info->filename,argv[i+1],
2334 MaxTextExtent);
2335 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002336 if (profile != (StringInfo *) NULL)
2337 {
cristy071dd7b2010-04-09 13:04:54 +00002338 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002339 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002340 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002341 profile=DestroyStringInfo(profile);
2342 }
cristy071dd7b2010-04-09 13:04:54 +00002343 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002344 break;
2345 }
2346 ResetImageProfileIterator(profile_image);
2347 name=GetNextImageProfile(profile_image);
2348 while (name != (const char *) NULL)
2349 {
2350 profile=GetImageProfile(profile_image,name);
2351 if (profile != (StringInfo *) NULL)
2352 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002353 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002354 name=GetNextImageProfile(profile_image);
2355 }
2356 profile_image=DestroyImage(profile_image);
2357 break;
2358 }
2359 break;
2360 }
2361 case 'q':
2362 {
2363 if (LocaleCompare("quantize",option+1) == 0)
2364 {
2365 if (*option == '+')
2366 {
2367 quantize_info->colorspace=UndefinedColorspace;
2368 break;
2369 }
2370 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2371 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2372 break;
2373 }
2374 break;
2375 }
2376 case 'r':
2377 {
2378 if (LocaleCompare("radial-blur",option+1) == 0)
2379 {
cristy3ed852e2009-09-05 21:47:34 +00002380 /*
2381 Radial blur image.
2382 */
cristy6b3da3a2010-06-20 02:21:46 +00002383 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002384 mogrify_image=RadialBlurImageChannel(*image,channel,
cristya5447be2010-01-11 00:20:51 +00002385 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002386 break;
2387 }
2388 if (LocaleCompare("raise",option+1) == 0)
2389 {
2390 /*
2391 Surround image with a raise of solid color.
2392 */
2393 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2394 if ((flags & SigmaValue) == 0)
2395 geometry.height=geometry.width;
2396 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2397 MagickFalse);
2398 InheritException(exception,&(*image)->exception);
2399 break;
2400 }
2401 if (LocaleCompare("random-threshold",option+1) == 0)
2402 {
2403 /*
2404 Threshold image.
2405 */
cristy6b3da3a2010-06-20 02:21:46 +00002406 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002407 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2408 exception);
2409 break;
2410 }
2411 if (LocaleCompare("recolor",option+1) == 0)
2412 {
cristyf055ae42010-04-02 23:01:38 +00002413 KernelInfo
2414 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002415
cristy6b3da3a2010-06-20 02:21:46 +00002416 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002417 kernel=AcquireKernelInfo(argv[i+1]);
2418 if (kernel == (KernelInfo *) NULL)
2419 break;
cristyd241f442011-03-29 13:50:49 +00002420 mogrify_image=ColorMatrixImage(*image,kernel,exception);
cristyf055ae42010-04-02 23:01:38 +00002421 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00002422 break;
2423 }
2424 if (LocaleCompare("region",option+1) == 0)
2425 {
cristy6b3da3a2010-06-20 02:21:46 +00002426 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002427 if (region_image != (Image *) NULL)
2428 {
2429 /*
2430 Composite region.
2431 */
anthonye9c27192011-03-27 08:07:06 +00002432 (void) CompositeImage(region_image, CopyCompositeOp,*image,
cristy3ed852e2009-09-05 21:47:34 +00002433 region_geometry.x,region_geometry.y);
2434 InheritException(exception,&region_image->exception);
2435 *image=DestroyImage(*image);
2436 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00002437 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002438 }
2439 if (*option == '+')
anthonye9c27192011-03-27 08:07:06 +00002440 break;
cristy3ed852e2009-09-05 21:47:34 +00002441 /*
2442 Apply transformations to a selected region of the image.
2443 */
2444 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2445 exception);
cristyd241f442011-03-29 13:50:49 +00002446 mogrify_image=CropImage(*image,&region_geometry,exception);
2447 if (mogrify_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002448 break;
2449 region_image=(*image);
cristyd241f442011-03-29 13:50:49 +00002450 *image=mogrify_image;
2451 mogrify_image=(Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002452 break;
2453 }
2454 if (LocaleCompare("render",option+1) == 0)
2455 {
cristy6b3da3a2010-06-20 02:21:46 +00002456 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002457 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2458 break;
2459 }
2460 if (LocaleCompare("remap",option+1) == 0)
2461 {
2462 Image
2463 *remap_image;
2464
2465 /*
2466 Transform image colors to match this set of colors.
2467 */
cristy6b3da3a2010-06-20 02:21:46 +00002468 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002469 if (*option == '+')
2470 break;
cristy6b3da3a2010-06-20 02:21:46 +00002471 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002472 if (remap_image == (Image *) NULL)
2473 break;
2474 (void) RemapImage(quantize_info,*image,remap_image);
2475 InheritException(exception,&(*image)->exception);
2476 remap_image=DestroyImage(remap_image);
2477 break;
2478 }
2479 if (LocaleCompare("repage",option+1) == 0)
2480 {
2481 if (*option == '+')
2482 {
2483 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2484 break;
2485 }
2486 (void) ResetImagePage(*image,argv[i+1]);
2487 InheritException(exception,&(*image)->exception);
2488 break;
2489 }
2490 if (LocaleCompare("resample",option+1) == 0)
2491 {
cristy3ed852e2009-09-05 21:47:34 +00002492 /*
2493 Resample image.
2494 */
cristy6b3da3a2010-06-20 02:21:46 +00002495 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002496 flags=ParseGeometry(argv[i+1],&geometry_info);
2497 if ((flags & SigmaValue) == 0)
2498 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002499 mogrify_image=ResampleImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002500 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002501 break;
2502 }
2503 if (LocaleCompare("resize",option+1) == 0)
2504 {
cristy3ed852e2009-09-05 21:47:34 +00002505 /*
2506 Resize image.
2507 */
cristy6b3da3a2010-06-20 02:21:46 +00002508 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002509 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002510 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002511 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002512 break;
2513 }
cristy3ed852e2009-09-05 21:47:34 +00002514 if (LocaleCompare("roll",option+1) == 0)
2515 {
cristy3ed852e2009-09-05 21:47:34 +00002516 /*
2517 Roll image.
2518 */
cristy6b3da3a2010-06-20 02:21:46 +00002519 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002520 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002521 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00002522 break;
2523 }
2524 if (LocaleCompare("rotate",option+1) == 0)
2525 {
2526 char
2527 *geometry;
2528
cristy3ed852e2009-09-05 21:47:34 +00002529 /*
2530 Check for conditional image rotation.
2531 */
cristy6b3da3a2010-06-20 02:21:46 +00002532 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002533 if (strchr(argv[i+1],'>') != (char *) NULL)
2534 if ((*image)->columns <= (*image)->rows)
2535 break;
2536 if (strchr(argv[i+1],'<') != (char *) NULL)
2537 if ((*image)->columns >= (*image)->rows)
2538 break;
2539 /*
2540 Rotate image.
2541 */
2542 geometry=ConstantString(argv[i+1]);
2543 (void) SubstituteString(&geometry,">","");
2544 (void) SubstituteString(&geometry,"<","");
2545 (void) ParseGeometry(geometry,&geometry_info);
2546 geometry=DestroyString(geometry);
cristyd241f442011-03-29 13:50:49 +00002547 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002548 break;
2549 }
2550 break;
2551 }
2552 case 's':
2553 {
2554 if (LocaleCompare("sample",option+1) == 0)
2555 {
cristy3ed852e2009-09-05 21:47:34 +00002556 /*
2557 Sample image with pixel replication.
2558 */
cristy6b3da3a2010-06-20 02:21:46 +00002559 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002560 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002561 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002562 exception);
cristy3ed852e2009-09-05 21:47:34 +00002563 break;
2564 }
2565 if (LocaleCompare("scale",option+1) == 0)
2566 {
cristy3ed852e2009-09-05 21:47:34 +00002567 /*
2568 Resize image.
2569 */
cristy6b3da3a2010-06-20 02:21:46 +00002570 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002571 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002572 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002573 exception);
cristy3ed852e2009-09-05 21:47:34 +00002574 break;
2575 }
2576 if (LocaleCompare("selective-blur",option+1) == 0)
2577 {
cristy3ed852e2009-09-05 21:47:34 +00002578 /*
2579 Selectively blur pixels within a contrast threshold.
2580 */
cristy6b3da3a2010-06-20 02:21:46 +00002581 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002582 flags=ParseGeometry(argv[i+1],&geometry_info);
2583 if ((flags & PercentValue) != 0)
2584 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyd241f442011-03-29 13:50:49 +00002585 mogrify_image=SelectiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00002586 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002587 break;
2588 }
2589 if (LocaleCompare("separate",option+1) == 0)
2590 {
cristy3ed852e2009-09-05 21:47:34 +00002591 /*
2592 Break channels into separate images.
anthonye9c27192011-03-27 08:07:06 +00002593 WARNING: This can generate multiple images!
cristy3ed852e2009-09-05 21:47:34 +00002594 */
cristy6b3da3a2010-06-20 02:21:46 +00002595 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002596 mogrify_image=SeparateImages(*image,channel,exception);
cristy3ed852e2009-09-05 21:47:34 +00002597 break;
2598 }
2599 if (LocaleCompare("sepia-tone",option+1) == 0)
2600 {
2601 double
2602 threshold;
2603
cristy3ed852e2009-09-05 21:47:34 +00002604 /*
2605 Sepia-tone image.
2606 */
cristy6b3da3a2010-06-20 02:21:46 +00002607 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002608 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyd241f442011-03-29 13:50:49 +00002609 mogrify_image=SepiaToneImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00002610 break;
2611 }
2612 if (LocaleCompare("segment",option+1) == 0)
2613 {
2614 /*
2615 Segment image.
2616 */
cristy6b3da3a2010-06-20 02:21:46 +00002617 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002618 flags=ParseGeometry(argv[i+1],&geometry_info);
2619 if ((flags & SigmaValue) == 0)
2620 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002621 (void) SegmentImage(*image,(*image)->colorspace,
2622 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002623 InheritException(exception,&(*image)->exception);
2624 break;
2625 }
2626 if (LocaleCompare("set",option+1) == 0)
2627 {
cristy6d9a1292010-05-31 14:17:06 +00002628 char
2629 *value;
2630
cristy3ed852e2009-09-05 21:47:34 +00002631 /*
2632 Set image option.
2633 */
cristy6d9a1292010-05-31 14:17:06 +00002634 if (*option == '+')
2635 {
2636 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2637 (void) DeleteImageRegistry(argv[i+1]+9);
2638 else
2639 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002640 {
cristy6b3da3a2010-06-20 02:21:46 +00002641 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002642 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2643 }
cristy6d9a1292010-05-31 14:17:06 +00002644 else
2645 (void) DeleteImageProperty(*image,argv[i+1]);
2646 break;
2647 }
cristy6b3da3a2010-06-20 02:21:46 +00002648 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002649 if (value == (char *) NULL)
2650 break;
cristy3ed852e2009-09-05 21:47:34 +00002651 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002652 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2653 exception);
cristy3ed852e2009-09-05 21:47:34 +00002654 else
2655 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002656 {
cristy7f02ba12010-09-21 12:39:28 +00002657 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002658 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002659 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2660 }
cristy3ed852e2009-09-05 21:47:34 +00002661 else
cristy6d9a1292010-05-31 14:17:06 +00002662 (void) SetImageProperty(*image,argv[i+1],value);
2663 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002664 break;
2665 }
2666 if (LocaleCompare("shade",option+1) == 0)
2667 {
cristy3ed852e2009-09-05 21:47:34 +00002668 /*
2669 Shade image.
2670 */
cristy6b3da3a2010-06-20 02:21:46 +00002671 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002672 flags=ParseGeometry(argv[i+1],&geometry_info);
2673 if ((flags & SigmaValue) == 0)
2674 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00002675 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
cristy3ed852e2009-09-05 21:47:34 +00002676 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002677 break;
2678 }
2679 if (LocaleCompare("shadow",option+1) == 0)
2680 {
cristy3ed852e2009-09-05 21:47:34 +00002681 /*
2682 Shadow image.
2683 */
cristy6b3da3a2010-06-20 02:21:46 +00002684 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002685 flags=ParseGeometry(argv[i+1],&geometry_info);
2686 if ((flags & SigmaValue) == 0)
2687 geometry_info.sigma=1.0;
2688 if ((flags & XiValue) == 0)
2689 geometry_info.xi=4.0;
2690 if ((flags & PsiValue) == 0)
2691 geometry_info.psi=4.0;
cristyd241f442011-03-29 13:50:49 +00002692 mogrify_image=ShadowImage(*image,geometry_info.rho,
2693 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2694 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002695 break;
2696 }
2697 if (LocaleCompare("sharpen",option+1) == 0)
2698 {
cristy3ed852e2009-09-05 21:47:34 +00002699 /*
2700 Sharpen 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;
cristyd241f442011-03-29 13:50:49 +00002706 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002707 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002708 break;
2709 }
2710 if (LocaleCompare("shave",option+1) == 0)
2711 {
cristy3ed852e2009-09-05 21:47:34 +00002712 /*
2713 Shave the image edges.
2714 */
cristy6b3da3a2010-06-20 02:21:46 +00002715 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002716 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002717 mogrify_image=ShaveImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002718 break;
2719 }
2720 if (LocaleCompare("shear",option+1) == 0)
2721 {
cristy3ed852e2009-09-05 21:47:34 +00002722 /*
2723 Shear image.
2724 */
cristy6b3da3a2010-06-20 02:21:46 +00002725 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002726 flags=ParseGeometry(argv[i+1],&geometry_info);
2727 if ((flags & SigmaValue) == 0)
2728 geometry_info.sigma=geometry_info.rho;
cristyd241f442011-03-29 13:50:49 +00002729 mogrify_image=ShearImage(*image,geometry_info.rho,
2730 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002731 break;
2732 }
2733 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2734 {
2735 /*
2736 Sigmoidal non-linearity contrast control.
2737 */
cristy6b3da3a2010-06-20 02:21:46 +00002738 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002739 flags=ParseGeometry(argv[i+1],&geometry_info);
2740 if ((flags & SigmaValue) == 0)
2741 geometry_info.sigma=(double) QuantumRange/2.0;
2742 if ((flags & PercentValue) != 0)
2743 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2744 100.0;
2745 (void) SigmoidalContrastImageChannel(*image,channel,
2746 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2747 geometry_info.sigma);
2748 InheritException(exception,&(*image)->exception);
2749 break;
2750 }
2751 if (LocaleCompare("sketch",option+1) == 0)
2752 {
cristy3ed852e2009-09-05 21:47:34 +00002753 /*
2754 Sketch image.
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=1.0;
cristyd241f442011-03-29 13:50:49 +00002760 mogrify_image=SketchImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002761 geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002762 break;
2763 }
2764 if (LocaleCompare("solarize",option+1) == 0)
2765 {
2766 double
2767 threshold;
2768
cristy6b3da3a2010-06-20 02:21:46 +00002769 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002770 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002771 (void) SolarizeImage(*image,threshold);
2772 InheritException(exception,&(*image)->exception);
2773 break;
2774 }
2775 if (LocaleCompare("sparse-color",option+1) == 0)
2776 {
cristy3ed852e2009-09-05 21:47:34 +00002777 SparseColorMethod
2778 method;
2779
2780 char
2781 *arguments;
2782
2783 /*
2784 Sparse Color Interpolated Gradient
2785 */
cristy6b3da3a2010-06-20 02:21:46 +00002786 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002787 method=(SparseColorMethod) ParseMagickOption(
2788 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00002789 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00002790 InheritException(exception,&(*image)->exception);
2791 if (arguments == (char *) NULL)
2792 break;
cristyd241f442011-03-29 13:50:49 +00002793 mogrify_image=SparseColorOption(*image,channel,method,arguments,
cristy3ed852e2009-09-05 21:47:34 +00002794 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2795 arguments=DestroyString(arguments);
cristy3ed852e2009-09-05 21:47:34 +00002796 break;
2797 }
2798 if (LocaleCompare("splice",option+1) == 0)
2799 {
cristy3ed852e2009-09-05 21:47:34 +00002800 /*
2801 Splice a solid color into the image.
2802 */
cristy6b3da3a2010-06-20 02:21:46 +00002803 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002804 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002805 mogrify_image=SpliceImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002806 break;
2807 }
2808 if (LocaleCompare("spread",option+1) == 0)
2809 {
cristy3ed852e2009-09-05 21:47:34 +00002810 /*
2811 Spread an image.
2812 */
cristy6b3da3a2010-06-20 02:21:46 +00002813 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002814 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002815 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002816 break;
2817 }
cristy0834d642011-03-18 18:26:08 +00002818 if (LocaleCompare("statistic",option+1) == 0)
2819 {
cristy0834d642011-03-18 18:26:08 +00002820 StatisticType
2821 type;
2822
2823 (void) SyncImageSettings(mogrify_info,*image);
2824 type=(StatisticType) ParseMagickOption(MagickStatisticOptions,
2825 MagickFalse,argv[i+1]);
2826 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002827 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2828 geometry_info.rho,(size_t) geometry_info.sigma,exception);
cristy0834d642011-03-18 18:26:08 +00002829 break;
2830 }
cristy3ed852e2009-09-05 21:47:34 +00002831 if (LocaleCompare("stretch",option+1) == 0)
2832 {
2833 if (*option == '+')
2834 {
2835 draw_info->stretch=UndefinedStretch;
2836 break;
2837 }
2838 draw_info->stretch=(StretchType) ParseMagickOption(
2839 MagickStretchOptions,MagickFalse,argv[i+1]);
2840 break;
2841 }
2842 if (LocaleCompare("strip",option+1) == 0)
2843 {
2844 /*
2845 Strip image of profiles and comments.
2846 */
cristy6b3da3a2010-06-20 02:21:46 +00002847 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00002848 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00002849 InheritException(exception,&(*image)->exception);
2850 break;
2851 }
2852 if (LocaleCompare("stroke",option+1) == 0)
2853 {
2854 ExceptionInfo
2855 *sans;
2856
2857 if (*option == '+')
2858 {
2859 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2860 if (draw_info->stroke_pattern != (Image *) NULL)
2861 draw_info->stroke_pattern=DestroyImage(
2862 draw_info->stroke_pattern);
2863 break;
2864 }
2865 sans=AcquireExceptionInfo();
2866 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2867 sans=DestroyExceptionInfo(sans);
2868 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00002869 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002870 exception);
2871 break;
2872 }
2873 if (LocaleCompare("strokewidth",option+1) == 0)
2874 {
cristyf2f27272009-12-17 14:48:46 +00002875 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002876 break;
2877 }
2878 if (LocaleCompare("style",option+1) == 0)
2879 {
2880 if (*option == '+')
2881 {
2882 draw_info->style=UndefinedStyle;
2883 break;
2884 }
2885 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
2886 MagickFalse,argv[i+1]);
2887 break;
2888 }
2889 if (LocaleCompare("swirl",option+1) == 0)
2890 {
cristy3ed852e2009-09-05 21:47:34 +00002891 /*
2892 Swirl image.
2893 */
cristy6b3da3a2010-06-20 02:21:46 +00002894 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002895 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyd241f442011-03-29 13:50:49 +00002896 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002897 break;
2898 }
2899 break;
2900 }
2901 case 't':
2902 {
2903 if (LocaleCompare("threshold",option+1) == 0)
2904 {
2905 double
2906 threshold;
2907
2908 /*
2909 Threshold image.
2910 */
cristy6b3da3a2010-06-20 02:21:46 +00002911 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002912 if (*option == '+')
2913 threshold=(double) QuantumRange/2.5;
2914 else
cristyf2f27272009-12-17 14:48:46 +00002915 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002916 (void) BilevelImageChannel(*image,channel,threshold);
2917 InheritException(exception,&(*image)->exception);
2918 break;
2919 }
2920 if (LocaleCompare("thumbnail",option+1) == 0)
2921 {
cristy3ed852e2009-09-05 21:47:34 +00002922 /*
2923 Thumbnail image.
2924 */
cristy6b3da3a2010-06-20 02:21:46 +00002925 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002926 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
cristyd241f442011-03-29 13:50:49 +00002927 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2928 exception);
cristy3ed852e2009-09-05 21:47:34 +00002929 break;
2930 }
2931 if (LocaleCompare("tile",option+1) == 0)
2932 {
2933 if (*option == '+')
2934 {
2935 if (draw_info->fill_pattern != (Image *) NULL)
2936 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2937 break;
2938 }
cristy6b3da3a2010-06-20 02:21:46 +00002939 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002940 exception);
2941 break;
2942 }
2943 if (LocaleCompare("tint",option+1) == 0)
2944 {
cristy3ed852e2009-09-05 21:47:34 +00002945 /*
2946 Tint the image.
2947 */
cristy6b3da3a2010-06-20 02:21:46 +00002948 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002949 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
cristy3ed852e2009-09-05 21:47:34 +00002950 break;
2951 }
2952 if (LocaleCompare("transform",option+1) == 0)
2953 {
cristy3ed852e2009-09-05 21:47:34 +00002954 /*
2955 Affine transform image.
2956 */
cristy6b3da3a2010-06-20 02:21:46 +00002957 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002958 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
cristy3ed852e2009-09-05 21:47:34 +00002959 exception);
cristy3ed852e2009-09-05 21:47:34 +00002960 break;
2961 }
2962 if (LocaleCompare("transparent",option+1) == 0)
2963 {
2964 MagickPixelPacket
2965 target;
2966
cristy6b3da3a2010-06-20 02:21:46 +00002967 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002968 (void) QueryMagickColor(argv[i+1],&target,exception);
2969 (void) TransparentPaintImage(*image,&target,(Quantum)
2970 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
2971 InheritException(exception,&(*image)->exception);
2972 break;
2973 }
2974 if (LocaleCompare("transpose",option+1) == 0)
2975 {
cristy3ed852e2009-09-05 21:47:34 +00002976 /*
2977 Transpose image scanlines.
2978 */
cristy6b3da3a2010-06-20 02:21:46 +00002979 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002980 mogrify_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002981 break;
2982 }
2983 if (LocaleCompare("transverse",option+1) == 0)
2984 {
cristy3ed852e2009-09-05 21:47:34 +00002985 /*
2986 Transverse image scanlines.
2987 */
cristy6b3da3a2010-06-20 02:21:46 +00002988 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00002989 mogrify_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002990 break;
2991 }
2992 if (LocaleCompare("treedepth",option+1) == 0)
2993 {
cristye27293e2009-12-18 02:53:20 +00002994 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002995 break;
2996 }
2997 if (LocaleCompare("trim",option+1) == 0)
2998 {
cristy3ed852e2009-09-05 21:47:34 +00002999 /*
3000 Trim image.
3001 */
cristy6b3da3a2010-06-20 02:21:46 +00003002 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003003 mogrify_image=TrimImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003004 break;
3005 }
3006 if (LocaleCompare("type",option+1) == 0)
3007 {
3008 ImageType
3009 type;
3010
cristy6b3da3a2010-06-20 02:21:46 +00003011 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003012 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003013 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003014 else
3015 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3016 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003017 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003018 (void) SetImageType(*image,type);
3019 InheritException(exception,&(*image)->exception);
3020 break;
3021 }
3022 break;
3023 }
3024 case 'u':
3025 {
3026 if (LocaleCompare("undercolor",option+1) == 0)
3027 {
3028 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3029 exception);
3030 break;
3031 }
cristy045bd902010-01-30 18:56:24 +00003032 if (LocaleCompare("unique",option+1) == 0)
3033 {
3034 if (*option == '+')
3035 {
cristy83fae872010-04-22 15:04:16 +00003036 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003037 break;
3038 }
cristy83fae872010-04-22 15:04:16 +00003039 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003040 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003041 break;
3042 }
cristy3ed852e2009-09-05 21:47:34 +00003043 if (LocaleCompare("unique-colors",option+1) == 0)
3044 {
cristy3ed852e2009-09-05 21:47:34 +00003045 /*
3046 Unique image colors.
3047 */
cristy6b3da3a2010-06-20 02:21:46 +00003048 (void) SyncImageSettings(mogrify_info,*image);
cristyd241f442011-03-29 13:50:49 +00003049 mogrify_image=UniqueImageColors(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003050 break;
3051 }
3052 if (LocaleCompare("unsharp",option+1) == 0)
3053 {
cristy3ed852e2009-09-05 21:47:34 +00003054 /*
3055 Unsharp mask image.
3056 */
cristy6b3da3a2010-06-20 02:21:46 +00003057 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003058 flags=ParseGeometry(argv[i+1],&geometry_info);
3059 if ((flags & SigmaValue) == 0)
3060 geometry_info.sigma=1.0;
3061 if ((flags & XiValue) == 0)
3062 geometry_info.xi=1.0;
3063 if ((flags & PsiValue) == 0)
3064 geometry_info.psi=0.05;
cristyd241f442011-03-29 13:50:49 +00003065 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3066 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3067 geometry_info.psi,exception);
cristy3ed852e2009-09-05 21:47:34 +00003068 break;
3069 }
3070 break;
3071 }
3072 case 'v':
3073 {
3074 if (LocaleCompare("verbose",option+1) == 0)
3075 {
3076 (void) SetImageArtifact(*image,option+1,
3077 *option == '+' ? "false" : "true");
3078 break;
3079 }
3080 if (LocaleCompare("vignette",option+1) == 0)
3081 {
cristy3ed852e2009-09-05 21:47:34 +00003082 /*
3083 Vignette image.
3084 */
cristy6b3da3a2010-06-20 02:21:46 +00003085 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003086 flags=ParseGeometry(argv[i+1],&geometry_info);
3087 if ((flags & SigmaValue) == 0)
3088 geometry_info.sigma=1.0;
3089 if ((flags & XiValue) == 0)
3090 geometry_info.xi=0.1*(*image)->columns;
3091 if ((flags & PsiValue) == 0)
3092 geometry_info.psi=0.1*(*image)->rows;
cristyd241f442011-03-29 13:50:49 +00003093 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003094 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003095 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003096 break;
3097 }
3098 if (LocaleCompare("virtual-pixel",option+1) == 0)
3099 {
3100 if (*option == '+')
3101 {
3102 (void) SetImageVirtualPixelMethod(*image,
3103 UndefinedVirtualPixelMethod);
3104 break;
3105 }
3106 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3107 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3108 argv[i+1]));
3109 break;
3110 }
3111 break;
3112 }
3113 case 'w':
3114 {
3115 if (LocaleCompare("wave",option+1) == 0)
3116 {
cristy3ed852e2009-09-05 21:47:34 +00003117 /*
3118 Wave image.
3119 */
cristy6b3da3a2010-06-20 02:21:46 +00003120 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003121 flags=ParseGeometry(argv[i+1],&geometry_info);
3122 if ((flags & SigmaValue) == 0)
3123 geometry_info.sigma=1.0;
cristyd241f442011-03-29 13:50:49 +00003124 mogrify_image=WaveImage(*image,geometry_info.rho,
3125 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00003126 break;
3127 }
3128 if (LocaleCompare("weight",option+1) == 0)
3129 {
cristye27293e2009-12-18 02:53:20 +00003130 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003131 if (LocaleCompare(argv[i+1],"all") == 0)
3132 draw_info->weight=0;
3133 if (LocaleCompare(argv[i+1],"bold") == 0)
3134 draw_info->weight=700;
3135 if (LocaleCompare(argv[i+1],"bolder") == 0)
3136 if (draw_info->weight <= 800)
3137 draw_info->weight+=100;
3138 if (LocaleCompare(argv[i+1],"lighter") == 0)
3139 if (draw_info->weight >= 100)
3140 draw_info->weight-=100;
3141 if (LocaleCompare(argv[i+1],"normal") == 0)
3142 draw_info->weight=400;
3143 break;
3144 }
3145 if (LocaleCompare("white-threshold",option+1) == 0)
3146 {
3147 /*
3148 White threshold image.
3149 */
cristy6b3da3a2010-06-20 02:21:46 +00003150 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003151 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3152 exception);
3153 InheritException(exception,&(*image)->exception);
3154 break;
3155 }
3156 break;
3157 }
3158 default:
3159 break;
3160 }
anthonye9c27192011-03-27 08:07:06 +00003161 /*
3162 Replace current image with any image that was generated
3163 */
cristyd241f442011-03-29 13:50:49 +00003164 if (mogrify_image != (Image *) NULL)
3165 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003166 i+=count;
3167 }
3168 if (region_image != (Image *) NULL)
3169 {
3170 /*
3171 Composite transformed region onto image.
3172 */
cristy6b3da3a2010-06-20 02:21:46 +00003173 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00003174 (void) CompositeImage(region_image,CopyCompositeOp,*image,
3175 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003176 InheritException(exception,&region_image->exception);
3177 *image=DestroyImage(*image);
3178 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003179 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003180 }
3181 /*
3182 Free resources.
3183 */
3184 quantize_info=DestroyQuantizeInfo(quantize_info);
3185 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003186 mogrify_info=DestroyImageInfo(mogrify_info);
cristy72988482011-03-29 16:34:38 +00003187 status=(*image)->exception.severity == UndefinedException ? 1 : 0;
3188 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003189}
3190
3191/*
3192%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3193% %
3194% %
3195% %
cristy5063d812010-10-19 16:28:10 +00003196+ 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 +00003197% %
3198% %
3199% %
3200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3201%
3202% MogrifyImageCommand() transforms an image or a sequence of images. These
3203% transforms include image scaling, image rotation, color reduction, and
3204% others. The transmogrified image overwrites the original image.
3205%
3206% The format of the MogrifyImageCommand method is:
3207%
3208% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3209% const char **argv,char **metadata,ExceptionInfo *exception)
3210%
3211% A description of each parameter follows:
3212%
3213% o image_info: the image info.
3214%
3215% o argc: the number of elements in the argument vector.
3216%
3217% o argv: A text array containing the command line arguments.
3218%
3219% o metadata: any metadata is returned here.
3220%
3221% o exception: return any errors or warnings in this structure.
3222%
3223*/
3224
3225static MagickBooleanType MogrifyUsage(void)
3226{
3227 static const char
3228 *miscellaneous[]=
3229 {
3230 "-debug events display copious debugging information",
3231 "-help print program options",
3232 "-list type print a list of supported option arguments",
3233 "-log format format of debugging information",
3234 "-version print version information",
3235 (char *) NULL
3236 },
3237 *operators[]=
3238 {
3239 "-adaptive-blur geometry",
3240 " adaptively blur pixels; decrease effect near edges",
3241 "-adaptive-resize geometry",
3242 " adaptively resize image using 'mesh' interpolation",
3243 "-adaptive-sharpen geometry",
3244 " adaptively sharpen pixels; increase effect near edges",
3245 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3246 " transparent, extract, background, or shape",
3247 "-annotate geometry text",
3248 " annotate the image with text",
3249 "-auto-gamma automagically adjust gamma level of image",
3250 "-auto-level automagically adjust color levels of image",
3251 "-auto-orient automagically orient (rotate) image",
3252 "-bench iterations measure performance",
3253 "-black-threshold value",
3254 " force all pixels below the threshold into black",
3255 "-blue-shift simulate a scene at nighttime in the moonlight",
3256 "-blur geometry reduce image noise and reduce detail levels",
3257 "-border geometry surround image with a border of color",
3258 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003259 "-brightness-contrast geometry",
3260 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003261 "-cdl filename color correct with a color decision list",
3262 "-charcoal radius simulate a charcoal drawing",
3263 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003264 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003265 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003266 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003267 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003268 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003269 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003270 "-contrast enhance or reduce the image contrast",
3271 "-contrast-stretch geometry",
3272 " improve contrast by `stretching' the intensity range",
3273 "-convolve coefficients",
3274 " apply a convolution kernel to the image",
3275 "-cycle amount cycle the image colormap",
3276 "-decipher filename convert cipher pixels to plain pixels",
3277 "-deskew threshold straighten an image",
3278 "-despeckle reduce the speckles within an image",
3279 "-distort method args",
3280 " distort images according to given method ad args",
3281 "-draw string annotate the image with a graphic primitive",
3282 "-edge radius apply a filter to detect edges in the image",
3283 "-encipher filename convert plain pixels to cipher pixels",
3284 "-emboss radius emboss an image",
3285 "-enhance apply a digital filter to enhance a noisy image",
3286 "-equalize perform histogram equalization to an image",
3287 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003288 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003289 "-extent geometry set the image size",
3290 "-extract geometry extract area from image",
3291 "-fft implements the discrete Fourier transform (DFT)",
3292 "-flip flip image vertically",
3293 "-floodfill geometry color",
3294 " floodfill the image with color",
3295 "-flop flop image horizontally",
3296 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003297 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003298 " apply function over image values",
3299 "-gamma value level of gamma correction",
3300 "-gaussian-blur geometry",
3301 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003302 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003303 "-identify identify the format and characteristics of the image",
3304 "-ift implements the inverse discrete Fourier transform (DFT)",
3305 "-implode amount implode image pixels about the center",
3306 "-lat geometry local adaptive thresholding",
3307 "-layers method optimize, merge, or compare image layers",
3308 "-level value adjust the level of image contrast",
3309 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003310 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003311 "-linear-stretch geometry",
3312 " improve contrast by `stretching with saturation'",
3313 "-liquid-rescale geometry",
3314 " rescale image with seam-carving",
3315 "-median radius apply a median filter to the image",
cristy2ecd9be2011-02-28 01:17:26 +00003316 "-mode radius make each pixel the 'predominate color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003317 "-modulate value vary the brightness, saturation, and hue",
3318 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003319 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003320 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003321 "-motion-blur geometry",
3322 " simulate motion blur",
3323 "-negate replace every pixel with its complementary color ",
3324 "-noise radius add or reduce noise in an image",
3325 "-normalize transform image to span the full range of colors",
3326 "-opaque color change this color to the fill color",
3327 "-ordered-dither NxN",
3328 " add a noise pattern to the image with specific",
3329 " amplitudes",
3330 "-paint radius simulate an oil painting",
3331 "-polaroid angle simulate a Polaroid picture",
3332 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003333 "-profile filename add, delete, or apply an image profile",
3334 "-quantize colorspace reduce colors in this colorspace",
3335 "-radial-blur angle radial blur the image",
3336 "-raise value lighten/darken image edges to create a 3-D effect",
3337 "-random-threshold low,high",
3338 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003339 "-region geometry apply options to a portion of the image",
3340 "-render render vector graphics",
3341 "-repage geometry size and location of an image canvas",
3342 "-resample geometry change the resolution of an image",
3343 "-resize geometry resize the image",
3344 "-roll geometry roll an image vertically or horizontally",
3345 "-rotate degrees apply Paeth rotation to the image",
3346 "-sample geometry scale image with pixel sampling",
3347 "-scale geometry scale the image",
3348 "-segment values segment an image",
3349 "-selective-blur geometry",
3350 " selectively blur pixels within a contrast threshold",
3351 "-sepia-tone threshold",
3352 " simulate a sepia-toned photo",
3353 "-set property value set an image property",
3354 "-shade degrees shade the image using a distant light source",
3355 "-shadow geometry simulate an image shadow",
3356 "-sharpen geometry sharpen the image",
3357 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003358 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003359 "-sigmoidal-contrast geometry",
3360 " increase the contrast without saturating highlights or shadows",
3361 "-sketch geometry simulate a pencil sketch",
3362 "-solarize threshold negate all pixels above the threshold level",
3363 "-sparse-color method args",
3364 " fill in a image based on a few color points",
3365 "-splice geometry splice the background color into the image",
3366 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003367 "-statistic type radius",
3368 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-strip strip image of all profiles and comments",
3370 "-swirl degrees swirl image pixels about the center",
3371 "-threshold value threshold the image",
3372 "-thumbnail geometry create a thumbnail of the image",
3373 "-tile filename tile image when filling a graphic primitive",
3374 "-tint value tint the image with the fill color",
3375 "-transform affine transform image",
3376 "-transparent color make this color transparent within the image",
3377 "-transpose flip image vertically and rotate 90 degrees",
3378 "-transverse flop image horizontally and rotate 270 degrees",
3379 "-trim trim image edges",
3380 "-type type image type",
3381 "-unique-colors discard all but one of any pixel color",
3382 "-unsharp geometry sharpen the image",
3383 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003384 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003385 "-white-threshold value",
3386 " force all pixels above the threshold into white",
3387 (char *) NULL
3388 },
3389 *sequence_operators[]=
3390 {
cristy4285d782011-02-09 20:12:28 +00003391 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003392 "-clut apply a color lookup table to the image",
3393 "-coalesce merge a sequence of images",
3394 "-combine combine a sequence of images",
3395 "-composite composite image",
3396 "-crop geometry cut out a rectangular region of the image",
3397 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003398 "-evaluate-sequence operator",
3399 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003400 "-flatten flatten a sequence of images",
3401 "-fx expression apply mathematical expression to an image channel(s)",
3402 "-hald-clut apply a Hald color lookup table to the image",
3403 "-morph value morph an image sequence",
3404 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003405 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003406 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003407 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003408 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003409 "-write filename write images to this file",
3410 (char *) NULL
3411 },
3412 *settings[]=
3413 {
3414 "-adjoin join images into a single multi-image file",
3415 "-affine matrix affine transform matrix",
3416 "-alpha option activate, deactivate, reset, or set the alpha channel",
3417 "-antialias remove pixel-aliasing",
3418 "-authenticate password",
3419 " decipher image with this password",
3420 "-attenuate value lessen (or intensify) when adding noise to an image",
3421 "-background color background color",
3422 "-bias value add bias when convolving an image",
3423 "-black-point-compensation",
3424 " use black point compensation",
3425 "-blue-primary point chromaticity blue primary point",
3426 "-bordercolor color border color",
3427 "-caption string assign a caption to an image",
3428 "-channel type apply option to select image channels",
3429 "-colors value preferred number of colors in the image",
3430 "-colorspace type alternate image colorspace",
3431 "-comment string annotate image with comment",
3432 "-compose operator set image composite operator",
3433 "-compress type type of pixel compression when writing the image",
3434 "-define format:option",
3435 " define one or more image format options",
3436 "-delay value display the next image after pausing",
3437 "-density geometry horizontal and vertical density of the image",
3438 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003439 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003440 "-display server get image or font from this X server",
3441 "-dispose method layer disposal method",
3442 "-dither method apply error diffusion to image",
3443 "-encoding type text encoding type",
3444 "-endian type endianness (MSB or LSB) of the image",
3445 "-family name render text with this font family",
3446 "-fill color color to use when filling a graphic primitive",
3447 "-filter type use this filter when resizing an image",
3448 "-font name render text with this font",
3449 "-format \"string\" output formatted image characteristics",
3450 "-fuzz distance colors within this distance are considered equal",
3451 "-gravity type horizontal and vertical text placement",
3452 "-green-primary point chromaticity green primary point",
3453 "-intent type type of rendering intent when managing the image color",
3454 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003455 "-interline-spacing value",
3456 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003457 "-interpolate method pixel color interpolation method",
3458 "-interword-spacing value",
3459 " set the space between two words",
3460 "-kerning value set the space between two letters",
3461 "-label string assign a label to an image",
3462 "-limit type value pixel cache resource limit",
3463 "-loop iterations add Netscape loop extension to your GIF animation",
3464 "-mask filename associate a mask with the image",
3465 "-mattecolor color frame color",
3466 "-monitor monitor progress",
3467 "-orient type image orientation",
3468 "-page geometry size and location of an image canvas (setting)",
3469 "-ping efficiently determine image attributes",
3470 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003471 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003472 "-preview type image preview type",
3473 "-quality value JPEG/MIFF/PNG compression level",
3474 "-quiet suppress all warning messages",
3475 "-red-primary point chromaticity red primary point",
3476 "-regard-warnings pay attention to warning messages",
3477 "-remap filename transform image colors to match this set of colors",
3478 "-respect-parentheses settings remain in effect until parenthesis boundary",
3479 "-sampling-factor geometry",
3480 " horizontal and vertical sampling factor",
3481 "-scene value image scene number",
3482 "-seed value seed a new sequence of pseudo-random numbers",
3483 "-size geometry width and height of image",
3484 "-stretch type render text with this font stretch",
3485 "-stroke color graphic primitive stroke color",
3486 "-strokewidth value graphic primitive stroke width",
3487 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003488 "-synchronize synchronize image to storage device",
3489 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003490 "-texture filename name of texture to tile onto the image background",
3491 "-tile-offset geometry",
3492 " tile offset",
3493 "-treedepth value color tree depth",
3494 "-transparent-color color",
3495 " transparent color",
3496 "-undercolor color annotation bounding box color",
3497 "-units type the units of image resolution",
3498 "-verbose print detailed information about the image",
3499 "-view FlashPix viewing transforms",
3500 "-virtual-pixel method",
3501 " virtual pixel access method",
3502 "-weight type render text with this font weight",
3503 "-white-point point chromaticity white point",
3504 (char *) NULL
3505 },
3506 *stack_operators[]=
3507 {
anthonyb69c4b32011-03-23 04:37:44 +00003508 "-delete indexes delete the image from the image sequence",
3509 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003510 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003511 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003512 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003513 "-swap indexes swap two images in the image sequence",
3514 (char *) NULL
3515 };
3516
3517 const char
3518 **p;
3519
cristybb503372010-05-27 20:51:26 +00003520 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003521 (void) printf("Copyright: %s\n",GetMagickCopyright());
3522 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003523 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3524 GetClientName());
3525 (void) printf("\nImage Settings:\n");
3526 for (p=settings; *p != (char *) NULL; p++)
3527 (void) printf(" %s\n",*p);
3528 (void) printf("\nImage Operators:\n");
3529 for (p=operators; *p != (char *) NULL; p++)
3530 (void) printf(" %s\n",*p);
3531 (void) printf("\nImage Sequence Operators:\n");
3532 for (p=sequence_operators; *p != (char *) NULL; p++)
3533 (void) printf(" %s\n",*p);
3534 (void) printf("\nImage Stack Operators:\n");
3535 for (p=stack_operators; *p != (char *) NULL; p++)
3536 (void) printf(" %s\n",*p);
3537 (void) printf("\nMiscellaneous Options:\n");
3538 for (p=miscellaneous; *p != (char *) NULL; p++)
3539 (void) printf(" %s\n",*p);
3540 (void) printf(
3541 "\nBy default, the image format of `file' is determined by its magic\n");
3542 (void) printf(
3543 "number. To specify a particular image format, precede the filename\n");
3544 (void) printf(
3545 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3546 (void) printf(
3547 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3548 (void) printf("'-' for standard input or output.\n");
3549 return(MagickFalse);
3550}
3551
3552WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3553 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3554{
3555#define DestroyMogrify() \
3556{ \
3557 if (format != (char *) NULL) \
3558 format=DestroyString(format); \
3559 if (path != (char *) NULL) \
3560 path=DestroyString(path); \
3561 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003562 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003563 argv[i]=DestroyString(argv[i]); \
3564 argv=(char **) RelinquishMagickMemory(argv); \
3565}
3566#define ThrowMogrifyException(asperity,tag,option) \
3567{ \
3568 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3569 option); \
3570 DestroyMogrify(); \
3571 return(MagickFalse); \
3572}
3573#define ThrowMogrifyInvalidArgumentException(option,argument) \
3574{ \
3575 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3576 "InvalidArgument","`%s': %s",argument,option); \
3577 DestroyMogrify(); \
3578 return(MagickFalse); \
3579}
3580
3581 char
3582 *format,
3583 *option,
3584 *path;
3585
3586 Image
3587 *image;
3588
3589 ImageStack
3590 image_stack[MaxImageStackDepth+1];
3591
cristy3ed852e2009-09-05 21:47:34 +00003592 MagickBooleanType
3593 global_colormap;
3594
3595 MagickBooleanType
3596 fire,
cristyebbcfea2011-02-25 02:43:54 +00003597 pend,
3598 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003599
3600 MagickStatusType
3601 status;
3602
cristyebbcfea2011-02-25 02:43:54 +00003603 register ssize_t
3604 i;
3605
3606 ssize_t
3607 j,
3608 k;
3609
cristy3ed852e2009-09-05 21:47:34 +00003610 /*
3611 Set defaults.
3612 */
3613 assert(image_info != (ImageInfo *) NULL);
3614 assert(image_info->signature == MagickSignature);
3615 if (image_info->debug != MagickFalse)
3616 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3617 assert(exception != (ExceptionInfo *) NULL);
3618 if (argc == 2)
3619 {
3620 option=argv[1];
3621 if ((LocaleCompare("version",option+1) == 0) ||
3622 (LocaleCompare("-version",option+1) == 0))
3623 {
3624 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003625 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003626 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
3627 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003628 return(MagickFalse);
3629 }
3630 }
3631 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003632 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003633 format=(char *) NULL;
3634 path=(char *) NULL;
3635 global_colormap=MagickFalse;
3636 k=0;
3637 j=1;
3638 NewImageStack();
3639 option=(char *) NULL;
3640 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003641 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003642 status=MagickTrue;
3643 /*
3644 Parse command line.
3645 */
3646 ReadCommandlLine(argc,&argv);
3647 status=ExpandFilenames(&argc,&argv);
3648 if (status == MagickFalse)
3649 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3650 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003651 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003652 {
3653 option=argv[i];
3654 if (LocaleCompare(option,"(") == 0)
3655 {
3656 FireImageStack(MagickFalse,MagickTrue,pend);
3657 if (k == MaxImageStackDepth)
3658 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3659 option);
3660 PushImageStack();
3661 continue;
3662 }
3663 if (LocaleCompare(option,")") == 0)
3664 {
3665 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3666 if (k == 0)
3667 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3668 PopImageStack();
3669 continue;
3670 }
3671 if (IsMagickOption(option) == MagickFalse)
3672 {
3673 char
3674 backup_filename[MaxTextExtent],
3675 *filename;
3676
3677 Image
3678 *images;
3679
3680 /*
3681 Option is a file name: begin by reading image from specified file.
3682 */
3683 FireImageStack(MagickFalse,MagickFalse,pend);
3684 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003685 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003686 filename=argv[++i];
3687 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3688 images=ReadImages(image_info,exception);
3689 status&=(images != (Image *) NULL) &&
3690 (exception->severity < ErrorException);
3691 if (images == (Image *) NULL)
3692 continue;
cristydaa76602010-06-30 13:05:11 +00003693 if (format != (char *) NULL)
3694 (void) CopyMagickString(images->filename,images->magick_filename,
3695 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003696 if (path != (char *) NULL)
3697 {
3698 GetPathComponent(option,TailPath,filename);
3699 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
3700 path,*DirectorySeparator,filename);
3701 }
3702 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003703 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003704 AppendImageStack(images);
3705 FinalizeImageSettings(image_info,image,MagickFalse);
3706 if (global_colormap != MagickFalse)
3707 {
3708 QuantizeInfo
3709 *quantize_info;
3710
3711 quantize_info=AcquireQuantizeInfo(image_info);
3712 (void) RemapImages(quantize_info,images,(Image *) NULL);
3713 quantize_info=DestroyQuantizeInfo(quantize_info);
3714 }
3715 *backup_filename='\0';
3716 if ((LocaleCompare(image->filename,"-") != 0) &&
3717 (IsPathWritable(image->filename) != MagickFalse))
3718 {
cristybb503372010-05-27 20:51:26 +00003719 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003720 i;
3721
3722 /*
3723 Rename image file as backup.
3724 */
3725 (void) CopyMagickString(backup_filename,image->filename,
3726 MaxTextExtent);
3727 for (i=0; i < 6; i++)
3728 {
3729 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3730 if (IsPathAccessible(backup_filename) == MagickFalse)
3731 break;
3732 }
3733 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3734 (rename(image->filename,backup_filename) != 0))
3735 *backup_filename='\0';
3736 }
3737 /*
3738 Write transmogrified image to disk.
3739 */
3740 image_info->synchronize=MagickTrue;
3741 status&=WriteImages(image_info,image,image->filename,exception);
3742 if ((status == MagickFalse) && (*backup_filename != '\0'))
3743 (void) remove(backup_filename);
3744 RemoveAllImageStack();
3745 continue;
3746 }
3747 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3748 switch (*(option+1))
3749 {
3750 case 'a':
3751 {
3752 if (LocaleCompare("adaptive-blur",option+1) == 0)
3753 {
3754 i++;
cristybb503372010-05-27 20:51:26 +00003755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003756 ThrowMogrifyException(OptionError,"MissingArgument",option);
3757 if (IsGeometry(argv[i]) == MagickFalse)
3758 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3759 break;
3760 }
3761 if (LocaleCompare("adaptive-resize",option+1) == 0)
3762 {
3763 i++;
cristybb503372010-05-27 20:51:26 +00003764 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003765 ThrowMogrifyException(OptionError,"MissingArgument",option);
3766 if (IsGeometry(argv[i]) == MagickFalse)
3767 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3768 break;
3769 }
3770 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3771 {
3772 i++;
cristybb503372010-05-27 20:51:26 +00003773 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003774 ThrowMogrifyException(OptionError,"MissingArgument",option);
3775 if (IsGeometry(argv[i]) == MagickFalse)
3776 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3777 break;
3778 }
3779 if (LocaleCompare("affine",option+1) == 0)
3780 {
3781 if (*option == '+')
3782 break;
3783 i++;
cristybb503372010-05-27 20:51:26 +00003784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003785 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003786 break;
3787 }
3788 if (LocaleCompare("alpha",option+1) == 0)
3789 {
cristybb503372010-05-27 20:51:26 +00003790 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003791 type;
3792
3793 if (*option == '+')
3794 break;
3795 i++;
cristybb503372010-05-27 20:51:26 +00003796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003797 ThrowMogrifyException(OptionError,"MissingArgument",option);
3798 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
3799 if (type < 0)
3800 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3801 argv[i]);
3802 break;
3803 }
3804 if (LocaleCompare("annotate",option+1) == 0)
3805 {
3806 if (*option == '+')
3807 break;
3808 i++;
cristybb503372010-05-27 20:51:26 +00003809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003810 ThrowMogrifyException(OptionError,"MissingArgument",option);
3811 if (IsGeometry(argv[i]) == MagickFalse)
3812 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003814 ThrowMogrifyException(OptionError,"MissingArgument",option);
3815 i++;
3816 break;
3817 }
3818 if (LocaleCompare("antialias",option+1) == 0)
3819 break;
3820 if (LocaleCompare("append",option+1) == 0)
3821 break;
3822 if (LocaleCompare("attenuate",option+1) == 0)
3823 {
3824 if (*option == '+')
3825 break;
3826 i++;
cristybb503372010-05-27 20:51:26 +00003827 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003828 ThrowMogrifyException(OptionError,"MissingArgument",option);
3829 if (IsGeometry(argv[i]) == MagickFalse)
3830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3831 break;
3832 }
3833 if (LocaleCompare("authenticate",option+1) == 0)
3834 {
3835 if (*option == '+')
3836 break;
3837 i++;
cristybb503372010-05-27 20:51:26 +00003838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003839 ThrowMogrifyException(OptionError,"MissingArgument",option);
3840 break;
3841 }
3842 if (LocaleCompare("auto-gamma",option+1) == 0)
3843 break;
3844 if (LocaleCompare("auto-level",option+1) == 0)
3845 break;
3846 if (LocaleCompare("auto-orient",option+1) == 0)
3847 break;
3848 if (LocaleCompare("average",option+1) == 0)
3849 break;
3850 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3851 }
3852 case 'b':
3853 {
3854 if (LocaleCompare("background",option+1) == 0)
3855 {
3856 if (*option == '+')
3857 break;
3858 i++;
cristybb503372010-05-27 20:51:26 +00003859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003860 ThrowMogrifyException(OptionError,"MissingArgument",option);
3861 break;
3862 }
3863 if (LocaleCompare("bias",option+1) == 0)
3864 {
3865 if (*option == '+')
3866 break;
3867 i++;
cristybb503372010-05-27 20:51:26 +00003868 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003869 ThrowMogrifyException(OptionError,"MissingArgument",option);
3870 if (IsGeometry(argv[i]) == MagickFalse)
3871 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3872 break;
3873 }
3874 if (LocaleCompare("black-point-compensation",option+1) == 0)
3875 break;
3876 if (LocaleCompare("black-threshold",option+1) == 0)
3877 {
3878 if (*option == '+')
3879 break;
3880 i++;
cristybb503372010-05-27 20:51:26 +00003881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003882 ThrowMogrifyException(OptionError,"MissingArgument",option);
3883 if (IsGeometry(argv[i]) == MagickFalse)
3884 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3885 break;
3886 }
3887 if (LocaleCompare("blue-primary",option+1) == 0)
3888 {
3889 if (*option == '+')
3890 break;
3891 i++;
cristybb503372010-05-27 20:51:26 +00003892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003893 ThrowMogrifyException(OptionError,"MissingArgument",option);
3894 if (IsGeometry(argv[i]) == MagickFalse)
3895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3896 break;
3897 }
3898 if (LocaleCompare("blue-shift",option+1) == 0)
3899 {
3900 i++;
cristybb503372010-05-27 20:51:26 +00003901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003902 ThrowMogrifyException(OptionError,"MissingArgument",option);
3903 if (IsGeometry(argv[i]) == MagickFalse)
3904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3905 break;
3906 }
3907 if (LocaleCompare("blur",option+1) == 0)
3908 {
3909 i++;
cristybb503372010-05-27 20:51:26 +00003910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003911 ThrowMogrifyException(OptionError,"MissingArgument",option);
3912 if (IsGeometry(argv[i]) == MagickFalse)
3913 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3914 break;
3915 }
3916 if (LocaleCompare("border",option+1) == 0)
3917 {
3918 if (*option == '+')
3919 break;
3920 i++;
cristybb503372010-05-27 20:51:26 +00003921 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003922 ThrowMogrifyException(OptionError,"MissingArgument",option);
3923 if (IsGeometry(argv[i]) == MagickFalse)
3924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3925 break;
3926 }
3927 if (LocaleCompare("bordercolor",option+1) == 0)
3928 {
3929 if (*option == '+')
3930 break;
3931 i++;
cristybb503372010-05-27 20:51:26 +00003932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003933 ThrowMogrifyException(OptionError,"MissingArgument",option);
3934 break;
3935 }
3936 if (LocaleCompare("box",option+1) == 0)
3937 {
3938 if (*option == '+')
3939 break;
3940 i++;
cristybb503372010-05-27 20:51:26 +00003941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003942 ThrowMogrifyException(OptionError,"MissingArgument",option);
3943 break;
3944 }
cristya28d6b82010-01-11 20:03:47 +00003945 if (LocaleCompare("brightness-contrast",option+1) == 0)
3946 {
3947 i++;
cristybb503372010-05-27 20:51:26 +00003948 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003949 ThrowMogrifyException(OptionError,"MissingArgument",option);
3950 if (IsGeometry(argv[i]) == MagickFalse)
3951 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3952 break;
3953 }
cristy3ed852e2009-09-05 21:47:34 +00003954 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3955 }
3956 case 'c':
3957 {
3958 if (LocaleCompare("cache",option+1) == 0)
3959 {
3960 if (*option == '+')
3961 break;
3962 i++;
cristybb503372010-05-27 20:51:26 +00003963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003964 ThrowMogrifyException(OptionError,"MissingArgument",option);
3965 if (IsGeometry(argv[i]) == MagickFalse)
3966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3967 break;
3968 }
3969 if (LocaleCompare("caption",option+1) == 0)
3970 {
3971 if (*option == '+')
3972 break;
3973 i++;
cristybb503372010-05-27 20:51:26 +00003974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003975 ThrowMogrifyException(OptionError,"MissingArgument",option);
3976 break;
3977 }
3978 if (LocaleCompare("channel",option+1) == 0)
3979 {
cristybb503372010-05-27 20:51:26 +00003980 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003981 channel;
3982
3983 if (*option == '+')
3984 break;
3985 i++;
cristybb503372010-05-27 20:51:26 +00003986 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003987 ThrowMogrifyException(OptionError,"MissingArgument",option);
3988 channel=ParseChannelOption(argv[i]);
3989 if (channel < 0)
3990 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3991 argv[i]);
3992 break;
3993 }
3994 if (LocaleCompare("cdl",option+1) == 0)
3995 {
3996 if (*option == '+')
3997 break;
3998 i++;
cristybb503372010-05-27 20:51:26 +00003999 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004000 ThrowMogrifyException(OptionError,"MissingArgument",option);
4001 break;
4002 }
4003 if (LocaleCompare("charcoal",option+1) == 0)
4004 {
4005 if (*option == '+')
4006 break;
4007 i++;
cristybb503372010-05-27 20:51:26 +00004008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004009 ThrowMogrifyException(OptionError,"MissingArgument",option);
4010 if (IsGeometry(argv[i]) == MagickFalse)
4011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4012 break;
4013 }
4014 if (LocaleCompare("chop",option+1) == 0)
4015 {
4016 if (*option == '+')
4017 break;
4018 i++;
cristybb503372010-05-27 20:51:26 +00004019 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004020 ThrowMogrifyException(OptionError,"MissingArgument",option);
4021 if (IsGeometry(argv[i]) == MagickFalse)
4022 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4023 break;
4024 }
cristy1eb45dd2009-09-25 16:38:06 +00004025 if (LocaleCompare("clamp",option+1) == 0)
4026 break;
4027 if (LocaleCompare("clip",option+1) == 0)
4028 break;
cristy3ed852e2009-09-05 21:47:34 +00004029 if (LocaleCompare("clip-mask",option+1) == 0)
4030 {
4031 if (*option == '+')
4032 break;
4033 i++;
cristybb503372010-05-27 20:51:26 +00004034 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004035 ThrowMogrifyException(OptionError,"MissingArgument",option);
4036 break;
4037 }
4038 if (LocaleCompare("clut",option+1) == 0)
4039 break;
4040 if (LocaleCompare("coalesce",option+1) == 0)
4041 break;
4042 if (LocaleCompare("colorize",option+1) == 0)
4043 {
4044 if (*option == '+')
4045 break;
4046 i++;
cristybb503372010-05-27 20:51:26 +00004047 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004048 ThrowMogrifyException(OptionError,"MissingArgument",option);
4049 if (IsGeometry(argv[i]) == MagickFalse)
4050 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4051 break;
4052 }
cristye6365592010-04-02 17:31:23 +00004053 if (LocaleCompare("color-matrix",option+1) == 0)
4054 {
cristyb6bd4ad2010-08-08 01:12:27 +00004055 KernelInfo
4056 *kernel_info;
4057
cristye6365592010-04-02 17:31:23 +00004058 if (*option == '+')
4059 break;
4060 i++;
cristybb503372010-05-27 20:51:26 +00004061 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004062 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004063 kernel_info=AcquireKernelInfo(argv[i]);
4064 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004065 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004066 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004067 break;
4068 }
cristy3ed852e2009-09-05 21:47:34 +00004069 if (LocaleCompare("colors",option+1) == 0)
4070 {
4071 if (*option == '+')
4072 break;
4073 i++;
cristybb503372010-05-27 20:51:26 +00004074 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004075 ThrowMogrifyException(OptionError,"MissingArgument",option);
4076 if (IsGeometry(argv[i]) == MagickFalse)
4077 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4078 break;
4079 }
4080 if (LocaleCompare("colorspace",option+1) == 0)
4081 {
cristybb503372010-05-27 20:51:26 +00004082 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004083 colorspace;
4084
4085 if (*option == '+')
4086 break;
4087 i++;
cristybb503372010-05-27 20:51:26 +00004088 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004089 ThrowMogrifyException(OptionError,"MissingArgument",option);
4090 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4091 argv[i]);
4092 if (colorspace < 0)
4093 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4094 argv[i]);
4095 break;
4096 }
4097 if (LocaleCompare("combine",option+1) == 0)
4098 break;
4099 if (LocaleCompare("comment",option+1) == 0)
4100 {
4101 if (*option == '+')
4102 break;
4103 i++;
cristybb503372010-05-27 20:51:26 +00004104 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004105 ThrowMogrifyException(OptionError,"MissingArgument",option);
4106 break;
4107 }
4108 if (LocaleCompare("composite",option+1) == 0)
4109 break;
4110 if (LocaleCompare("compress",option+1) == 0)
4111 {
cristybb503372010-05-27 20:51:26 +00004112 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004113 compress;
4114
4115 if (*option == '+')
4116 break;
4117 i++;
cristybb503372010-05-27 20:51:26 +00004118 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004119 ThrowMogrifyException(OptionError,"MissingArgument",option);
4120 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4121 argv[i]);
4122 if (compress < 0)
4123 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4124 argv[i]);
4125 break;
4126 }
cristy22879752009-10-25 23:55:40 +00004127 if (LocaleCompare("concurrent",option+1) == 0)
4128 break;
cristy3ed852e2009-09-05 21:47:34 +00004129 if (LocaleCompare("contrast",option+1) == 0)
4130 break;
4131 if (LocaleCompare("contrast-stretch",option+1) == 0)
4132 {
4133 i++;
cristybb503372010-05-27 20:51:26 +00004134 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004135 ThrowMogrifyException(OptionError,"MissingArgument",option);
4136 if (IsGeometry(argv[i]) == MagickFalse)
4137 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4138 break;
4139 }
4140 if (LocaleCompare("convolve",option+1) == 0)
4141 {
cristyb6bd4ad2010-08-08 01:12:27 +00004142 KernelInfo
4143 *kernel_info;
4144
cristy3ed852e2009-09-05 21:47:34 +00004145 if (*option == '+')
4146 break;
4147 i++;
cristybb503372010-05-27 20:51:26 +00004148 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004149 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004150 kernel_info=AcquireKernelInfo(argv[i]);
4151 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004152 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004153 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004154 break;
4155 }
4156 if (LocaleCompare("crop",option+1) == 0)
4157 {
4158 if (*option == '+')
4159 break;
4160 i++;
cristybb503372010-05-27 20:51:26 +00004161 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004162 ThrowMogrifyException(OptionError,"MissingArgument",option);
4163 if (IsGeometry(argv[i]) == MagickFalse)
4164 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4165 break;
4166 }
4167 if (LocaleCompare("cycle",option+1) == 0)
4168 {
4169 if (*option == '+')
4170 break;
4171 i++;
cristybb503372010-05-27 20:51:26 +00004172 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004173 ThrowMogrifyException(OptionError,"MissingArgument",option);
4174 if (IsGeometry(argv[i]) == MagickFalse)
4175 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4176 break;
4177 }
4178 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4179 }
4180 case 'd':
4181 {
4182 if (LocaleCompare("decipher",option+1) == 0)
4183 {
4184 if (*option == '+')
4185 break;
4186 i++;
cristybb503372010-05-27 20:51:26 +00004187 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004188 ThrowMogrifyException(OptionError,"MissingArgument",option);
4189 break;
4190 }
4191 if (LocaleCompare("deconstruct",option+1) == 0)
4192 break;
4193 if (LocaleCompare("debug",option+1) == 0)
4194 {
cristybb503372010-05-27 20:51:26 +00004195 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004196 event;
4197
4198 if (*option == '+')
4199 break;
4200 i++;
cristybb503372010-05-27 20:51:26 +00004201 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004202 ThrowMogrifyException(OptionError,"MissingArgument",option);
4203 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4204 if (event < 0)
4205 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4206 argv[i]);
4207 (void) SetLogEventMask(argv[i]);
4208 break;
4209 }
4210 if (LocaleCompare("define",option+1) == 0)
4211 {
4212 i++;
cristybb503372010-05-27 20:51:26 +00004213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004214 ThrowMogrifyException(OptionError,"MissingArgument",option);
4215 if (*option == '+')
4216 {
4217 const char
4218 *define;
4219
4220 define=GetImageOption(image_info,argv[i]);
4221 if (define == (const char *) NULL)
4222 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4223 break;
4224 }
4225 break;
4226 }
4227 if (LocaleCompare("delay",option+1) == 0)
4228 {
4229 if (*option == '+')
4230 break;
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 (IsGeometry(argv[i]) == MagickFalse)
4235 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4236 break;
4237 }
cristyecb10ff2011-03-22 13:14:03 +00004238 if (LocaleCompare("delete",option+1) == 0)
4239 {
4240 if (*option == '+')
4241 break;
4242 i++;
4243 if (i == (ssize_t) (argc-1))
4244 ThrowMogrifyException(OptionError,"MissingArgument",option);
4245 if (IsGeometry(argv[i]) == MagickFalse)
4246 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4247 break;
4248 }
cristy3ed852e2009-09-05 21:47:34 +00004249 if (LocaleCompare("density",option+1) == 0)
4250 {
4251 if (*option == '+')
4252 break;
4253 i++;
cristybb503372010-05-27 20:51:26 +00004254 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004255 ThrowMogrifyException(OptionError,"MissingArgument",option);
4256 if (IsGeometry(argv[i]) == MagickFalse)
4257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4258 break;
4259 }
4260 if (LocaleCompare("depth",option+1) == 0)
4261 {
4262 if (*option == '+')
4263 break;
4264 i++;
cristybb503372010-05-27 20:51:26 +00004265 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004266 ThrowMogrifyException(OptionError,"MissingArgument",option);
4267 if (IsGeometry(argv[i]) == MagickFalse)
4268 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4269 break;
4270 }
4271 if (LocaleCompare("deskew",option+1) == 0)
4272 {
4273 if (*option == '+')
4274 break;
4275 i++;
cristybb503372010-05-27 20:51:26 +00004276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004277 ThrowMogrifyException(OptionError,"MissingArgument",option);
4278 if (IsGeometry(argv[i]) == MagickFalse)
4279 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4280 break;
4281 }
4282 if (LocaleCompare("despeckle",option+1) == 0)
4283 break;
4284 if (LocaleCompare("dft",option+1) == 0)
4285 break;
cristyc9b12952010-03-28 01:12:28 +00004286 if (LocaleCompare("direction",option+1) == 0)
4287 {
cristybb503372010-05-27 20:51:26 +00004288 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004289 direction;
4290
4291 if (*option == '+')
4292 break;
4293 i++;
cristybb503372010-05-27 20:51:26 +00004294 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004295 ThrowMogrifyException(OptionError,"MissingArgument",option);
4296 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4297 argv[i]);
4298 if (direction < 0)
4299 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4300 argv[i]);
4301 break;
4302 }
cristy3ed852e2009-09-05 21:47:34 +00004303 if (LocaleCompare("display",option+1) == 0)
4304 {
4305 if (*option == '+')
4306 break;
4307 i++;
cristybb503372010-05-27 20:51:26 +00004308 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004309 ThrowMogrifyException(OptionError,"MissingArgument",option);
4310 break;
4311 }
4312 if (LocaleCompare("dispose",option+1) == 0)
4313 {
cristybb503372010-05-27 20:51:26 +00004314 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004315 dispose;
4316
4317 if (*option == '+')
4318 break;
4319 i++;
cristybb503372010-05-27 20:51:26 +00004320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004321 ThrowMogrifyException(OptionError,"MissingArgument",option);
4322 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4323 if (dispose < 0)
4324 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4325 argv[i]);
4326 break;
4327 }
4328 if (LocaleCompare("distort",option+1) == 0)
4329 {
cristybb503372010-05-27 20:51:26 +00004330 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004331 op;
4332
4333 i++;
cristybb503372010-05-27 20:51:26 +00004334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004335 ThrowMogrifyException(OptionError,"MissingArgument",option);
4336 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4337 if (op < 0)
4338 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4339 argv[i]);
4340 i++;
cristybb503372010-05-27 20:51:26 +00004341 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004342 ThrowMogrifyException(OptionError,"MissingArgument",option);
4343 break;
4344 }
4345 if (LocaleCompare("dither",option+1) == 0)
4346 {
cristybb503372010-05-27 20:51:26 +00004347 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004348 method;
4349
4350 if (*option == '+')
4351 break;
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 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4356 if (method < 0)
4357 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4358 argv[i]);
4359 break;
4360 }
4361 if (LocaleCompare("draw",option+1) == 0)
4362 {
4363 if (*option == '+')
4364 break;
4365 i++;
cristybb503372010-05-27 20:51:26 +00004366 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004367 ThrowMogrifyException(OptionError,"MissingArgument",option);
4368 break;
4369 }
cristyecb10ff2011-03-22 13:14:03 +00004370 if (LocaleCompare("duplicate",option+1) == 0)
4371 {
4372 if (*option == '+')
4373 break;
4374 i++;
4375 if (i == (ssize_t) (argc-1))
4376 ThrowMogrifyException(OptionError,"MissingArgument",option);
4377 if (IsGeometry(argv[i]) == MagickFalse)
4378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4379 break;
4380 }
cristy22879752009-10-25 23:55:40 +00004381 if (LocaleCompare("duration",option+1) == 0)
4382 {
4383 if (*option == '+')
4384 break;
4385 i++;
cristybb503372010-05-27 20:51:26 +00004386 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004387 ThrowMogrifyException(OptionError,"MissingArgument",option);
4388 if (IsGeometry(argv[i]) == MagickFalse)
4389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4390 break;
4391 }
cristy3ed852e2009-09-05 21:47:34 +00004392 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4393 }
4394 case 'e':
4395 {
4396 if (LocaleCompare("edge",option+1) == 0)
4397 {
4398 if (*option == '+')
4399 break;
4400 i++;
cristybb503372010-05-27 20:51:26 +00004401 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004402 ThrowMogrifyException(OptionError,"MissingArgument",option);
4403 if (IsGeometry(argv[i]) == MagickFalse)
4404 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4405 break;
4406 }
4407 if (LocaleCompare("emboss",option+1) == 0)
4408 {
4409 if (*option == '+')
4410 break;
4411 i++;
cristybb503372010-05-27 20:51:26 +00004412 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004413 ThrowMogrifyException(OptionError,"MissingArgument",option);
4414 if (IsGeometry(argv[i]) == MagickFalse)
4415 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4416 break;
4417 }
4418 if (LocaleCompare("encipher",option+1) == 0)
4419 {
4420 if (*option == '+')
4421 break;
4422 i++;
cristybb503372010-05-27 20:51:26 +00004423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004424 ThrowMogrifyException(OptionError,"MissingArgument",option);
4425 break;
4426 }
4427 if (LocaleCompare("encoding",option+1) == 0)
4428 {
4429 if (*option == '+')
4430 break;
4431 i++;
cristybb503372010-05-27 20:51:26 +00004432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004433 ThrowMogrifyException(OptionError,"MissingArgument",option);
4434 break;
4435 }
4436 if (LocaleCompare("endian",option+1) == 0)
4437 {
cristybb503372010-05-27 20:51:26 +00004438 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004439 endian;
4440
4441 if (*option == '+')
4442 break;
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
4446 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4447 if (endian < 0)
4448 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4449 argv[i]);
4450 break;
4451 }
4452 if (LocaleCompare("enhance",option+1) == 0)
4453 break;
4454 if (LocaleCompare("equalize",option+1) == 0)
4455 break;
4456 if (LocaleCompare("evaluate",option+1) == 0)
4457 {
cristybb503372010-05-27 20:51:26 +00004458 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004459 op;
4460
4461 if (*option == '+')
4462 break;
4463 i++;
cristybb503372010-05-27 20:51:26 +00004464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004465 ThrowMogrifyException(OptionError,"MissingArgument",option);
4466 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4467 if (op < 0)
4468 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4469 argv[i]);
4470 i++;
cristybb503372010-05-27 20:51:26 +00004471 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004472 ThrowMogrifyException(OptionError,"MissingArgument",option);
4473 if (IsGeometry(argv[i]) == MagickFalse)
4474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4475 break;
4476 }
cristyd18ae7c2010-03-07 17:39:52 +00004477 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4478 {
cristybb503372010-05-27 20:51:26 +00004479 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004480 op;
4481
4482 if (*option == '+')
4483 break;
4484 i++;
cristybb503372010-05-27 20:51:26 +00004485 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004486 ThrowMogrifyException(OptionError,"MissingArgument",option);
4487 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4488 if (op < 0)
4489 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4490 argv[i]);
4491 break;
4492 }
cristy3ed852e2009-09-05 21:47:34 +00004493 if (LocaleCompare("extent",option+1) == 0)
4494 {
4495 if (*option == '+')
4496 break;
4497 i++;
cristybb503372010-05-27 20:51:26 +00004498 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004499 ThrowMogrifyException(OptionError,"MissingArgument",option);
4500 if (IsGeometry(argv[i]) == MagickFalse)
4501 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4502 break;
4503 }
4504 if (LocaleCompare("extract",option+1) == 0)
4505 {
4506 if (*option == '+')
4507 break;
4508 i++;
cristybb503372010-05-27 20:51:26 +00004509 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004510 ThrowMogrifyException(OptionError,"MissingArgument",option);
4511 if (IsGeometry(argv[i]) == MagickFalse)
4512 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4513 break;
4514 }
4515 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4516 }
4517 case 'f':
4518 {
4519 if (LocaleCompare("family",option+1) == 0)
4520 {
4521 if (*option == '+')
4522 break;
4523 i++;
cristybb503372010-05-27 20:51:26 +00004524 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004525 ThrowMogrifyException(OptionError,"MissingArgument",option);
4526 break;
4527 }
4528 if (LocaleCompare("fill",option+1) == 0)
4529 {
4530 if (*option == '+')
4531 break;
4532 i++;
cristybb503372010-05-27 20:51:26 +00004533 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004534 ThrowMogrifyException(OptionError,"MissingArgument",option);
4535 break;
4536 }
4537 if (LocaleCompare("filter",option+1) == 0)
4538 {
cristybb503372010-05-27 20:51:26 +00004539 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004540 filter;
4541
4542 if (*option == '+')
4543 break;
4544 i++;
cristybb503372010-05-27 20:51:26 +00004545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004546 ThrowMogrifyException(OptionError,"MissingArgument",option);
4547 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4548 if (filter < 0)
4549 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4550 argv[i]);
4551 break;
4552 }
4553 if (LocaleCompare("flatten",option+1) == 0)
4554 break;
4555 if (LocaleCompare("flip",option+1) == 0)
4556 break;
4557 if (LocaleCompare("flop",option+1) == 0)
4558 break;
4559 if (LocaleCompare("floodfill",option+1) == 0)
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 if (IsGeometry(argv[i]) == MagickFalse)
4567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4568 i++;
cristybb503372010-05-27 20:51:26 +00004569 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004570 ThrowMogrifyException(OptionError,"MissingArgument",option);
4571 break;
4572 }
4573 if (LocaleCompare("font",option+1) == 0)
4574 {
4575 if (*option == '+')
4576 break;
4577 i++;
cristybb503372010-05-27 20:51:26 +00004578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004579 ThrowMogrifyException(OptionError,"MissingArgument",option);
4580 break;
4581 }
4582 if (LocaleCompare("format",option+1) == 0)
4583 {
4584 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4585 (void) CloneString(&format,(char *) NULL);
4586 if (*option == '+')
4587 break;
4588 i++;
cristybb503372010-05-27 20:51:26 +00004589 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004590 ThrowMogrifyException(OptionError,"MissingArgument",option);
4591 (void) CloneString(&format,argv[i]);
4592 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4593 (void) ConcatenateMagickString(image_info->filename,":",
4594 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004595 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004596 if (*image_info->magick == '\0')
4597 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4598 format);
4599 break;
4600 }
4601 if (LocaleCompare("frame",option+1) == 0)
4602 {
4603 if (*option == '+')
4604 break;
4605 i++;
cristybb503372010-05-27 20:51:26 +00004606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004607 ThrowMogrifyException(OptionError,"MissingArgument",option);
4608 if (IsGeometry(argv[i]) == MagickFalse)
4609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4610 break;
4611 }
4612 if (LocaleCompare("function",option+1) == 0)
4613 {
cristybb503372010-05-27 20:51:26 +00004614 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004615 op;
4616
4617 if (*option == '+')
4618 break;
4619 i++;
cristybb503372010-05-27 20:51:26 +00004620 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4623 if (op < 0)
4624 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4625 i++;
cristybb503372010-05-27 20:51:26 +00004626 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004627 ThrowMogrifyException(OptionError,"MissingArgument",option);
4628 break;
4629 }
4630 if (LocaleCompare("fuzz",option+1) == 0)
4631 {
4632 if (*option == '+')
4633 break;
4634 i++;
cristybb503372010-05-27 20:51:26 +00004635 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004636 ThrowMogrifyException(OptionError,"MissingArgument",option);
4637 if (IsGeometry(argv[i]) == MagickFalse)
4638 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4639 break;
4640 }
4641 if (LocaleCompare("fx",option+1) == 0)
4642 {
4643 if (*option == '+')
4644 break;
4645 i++;
cristybb503372010-05-27 20:51:26 +00004646 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004647 ThrowMogrifyException(OptionError,"MissingArgument",option);
4648 break;
4649 }
4650 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4651 }
4652 case 'g':
4653 {
4654 if (LocaleCompare("gamma",option+1) == 0)
4655 {
4656 i++;
cristybb503372010-05-27 20:51:26 +00004657 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004658 ThrowMogrifyException(OptionError,"MissingArgument",option);
4659 if (IsGeometry(argv[i]) == MagickFalse)
4660 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4661 break;
4662 }
4663 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4664 (LocaleCompare("gaussian",option+1) == 0))
4665 {
4666 i++;
cristybb503372010-05-27 20:51:26 +00004667 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004668 ThrowMogrifyException(OptionError,"MissingArgument",option);
4669 if (IsGeometry(argv[i]) == MagickFalse)
4670 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4671 break;
4672 }
4673 if (LocaleCompare("geometry",option+1) == 0)
4674 {
4675 if (*option == '+')
4676 break;
4677 i++;
cristybb503372010-05-27 20:51:26 +00004678 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004679 ThrowMogrifyException(OptionError,"MissingArgument",option);
4680 if (IsGeometry(argv[i]) == MagickFalse)
4681 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4682 break;
4683 }
4684 if (LocaleCompare("gravity",option+1) == 0)
4685 {
cristybb503372010-05-27 20:51:26 +00004686 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004687 gravity;
4688
4689 if (*option == '+')
4690 break;
4691 i++;
cristybb503372010-05-27 20:51:26 +00004692 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004693 ThrowMogrifyException(OptionError,"MissingArgument",option);
4694 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
4695 if (gravity < 0)
4696 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4697 argv[i]);
4698 break;
4699 }
4700 if (LocaleCompare("green-primary",option+1) == 0)
4701 {
4702 if (*option == '+')
4703 break;
4704 i++;
cristybb503372010-05-27 20:51:26 +00004705 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004706 ThrowMogrifyException(OptionError,"MissingArgument",option);
4707 if (IsGeometry(argv[i]) == MagickFalse)
4708 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4709 break;
4710 }
4711 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4712 }
4713 case 'h':
4714 {
4715 if (LocaleCompare("hald-clut",option+1) == 0)
4716 break;
4717 if ((LocaleCompare("help",option+1) == 0) ||
4718 (LocaleCompare("-help",option+1) == 0))
4719 return(MogrifyUsage());
4720 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4721 }
4722 case 'i':
4723 {
4724 if (LocaleCompare("identify",option+1) == 0)
4725 break;
4726 if (LocaleCompare("idft",option+1) == 0)
4727 break;
4728 if (LocaleCompare("implode",option+1) == 0)
4729 {
4730 if (*option == '+')
4731 break;
4732 i++;
cristybb503372010-05-27 20:51:26 +00004733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004734 ThrowMogrifyException(OptionError,"MissingArgument",option);
4735 if (IsGeometry(argv[i]) == MagickFalse)
4736 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4737 break;
4738 }
4739 if (LocaleCompare("intent",option+1) == 0)
4740 {
cristybb503372010-05-27 20:51:26 +00004741 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004742 intent;
4743
4744 if (*option == '+')
4745 break;
4746 i++;
cristybb503372010-05-27 20:51:26 +00004747 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004748 ThrowMogrifyException(OptionError,"MissingArgument",option);
4749 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
4750 if (intent < 0)
4751 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4752 argv[i]);
4753 break;
4754 }
4755 if (LocaleCompare("interlace",option+1) == 0)
4756 {
cristybb503372010-05-27 20:51:26 +00004757 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004758 interlace;
4759
4760 if (*option == '+')
4761 break;
4762 i++;
cristybb503372010-05-27 20:51:26 +00004763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004764 ThrowMogrifyException(OptionError,"MissingArgument",option);
4765 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
4766 argv[i]);
4767 if (interlace < 0)
4768 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4769 argv[i]);
4770 break;
4771 }
cristyb32b90a2009-09-07 21:45:48 +00004772 if (LocaleCompare("interline-spacing",option+1) == 0)
4773 {
4774 if (*option == '+')
4775 break;
4776 i++;
cristybb503372010-05-27 20:51:26 +00004777 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004778 ThrowMogrifyException(OptionError,"MissingArgument",option);
4779 if (IsGeometry(argv[i]) == MagickFalse)
4780 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4781 break;
4782 }
cristy3ed852e2009-09-05 21:47:34 +00004783 if (LocaleCompare("interpolate",option+1) == 0)
4784 {
cristybb503372010-05-27 20:51:26 +00004785 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004786 interpolate;
4787
4788 if (*option == '+')
4789 break;
4790 i++;
cristybb503372010-05-27 20:51:26 +00004791 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004792 ThrowMogrifyException(OptionError,"MissingArgument",option);
4793 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
4794 argv[i]);
4795 if (interpolate < 0)
4796 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4797 argv[i]);
4798 break;
4799 }
4800 if (LocaleCompare("interword-spacing",option+1) == 0)
4801 {
4802 if (*option == '+')
4803 break;
4804 i++;
cristybb503372010-05-27 20:51:26 +00004805 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004806 ThrowMogrifyException(OptionError,"MissingArgument",option);
4807 if (IsGeometry(argv[i]) == MagickFalse)
4808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4809 break;
4810 }
4811 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4812 }
4813 case 'k':
4814 {
4815 if (LocaleCompare("kerning",option+1) == 0)
4816 {
4817 if (*option == '+')
4818 break;
4819 i++;
cristybb503372010-05-27 20:51:26 +00004820 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004821 ThrowMogrifyException(OptionError,"MissingArgument",option);
4822 if (IsGeometry(argv[i]) == MagickFalse)
4823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4824 break;
4825 }
4826 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4827 }
4828 case 'l':
4829 {
4830 if (LocaleCompare("label",option+1) == 0)
4831 {
4832 if (*option == '+')
4833 break;
4834 i++;
cristybb503372010-05-27 20:51:26 +00004835 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004836 ThrowMogrifyException(OptionError,"MissingArgument",option);
4837 break;
4838 }
4839 if (LocaleCompare("lat",option+1) == 0)
4840 {
4841 if (*option == '+')
4842 break;
4843 i++;
cristybb503372010-05-27 20:51:26 +00004844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004845 ThrowMogrifyException(OptionError,"MissingArgument",option);
4846 if (IsGeometry(argv[i]) == MagickFalse)
4847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4848 }
4849 if (LocaleCompare("layers",option+1) == 0)
4850 {
cristybb503372010-05-27 20:51:26 +00004851 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004852 type;
4853
4854 if (*option == '+')
4855 break;
4856 i++;
cristybb503372010-05-27 20:51:26 +00004857 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004858 ThrowMogrifyException(OptionError,"MissingArgument",option);
4859 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
4860 if (type < 0)
4861 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4862 argv[i]);
4863 break;
4864 }
4865 if (LocaleCompare("level",option+1) == 0)
4866 {
4867 i++;
cristybb503372010-05-27 20:51:26 +00004868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004869 ThrowMogrifyException(OptionError,"MissingArgument",option);
4870 if (IsGeometry(argv[i]) == MagickFalse)
4871 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4872 break;
4873 }
4874 if (LocaleCompare("level-colors",option+1) == 0)
4875 {
4876 i++;
cristybb503372010-05-27 20:51:26 +00004877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004878 ThrowMogrifyException(OptionError,"MissingArgument",option);
4879 break;
4880 }
4881 if (LocaleCompare("linewidth",option+1) == 0)
4882 {
4883 if (*option == '+')
4884 break;
4885 i++;
cristybb503372010-05-27 20:51:26 +00004886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004887 ThrowMogrifyException(OptionError,"MissingArgument",option);
4888 if (IsGeometry(argv[i]) == MagickFalse)
4889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4890 break;
4891 }
4892 if (LocaleCompare("limit",option+1) == 0)
4893 {
4894 char
4895 *p;
4896
4897 double
4898 value;
4899
cristybb503372010-05-27 20:51:26 +00004900 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004901 resource;
4902
4903 if (*option == '+')
4904 break;
4905 i++;
cristybb503372010-05-27 20:51:26 +00004906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004907 ThrowMogrifyException(OptionError,"MissingArgument",option);
4908 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
4909 argv[i]);
4910 if (resource < 0)
4911 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4912 argv[i]);
4913 i++;
cristybb503372010-05-27 20:51:26 +00004914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004915 ThrowMogrifyException(OptionError,"MissingArgument",option);
4916 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004917 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004918 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4919 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4920 break;
4921 }
4922 if (LocaleCompare("liquid-rescale",option+1) == 0)
4923 {
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 if (IsGeometry(argv[i]) == MagickFalse)
4928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4929 break;
4930 }
4931 if (LocaleCompare("list",option+1) == 0)
4932 {
cristybb503372010-05-27 20:51:26 +00004933 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004934 list;
4935
4936 if (*option == '+')
4937 break;
4938 i++;
cristybb503372010-05-27 20:51:26 +00004939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004940 ThrowMogrifyException(OptionError,"MissingArgument",option);
4941 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
4942 if (list < 0)
4943 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004944 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004945 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004946 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004947 }
4948 if (LocaleCompare("log",option+1) == 0)
4949 {
4950 if (*option == '+')
4951 break;
4952 i++;
cristybb503372010-05-27 20:51:26 +00004953 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004954 (strchr(argv[i],'%') == (char *) NULL))
4955 ThrowMogrifyException(OptionError,"MissingArgument",option);
4956 break;
4957 }
4958 if (LocaleCompare("loop",option+1) == 0)
4959 {
4960 if (*option == '+')
4961 break;
4962 i++;
cristybb503372010-05-27 20:51:26 +00004963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004964 ThrowMogrifyException(OptionError,"MissingArgument",option);
4965 if (IsGeometry(argv[i]) == MagickFalse)
4966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4967 break;
4968 }
4969 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4970 }
4971 case 'm':
4972 {
4973 if (LocaleCompare("map",option+1) == 0)
4974 {
4975 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4976 if (*option == '+')
4977 break;
4978 i++;
cristybb503372010-05-27 20:51:26 +00004979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004980 ThrowMogrifyException(OptionError,"MissingArgument",option);
4981 break;
4982 }
4983 if (LocaleCompare("mask",option+1) == 0)
4984 {
4985 if (*option == '+')
4986 break;
4987 i++;
cristybb503372010-05-27 20:51:26 +00004988 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004989 ThrowMogrifyException(OptionError,"MissingArgument",option);
4990 break;
4991 }
4992 if (LocaleCompare("matte",option+1) == 0)
4993 break;
4994 if (LocaleCompare("mattecolor",option+1) == 0)
4995 {
4996 if (*option == '+')
4997 break;
4998 i++;
cristybb503372010-05-27 20:51:26 +00004999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005000 ThrowMogrifyException(OptionError,"MissingArgument",option);
5001 break;
5002 }
cristyf40785b2010-03-06 02:27:27 +00005003 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005004 break;
cristyf40785b2010-03-06 02:27:27 +00005005 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005006 break;
cristy3ed852e2009-09-05 21:47:34 +00005007 if (LocaleCompare("modulate",option+1) == 0)
5008 {
5009 if (*option == '+')
5010 break;
5011 i++;
cristybb503372010-05-27 20:51:26 +00005012 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005013 ThrowMogrifyException(OptionError,"MissingArgument",option);
5014 if (IsGeometry(argv[i]) == MagickFalse)
5015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5016 break;
5017 }
5018 if (LocaleCompare("median",option+1) == 0)
5019 {
5020 if (*option == '+')
5021 break;
5022 i++;
cristybb503372010-05-27 20:51:26 +00005023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005024 ThrowMogrifyException(OptionError,"MissingArgument",option);
5025 if (IsGeometry(argv[i]) == MagickFalse)
5026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5027 break;
5028 }
cristy69ec32d2011-02-27 23:57:09 +00005029 if (LocaleCompare("mode",option+1) == 0)
5030 {
5031 if (*option == '+')
5032 break;
5033 i++;
5034 if (i == (ssize_t) argc)
5035 ThrowMogrifyException(OptionError,"MissingArgument",option);
5036 if (IsGeometry(argv[i]) == MagickFalse)
5037 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5038 break;
5039 }
cristy3ed852e2009-09-05 21:47:34 +00005040 if (LocaleCompare("monitor",option+1) == 0)
5041 break;
5042 if (LocaleCompare("monochrome",option+1) == 0)
5043 break;
5044 if (LocaleCompare("morph",option+1) == 0)
5045 {
5046 if (*option == '+')
5047 break;
5048 i++;
cristybb503372010-05-27 20:51:26 +00005049 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005050 ThrowMogrifyException(OptionError,"MissingArgument",option);
5051 if (IsGeometry(argv[i]) == MagickFalse)
5052 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5053 break;
5054 }
anthony29188a82010-01-22 10:12:34 +00005055 if (LocaleCompare("morphology",option+1) == 0)
5056 {
anthony29188a82010-01-22 10:12:34 +00005057 char
5058 token[MaxTextExtent];
5059
cristyb6bd4ad2010-08-08 01:12:27 +00005060 KernelInfo
5061 *kernel_info;
5062
5063 ssize_t
5064 op;
5065
anthony29188a82010-01-22 10:12:34 +00005066 i++;
cristybb503372010-05-27 20:51:26 +00005067 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005068 ThrowMogrifyException(OptionError,"MissingArgument",option);
5069 GetMagickToken(argv[i],NULL,token);
5070 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5071 if (op < 0)
5072 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005073 token);
anthony29188a82010-01-22 10:12:34 +00005074 i++;
cristybb503372010-05-27 20:51:26 +00005075 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005076 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005077 kernel_info=AcquireKernelInfo(argv[i]);
5078 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005079 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005080 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005081 break;
5082 }
cristy3ed852e2009-09-05 21:47:34 +00005083 if (LocaleCompare("mosaic",option+1) == 0)
5084 break;
5085 if (LocaleCompare("motion-blur",option+1) == 0)
5086 {
5087 if (*option == '+')
5088 break;
5089 i++;
cristybb503372010-05-27 20:51:26 +00005090 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005091 ThrowMogrifyException(OptionError,"MissingArgument",option);
5092 if (IsGeometry(argv[i]) == MagickFalse)
5093 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5094 break;
5095 }
5096 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5097 }
5098 case 'n':
5099 {
5100 if (LocaleCompare("negate",option+1) == 0)
5101 break;
5102 if (LocaleCompare("noise",option+1) == 0)
5103 {
5104 i++;
cristybb503372010-05-27 20:51:26 +00005105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005106 ThrowMogrifyException(OptionError,"MissingArgument",option);
5107 if (*option == '+')
5108 {
cristybb503372010-05-27 20:51:26 +00005109 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005110 noise;
5111
5112 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5113 if (noise < 0)
5114 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5115 argv[i]);
5116 break;
5117 }
5118 if (IsGeometry(argv[i]) == MagickFalse)
5119 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5120 break;
5121 }
5122 if (LocaleCompare("noop",option+1) == 0)
5123 break;
5124 if (LocaleCompare("normalize",option+1) == 0)
5125 break;
5126 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5127 }
5128 case 'o':
5129 {
5130 if (LocaleCompare("opaque",option+1) == 0)
5131 {
cristy3ed852e2009-09-05 21:47:34 +00005132 i++;
cristybb503372010-05-27 20:51:26 +00005133 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005134 ThrowMogrifyException(OptionError,"MissingArgument",option);
5135 break;
5136 }
5137 if (LocaleCompare("ordered-dither",option+1) == 0)
5138 {
5139 if (*option == '+')
5140 break;
5141 i++;
cristybb503372010-05-27 20:51:26 +00005142 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005143 ThrowMogrifyException(OptionError,"MissingArgument",option);
5144 break;
5145 }
5146 if (LocaleCompare("orient",option+1) == 0)
5147 {
cristybb503372010-05-27 20:51:26 +00005148 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005149 orientation;
5150
5151 orientation=UndefinedOrientation;
5152 if (*option == '+')
5153 break;
5154 i++;
cristybb503372010-05-27 20:51:26 +00005155 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005156 ThrowMogrifyException(OptionError,"MissingArgument",option);
5157 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5158 argv[i]);
5159 if (orientation < 0)
5160 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5161 argv[i]);
5162 break;
5163 }
5164 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5165 }
5166 case 'p':
5167 {
5168 if (LocaleCompare("page",option+1) == 0)
5169 {
5170 if (*option == '+')
5171 break;
5172 i++;
cristybb503372010-05-27 20:51:26 +00005173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 break;
5176 }
5177 if (LocaleCompare("paint",option+1) == 0)
5178 {
5179 if (*option == '+')
5180 break;
5181 i++;
cristybb503372010-05-27 20:51:26 +00005182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005183 ThrowMogrifyException(OptionError,"MissingArgument",option);
5184 if (IsGeometry(argv[i]) == MagickFalse)
5185 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5186 break;
5187 }
5188 if (LocaleCompare("path",option+1) == 0)
5189 {
5190 (void) CloneString(&path,(char *) NULL);
5191 if (*option == '+')
5192 break;
5193 i++;
cristybb503372010-05-27 20:51:26 +00005194 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005195 ThrowMogrifyException(OptionError,"MissingArgument",option);
5196 (void) CloneString(&path,argv[i]);
5197 break;
5198 }
5199 if (LocaleCompare("pointsize",option+1) == 0)
5200 {
5201 if (*option == '+')
5202 break;
5203 i++;
cristybb503372010-05-27 20:51:26 +00005204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005205 ThrowMogrifyException(OptionError,"MissingArgument",option);
5206 if (IsGeometry(argv[i]) == MagickFalse)
5207 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5208 break;
5209 }
5210 if (LocaleCompare("polaroid",option+1) == 0)
5211 {
5212 if (*option == '+')
5213 break;
5214 i++;
cristybb503372010-05-27 20:51:26 +00005215 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005216 ThrowMogrifyException(OptionError,"MissingArgument",option);
5217 if (IsGeometry(argv[i]) == MagickFalse)
5218 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5219 break;
5220 }
5221 if (LocaleCompare("posterize",option+1) == 0)
5222 {
5223 if (*option == '+')
5224 break;
5225 i++;
cristybb503372010-05-27 20:51:26 +00005226 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005227 ThrowMogrifyException(OptionError,"MissingArgument",option);
5228 if (IsGeometry(argv[i]) == MagickFalse)
5229 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5230 break;
5231 }
cristye7f51092010-01-17 00:39:37 +00005232 if (LocaleCompare("precision",option+1) == 0)
5233 {
5234 if (*option == '+')
5235 break;
5236 i++;
cristybb503372010-05-27 20:51:26 +00005237 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005238 ThrowMogrifyException(OptionError,"MissingArgument",option);
5239 if (IsGeometry(argv[i]) == MagickFalse)
5240 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5241 break;
5242 }
cristy3ed852e2009-09-05 21:47:34 +00005243 if (LocaleCompare("print",option+1) == 0)
5244 {
5245 if (*option == '+')
5246 break;
5247 i++;
cristybb503372010-05-27 20:51:26 +00005248 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005249 ThrowMogrifyException(OptionError,"MissingArgument",option);
5250 break;
5251 }
5252 if (LocaleCompare("process",option+1) == 0)
5253 {
5254 if (*option == '+')
5255 break;
5256 i++;
cristybb503372010-05-27 20:51:26 +00005257 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005258 ThrowMogrifyException(OptionError,"MissingArgument",option);
5259 break;
5260 }
5261 if (LocaleCompare("profile",option+1) == 0)
5262 {
5263 i++;
cristybb503372010-05-27 20:51:26 +00005264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005265 ThrowMogrifyException(OptionError,"MissingArgument",option);
5266 break;
5267 }
5268 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5269 }
5270 case 'q':
5271 {
5272 if (LocaleCompare("quality",option+1) == 0)
5273 {
5274 if (*option == '+')
5275 break;
5276 i++;
cristybb503372010-05-27 20:51:26 +00005277 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005278 ThrowMogrifyException(OptionError,"MissingArgument",option);
5279 if (IsGeometry(argv[i]) == MagickFalse)
5280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5281 break;
5282 }
5283 if (LocaleCompare("quantize",option+1) == 0)
5284 {
cristybb503372010-05-27 20:51:26 +00005285 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005286 colorspace;
5287
5288 if (*option == '+')
5289 break;
5290 i++;
cristybb503372010-05-27 20:51:26 +00005291 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005292 ThrowMogrifyException(OptionError,"MissingArgument",option);
5293 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5294 argv[i]);
5295 if (colorspace < 0)
5296 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5297 argv[i]);
5298 break;
5299 }
5300 if (LocaleCompare("quiet",option+1) == 0)
5301 break;
5302 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5303 }
5304 case 'r':
5305 {
5306 if (LocaleCompare("radial-blur",option+1) == 0)
5307 {
5308 i++;
cristybb503372010-05-27 20:51:26 +00005309 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005310 ThrowMogrifyException(OptionError,"MissingArgument",option);
5311 if (IsGeometry(argv[i]) == MagickFalse)
5312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5313 break;
5314 }
5315 if (LocaleCompare("raise",option+1) == 0)
5316 {
5317 i++;
cristybb503372010-05-27 20:51:26 +00005318 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005319 ThrowMogrifyException(OptionError,"MissingArgument",option);
5320 if (IsGeometry(argv[i]) == MagickFalse)
5321 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5322 break;
5323 }
5324 if (LocaleCompare("random-threshold",option+1) == 0)
5325 {
5326 if (*option == '+')
5327 break;
5328 i++;
cristybb503372010-05-27 20:51:26 +00005329 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005330 ThrowMogrifyException(OptionError,"MissingArgument",option);
5331 if (IsGeometry(argv[i]) == MagickFalse)
5332 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5333 break;
5334 }
cristye6365592010-04-02 17:31:23 +00005335 if (LocaleCompare("recolor",option+1) == 0)
5336 {
5337 if (*option == '+')
5338 break;
5339 i++;
cristybb503372010-05-27 20:51:26 +00005340 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005341 ThrowMogrifyException(OptionError,"MissingArgument",option);
5342 if (IsGeometry(argv[i]) == MagickFalse)
5343 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5344 break;
5345 }
cristy3ed852e2009-09-05 21:47:34 +00005346 if (LocaleCompare("red-primary",option+1) == 0)
5347 {
5348 if (*option == '+')
5349 break;
5350 i++;
cristybb503372010-05-27 20:51:26 +00005351 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005352 ThrowMogrifyException(OptionError,"MissingArgument",option);
5353 if (IsGeometry(argv[i]) == MagickFalse)
5354 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5355 }
cristy9f2083a2010-04-22 19:48:05 +00005356 if (LocaleCompare("regard-warnings",option+1) == 0)
5357 break;
cristy3ed852e2009-09-05 21:47:34 +00005358 if (LocaleCompare("region",option+1) == 0)
5359 {
5360 if (*option == '+')
5361 break;
5362 i++;
cristybb503372010-05-27 20:51:26 +00005363 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005364 ThrowMogrifyException(OptionError,"MissingArgument",option);
5365 if (IsGeometry(argv[i]) == MagickFalse)
5366 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5367 break;
5368 }
cristyf0c78232010-03-15 12:53:40 +00005369 if (LocaleCompare("remap",option+1) == 0)
5370 {
5371 if (*option == '+')
5372 break;
5373 i++;
cristybb503372010-05-27 20:51:26 +00005374 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005375 ThrowMogrifyException(OptionError,"MissingArgument",option);
5376 break;
5377 }
cristy3ed852e2009-09-05 21:47:34 +00005378 if (LocaleCompare("render",option+1) == 0)
5379 break;
5380 if (LocaleCompare("repage",option+1) == 0)
5381 {
5382 if (*option == '+')
5383 break;
5384 i++;
cristybb503372010-05-27 20:51:26 +00005385 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005386 ThrowMogrifyException(OptionError,"MissingArgument",option);
5387 if (IsGeometry(argv[i]) == MagickFalse)
5388 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5389 break;
5390 }
5391 if (LocaleCompare("resample",option+1) == 0)
5392 {
5393 if (*option == '+')
5394 break;
5395 i++;
cristybb503372010-05-27 20:51:26 +00005396 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005397 ThrowMogrifyException(OptionError,"MissingArgument",option);
5398 if (IsGeometry(argv[i]) == MagickFalse)
5399 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5400 break;
5401 }
5402 if (LocaleCompare("resize",option+1) == 0)
5403 {
5404 if (*option == '+')
5405 break;
5406 i++;
cristybb503372010-05-27 20:51:26 +00005407 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005408 ThrowMogrifyException(OptionError,"MissingArgument",option);
5409 if (IsGeometry(argv[i]) == MagickFalse)
5410 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5411 break;
5412 }
cristyebbcfea2011-02-25 02:43:54 +00005413 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5414 {
5415 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5416 break;
5417 }
cristy3ed852e2009-09-05 21:47:34 +00005418 if (LocaleCompare("reverse",option+1) == 0)
5419 break;
5420 if (LocaleCompare("roll",option+1) == 0)
5421 {
5422 if (*option == '+')
5423 break;
5424 i++;
cristybb503372010-05-27 20:51:26 +00005425 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005426 ThrowMogrifyException(OptionError,"MissingArgument",option);
5427 if (IsGeometry(argv[i]) == MagickFalse)
5428 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5429 break;
5430 }
5431 if (LocaleCompare("rotate",option+1) == 0)
5432 {
5433 i++;
cristybb503372010-05-27 20:51:26 +00005434 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005435 ThrowMogrifyException(OptionError,"MissingArgument",option);
5436 if (IsGeometry(argv[i]) == MagickFalse)
5437 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5438 break;
5439 }
5440 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5441 }
5442 case 's':
5443 {
5444 if (LocaleCompare("sample",option+1) == 0)
5445 {
5446 if (*option == '+')
5447 break;
5448 i++;
cristybb503372010-05-27 20:51:26 +00005449 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005450 ThrowMogrifyException(OptionError,"MissingArgument",option);
5451 if (IsGeometry(argv[i]) == MagickFalse)
5452 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5453 break;
5454 }
5455 if (LocaleCompare("sampling-factor",option+1) == 0)
5456 {
5457 if (*option == '+')
5458 break;
5459 i++;
cristybb503372010-05-27 20:51:26 +00005460 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005461 ThrowMogrifyException(OptionError,"MissingArgument",option);
5462 if (IsGeometry(argv[i]) == MagickFalse)
5463 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5464 break;
5465 }
5466 if (LocaleCompare("scale",option+1) == 0)
5467 {
5468 if (*option == '+')
5469 break;
5470 i++;
cristybb503372010-05-27 20:51:26 +00005471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005472 ThrowMogrifyException(OptionError,"MissingArgument",option);
5473 if (IsGeometry(argv[i]) == MagickFalse)
5474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5475 break;
5476 }
5477 if (LocaleCompare("scene",option+1) == 0)
5478 {
5479 if (*option == '+')
5480 break;
5481 i++;
cristybb503372010-05-27 20:51:26 +00005482 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005483 ThrowMogrifyException(OptionError,"MissingArgument",option);
5484 if (IsGeometry(argv[i]) == MagickFalse)
5485 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5486 break;
5487 }
5488 if (LocaleCompare("seed",option+1) == 0)
5489 {
5490 if (*option == '+')
5491 break;
5492 i++;
cristybb503372010-05-27 20:51:26 +00005493 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005494 ThrowMogrifyException(OptionError,"MissingArgument",option);
5495 if (IsGeometry(argv[i]) == MagickFalse)
5496 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5497 break;
5498 }
5499 if (LocaleCompare("segment",option+1) == 0)
5500 {
5501 if (*option == '+')
5502 break;
5503 i++;
cristybb503372010-05-27 20:51:26 +00005504 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005505 ThrowMogrifyException(OptionError,"MissingArgument",option);
5506 if (IsGeometry(argv[i]) == MagickFalse)
5507 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5508 break;
5509 }
5510 if (LocaleCompare("selective-blur",option+1) == 0)
5511 {
5512 i++;
cristybb503372010-05-27 20:51:26 +00005513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005514 ThrowMogrifyException(OptionError,"MissingArgument",option);
5515 if (IsGeometry(argv[i]) == MagickFalse)
5516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5517 break;
5518 }
5519 if (LocaleCompare("separate",option+1) == 0)
5520 break;
5521 if (LocaleCompare("sepia-tone",option+1) == 0)
5522 {
5523 if (*option == '+')
5524 break;
5525 i++;
cristybb503372010-05-27 20:51:26 +00005526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005527 ThrowMogrifyException(OptionError,"MissingArgument",option);
5528 if (IsGeometry(argv[i]) == MagickFalse)
5529 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5530 break;
5531 }
5532 if (LocaleCompare("set",option+1) == 0)
5533 {
5534 i++;
cristybb503372010-05-27 20:51:26 +00005535 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005536 ThrowMogrifyException(OptionError,"MissingArgument",option);
5537 if (*option == '+')
5538 break;
5539 i++;
cristybb503372010-05-27 20:51:26 +00005540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005541 ThrowMogrifyException(OptionError,"MissingArgument",option);
5542 break;
5543 }
5544 if (LocaleCompare("shade",option+1) == 0)
5545 {
5546 i++;
cristybb503372010-05-27 20:51:26 +00005547 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005548 ThrowMogrifyException(OptionError,"MissingArgument",option);
5549 if (IsGeometry(argv[i]) == MagickFalse)
5550 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5551 break;
5552 }
5553 if (LocaleCompare("shadow",option+1) == 0)
5554 {
5555 if (*option == '+')
5556 break;
5557 i++;
cristybb503372010-05-27 20:51:26 +00005558 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005559 ThrowMogrifyException(OptionError,"MissingArgument",option);
5560 if (IsGeometry(argv[i]) == MagickFalse)
5561 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5562 break;
5563 }
5564 if (LocaleCompare("sharpen",option+1) == 0)
5565 {
5566 i++;
cristybb503372010-05-27 20:51:26 +00005567 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005568 ThrowMogrifyException(OptionError,"MissingArgument",option);
5569 if (IsGeometry(argv[i]) == MagickFalse)
5570 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5571 break;
5572 }
5573 if (LocaleCompare("shave",option+1) == 0)
5574 {
5575 if (*option == '+')
5576 break;
5577 i++;
cristybb503372010-05-27 20:51:26 +00005578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005579 ThrowMogrifyException(OptionError,"MissingArgument",option);
5580 if (IsGeometry(argv[i]) == MagickFalse)
5581 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582 break;
5583 }
5584 if (LocaleCompare("shear",option+1) == 0)
5585 {
5586 i++;
cristybb503372010-05-27 20:51:26 +00005587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005588 ThrowMogrifyException(OptionError,"MissingArgument",option);
5589 if (IsGeometry(argv[i]) == MagickFalse)
5590 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5591 break;
5592 }
5593 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5594 {
5595 i++;
cristybb503372010-05-27 20:51:26 +00005596 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005597 ThrowMogrifyException(OptionError,"MissingArgument",option);
5598 if (IsGeometry(argv[i]) == MagickFalse)
5599 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5600 break;
5601 }
5602 if (LocaleCompare("size",option+1) == 0)
5603 {
5604 if (*option == '+')
5605 break;
5606 i++;
cristybb503372010-05-27 20:51:26 +00005607 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005608 ThrowMogrifyException(OptionError,"MissingArgument",option);
5609 if (IsGeometry(argv[i]) == MagickFalse)
5610 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5611 break;
5612 }
5613 if (LocaleCompare("sketch",option+1) == 0)
5614 {
5615 if (*option == '+')
5616 break;
5617 i++;
cristybb503372010-05-27 20:51:26 +00005618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005619 ThrowMogrifyException(OptionError,"MissingArgument",option);
5620 if (IsGeometry(argv[i]) == MagickFalse)
5621 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5622 break;
5623 }
cristy4285d782011-02-09 20:12:28 +00005624 if (LocaleCompare("smush",option+1) == 0)
5625 {
cristy4285d782011-02-09 20:12:28 +00005626 i++;
5627 if (i == (ssize_t) argc)
5628 ThrowMogrifyException(OptionError,"MissingArgument",option);
5629 if (IsGeometry(argv[i]) == MagickFalse)
5630 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005631 i++;
5632 break;
5633 }
cristy3ed852e2009-09-05 21:47:34 +00005634 if (LocaleCompare("solarize",option+1) == 0)
5635 {
5636 if (*option == '+')
5637 break;
5638 i++;
cristybb503372010-05-27 20:51:26 +00005639 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005640 ThrowMogrifyException(OptionError,"MissingArgument",option);
5641 if (IsGeometry(argv[i]) == MagickFalse)
5642 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5643 break;
5644 }
5645 if (LocaleCompare("sparse-color",option+1) == 0)
5646 {
cristybb503372010-05-27 20:51:26 +00005647 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005648 op;
5649
5650 i++;
cristybb503372010-05-27 20:51:26 +00005651 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005652 ThrowMogrifyException(OptionError,"MissingArgument",option);
5653 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5654 if (op < 0)
5655 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5656 argv[i]);
5657 i++;
cristybb503372010-05-27 20:51:26 +00005658 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005659 ThrowMogrifyException(OptionError,"MissingArgument",option);
5660 break;
5661 }
5662 if (LocaleCompare("spread",option+1) == 0)
5663 {
5664 if (*option == '+')
5665 break;
5666 i++;
cristybb503372010-05-27 20:51:26 +00005667 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005668 ThrowMogrifyException(OptionError,"MissingArgument",option);
5669 if (IsGeometry(argv[i]) == MagickFalse)
5670 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5671 break;
5672 }
cristy0834d642011-03-18 18:26:08 +00005673 if (LocaleCompare("statistic",option+1) == 0)
5674 {
5675 ssize_t
5676 op;
5677
5678 if (*option == '+')
5679 break;
5680 i++;
5681 if (i == (ssize_t) argc)
5682 ThrowMogrifyException(OptionError,"MissingArgument",option);
5683 op=ParseMagickOption(MagickStatisticOptions,MagickFalse,argv[i]);
5684 if (op < 0)
5685 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5686 argv[i]);
5687 i++;
5688 if (i == (ssize_t) (argc-1))
5689 ThrowMogrifyException(OptionError,"MissingArgument",option);
5690 if (IsGeometry(argv[i]) == MagickFalse)
5691 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5692 break;
5693 }
cristy3ed852e2009-09-05 21:47:34 +00005694 if (LocaleCompare("stretch",option+1) == 0)
5695 {
cristybb503372010-05-27 20:51:26 +00005696 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005697 stretch;
5698
5699 if (*option == '+')
5700 break;
5701 i++;
cristybb503372010-05-27 20:51:26 +00005702 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005703 ThrowMogrifyException(OptionError,"MissingArgument",option);
5704 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
5705 if (stretch < 0)
5706 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5707 argv[i]);
5708 break;
5709 }
5710 if (LocaleCompare("strip",option+1) == 0)
5711 break;
5712 if (LocaleCompare("stroke",option+1) == 0)
5713 {
5714 if (*option == '+')
5715 break;
5716 i++;
cristybb503372010-05-27 20:51:26 +00005717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005718 ThrowMogrifyException(OptionError,"MissingArgument",option);
5719 break;
5720 }
5721 if (LocaleCompare("strokewidth",option+1) == 0)
5722 {
5723 if (*option == '+')
5724 break;
5725 i++;
cristybb503372010-05-27 20:51:26 +00005726 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005727 ThrowMogrifyException(OptionError,"MissingArgument",option);
5728 if (IsGeometry(argv[i]) == MagickFalse)
5729 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5730 break;
5731 }
5732 if (LocaleCompare("style",option+1) == 0)
5733 {
cristybb503372010-05-27 20:51:26 +00005734 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005735 style;
5736
5737 if (*option == '+')
5738 break;
5739 i++;
cristybb503372010-05-27 20:51:26 +00005740 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005741 ThrowMogrifyException(OptionError,"MissingArgument",option);
5742 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
5743 if (style < 0)
5744 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5745 argv[i]);
5746 break;
5747 }
cristyecb10ff2011-03-22 13:14:03 +00005748 if (LocaleCompare("swap",option+1) == 0)
5749 {
5750 if (*option == '+')
5751 break;
5752 i++;
5753 if (i == (ssize_t) (argc-1))
5754 ThrowMogrifyException(OptionError,"MissingArgument",option);
5755 if (IsGeometry(argv[i]) == MagickFalse)
5756 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5757 break;
5758 }
cristy3ed852e2009-09-05 21:47:34 +00005759 if (LocaleCompare("swirl",option+1) == 0)
5760 {
5761 if (*option == '+')
5762 break;
5763 i++;
cristybb503372010-05-27 20:51:26 +00005764 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005765 ThrowMogrifyException(OptionError,"MissingArgument",option);
5766 if (IsGeometry(argv[i]) == MagickFalse)
5767 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5768 break;
5769 }
cristyd9a29192010-10-16 16:49:53 +00005770 if (LocaleCompare("synchronize",option+1) == 0)
5771 break;
cristy3ed852e2009-09-05 21:47:34 +00005772 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5773 }
5774 case 't':
5775 {
5776 if (LocaleCompare("taint",option+1) == 0)
5777 break;
5778 if (LocaleCompare("texture",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 break;
5786 }
5787 if (LocaleCompare("tile",option+1) == 0)
5788 {
5789 if (*option == '+')
5790 break;
5791 i++;
cristybb503372010-05-27 20:51:26 +00005792 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005793 ThrowMogrifyException(OptionError,"MissingArgument",option);
5794 break;
5795 }
5796 if (LocaleCompare("tile-offset",option+1) == 0)
5797 {
5798 if (*option == '+')
5799 break;
5800 i++;
cristybb503372010-05-27 20:51:26 +00005801 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005802 ThrowMogrifyException(OptionError,"MissingArgument",option);
5803 if (IsGeometry(argv[i]) == MagickFalse)
5804 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5805 break;
5806 }
5807 if (LocaleCompare("tint",option+1) == 0)
5808 {
5809 if (*option == '+')
5810 break;
5811 i++;
cristybb503372010-05-27 20:51:26 +00005812 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005813 ThrowMogrifyException(OptionError,"MissingArgument",option);
5814 if (IsGeometry(argv[i]) == MagickFalse)
5815 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5816 break;
5817 }
5818 if (LocaleCompare("transform",option+1) == 0)
5819 break;
5820 if (LocaleCompare("transpose",option+1) == 0)
5821 break;
5822 if (LocaleCompare("transverse",option+1) == 0)
5823 break;
5824 if (LocaleCompare("threshold",option+1) == 0)
5825 {
5826 if (*option == '+')
5827 break;
5828 i++;
cristybb503372010-05-27 20:51:26 +00005829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005830 ThrowMogrifyException(OptionError,"MissingArgument",option);
5831 if (IsGeometry(argv[i]) == MagickFalse)
5832 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5833 break;
5834 }
5835 if (LocaleCompare("thumbnail",option+1) == 0)
5836 {
5837 if (*option == '+')
5838 break;
5839 i++;
cristybb503372010-05-27 20:51:26 +00005840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005841 ThrowMogrifyException(OptionError,"MissingArgument",option);
5842 if (IsGeometry(argv[i]) == MagickFalse)
5843 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5844 break;
5845 }
5846 if (LocaleCompare("transparent",option+1) == 0)
5847 {
5848 i++;
cristybb503372010-05-27 20:51:26 +00005849 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005850 ThrowMogrifyException(OptionError,"MissingArgument",option);
5851 break;
5852 }
5853 if (LocaleCompare("transparent-color",option+1) == 0)
5854 {
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 break;
5861 }
5862 if (LocaleCompare("treedepth",option+1) == 0)
5863 {
5864 if (*option == '+')
5865 break;
5866 i++;
cristybb503372010-05-27 20:51:26 +00005867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005868 ThrowMogrifyException(OptionError,"MissingArgument",option);
5869 if (IsGeometry(argv[i]) == MagickFalse)
5870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5871 break;
5872 }
5873 if (LocaleCompare("trim",option+1) == 0)
5874 break;
5875 if (LocaleCompare("type",option+1) == 0)
5876 {
cristybb503372010-05-27 20:51:26 +00005877 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005878 type;
5879
5880 if (*option == '+')
5881 break;
5882 i++;
cristybb503372010-05-27 20:51:26 +00005883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005884 ThrowMogrifyException(OptionError,"MissingArgument",option);
5885 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
5886 if (type < 0)
5887 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5888 argv[i]);
5889 break;
5890 }
5891 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5892 }
5893 case 'u':
5894 {
5895 if (LocaleCompare("undercolor",option+1) == 0)
5896 {
5897 if (*option == '+')
5898 break;
5899 i++;
cristybb503372010-05-27 20:51:26 +00005900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005901 ThrowMogrifyException(OptionError,"MissingArgument",option);
5902 break;
5903 }
5904 if (LocaleCompare("unique-colors",option+1) == 0)
5905 break;
5906 if (LocaleCompare("units",option+1) == 0)
5907 {
cristybb503372010-05-27 20:51:26 +00005908 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005909 units;
5910
5911 if (*option == '+')
5912 break;
5913 i++;
cristybb503372010-05-27 20:51:26 +00005914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005915 ThrowMogrifyException(OptionError,"MissingArgument",option);
5916 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
5917 argv[i]);
5918 if (units < 0)
5919 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5920 argv[i]);
5921 break;
5922 }
5923 if (LocaleCompare("unsharp",option+1) == 0)
5924 {
5925 i++;
cristybb503372010-05-27 20:51:26 +00005926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005927 ThrowMogrifyException(OptionError,"MissingArgument",option);
5928 if (IsGeometry(argv[i]) == MagickFalse)
5929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5930 break;
5931 }
5932 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5933 }
5934 case 'v':
5935 {
5936 if (LocaleCompare("verbose",option+1) == 0)
5937 {
5938 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5939 break;
5940 }
5941 if ((LocaleCompare("version",option+1) == 0) ||
5942 (LocaleCompare("-version",option+1) == 0))
5943 {
5944 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005945 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00005946 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
5947 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005948 break;
5949 }
5950 if (LocaleCompare("view",option+1) == 0)
5951 {
5952 if (*option == '+')
5953 break;
5954 i++;
cristybb503372010-05-27 20:51:26 +00005955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005956 ThrowMogrifyException(OptionError,"MissingArgument",option);
5957 break;
5958 }
5959 if (LocaleCompare("vignette",option+1) == 0)
5960 {
5961 if (*option == '+')
5962 break;
5963 i++;
cristybb503372010-05-27 20:51:26 +00005964 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005965 ThrowMogrifyException(OptionError,"MissingArgument",option);
5966 if (IsGeometry(argv[i]) == MagickFalse)
5967 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5968 break;
5969 }
5970 if (LocaleCompare("virtual-pixel",option+1) == 0)
5971 {
cristybb503372010-05-27 20:51:26 +00005972 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005973 method;
5974
5975 if (*option == '+')
5976 break;
5977 i++;
cristybb503372010-05-27 20:51:26 +00005978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005979 ThrowMogrifyException(OptionError,"MissingArgument",option);
5980 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
5981 argv[i]);
5982 if (method < 0)
5983 ThrowMogrifyException(OptionError,
5984 "UnrecognizedVirtualPixelMethod",argv[i]);
5985 break;
5986 }
5987 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5988 }
5989 case 'w':
5990 {
5991 if (LocaleCompare("wave",option+1) == 0)
5992 {
5993 i++;
cristybb503372010-05-27 20:51:26 +00005994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005995 ThrowMogrifyException(OptionError,"MissingArgument",option);
5996 if (IsGeometry(argv[i]) == MagickFalse)
5997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5998 break;
5999 }
6000 if (LocaleCompare("weight",option+1) == 0)
6001 {
6002 if (*option == '+')
6003 break;
6004 i++;
cristybb503372010-05-27 20:51:26 +00006005 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006006 ThrowMogrifyException(OptionError,"MissingArgument",option);
6007 break;
6008 }
6009 if (LocaleCompare("white-point",option+1) == 0)
6010 {
6011 if (*option == '+')
6012 break;
6013 i++;
cristybb503372010-05-27 20:51:26 +00006014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006015 ThrowMogrifyException(OptionError,"MissingArgument",option);
6016 if (IsGeometry(argv[i]) == MagickFalse)
6017 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6018 break;
6019 }
6020 if (LocaleCompare("white-threshold",option+1) == 0)
6021 {
6022 if (*option == '+')
6023 break;
6024 i++;
cristybb503372010-05-27 20:51:26 +00006025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006026 ThrowMogrifyException(OptionError,"MissingArgument",option);
6027 if (IsGeometry(argv[i]) == MagickFalse)
6028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6029 break;
6030 }
6031 if (LocaleCompare("write",option+1) == 0)
6032 {
6033 i++;
cristybb503372010-05-27 20:51:26 +00006034 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006035 ThrowMogrifyException(OptionError,"MissingArgument",option);
6036 break;
6037 }
6038 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6039 }
6040 case '?':
6041 break;
6042 default:
6043 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6044 }
6045 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6046 MagickFalse : MagickTrue;
6047 if (fire != MagickFalse)
6048 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6049 }
6050 if (k != 0)
6051 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006052 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006053 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6054 DestroyMogrify();
6055 return(status != 0 ? MagickTrue : MagickFalse);
6056}
6057
6058/*
6059%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6060% %
6061% %
6062% %
6063+ M o g r i f y I m a g e I n f o %
6064% %
6065% %
6066% %
6067%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6068%
6069% MogrifyImageInfo() applies image processing settings to the image as
6070% prescribed by command line options.
6071%
6072% The format of the MogrifyImageInfo method is:
6073%
6074% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6075% const char **argv,ExceptionInfo *exception)
6076%
6077% A description of each parameter follows:
6078%
6079% o image_info: the image info..
6080%
6081% o argc: Specifies a pointer to an integer describing the number of
6082% elements in the argument vector.
6083%
6084% o argv: Specifies a pointer to a text array containing the command line
6085% arguments.
6086%
6087% o exception: return any errors or warnings in this structure.
6088%
6089*/
6090WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6091 const int argc,const char **argv,ExceptionInfo *exception)
6092{
6093 const char
6094 *option;
6095
6096 GeometryInfo
6097 geometry_info;
6098
cristybb503372010-05-27 20:51:26 +00006099 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006100 count;
6101
cristybb503372010-05-27 20:51:26 +00006102 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006103 i;
6104
6105 /*
6106 Initialize method variables.
6107 */
6108 assert(image_info != (ImageInfo *) NULL);
6109 assert(image_info->signature == MagickSignature);
6110 if (image_info->debug != MagickFalse)
6111 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6112 image_info->filename);
6113 if (argc < 0)
6114 return(MagickTrue);
6115 /*
6116 Set the image settings.
6117 */
cristybb503372010-05-27 20:51:26 +00006118 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006119 {
6120 option=argv[i];
6121 if (IsMagickOption(option) == MagickFalse)
6122 continue;
6123 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6124 0L);
cristycee97112010-05-28 00:44:52 +00006125 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006126 break;
6127 switch (*(option+1))
6128 {
6129 case 'a':
6130 {
6131 if (LocaleCompare("adjoin",option+1) == 0)
6132 {
6133 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6134 break;
6135 }
6136 if (LocaleCompare("antialias",option+1) == 0)
6137 {
6138 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6139 break;
6140 }
6141 if (LocaleCompare("attenuate",option+1) == 0)
6142 {
6143 if (*option == '+')
6144 {
6145 (void) DeleteImageOption(image_info,option+1);
6146 break;
6147 }
6148 (void) SetImageOption(image_info,option+1,argv[i+1]);
6149 break;
6150 }
6151 if (LocaleCompare("authenticate",option+1) == 0)
6152 {
6153 if (*option == '+')
6154 (void) CloneString(&image_info->authenticate,(char *) NULL);
6155 else
6156 (void) CloneString(&image_info->authenticate,argv[i+1]);
6157 break;
6158 }
6159 break;
6160 }
6161 case 'b':
6162 {
6163 if (LocaleCompare("background",option+1) == 0)
6164 {
6165 if (*option == '+')
6166 {
6167 (void) DeleteImageOption(image_info,option+1);
6168 (void) QueryColorDatabase(BackgroundColor,
6169 &image_info->background_color,exception);
6170 break;
6171 }
6172 (void) SetImageOption(image_info,option+1,argv[i+1]);
6173 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6174 exception);
6175 break;
6176 }
6177 if (LocaleCompare("bias",option+1) == 0)
6178 {
6179 if (*option == '+')
6180 {
6181 (void) SetImageOption(image_info,option+1,"0.0");
6182 break;
6183 }
6184 (void) SetImageOption(image_info,option+1,argv[i+1]);
6185 break;
6186 }
6187 if (LocaleCompare("black-point-compensation",option+1) == 0)
6188 {
6189 if (*option == '+')
6190 {
6191 (void) SetImageOption(image_info,option+1,"false");
6192 break;
6193 }
6194 (void) SetImageOption(image_info,option+1,"true");
6195 break;
6196 }
6197 if (LocaleCompare("blue-primary",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("bordercolor",option+1) == 0)
6208 {
6209 if (*option == '+')
6210 {
6211 (void) DeleteImageOption(image_info,option+1);
6212 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6213 exception);
6214 break;
6215 }
6216 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6217 exception);
6218 (void) SetImageOption(image_info,option+1,argv[i+1]);
6219 break;
6220 }
6221 if (LocaleCompare("box",option+1) == 0)
6222 {
6223 if (*option == '+')
6224 {
6225 (void) SetImageOption(image_info,"undercolor","none");
6226 break;
6227 }
6228 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6229 break;
6230 }
6231 break;
6232 }
6233 case 'c':
6234 {
6235 if (LocaleCompare("cache",option+1) == 0)
6236 {
6237 MagickSizeType
6238 limit;
6239
6240 limit=MagickResourceInfinity;
6241 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006242 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006243 (void) SetMagickResourceLimit(MemoryResource,limit);
6244 (void) SetMagickResourceLimit(MapResource,2*limit);
6245 break;
6246 }
6247 if (LocaleCompare("caption",option+1) == 0)
6248 {
6249 if (*option == '+')
6250 {
6251 (void) DeleteImageOption(image_info,option+1);
6252 break;
6253 }
6254 (void) SetImageOption(image_info,option+1,argv[i+1]);
6255 break;
6256 }
6257 if (LocaleCompare("channel",option+1) == 0)
6258 {
6259 if (*option == '+')
6260 {
6261 image_info->channel=DefaultChannels;
6262 break;
6263 }
6264 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6265 break;
6266 }
6267 if (LocaleCompare("colors",option+1) == 0)
6268 {
cristye27293e2009-12-18 02:53:20 +00006269 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006270 break;
6271 }
6272 if (LocaleCompare("colorspace",option+1) == 0)
6273 {
6274 if (*option == '+')
6275 {
6276 image_info->colorspace=UndefinedColorspace;
6277 (void) SetImageOption(image_info,option+1,"undefined");
6278 break;
6279 }
6280 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6281 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6282 (void) SetImageOption(image_info,option+1,argv[i+1]);
6283 break;
6284 }
6285 if (LocaleCompare("compress",option+1) == 0)
6286 {
6287 if (*option == '+')
6288 {
6289 image_info->compression=UndefinedCompression;
6290 (void) SetImageOption(image_info,option+1,"undefined");
6291 break;
6292 }
6293 image_info->compression=(CompressionType) ParseMagickOption(
6294 MagickCompressOptions,MagickFalse,argv[i+1]);
6295 (void) SetImageOption(image_info,option+1,argv[i+1]);
6296 break;
6297 }
6298 if (LocaleCompare("comment",option+1) == 0)
6299 {
6300 if (*option == '+')
6301 {
6302 (void) DeleteImageOption(image_info,option+1);
6303 break;
6304 }
6305 (void) SetImageOption(image_info,option+1,argv[i+1]);
6306 break;
6307 }
6308 if (LocaleCompare("compose",option+1) == 0)
6309 {
6310 if (*option == '+')
6311 {
6312 (void) SetImageOption(image_info,option+1,"undefined");
6313 break;
6314 }
6315 (void) SetImageOption(image_info,option+1,argv[i+1]);
6316 break;
6317 }
6318 if (LocaleCompare("compress",option+1) == 0)
6319 {
6320 if (*option == '+')
6321 {
6322 image_info->compression=UndefinedCompression;
6323 (void) SetImageOption(image_info,option+1,"undefined");
6324 break;
6325 }
6326 image_info->compression=(CompressionType) ParseMagickOption(
6327 MagickCompressOptions,MagickFalse,argv[i+1]);
6328 (void) SetImageOption(image_info,option+1,argv[i+1]);
6329 break;
6330 }
6331 break;
6332 }
6333 case 'd':
6334 {
6335 if (LocaleCompare("debug",option+1) == 0)
6336 {
6337 if (*option == '+')
6338 (void) SetLogEventMask("none");
6339 else
6340 (void) SetLogEventMask(argv[i+1]);
6341 image_info->debug=IsEventLogging();
6342 break;
6343 }
6344 if (LocaleCompare("define",option+1) == 0)
6345 {
6346 if (*option == '+')
6347 {
6348 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6349 (void) DeleteImageRegistry(argv[i+1]+9);
6350 else
6351 (void) DeleteImageOption(image_info,argv[i+1]);
6352 break;
6353 }
6354 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6355 {
6356 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6357 exception);
6358 break;
6359 }
6360 (void) DefineImageOption(image_info,argv[i+1]);
6361 break;
6362 }
6363 if (LocaleCompare("delay",option+1) == 0)
6364 {
6365 if (*option == '+')
6366 {
6367 (void) SetImageOption(image_info,option+1,"0");
6368 break;
6369 }
6370 (void) SetImageOption(image_info,option+1,argv[i+1]);
6371 break;
6372 }
6373 if (LocaleCompare("density",option+1) == 0)
6374 {
6375 /*
6376 Set image density.
6377 */
6378 if (*option == '+')
6379 {
6380 if (image_info->density != (char *) NULL)
6381 image_info->density=DestroyString(image_info->density);
6382 (void) SetImageOption(image_info,option+1,"72");
6383 break;
6384 }
6385 (void) CloneString(&image_info->density,argv[i+1]);
6386 (void) SetImageOption(image_info,option+1,argv[i+1]);
6387 break;
6388 }
6389 if (LocaleCompare("depth",option+1) == 0)
6390 {
6391 if (*option == '+')
6392 {
6393 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6394 break;
6395 }
cristye27293e2009-12-18 02:53:20 +00006396 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006397 break;
6398 }
cristyc9b12952010-03-28 01:12:28 +00006399 if (LocaleCompare("direction",option+1) == 0)
6400 {
6401 if (*option == '+')
6402 {
6403 (void) SetImageOption(image_info,option+1,"undefined");
6404 break;
6405 }
6406 (void) SetImageOption(image_info,option+1,argv[i+1]);
6407 break;
6408 }
cristy3ed852e2009-09-05 21:47:34 +00006409 if (LocaleCompare("display",option+1) == 0)
6410 {
6411 if (*option == '+')
6412 {
6413 if (image_info->server_name != (char *) NULL)
6414 image_info->server_name=DestroyString(
6415 image_info->server_name);
6416 break;
6417 }
6418 (void) CloneString(&image_info->server_name,argv[i+1]);
6419 break;
6420 }
6421 if (LocaleCompare("dispose",option+1) == 0)
6422 {
6423 if (*option == '+')
6424 {
6425 (void) SetImageOption(image_info,option+1,"undefined");
6426 break;
6427 }
6428 (void) SetImageOption(image_info,option+1,argv[i+1]);
6429 break;
6430 }
6431 if (LocaleCompare("dither",option+1) == 0)
6432 {
6433 if (*option == '+')
6434 {
6435 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006436 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006437 break;
6438 }
6439 (void) SetImageOption(image_info,option+1,argv[i+1]);
6440 image_info->dither=MagickTrue;
6441 break;
6442 }
6443 break;
6444 }
6445 case 'e':
6446 {
6447 if (LocaleCompare("encoding",option+1) == 0)
6448 {
6449 if (*option == '+')
6450 {
6451 (void) SetImageOption(image_info,option+1,"undefined");
6452 break;
6453 }
6454 (void) SetImageOption(image_info,option+1,argv[i+1]);
6455 break;
6456 }
6457 if (LocaleCompare("endian",option+1) == 0)
6458 {
6459 if (*option == '+')
6460 {
6461 image_info->endian=UndefinedEndian;
6462 (void) SetImageOption(image_info,option+1,"undefined");
6463 break;
6464 }
6465 image_info->endian=(EndianType) ParseMagickOption(
6466 MagickEndianOptions,MagickFalse,argv[i+1]);
6467 (void) SetImageOption(image_info,option+1,argv[i+1]);
6468 break;
6469 }
6470 if (LocaleCompare("extract",option+1) == 0)
6471 {
6472 /*
6473 Set image extract geometry.
6474 */
6475 if (*option == '+')
6476 {
6477 if (image_info->extract != (char *) NULL)
6478 image_info->extract=DestroyString(image_info->extract);
6479 break;
6480 }
6481 (void) CloneString(&image_info->extract,argv[i+1]);
6482 break;
6483 }
6484 break;
6485 }
6486 case 'f':
6487 {
6488 if (LocaleCompare("fill",option+1) == 0)
6489 {
6490 if (*option == '+')
6491 {
6492 (void) SetImageOption(image_info,option+1,"none");
6493 break;
6494 }
6495 (void) SetImageOption(image_info,option+1,argv[i+1]);
6496 break;
6497 }
6498 if (LocaleCompare("filter",option+1) == 0)
6499 {
6500 if (*option == '+')
6501 {
6502 (void) SetImageOption(image_info,option+1,"undefined");
6503 break;
6504 }
6505 (void) SetImageOption(image_info,option+1,argv[i+1]);
6506 break;
6507 }
6508 if (LocaleCompare("font",option+1) == 0)
6509 {
6510 if (*option == '+')
6511 {
6512 if (image_info->font != (char *) NULL)
6513 image_info->font=DestroyString(image_info->font);
6514 break;
6515 }
6516 (void) CloneString(&image_info->font,argv[i+1]);
6517 break;
6518 }
6519 if (LocaleCompare("format",option+1) == 0)
6520 {
6521 register const char
6522 *q;
6523
6524 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006525 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006526 image_info->ping=MagickFalse;
6527 (void) SetImageOption(image_info,option+1,argv[i+1]);
6528 break;
6529 }
6530 if (LocaleCompare("fuzz",option+1) == 0)
6531 {
6532 if (*option == '+')
6533 {
6534 image_info->fuzz=0.0;
6535 (void) SetImageOption(image_info,option+1,"0");
6536 break;
6537 }
cristyf2f27272009-12-17 14:48:46 +00006538 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006539 1.0);
6540 (void) SetImageOption(image_info,option+1,argv[i+1]);
6541 break;
6542 }
6543 break;
6544 }
6545 case 'g':
6546 {
6547 if (LocaleCompare("gravity",option+1) == 0)
6548 {
6549 if (*option == '+')
6550 {
6551 (void) SetImageOption(image_info,option+1,"undefined");
6552 break;
6553 }
6554 (void) SetImageOption(image_info,option+1,argv[i+1]);
6555 break;
6556 }
6557 if (LocaleCompare("green-primary",option+1) == 0)
6558 {
6559 if (*option == '+')
6560 {
6561 (void) SetImageOption(image_info,option+1,"0.0");
6562 break;
6563 }
6564 (void) SetImageOption(image_info,option+1,argv[i+1]);
6565 break;
6566 }
6567 break;
6568 }
6569 case 'i':
6570 {
6571 if (LocaleCompare("intent",option+1) == 0)
6572 {
6573 if (*option == '+')
6574 {
6575 (void) SetImageOption(image_info,option+1,"undefined");
6576 break;
6577 }
6578 (void) SetImageOption(image_info,option+1,argv[i+1]);
6579 break;
6580 }
6581 if (LocaleCompare("interlace",option+1) == 0)
6582 {
6583 if (*option == '+')
6584 {
6585 image_info->interlace=UndefinedInterlace;
6586 (void) SetImageOption(image_info,option+1,"undefined");
6587 break;
6588 }
6589 image_info->interlace=(InterlaceType) ParseMagickOption(
6590 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6591 (void) SetImageOption(image_info,option+1,argv[i+1]);
6592 break;
6593 }
cristyb32b90a2009-09-07 21:45:48 +00006594 if (LocaleCompare("interline-spacing",option+1) == 0)
6595 {
6596 if (*option == '+')
6597 {
6598 (void) SetImageOption(image_info,option+1,"undefined");
6599 break;
6600 }
6601 (void) SetImageOption(image_info,option+1,argv[i+1]);
6602 break;
6603 }
cristy3ed852e2009-09-05 21:47:34 +00006604 if (LocaleCompare("interpolate",option+1) == 0)
6605 {
6606 if (*option == '+')
6607 {
6608 (void) SetImageOption(image_info,option+1,"undefined");
6609 break;
6610 }
6611 (void) SetImageOption(image_info,option+1,argv[i+1]);
6612 break;
6613 }
6614 if (LocaleCompare("interword-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 }
6624 break;
6625 }
6626 case 'k':
6627 {
6628 if (LocaleCompare("kerning",option+1) == 0)
6629 {
6630 if (*option == '+')
6631 {
6632 (void) SetImageOption(image_info,option+1,"undefined");
6633 break;
6634 }
6635 (void) SetImageOption(image_info,option+1,argv[i+1]);
6636 break;
6637 }
6638 break;
6639 }
6640 case 'l':
6641 {
6642 if (LocaleCompare("label",option+1) == 0)
6643 {
6644 if (*option == '+')
6645 {
6646 (void) DeleteImageOption(image_info,option+1);
6647 break;
6648 }
6649 (void) SetImageOption(image_info,option+1,argv[i+1]);
6650 break;
6651 }
6652 if (LocaleCompare("limit",option+1) == 0)
6653 {
6654 MagickSizeType
6655 limit;
6656
6657 ResourceType
6658 type;
6659
6660 if (*option == '+')
6661 break;
6662 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6663 MagickFalse,argv[i+1]);
6664 limit=MagickResourceInfinity;
6665 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006666 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006667 (void) SetMagickResourceLimit(type,limit);
6668 break;
6669 }
6670 if (LocaleCompare("list",option+1) == 0)
6671 {
cristybb503372010-05-27 20:51:26 +00006672 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006673 list;
6674
6675 /*
6676 Display configuration list.
6677 */
6678 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6679 switch (list)
6680 {
6681 case MagickCoderOptions:
6682 {
6683 (void) ListCoderInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickColorOptions:
6687 {
6688 (void) ListColorInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickConfigureOptions:
6692 {
6693 (void) ListConfigureInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickDelegateOptions:
6697 {
6698 (void) ListDelegateInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickFontOptions:
6702 {
6703 (void) ListTypeInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickFormatOptions:
6707 {
6708 (void) ListMagickInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickLocaleOptions:
6712 {
6713 (void) ListLocaleInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickLogOptions:
6717 {
6718 (void) ListLogInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickMagicOptions:
6722 {
6723 (void) ListMagicInfo((FILE *) NULL,exception);
6724 break;
6725 }
6726 case MagickMimeOptions:
6727 {
6728 (void) ListMimeInfo((FILE *) NULL,exception);
6729 break;
6730 }
6731 case MagickModuleOptions:
6732 {
6733 (void) ListModuleInfo((FILE *) NULL,exception);
6734 break;
6735 }
6736 case MagickPolicyOptions:
6737 {
6738 (void) ListPolicyInfo((FILE *) NULL,exception);
6739 break;
6740 }
6741 case MagickResourceOptions:
6742 {
6743 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6744 break;
6745 }
6746 case MagickThresholdOptions:
6747 {
6748 (void) ListThresholdMaps((FILE *) NULL,exception);
6749 break;
6750 }
6751 default:
6752 {
6753 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
6754 exception);
6755 break;
6756 }
6757 }
cristyaeb2cbc2010-05-07 13:28:58 +00006758 break;
cristy3ed852e2009-09-05 21:47:34 +00006759 }
6760 if (LocaleCompare("log",option+1) == 0)
6761 {
6762 if (*option == '+')
6763 break;
6764 (void) SetLogFormat(argv[i+1]);
6765 break;
6766 }
6767 if (LocaleCompare("loop",option+1) == 0)
6768 {
6769 if (*option == '+')
6770 {
6771 (void) SetImageOption(image_info,option+1,"0");
6772 break;
6773 }
6774 (void) SetImageOption(image_info,option+1,argv[i+1]);
6775 break;
6776 }
6777 break;
6778 }
6779 case 'm':
6780 {
6781 if (LocaleCompare("matte",option+1) == 0)
6782 {
6783 if (*option == '+')
6784 {
6785 (void) SetImageOption(image_info,option+1,"false");
6786 break;
6787 }
6788 (void) SetImageOption(image_info,option+1,"true");
6789 break;
6790 }
6791 if (LocaleCompare("mattecolor",option+1) == 0)
6792 {
6793 if (*option == '+')
6794 {
6795 (void) SetImageOption(image_info,option+1,argv[i+1]);
6796 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6797 exception);
6798 break;
6799 }
6800 (void) SetImageOption(image_info,option+1,argv[i+1]);
6801 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6802 exception);
6803 break;
6804 }
6805 if (LocaleCompare("monitor",option+1) == 0)
6806 {
6807 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6808 (void *) NULL);
6809 break;
6810 }
6811 if (LocaleCompare("monochrome",option+1) == 0)
6812 {
6813 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6814 break;
6815 }
6816 break;
6817 }
6818 case 'o':
6819 {
6820 if (LocaleCompare("orient",option+1) == 0)
6821 {
6822 if (*option == '+')
6823 {
6824 image_info->orientation=UndefinedOrientation;
6825 (void) SetImageOption(image_info,option+1,"undefined");
6826 break;
6827 }
6828 image_info->orientation=(OrientationType) ParseMagickOption(
6829 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006830 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006831 break;
6832 }
6833 }
6834 case 'p':
6835 {
6836 if (LocaleCompare("page",option+1) == 0)
6837 {
6838 char
6839 *canonical_page,
6840 page[MaxTextExtent];
6841
6842 const char
6843 *image_option;
6844
6845 MagickStatusType
6846 flags;
6847
6848 RectangleInfo
6849 geometry;
6850
6851 if (*option == '+')
6852 {
6853 (void) DeleteImageOption(image_info,option+1);
6854 (void) CloneString(&image_info->page,(char *) NULL);
6855 break;
6856 }
6857 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6858 image_option=GetImageOption(image_info,"page");
6859 if (image_option != (const char *) NULL)
6860 flags=ParseAbsoluteGeometry(image_option,&geometry);
6861 canonical_page=GetPageGeometry(argv[i+1]);
6862 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6863 canonical_page=DestroyString(canonical_page);
6864 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006865 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006866 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6867 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006868 (unsigned long) geometry.width,(unsigned long) geometry.height,
6869 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006870 (void) SetImageOption(image_info,option+1,page);
6871 (void) CloneString(&image_info->page,page);
6872 break;
6873 }
6874 if (LocaleCompare("pen",option+1) == 0)
6875 {
6876 if (*option == '+')
6877 {
6878 (void) SetImageOption(image_info,option+1,"none");
6879 break;
6880 }
6881 (void) SetImageOption(image_info,option+1,argv[i+1]);
6882 break;
6883 }
6884 if (LocaleCompare("ping",option+1) == 0)
6885 {
6886 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6887 break;
6888 }
6889 if (LocaleCompare("pointsize",option+1) == 0)
6890 {
6891 if (*option == '+')
6892 geometry_info.rho=0.0;
6893 else
6894 (void) ParseGeometry(argv[i+1],&geometry_info);
6895 image_info->pointsize=geometry_info.rho;
6896 break;
6897 }
cristye7f51092010-01-17 00:39:37 +00006898 if (LocaleCompare("precision",option+1) == 0)
6899 {
cristybf2766a2010-01-17 03:33:23 +00006900 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006901 break;
6902 }
cristy3ed852e2009-09-05 21:47:34 +00006903 if (LocaleCompare("preview",option+1) == 0)
6904 {
6905 /*
6906 Preview image.
6907 */
6908 if (*option == '+')
6909 {
6910 image_info->preview_type=UndefinedPreview;
6911 break;
6912 }
6913 image_info->preview_type=(PreviewType) ParseMagickOption(
6914 MagickPreviewOptions,MagickFalse,argv[i+1]);
6915 break;
6916 }
6917 break;
6918 }
6919 case 'q':
6920 {
6921 if (LocaleCompare("quality",option+1) == 0)
6922 {
6923 /*
6924 Set image compression quality.
6925 */
6926 if (*option == '+')
6927 {
6928 image_info->quality=UndefinedCompressionQuality;
6929 (void) SetImageOption(image_info,option+1,"0");
6930 break;
6931 }
cristye27293e2009-12-18 02:53:20 +00006932 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006933 (void) SetImageOption(image_info,option+1,argv[i+1]);
6934 break;
6935 }
6936 if (LocaleCompare("quiet",option+1) == 0)
6937 {
6938 static WarningHandler
6939 warning_handler = (WarningHandler) NULL;
6940
6941 if (*option == '+')
6942 {
6943 /*
6944 Restore error or warning messages.
6945 */
6946 warning_handler=SetWarningHandler(warning_handler);
6947 break;
6948 }
6949 /*
6950 Suppress error or warning messages.
6951 */
6952 warning_handler=SetWarningHandler((WarningHandler) NULL);
6953 break;
6954 }
6955 break;
6956 }
6957 case 'r':
6958 {
6959 if (LocaleCompare("red-primary",option+1) == 0)
6960 {
6961 if (*option == '+')
6962 {
6963 (void) SetImageOption(image_info,option+1,"0.0");
6964 break;
6965 }
6966 (void) SetImageOption(image_info,option+1,argv[i+1]);
6967 break;
6968 }
6969 break;
6970 }
6971 case 's':
6972 {
6973 if (LocaleCompare("sampling-factor",option+1) == 0)
6974 {
6975 /*
6976 Set image sampling factor.
6977 */
6978 if (*option == '+')
6979 {
6980 if (image_info->sampling_factor != (char *) NULL)
6981 image_info->sampling_factor=DestroyString(
6982 image_info->sampling_factor);
6983 break;
6984 }
6985 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6986 break;
6987 }
6988 if (LocaleCompare("scene",option+1) == 0)
6989 {
6990 /*
6991 Set image scene.
6992 */
6993 if (*option == '+')
6994 {
6995 image_info->scene=0;
6996 (void) SetImageOption(image_info,option+1,"0");
6997 break;
6998 }
cristye27293e2009-12-18 02:53:20 +00006999 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007000 (void) SetImageOption(image_info,option+1,argv[i+1]);
7001 break;
7002 }
7003 if (LocaleCompare("seed",option+1) == 0)
7004 {
cristybb503372010-05-27 20:51:26 +00007005 size_t
cristy3ed852e2009-09-05 21:47:34 +00007006 seed;
7007
7008 if (*option == '+')
7009 {
cristybb503372010-05-27 20:51:26 +00007010 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007011 SeedPseudoRandomGenerator(seed);
7012 break;
7013 }
cristye27293e2009-12-18 02:53:20 +00007014 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007015 SeedPseudoRandomGenerator(seed);
7016 break;
7017 }
7018 if (LocaleCompare("size",option+1) == 0)
7019 {
7020 if (*option == '+')
7021 {
7022 if (image_info->size != (char *) NULL)
7023 image_info->size=DestroyString(image_info->size);
7024 break;
7025 }
7026 (void) CloneString(&image_info->size,argv[i+1]);
7027 break;
7028 }
7029 if (LocaleCompare("stroke",option+1) == 0)
7030 {
7031 if (*option == '+')
7032 {
7033 (void) SetImageOption(image_info,option+1,"none");
7034 break;
7035 }
7036 (void) SetImageOption(image_info,option+1,argv[i+1]);
7037 break;
7038 }
7039 if (LocaleCompare("strokewidth",option+1) == 0)
7040 {
7041 if (*option == '+')
7042 {
7043 (void) SetImageOption(image_info,option+1,"0");
7044 break;
7045 }
7046 (void) SetImageOption(image_info,option+1,argv[i+1]);
7047 break;
7048 }
cristyd9a29192010-10-16 16:49:53 +00007049 if (LocaleCompare("synchronize",option+1) == 0)
7050 {
7051 if (*option == '+')
7052 {
7053 image_info->synchronize=MagickFalse;
7054 break;
7055 }
7056 image_info->synchronize=MagickTrue;
7057 break;
7058 }
cristy3ed852e2009-09-05 21:47:34 +00007059 break;
7060 }
7061 case 't':
7062 {
7063 if (LocaleCompare("taint",option+1) == 0)
7064 {
7065 if (*option == '+')
7066 {
7067 (void) SetImageOption(image_info,option+1,"false");
7068 break;
7069 }
7070 (void) SetImageOption(image_info,option+1,"true");
7071 break;
7072 }
7073 if (LocaleCompare("texture",option+1) == 0)
7074 {
7075 if (*option == '+')
7076 {
7077 if (image_info->texture != (char *) NULL)
7078 image_info->texture=DestroyString(image_info->texture);
7079 break;
7080 }
7081 (void) CloneString(&image_info->texture,argv[i+1]);
7082 break;
7083 }
7084 if (LocaleCompare("tile-offset",option+1) == 0)
7085 {
7086 if (*option == '+')
7087 {
7088 (void) SetImageOption(image_info,option+1,"0");
7089 break;
7090 }
7091 (void) SetImageOption(image_info,option+1,argv[i+1]);
7092 break;
7093 }
7094 if (LocaleCompare("transparent-color",option+1) == 0)
7095 {
7096 if (*option == '+')
7097 {
7098 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7099 (void) SetImageOption(image_info,option+1,"none");
7100 break;
7101 }
7102 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7103 exception);
7104 (void) SetImageOption(image_info,option+1,argv[i+1]);
7105 break;
7106 }
7107 if (LocaleCompare("type",option+1) == 0)
7108 {
7109 if (*option == '+')
7110 {
cristy5f1c1ff2010-12-23 21:38:06 +00007111 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007112 (void) SetImageOption(image_info,option+1,"undefined");
7113 break;
7114 }
7115 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7116 MagickFalse,argv[i+1]);
7117 (void) SetImageOption(image_info,option+1,argv[i+1]);
7118 break;
7119 }
7120 break;
7121 }
7122 case 'u':
7123 {
7124 if (LocaleCompare("undercolor",option+1) == 0)
7125 {
7126 if (*option == '+')
7127 {
7128 (void) DeleteImageOption(image_info,option+1);
7129 break;
7130 }
7131 (void) SetImageOption(image_info,option+1,argv[i+1]);
7132 break;
7133 }
7134 if (LocaleCompare("units",option+1) == 0)
7135 {
7136 if (*option == '+')
7137 {
7138 image_info->units=UndefinedResolution;
7139 (void) SetImageOption(image_info,option+1,"undefined");
7140 break;
7141 }
7142 image_info->units=(ResolutionType) ParseMagickOption(
7143 MagickResolutionOptions,MagickFalse,argv[i+1]);
7144 (void) SetImageOption(image_info,option+1,argv[i+1]);
7145 break;
7146 }
7147 break;
7148 }
7149 case 'v':
7150 {
7151 if (LocaleCompare("verbose",option+1) == 0)
7152 {
7153 if (*option == '+')
7154 {
7155 image_info->verbose=MagickFalse;
7156 break;
7157 }
7158 image_info->verbose=MagickTrue;
7159 image_info->ping=MagickFalse;
7160 break;
7161 }
7162 if (LocaleCompare("view",option+1) == 0)
7163 {
7164 if (*option == '+')
7165 {
7166 if (image_info->view != (char *) NULL)
7167 image_info->view=DestroyString(image_info->view);
7168 break;
7169 }
7170 (void) CloneString(&image_info->view,argv[i+1]);
7171 break;
7172 }
7173 if (LocaleCompare("virtual-pixel",option+1) == 0)
7174 {
7175 if (*option == '+')
7176 {
7177 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7178 (void) SetImageOption(image_info,option+1,"undefined");
7179 break;
7180 }
7181 image_info->virtual_pixel_method=(VirtualPixelMethod)
7182 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7183 argv[i+1]);
7184 (void) SetImageOption(image_info,option+1,argv[i+1]);
7185 break;
7186 }
7187 break;
7188 }
7189 case 'w':
7190 {
7191 if (LocaleCompare("white-point",option+1) == 0)
7192 {
7193 if (*option == '+')
7194 {
7195 (void) SetImageOption(image_info,option+1,"0.0");
7196 break;
7197 }
7198 (void) SetImageOption(image_info,option+1,argv[i+1]);
7199 break;
7200 }
7201 break;
7202 }
7203 default:
7204 break;
7205 }
7206 i+=count;
7207 }
7208 return(MagickTrue);
7209}
7210
7211/*
7212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7213% %
7214% %
7215% %
7216+ M o g r i f y I m a g e L i s t %
7217% %
7218% %
7219% %
7220%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7221%
7222% MogrifyImageList() applies any command line options that might affect the
7223% entire image list (e.g. -append, -coalesce, etc.).
7224%
7225% The format of the MogrifyImage method is:
7226%
7227% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7228% const char **argv,Image **images,ExceptionInfo *exception)
7229%
7230% A description of each parameter follows:
7231%
7232% o image_info: the image info..
7233%
7234% o argc: Specifies a pointer to an integer describing the number of
7235% elements in the argument vector.
7236%
7237% o argv: Specifies a pointer to a text array containing the command line
7238% arguments.
7239%
anthonye9c27192011-03-27 08:07:06 +00007240% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007241%
7242% o exception: return any errors or warnings in this structure.
7243%
7244*/
7245WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7246 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7247{
7248 ChannelType
7249 channel;
7250
7251 const char
7252 *option;
7253
cristy6b3da3a2010-06-20 02:21:46 +00007254 ImageInfo
7255 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007256
7257 MagickStatusType
7258 status;
7259
7260 QuantizeInfo
7261 *quantize_info;
7262
cristybb503372010-05-27 20:51:26 +00007263 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007264 i;
7265
cristy6b3da3a2010-06-20 02:21:46 +00007266 ssize_t
7267 count,
7268 index;
7269
cristy3ed852e2009-09-05 21:47:34 +00007270 /*
7271 Apply options to the image list.
7272 */
7273 assert(image_info != (ImageInfo *) NULL);
7274 assert(image_info->signature == MagickSignature);
7275 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007276 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007277 assert((*images)->signature == MagickSignature);
7278 if ((*images)->debug != MagickFalse)
7279 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7280 (*images)->filename);
7281 if ((argc <= 0) || (*argv == (char *) NULL))
7282 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007283 mogrify_info=CloneImageInfo(image_info);
7284 quantize_info=AcquireQuantizeInfo(mogrify_info);
7285 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007286 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007287 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007288 {
cristy74fe8f12009-10-03 19:09:01 +00007289 if (*images == (Image *) NULL)
7290 break;
cristy3ed852e2009-09-05 21:47:34 +00007291 option=argv[i];
7292 if (IsMagickOption(option) == MagickFalse)
7293 continue;
7294 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7295 0L);
cristycee97112010-05-28 00:44:52 +00007296 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007297 break;
cristy6b3da3a2010-06-20 02:21:46 +00007298 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007299 switch (*(option+1))
7300 {
7301 case 'a':
7302 {
7303 if (LocaleCompare("affinity",option+1) == 0)
7304 {
cristy6b3da3a2010-06-20 02:21:46 +00007305 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007306 if (*option == '+')
7307 {
7308 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7309 InheritException(exception,&(*images)->exception);
7310 break;
7311 }
7312 i++;
7313 break;
7314 }
7315 if (LocaleCompare("append",option+1) == 0)
7316 {
7317 Image
7318 *append_image;
7319
cristy6b3da3a2010-06-20 02:21:46 +00007320 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007321 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7322 MagickFalse,exception);
7323 if (append_image == (Image *) NULL)
7324 {
7325 status=MagickFalse;
7326 break;
7327 }
7328 *images=DestroyImageList(*images);
7329 *images=append_image;
7330 break;
7331 }
7332 if (LocaleCompare("average",option+1) == 0)
7333 {
7334 Image
7335 *average_image;
7336
cristyd18ae7c2010-03-07 17:39:52 +00007337 /*
7338 Average an image sequence (deprecated).
7339 */
cristy6b3da3a2010-06-20 02:21:46 +00007340 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007341 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7342 exception);
cristy3ed852e2009-09-05 21:47:34 +00007343 if (average_image == (Image *) NULL)
7344 {
7345 status=MagickFalse;
7346 break;
7347 }
7348 *images=DestroyImageList(*images);
7349 *images=average_image;
7350 break;
7351 }
7352 break;
7353 }
7354 case 'c':
7355 {
7356 if (LocaleCompare("channel",option+1) == 0)
7357 {
7358 if (*option == '+')
7359 {
7360 channel=DefaultChannels;
7361 break;
7362 }
7363 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7364 break;
7365 }
7366 if (LocaleCompare("clut",option+1) == 0)
7367 {
7368 Image
7369 *clut_image,
7370 *image;
7371
cristy6b3da3a2010-06-20 02:21:46 +00007372 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007373 image=RemoveFirstImageFromList(images);
7374 clut_image=RemoveFirstImageFromList(images);
7375 if (clut_image == (Image *) NULL)
7376 {
7377 status=MagickFalse;
7378 break;
7379 }
7380 (void) ClutImageChannel(image,channel,clut_image);
7381 clut_image=DestroyImage(clut_image);
7382 InheritException(exception,&image->exception);
7383 *images=DestroyImageList(*images);
7384 *images=image;
7385 break;
7386 }
7387 if (LocaleCompare("coalesce",option+1) == 0)
7388 {
7389 Image
7390 *coalesce_image;
7391
cristy6b3da3a2010-06-20 02:21:46 +00007392 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007393 coalesce_image=CoalesceImages(*images,exception);
7394 if (coalesce_image == (Image *) NULL)
7395 {
7396 status=MagickFalse;
7397 break;
7398 }
7399 *images=DestroyImageList(*images);
7400 *images=coalesce_image;
7401 break;
7402 }
7403 if (LocaleCompare("combine",option+1) == 0)
7404 {
7405 Image
7406 *combine_image;
7407
cristy6b3da3a2010-06-20 02:21:46 +00007408 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007409 combine_image=CombineImages(*images,channel,exception);
7410 if (combine_image == (Image *) NULL)
7411 {
7412 status=MagickFalse;
7413 break;
7414 }
7415 *images=DestroyImageList(*images);
7416 *images=combine_image;
7417 break;
7418 }
7419 if (LocaleCompare("composite",option+1) == 0)
7420 {
7421 Image
7422 *mask_image,
7423 *composite_image,
7424 *image;
7425
7426 RectangleInfo
7427 geometry;
7428
cristy6b3da3a2010-06-20 02:21:46 +00007429 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007430 image=RemoveFirstImageFromList(images);
7431 composite_image=RemoveFirstImageFromList(images);
7432 if (composite_image == (Image *) NULL)
7433 {
7434 status=MagickFalse;
7435 break;
7436 }
7437 (void) TransformImage(&composite_image,(char *) NULL,
7438 composite_image->geometry);
7439 SetGeometry(composite_image,&geometry);
7440 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7441 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7442 &geometry);
7443 mask_image=RemoveFirstImageFromList(images);
7444 if (mask_image != (Image *) NULL)
7445 {
7446 if ((image->compose == DisplaceCompositeOp) ||
7447 (image->compose == DistortCompositeOp))
7448 {
7449 /*
7450 Merge Y displacement into X displacement image.
7451 */
7452 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7453 mask_image,0,0);
7454 mask_image=DestroyImage(mask_image);
7455 }
7456 else
7457 {
7458 /*
7459 Set a blending mask for the composition.
7460 */
7461 image->mask=mask_image;
7462 (void) NegateImage(image->mask,MagickFalse);
7463 }
7464 }
7465 (void) CompositeImageChannel(image,channel,image->compose,
7466 composite_image,geometry.x,geometry.y);
7467 if (image->mask != (Image *) NULL)
7468 image->mask=DestroyImage(image->mask);
7469 composite_image=DestroyImage(composite_image);
7470 InheritException(exception,&image->exception);
7471 *images=DestroyImageList(*images);
7472 *images=image;
7473 break;
7474 }
anthony9f4f0342011-03-28 11:47:22 +00007475#if 0
7476This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007477 if (LocaleCompare("crop",option+1) == 0)
7478 {
7479 MagickStatusType
7480 flags;
7481
7482 RectangleInfo
7483 geometry;
7484
anthonye9c27192011-03-27 08:07:06 +00007485 /*
anthony9f4f0342011-03-28 11:47:22 +00007486 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007487 */
cristy6b3da3a2010-06-20 02:21:46 +00007488 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007489 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7490 if (((geometry.width == 0) && (geometry.height == 0)) ||
7491 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7492 break;
7493 (void) TransformImages(images,argv[i+1],(char *) NULL);
7494 InheritException(exception,&(*images)->exception);
7495 break;
7496 }
anthony9f4f0342011-03-28 11:47:22 +00007497#endif
cristy3ed852e2009-09-05 21:47:34 +00007498 break;
7499 }
7500 case 'd':
7501 {
7502 if (LocaleCompare("deconstruct",option+1) == 0)
7503 {
7504 Image
7505 *deconstruct_image;
7506
cristy6b3da3a2010-06-20 02:21:46 +00007507 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007508 deconstruct_image=DeconstructImages(*images,exception);
7509 if (deconstruct_image == (Image *) NULL)
7510 {
7511 status=MagickFalse;
7512 break;
7513 }
7514 *images=DestroyImageList(*images);
7515 *images=deconstruct_image;
7516 break;
7517 }
7518 if (LocaleCompare("delete",option+1) == 0)
7519 {
7520 if (*option == '+')
7521 DeleteImages(images,"-1",exception);
7522 else
7523 DeleteImages(images,argv[i+1],exception);
7524 break;
7525 }
7526 if (LocaleCompare("dither",option+1) == 0)
7527 {
7528 if (*option == '+')
7529 {
7530 quantize_info->dither=MagickFalse;
7531 break;
7532 }
7533 quantize_info->dither=MagickTrue;
7534 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7535 MagickDitherOptions,MagickFalse,argv[i+1]);
7536 break;
7537 }
cristyecb10ff2011-03-22 13:14:03 +00007538 if (LocaleCompare("duplicate",option+1) == 0)
7539 {
cristy72988482011-03-29 16:34:38 +00007540 Image
7541 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007542
anthony2b6bcae2011-03-23 13:05:34 +00007543 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007544 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7545 else
7546 {
7547 const char
7548 *p;
7549
anthony2b6bcae2011-03-23 13:05:34 +00007550 size_t
7551 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007552
anthony2b6bcae2011-03-23 13:05:34 +00007553 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007554 p=strchr(argv[i+1],',');
7555 if (p == (const char *) NULL)
7556 duplicate_images=DuplicateImages(*images,number_duplicates,
7557 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007558 else
cristy72988482011-03-29 16:34:38 +00007559 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7560 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007561 }
7562 AppendImageToList(images, duplicate_images);
7563 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007564 break;
7565 }
cristy3ed852e2009-09-05 21:47:34 +00007566 break;
7567 }
cristyd18ae7c2010-03-07 17:39:52 +00007568 case 'e':
7569 {
7570 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7571 {
7572 Image
7573 *evaluate_image;
7574
7575 MagickEvaluateOperator
7576 op;
7577
cristy6b3da3a2010-06-20 02:21:46 +00007578 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007579 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7580 MagickFalse,argv[i+1]);
7581 evaluate_image=EvaluateImages(*images,op,exception);
7582 if (evaluate_image == (Image *) NULL)
7583 {
7584 status=MagickFalse;
7585 break;
7586 }
7587 *images=DestroyImageList(*images);
7588 *images=evaluate_image;
7589 break;
7590 }
7591 break;
7592 }
cristy3ed852e2009-09-05 21:47:34 +00007593 case 'f':
7594 {
cristyf0a247f2009-10-04 00:20:03 +00007595 if (LocaleCompare("fft",option+1) == 0)
7596 {
7597 Image
7598 *fourier_image;
7599
7600 /*
7601 Implements the discrete Fourier transform (DFT).
7602 */
cristy6b3da3a2010-06-20 02:21:46 +00007603 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007604 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7605 MagickTrue : MagickFalse,exception);
7606 if (fourier_image == (Image *) NULL)
7607 break;
7608 *images=DestroyImage(*images);
7609 *images=fourier_image;
7610 break;
7611 }
cristy3ed852e2009-09-05 21:47:34 +00007612 if (LocaleCompare("flatten",option+1) == 0)
7613 {
7614 Image
7615 *flatten_image;
7616
cristy6b3da3a2010-06-20 02:21:46 +00007617 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007618 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7619 if (flatten_image == (Image *) NULL)
7620 break;
7621 *images=DestroyImageList(*images);
7622 *images=flatten_image;
7623 break;
7624 }
7625 if (LocaleCompare("fx",option+1) == 0)
7626 {
7627 Image
7628 *fx_image;
7629
cristy6b3da3a2010-06-20 02:21:46 +00007630 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007631 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7632 if (fx_image == (Image *) NULL)
7633 {
7634 status=MagickFalse;
7635 break;
7636 }
7637 *images=DestroyImageList(*images);
7638 *images=fx_image;
7639 break;
7640 }
7641 break;
7642 }
7643 case 'h':
7644 {
7645 if (LocaleCompare("hald-clut",option+1) == 0)
7646 {
7647 Image
7648 *hald_image,
7649 *image;
7650
cristy6b3da3a2010-06-20 02:21:46 +00007651 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007652 image=RemoveFirstImageFromList(images);
7653 hald_image=RemoveFirstImageFromList(images);
7654 if (hald_image == (Image *) NULL)
7655 {
7656 status=MagickFalse;
7657 break;
7658 }
7659 (void) HaldClutImageChannel(image,channel,hald_image);
7660 hald_image=DestroyImage(hald_image);
7661 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007662 if (*images != (Image *) NULL)
7663 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007664 *images=image;
7665 break;
7666 }
7667 break;
7668 }
7669 case 'i':
7670 {
7671 if (LocaleCompare("ift",option+1) == 0)
7672 {
7673 Image
cristy8587f882009-11-13 20:28:49 +00007674 *fourier_image,
7675 *magnitude_image,
7676 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007677
7678 /*
7679 Implements the inverse fourier discrete Fourier transform (DFT).
7680 */
cristy6b3da3a2010-06-20 02:21:46 +00007681 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007682 magnitude_image=RemoveFirstImageFromList(images);
7683 phase_image=RemoveFirstImageFromList(images);
7684 if (phase_image == (Image *) NULL)
7685 {
7686 status=MagickFalse;
7687 break;
7688 }
7689 fourier_image=InverseFourierTransformImage(magnitude_image,
7690 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007691 if (fourier_image == (Image *) NULL)
7692 break;
cristy0aff6ea2009-11-14 01:40:53 +00007693 if (*images != (Image *) NULL)
7694 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007695 *images=fourier_image;
7696 break;
7697 }
7698 if (LocaleCompare("insert",option+1) == 0)
7699 {
7700 Image
7701 *p,
7702 *q;
7703
7704 index=0;
7705 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007706 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007707 p=RemoveLastImageFromList(images);
7708 if (p == (Image *) NULL)
7709 {
7710 (void) ThrowMagickException(exception,GetMagickModule(),
7711 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7712 status=MagickFalse;
7713 break;
7714 }
7715 q=p;
7716 if (index == 0)
7717 PrependImageToList(images,q);
7718 else
cristybb503372010-05-27 20:51:26 +00007719 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007720 AppendImageToList(images,q);
7721 else
7722 {
7723 q=GetImageFromList(*images,index-1);
7724 if (q == (Image *) NULL)
7725 {
7726 (void) ThrowMagickException(exception,GetMagickModule(),
7727 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7728 status=MagickFalse;
7729 break;
7730 }
7731 InsertImageInList(&q,p);
7732 }
7733 *images=GetFirstImageInList(q);
7734 break;
7735 }
7736 break;
7737 }
7738 case 'l':
7739 {
7740 if (LocaleCompare("layers",option+1) == 0)
7741 {
7742 Image
7743 *layers;
7744
7745 ImageLayerMethod
7746 method;
7747
cristy6b3da3a2010-06-20 02:21:46 +00007748 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007749 layers=(Image *) NULL;
7750 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7751 MagickFalse,argv[i+1]);
7752 switch (method)
7753 {
7754 case CoalesceLayer:
7755 {
7756 layers=CoalesceImages(*images,exception);
7757 break;
7758 }
7759 case CompareAnyLayer:
7760 case CompareClearLayer:
7761 case CompareOverlayLayer:
7762 default:
7763 {
7764 layers=CompareImageLayers(*images,method,exception);
7765 break;
7766 }
7767 case MergeLayer:
7768 case FlattenLayer:
7769 case MosaicLayer:
7770 case TrimBoundsLayer:
7771 {
7772 layers=MergeImageLayers(*images,method,exception);
7773 break;
7774 }
7775 case DisposeLayer:
7776 {
7777 layers=DisposeImages(*images,exception);
7778 break;
7779 }
7780 case OptimizeImageLayer:
7781 {
7782 layers=OptimizeImageLayers(*images,exception);
7783 break;
7784 }
7785 case OptimizePlusLayer:
7786 {
7787 layers=OptimizePlusImageLayers(*images,exception);
7788 break;
7789 }
7790 case OptimizeTransLayer:
7791 {
7792 OptimizeImageTransparency(*images,exception);
7793 break;
7794 }
7795 case RemoveDupsLayer:
7796 {
7797 RemoveDuplicateLayers(images,exception);
7798 break;
7799 }
7800 case RemoveZeroLayer:
7801 {
7802 RemoveZeroDelayLayers(images,exception);
7803 break;
7804 }
7805 case OptimizeLayer:
7806 {
7807 /*
7808 General Purpose, GIF Animation Optimizer.
7809 */
7810 layers=CoalesceImages(*images,exception);
7811 if (layers == (Image *) NULL)
7812 {
7813 status=MagickFalse;
7814 break;
7815 }
7816 InheritException(exception,&layers->exception);
7817 *images=DestroyImageList(*images);
7818 *images=layers;
7819 layers=OptimizeImageLayers(*images,exception);
7820 if (layers == (Image *) NULL)
7821 {
7822 status=MagickFalse;
7823 break;
7824 }
7825 InheritException(exception,&layers->exception);
7826 *images=DestroyImageList(*images);
7827 *images=layers;
7828 layers=(Image *) NULL;
7829 OptimizeImageTransparency(*images,exception);
7830 InheritException(exception,&(*images)->exception);
7831 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7832 break;
7833 }
7834 case CompositeLayer:
7835 {
7836 CompositeOperator
7837 compose;
7838
7839 Image
7840 *source;
7841
7842 RectangleInfo
7843 geometry;
7844
7845 /*
7846 Split image sequence at the first 'NULL:' image.
7847 */
7848 source=(*images);
7849 while (source != (Image *) NULL)
7850 {
7851 source=GetNextImageInList(source);
7852 if ((source != (Image *) NULL) &&
7853 (LocaleCompare(source->magick,"NULL") == 0))
7854 break;
7855 }
7856 if (source != (Image *) NULL)
7857 {
7858 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7859 (GetNextImageInList(source) == (Image *) NULL))
7860 source=(Image *) NULL;
7861 else
7862 {
7863 /*
7864 Separate the two lists, junk the null: image.
7865 */
7866 source=SplitImageList(source->previous);
7867 DeleteImageFromList(&source);
7868 }
7869 }
7870 if (source == (Image *) NULL)
7871 {
7872 (void) ThrowMagickException(exception,GetMagickModule(),
7873 OptionError,"MissingNullSeparator","layers Composite");
7874 status=MagickFalse;
7875 break;
7876 }
7877 /*
7878 Adjust offset with gravity and virtual canvas.
7879 */
7880 SetGeometry(*images,&geometry);
7881 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7882 geometry.width=source->page.width != 0 ?
7883 source->page.width : source->columns;
7884 geometry.height=source->page.height != 0 ?
7885 source->page.height : source->rows;
7886 GravityAdjustGeometry((*images)->page.width != 0 ?
7887 (*images)->page.width : (*images)->columns,
7888 (*images)->page.height != 0 ? (*images)->page.height :
7889 (*images)->rows,(*images)->gravity,&geometry);
7890 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007891 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007892 if (option != (const char *) NULL)
7893 compose=(CompositeOperator) ParseMagickOption(
7894 MagickComposeOptions,MagickFalse,option);
7895 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7896 exception);
7897 source=DestroyImageList(source);
7898 break;
7899 }
7900 }
7901 if (layers == (Image *) NULL)
7902 break;
7903 InheritException(exception,&layers->exception);
7904 *images=DestroyImageList(*images);
7905 *images=layers;
7906 break;
7907 }
7908 break;
7909 }
7910 case 'm':
7911 {
7912 if (LocaleCompare("map",option+1) == 0)
7913 {
cristy6b3da3a2010-06-20 02:21:46 +00007914 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007915 if (*option == '+')
7916 {
7917 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7918 InheritException(exception,&(*images)->exception);
7919 break;
7920 }
7921 i++;
7922 break;
7923 }
cristyf40785b2010-03-06 02:27:27 +00007924 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007925 {
7926 Image
cristyf40785b2010-03-06 02:27:27 +00007927 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007928
cristyd18ae7c2010-03-07 17:39:52 +00007929 /*
7930 Maximum image sequence (deprecated).
7931 */
cristy6b3da3a2010-06-20 02:21:46 +00007932 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007933 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007934 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007935 {
7936 status=MagickFalse;
7937 break;
7938 }
7939 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007940 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007941 break;
7942 }
cristyf40785b2010-03-06 02:27:27 +00007943 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007944 {
7945 Image
cristyf40785b2010-03-06 02:27:27 +00007946 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007947
cristyd18ae7c2010-03-07 17:39:52 +00007948 /*
7949 Minimum image sequence (deprecated).
7950 */
cristy6b3da3a2010-06-20 02:21:46 +00007951 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007952 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007953 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007954 {
7955 status=MagickFalse;
7956 break;
7957 }
7958 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007959 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007960 break;
7961 }
cristy3ed852e2009-09-05 21:47:34 +00007962 if (LocaleCompare("morph",option+1) == 0)
7963 {
7964 Image
7965 *morph_image;
7966
cristy6b3da3a2010-06-20 02:21:46 +00007967 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007968 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007969 exception);
7970 if (morph_image == (Image *) NULL)
7971 {
7972 status=MagickFalse;
7973 break;
7974 }
7975 *images=DestroyImageList(*images);
7976 *images=morph_image;
7977 break;
7978 }
7979 if (LocaleCompare("mosaic",option+1) == 0)
7980 {
7981 Image
7982 *mosaic_image;
7983
cristy6b3da3a2010-06-20 02:21:46 +00007984 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007985 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7986 if (mosaic_image == (Image *) NULL)
7987 {
7988 status=MagickFalse;
7989 break;
7990 }
7991 *images=DestroyImageList(*images);
7992 *images=mosaic_image;
7993 break;
7994 }
7995 break;
7996 }
7997 case 'p':
7998 {
7999 if (LocaleCompare("print",option+1) == 0)
8000 {
8001 char
8002 *string;
8003
cristy6b3da3a2010-06-20 02:21:46 +00008004 (void) SyncImagesSettings(mogrify_info,*images);
8005 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008006 if (string == (char *) NULL)
8007 break;
8008 InheritException(exception,&(*images)->exception);
8009 (void) fprintf(stdout,"%s",string);
8010 string=DestroyString(string);
8011 }
8012 if (LocaleCompare("process",option+1) == 0)
8013 {
8014 char
8015 **arguments;
8016
8017 int
8018 j,
8019 number_arguments;
8020
cristy6b3da3a2010-06-20 02:21:46 +00008021 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008022 arguments=StringToArgv(argv[i+1],&number_arguments);
8023 if (arguments == (char **) NULL)
8024 break;
8025 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8026 {
8027 char
8028 breaker,
8029 quote,
8030 *token;
8031
8032 const char
8033 *arguments;
8034
8035 int
8036 next,
8037 status;
8038
8039 size_t
8040 length;
8041
8042 TokenInfo
8043 *token_info;
8044
8045 /*
8046 Support old style syntax, filter="-option arg".
8047 */
8048 length=strlen(argv[i+1]);
8049 token=(char *) NULL;
8050 if (~length >= MaxTextExtent)
8051 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8052 sizeof(*token));
8053 if (token == (char *) NULL)
8054 break;
8055 next=0;
8056 arguments=argv[i+1];
8057 token_info=AcquireTokenInfo();
8058 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8059 "\"",'\0',&breaker,&next,&quote);
8060 token_info=DestroyTokenInfo(token_info);
8061 if (status == 0)
8062 {
8063 const char
8064 *argv;
8065
8066 argv=(&(arguments[next]));
8067 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8068 exception);
8069 }
8070 token=DestroyString(token);
8071 break;
8072 }
cristy91c0da22010-05-02 01:44:07 +00008073 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008074 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8075 number_arguments-2,(const char **) arguments+2,exception);
8076 for (j=0; j < number_arguments; j++)
8077 arguments[j]=DestroyString(arguments[j]);
8078 arguments=(char **) RelinquishMagickMemory(arguments);
8079 break;
8080 }
8081 break;
8082 }
8083 case 'r':
8084 {
8085 if (LocaleCompare("reverse",option+1) == 0)
8086 {
8087 ReverseImageList(images);
8088 InheritException(exception,&(*images)->exception);
8089 break;
8090 }
8091 break;
8092 }
8093 case 's':
8094 {
cristy4285d782011-02-09 20:12:28 +00008095 if (LocaleCompare("smush",option+1) == 0)
8096 {
8097 Image
8098 *smush_image;
8099
8100 ssize_t
8101 offset;
8102
8103 (void) SyncImagesSettings(mogrify_info,*images);
8104 offset=(ssize_t) StringToLong(argv[i+1]);
8105 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8106 MagickFalse,offset,exception);
8107 if (smush_image == (Image *) NULL)
8108 {
8109 status=MagickFalse;
8110 break;
8111 }
8112 *images=DestroyImageList(*images);
8113 *images=smush_image;
8114 break;
8115 }
cristy3ed852e2009-09-05 21:47:34 +00008116 if (LocaleCompare("swap",option+1) == 0)
8117 {
8118 Image
8119 *p,
8120 *q,
8121 *swap;
8122
cristybb503372010-05-27 20:51:26 +00008123 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008124 swap_index;
8125
8126 index=(-1);
8127 swap_index=(-2);
8128 if (*option != '+')
8129 {
8130 GeometryInfo
8131 geometry_info;
8132
8133 MagickStatusType
8134 flags;
8135
8136 swap_index=(-1);
8137 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008138 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008139 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008140 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008141 }
8142 p=GetImageFromList(*images,index);
8143 q=GetImageFromList(*images,swap_index);
8144 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8145 {
8146 (void) ThrowMagickException(exception,GetMagickModule(),
8147 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8148 status=MagickFalse;
8149 break;
8150 }
8151 if (p == q)
8152 break;
8153 swap=CloneImage(p,0,0,MagickTrue,exception);
8154 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8155 ReplaceImageInList(&q,swap);
8156 *images=GetFirstImageInList(q);
8157 break;
8158 }
8159 break;
8160 }
8161 case 'w':
8162 {
8163 if (LocaleCompare("write",option+1) == 0)
8164 {
cristy071dd7b2010-04-09 13:04:54 +00008165 char
cristy06609ee2010-03-17 20:21:27 +00008166 key[MaxTextExtent];
8167
cristy3ed852e2009-09-05 21:47:34 +00008168 Image
8169 *write_images;
8170
8171 ImageInfo
8172 *write_info;
8173
cristy6b3da3a2010-06-20 02:21:46 +00008174 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008175 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8176 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008177 write_images=(*images);
8178 if (*option == '+')
8179 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008180 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008181 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8182 write_info=DestroyImageInfo(write_info);
8183 if (*option == '+')
8184 write_images=DestroyImageList(write_images);
8185 break;
8186 }
8187 break;
8188 }
8189 default:
8190 break;
8191 }
8192 i+=count;
8193 }
8194 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008195 mogrify_info=DestroyImageInfo(mogrify_info);
8196 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008197 return(status != 0 ? MagickTrue : MagickFalse);
8198}
8199
8200/*
8201%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8202% %
8203% %
8204% %
8205+ M o g r i f y I m a g e s %
8206% %
8207% %
8208% %
8209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8210%
8211% MogrifyImages() applies image processing options to a sequence of images as
8212% prescribed by command line options.
8213%
8214% The format of the MogrifyImage method is:
8215%
8216% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8217% const MagickBooleanType post,const int argc,const char **argv,
8218% Image **images,Exceptioninfo *exception)
8219%
8220% A description of each parameter follows:
8221%
8222% o image_info: the image info..
8223%
8224% o post: If true, post process image list operators otherwise pre-process.
8225%
8226% o argc: Specifies a pointer to an integer describing the number of
8227% elements in the argument vector.
8228%
8229% o argv: Specifies a pointer to a text array containing the command line
8230% arguments.
8231%
anthonye9c27192011-03-27 08:07:06 +00008232% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008233%
8234% o exception: return any errors or warnings in this structure.
8235%
8236*/
8237WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8238 const MagickBooleanType post,const int argc,const char **argv,
8239 Image **images,ExceptionInfo *exception)
8240{
8241#define MogrifyImageTag "Mogrify/Image"
8242
anthonye9c27192011-03-27 08:07:06 +00008243 MagickStatusType
8244 status;
cristy3ed852e2009-09-05 21:47:34 +00008245
cristy0e9f9c12010-02-11 03:00:47 +00008246 MagickBooleanType
8247 proceed;
8248
anthonye9c27192011-03-27 08:07:06 +00008249 size_t
8250 n;
cristy3ed852e2009-09-05 21:47:34 +00008251
cristybb503372010-05-27 20:51:26 +00008252 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008253 i;
8254
cristy3ed852e2009-09-05 21:47:34 +00008255 assert(image_info != (ImageInfo *) NULL);
8256 assert(image_info->signature == MagickSignature);
8257 if (images == (Image **) NULL)
8258 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008259 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008260 assert((*images)->signature == MagickSignature);
8261 if ((*images)->debug != MagickFalse)
8262 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8263 (*images)->filename);
8264 if ((argc <= 0) || (*argv == (char *) NULL))
8265 return(MagickTrue);
8266 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8267 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008268 status=0;
anthonye9c27192011-03-27 08:07:06 +00008269
8270 /*
8271 Pre-process multi-image sequence operators
8272 */
cristy3ed852e2009-09-05 21:47:34 +00008273 if (post == MagickFalse)
8274 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008275
8276 /*
8277 For each image, process simple single image operators
8278 */
8279 i=0;
8280 n=GetImageListLength(*images);
8281 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008282 {
anthonye9c27192011-03-27 08:07:06 +00008283 status&=MogrifyImage(image_info,argc,argv,images,exception);
8284 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008285 if (proceed == MagickFalse)
8286 break;
anthonye9c27192011-03-27 08:07:06 +00008287 if ( (*images)->next == (Image *) NULL )
8288 break;
8289 *images=(*images)->next;
8290 i++;
cristy3ed852e2009-09-05 21:47:34 +00008291 }
anthonye9c27192011-03-27 08:07:06 +00008292 assert( *images != (Image *) NULL );
8293
8294 /*
8295 Post-process, multi-image sequence operators
8296 */
8297 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008298 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008299 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008300 return(status != 0 ? MagickTrue : MagickFalse);
8301}