blob: 03161b0a891674e73e80c5e2e96ad6ca155b4e52 [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
677 *new_image;
678
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);
anthonye9c27192011-03-27 08:07:06 +0000690 new_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;
anthonye9c27192011-03-27 08:07:06 +0000704 new_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);
anthonye9c27192011-03-27 08:07:06 +0000715 new_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;
anthonye9c27192011-03-27 08:07:06 +0000728 new_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 {
anthonye9c27192011-03-27 08:07:06 +0000825 new_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000826 break;
827 }
828 case BottomRightOrientation:
829 {
anthonye9c27192011-03-27 08:07:06 +0000830 new_image=RotateImage(*image,180.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000831 break;
832 }
833 case BottomLeftOrientation:
834 {
anthonye9c27192011-03-27 08:07:06 +0000835 new_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000836 break;
837 }
838 case LeftTopOrientation:
839 {
anthonye9c27192011-03-27 08:07:06 +0000840 new_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000841 break;
842 }
843 case RightTopOrientation:
844 {
anthonye9c27192011-03-27 08:07:06 +0000845 new_image=RotateImage(*image,90.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000846 break;
847 }
848 case RightBottomOrientation:
849 {
anthonye9c27192011-03-27 08:07:06 +0000850 new_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000851 break;
852 }
853 case LeftBottomOrientation:
854 {
anthonye9c27192011-03-27 08:07:06 +0000855 new_image=RotateImage(*image,270.0,exception);
cristy3ed852e2009-09-05 21:47:34 +0000856 break;
857 }
858 default:
859 break;
860 }
anthonye9c27192011-03-27 08:07:06 +0000861 if (new_image != (Image *) NULL)
862 new_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);
anthonye9c27192011-03-27 08:07:06 +0000889 new_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;
anthonye9c27192011-03-27 08:07:06 +0000901 new_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;
anthonye9c27192011-03-27 08:07:06 +0000914 new_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;
anthonye9c27192011-03-27 08:07:06 +0000998 new_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);
anthonye9c27192011-03-27 08:07:06 +00001009 new_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);
anthonye9c27192011-03-27 08:07:06 +00001110 new_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;
anthonye9c27192011-03-27 08:07:06 +00001123 new_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;
anthonye9c27192011-03-27 08:07:06 +00001220 new_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
1228 NOTE that 'tile cropping' (no geometry offsets) is not
1229 performed here but is applied in MogrifyImageList().
1230 In any case 'equal area sub-division' via the '@' flag can
1231 and does generate multiple images here (if offset also given).
1232
1233 We could easily remove "-crop" handling in MogrifyImageList()
1234 simply by removing the next 'if' statement below.
1235
1236 The special handling (Clone of current image) is needed as
1237 TransformImage() will destory and replace the list the image is
1238 located in. This should be fixed.
1239 */
cristy6b3da3a2010-06-20 02:21:46 +00001240 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001241 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1242 if (((geometry.width != 0) || (geometry.height != 0)) &&
1243 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1244 break;
anthonye9c27192011-03-27 08:07:06 +00001245 new_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1246 new_image->next = new_image->previous = (Image *)NULL;
1247 (void) TransformImage(&new_image,argv[i+1],(char *) NULL);
1248 InheritException(exception,&new_image->exception);
cristy3ed852e2009-09-05 21:47:34 +00001249 break;
1250 }
1251 if (LocaleCompare("cycle",option+1) == 0)
1252 {
1253 /*
1254 Cycle an image colormap.
1255 */
cristy6b3da3a2010-06-20 02:21:46 +00001256 (void) SyncImageSettings(mogrify_info,*image);
cristy32c2aea2010-12-01 01:00:50 +00001257 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001258 InheritException(exception,&(*image)->exception);
1259 break;
1260 }
1261 break;
1262 }
1263 case 'd':
1264 {
1265 if (LocaleCompare("decipher",option+1) == 0)
1266 {
1267 StringInfo
1268 *passkey;
1269
1270 /*
1271 Decipher pixels.
1272 */
cristy6b3da3a2010-06-20 02:21:46 +00001273 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001274 passkey=FileToStringInfo(argv[i+1],~0,exception);
1275 if (passkey != (StringInfo *) NULL)
1276 {
1277 (void) PasskeyDecipherImage(*image,passkey,exception);
1278 passkey=DestroyStringInfo(passkey);
1279 }
1280 break;
1281 }
1282 if (LocaleCompare("density",option+1) == 0)
1283 {
1284 /*
1285 Set image density.
1286 */
1287 (void) CloneString(&draw_info->density,argv[i+1]);
1288 break;
1289 }
1290 if (LocaleCompare("depth",option+1) == 0)
1291 {
cristy6b3da3a2010-06-20 02:21:46 +00001292 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001293 if (*option == '+')
1294 {
1295 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1296 break;
1297 }
cristye27293e2009-12-18 02:53:20 +00001298 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001299 break;
1300 }
1301 if (LocaleCompare("deskew",option+1) == 0)
1302 {
1303 double
1304 threshold;
1305
cristy3ed852e2009-09-05 21:47:34 +00001306 /*
1307 Straighten the image.
1308 */
cristy6b3da3a2010-06-20 02:21:46 +00001309 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001310 if (*option == '+')
1311 threshold=40.0*QuantumRange/100.0;
1312 else
cristyf2f27272009-12-17 14:48:46 +00001313 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
anthonye9c27192011-03-27 08:07:06 +00001314 new_image=DeskewImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00001315 break;
1316 }
1317 if (LocaleCompare("despeckle",option+1) == 0)
1318 {
cristy3ed852e2009-09-05 21:47:34 +00001319 /*
1320 Reduce the speckles within an image.
1321 */
cristy6b3da3a2010-06-20 02:21:46 +00001322 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00001323 new_image=DespeckleImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001324 break;
1325 }
1326 if (LocaleCompare("display",option+1) == 0)
1327 {
1328 (void) CloneString(&draw_info->server_name,argv[i+1]);
1329 break;
1330 }
cristy3ed852e2009-09-05 21:47:34 +00001331 if (LocaleCompare("distort",option+1) == 0)
1332 {
1333 char
1334 *args,
1335 token[MaxTextExtent];
1336
1337 const char
1338 *p;
1339
1340 DistortImageMethod
1341 method;
1342
1343 double
1344 *arguments;
1345
cristybb503372010-05-27 20:51:26 +00001346 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001347 x;
1348
cristybb503372010-05-27 20:51:26 +00001349 size_t
cristy3ed852e2009-09-05 21:47:34 +00001350 number_arguments;
1351
1352 /*
1353 Distort image.
1354 */
cristy6b3da3a2010-06-20 02:21:46 +00001355 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001356 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1357 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001358 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001359 InheritException(exception,&(*image)->exception);
1360 if (args == (char *) NULL)
1361 break;
1362 p=(char *) args;
1363 for (x=0; *p != '\0'; x++)
1364 {
1365 GetMagickToken(p,&p,token);
1366 if (*token == ',')
1367 GetMagickToken(p,&p,token);
1368 }
cristybb503372010-05-27 20:51:26 +00001369 number_arguments=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001370 arguments=(double *) AcquireQuantumMemory(number_arguments,
1371 sizeof(*arguments));
1372 if (arguments == (double *) NULL)
1373 ThrowWandFatalException(ResourceLimitFatalError,
1374 "MemoryAllocationFailed",(*image)->filename);
1375 (void) ResetMagickMemory(arguments,0,number_arguments*
1376 sizeof(*arguments));
1377 p=(char *) args;
cristybb503372010-05-27 20:51:26 +00001378 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001379 {
1380 GetMagickToken(p,&p,token);
1381 if (*token == ',')
1382 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001383 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001384 }
1385 args=DestroyString(args);
anthonye9c27192011-03-27 08:07:06 +00001386 new_image=DistortImage(*image,method,number_arguments,arguments,
cristy3ed852e2009-09-05 21:47:34 +00001387 (*option == '+') ? MagickTrue : MagickFalse,exception);
1388 arguments=(double *) RelinquishMagickMemory(arguments);
cristy3ed852e2009-09-05 21:47:34 +00001389 break;
1390 }
1391 if (LocaleCompare("dither",option+1) == 0)
1392 {
1393 if (*option == '+')
1394 {
1395 quantize_info->dither=MagickFalse;
1396 break;
1397 }
1398 quantize_info->dither=MagickTrue;
1399 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1400 MagickDitherOptions,MagickFalse,argv[i+1]);
1401 if (quantize_info->dither_method == NoDitherMethod)
1402 quantize_info->dither=MagickFalse;
1403 break;
1404 }
1405 if (LocaleCompare("draw",option+1) == 0)
1406 {
1407 /*
1408 Draw image.
1409 */
cristy6b3da3a2010-06-20 02:21:46 +00001410 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001411 (void) CloneString(&draw_info->primitive,argv[i+1]);
1412 (void) DrawImage(*image,draw_info);
1413 InheritException(exception,&(*image)->exception);
1414 break;
1415 }
1416 break;
1417 }
1418 case 'e':
1419 {
1420 if (LocaleCompare("edge",option+1) == 0)
1421 {
cristy3ed852e2009-09-05 21:47:34 +00001422 /*
1423 Enhance edges in the image.
1424 */
cristy6b3da3a2010-06-20 02:21:46 +00001425 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001426 flags=ParseGeometry(argv[i+1],&geometry_info);
1427 if ((flags & SigmaValue) == 0)
1428 geometry_info.sigma=1.0;
anthonye9c27192011-03-27 08:07:06 +00001429 new_image=EdgeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001430 break;
1431 }
1432 if (LocaleCompare("emboss",option+1) == 0)
1433 {
cristy3ed852e2009-09-05 21:47:34 +00001434 /*
1435 Gaussian embossen image.
1436 */
cristy6b3da3a2010-06-20 02:21:46 +00001437 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001438 flags=ParseGeometry(argv[i+1],&geometry_info);
1439 if ((flags & SigmaValue) == 0)
1440 geometry_info.sigma=1.0;
anthonye9c27192011-03-27 08:07:06 +00001441 new_image=EmbossImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00001442 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001443 break;
1444 }
1445 if (LocaleCompare("encipher",option+1) == 0)
1446 {
1447 StringInfo
1448 *passkey;
1449
1450 /*
1451 Encipher pixels.
1452 */
cristy6b3da3a2010-06-20 02:21:46 +00001453 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001454 passkey=FileToStringInfo(argv[i+1],~0,exception);
1455 if (passkey != (StringInfo *) NULL)
1456 {
1457 (void) PasskeyEncipherImage(*image,passkey,exception);
1458 passkey=DestroyStringInfo(passkey);
1459 }
1460 break;
1461 }
1462 if (LocaleCompare("encoding",option+1) == 0)
1463 {
1464 (void) CloneString(&draw_info->encoding,argv[i+1]);
1465 break;
1466 }
1467 if (LocaleCompare("enhance",option+1) == 0)
1468 {
cristy3ed852e2009-09-05 21:47:34 +00001469 /*
1470 Enhance image.
1471 */
cristy6b3da3a2010-06-20 02:21:46 +00001472 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00001473 new_image=EnhanceImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001474 break;
1475 }
1476 if (LocaleCompare("equalize",option+1) == 0)
1477 {
1478 /*
1479 Equalize image.
1480 */
cristy6b3da3a2010-06-20 02:21:46 +00001481 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001482 (void) EqualizeImageChannel(*image,channel);
1483 InheritException(exception,&(*image)->exception);
1484 break;
1485 }
1486 if (LocaleCompare("evaluate",option+1) == 0)
1487 {
1488 double
1489 constant;
1490
1491 MagickEvaluateOperator
1492 op;
1493
cristy6b3da3a2010-06-20 02:21:46 +00001494 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001495 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1496 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001497 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001498 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1499 break;
1500 }
1501 if (LocaleCompare("extent",option+1) == 0)
1502 {
cristy3ed852e2009-09-05 21:47:34 +00001503 /*
1504 Set the image extent.
1505 */
cristy6b3da3a2010-06-20 02:21:46 +00001506 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001507 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001508 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001509 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001510 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001511 geometry.height=(*image)->rows;
anthonye9c27192011-03-27 08:07:06 +00001512 new_image=ExtentImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00001513 break;
1514 }
1515 break;
1516 }
1517 case 'f':
1518 {
1519 if (LocaleCompare("family",option+1) == 0)
1520 {
1521 if (*option == '+')
1522 {
1523 if (draw_info->family != (char *) NULL)
1524 draw_info->family=DestroyString(draw_info->family);
1525 break;
1526 }
1527 (void) CloneString(&draw_info->family,argv[i+1]);
1528 break;
1529 }
cristy0fe961c2010-01-30 03:09:54 +00001530 if (LocaleCompare("features",option+1) == 0)
1531 {
1532 if (*option == '+')
1533 {
1534 (void) DeleteImageArtifact(*image,"identify:features");
1535 break;
1536 }
1537 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1538 break;
1539 }
cristy3ed852e2009-09-05 21:47:34 +00001540 if (LocaleCompare("fill",option+1) == 0)
1541 {
1542 ExceptionInfo
1543 *sans;
1544
1545 GetMagickPixelPacket(*image,&fill);
1546 if (*option == '+')
1547 {
1548 (void) QueryMagickColor("none",&fill,exception);
1549 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1550 if (draw_info->fill_pattern != (Image *) NULL)
1551 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1552 break;
1553 }
1554 sans=AcquireExceptionInfo();
1555 (void) QueryMagickColor(argv[i+1],&fill,sans);
1556 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1557 sans=DestroyExceptionInfo(sans);
1558 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00001559 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00001560 exception);
1561 break;
1562 }
1563 if (LocaleCompare("flip",option+1) == 0)
1564 {
cristy3ed852e2009-09-05 21:47:34 +00001565 /*
1566 Flip image scanlines.
1567 */
cristy6b3da3a2010-06-20 02:21:46 +00001568 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00001569 new_image=FlipImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001570 break;
1571 }
1572 if (LocaleCompare("flop",option+1) == 0)
1573 {
cristy3ed852e2009-09-05 21:47:34 +00001574 /*
1575 Flop image scanlines.
1576 */
cristy6b3da3a2010-06-20 02:21:46 +00001577 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00001578 new_image=FlopImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00001579 break;
1580 }
1581 if (LocaleCompare("floodfill",option+1) == 0)
1582 {
1583 MagickPixelPacket
1584 target;
1585
1586 /*
1587 Floodfill image.
1588 */
cristy6b3da3a2010-06-20 02:21:46 +00001589 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001590 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1591 (void) QueryMagickColor(argv[i+2],&target,exception);
1592 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1593 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1594 InheritException(exception,&(*image)->exception);
1595 break;
1596 }
1597 if (LocaleCompare("font",option+1) == 0)
1598 {
1599 if (*option == '+')
1600 {
1601 if (draw_info->font != (char *) NULL)
1602 draw_info->font=DestroyString(draw_info->font);
1603 break;
1604 }
1605 (void) CloneString(&draw_info->font,argv[i+1]);
1606 break;
1607 }
1608 if (LocaleCompare("format",option+1) == 0)
1609 {
1610 format=argv[i+1];
1611 break;
1612 }
1613 if (LocaleCompare("frame",option+1) == 0)
1614 {
1615 FrameInfo
1616 frame_info;
1617
cristy3ed852e2009-09-05 21:47:34 +00001618 /*
1619 Surround image with an ornamental border.
1620 */
cristy6b3da3a2010-06-20 02:21:46 +00001621 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001622 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1623 frame_info.width=geometry.width;
1624 frame_info.height=geometry.height;
1625 if ((flags & HeightValue) == 0)
1626 frame_info.height=geometry.width;
1627 frame_info.outer_bevel=geometry.x;
1628 frame_info.inner_bevel=geometry.y;
cristybb503372010-05-27 20:51:26 +00001629 frame_info.x=(ssize_t) frame_info.width;
1630 frame_info.y=(ssize_t) frame_info.height;
cristy3ed852e2009-09-05 21:47:34 +00001631 frame_info.width=(*image)->columns+2*frame_info.width;
1632 frame_info.height=(*image)->rows+2*frame_info.height;
anthonye9c27192011-03-27 08:07:06 +00001633 new_image=FrameImage(*image,&frame_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00001634 break;
1635 }
1636 if (LocaleCompare("function",option+1) == 0)
1637 {
1638 char
1639 *arguments,
1640 token[MaxTextExtent];
1641
1642 const char
1643 *p;
1644
1645 double
1646 *parameters;
1647
1648 MagickFunction
1649 function;
1650
cristybb503372010-05-27 20:51:26 +00001651 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001652 x;
1653
cristybb503372010-05-27 20:51:26 +00001654 size_t
cristy3ed852e2009-09-05 21:47:34 +00001655 number_parameters;
1656
1657 /*
1658 Function Modify Image Values
1659 */
cristy6b3da3a2010-06-20 02:21:46 +00001660 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001661 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1662 MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00001663 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00001664 InheritException(exception,&(*image)->exception);
1665 if (arguments == (char *) NULL)
1666 break;
1667 p=(char *) arguments;
1668 for (x=0; *p != '\0'; x++)
1669 {
1670 GetMagickToken(p,&p,token);
1671 if (*token == ',')
1672 GetMagickToken(p,&p,token);
1673 }
cristybb503372010-05-27 20:51:26 +00001674 number_parameters=(size_t) x;
cristy3ed852e2009-09-05 21:47:34 +00001675 parameters=(double *) AcquireQuantumMemory(number_parameters,
1676 sizeof(*parameters));
1677 if (parameters == (double *) NULL)
1678 ThrowWandFatalException(ResourceLimitFatalError,
1679 "MemoryAllocationFailed",(*image)->filename);
1680 (void) ResetMagickMemory(parameters,0,number_parameters*
1681 sizeof(*parameters));
1682 p=(char *) arguments;
cristybb503372010-05-27 20:51:26 +00001683 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
cristy3ed852e2009-09-05 21:47:34 +00001684 {
1685 GetMagickToken(p,&p,token);
1686 if (*token == ',')
1687 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001688 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001689 }
1690 arguments=DestroyString(arguments);
1691 (void) FunctionImageChannel(*image,channel,function,
1692 number_parameters,parameters,exception);
1693 parameters=(double *) RelinquishMagickMemory(parameters);
1694 break;
1695 }
1696 break;
1697 }
1698 case 'g':
1699 {
1700 if (LocaleCompare("gamma",option+1) == 0)
1701 {
1702 /*
1703 Gamma image.
1704 */
cristy6b3da3a2010-06-20 02:21:46 +00001705 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001706 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001707 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001708 else
1709 {
1710 if (strchr(argv[i+1],',') != (char *) NULL)
1711 (void) GammaImage(*image,argv[i+1]);
1712 else
cristya5447be2010-01-11 00:20:51 +00001713 (void) GammaImageChannel(*image,channel,
1714 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001715 InheritException(exception,&(*image)->exception);
1716 }
1717 break;
1718 }
1719 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1720 (LocaleCompare("gaussian",option+1) == 0))
1721 {
cristy3ed852e2009-09-05 21:47:34 +00001722 /*
1723 Gaussian blur image.
1724 */
cristy6b3da3a2010-06-20 02:21:46 +00001725 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001726 flags=ParseGeometry(argv[i+1],&geometry_info);
1727 if ((flags & SigmaValue) == 0)
1728 geometry_info.sigma=1.0;
anthonye9c27192011-03-27 08:07:06 +00001729 new_image=GaussianBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00001730 geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00001731 break;
1732 }
1733 if (LocaleCompare("geometry",option+1) == 0)
1734 {
anthonye9c27192011-03-27 08:07:06 +00001735 /*
1736 Record Image offset, Resize last image.
1737 */
cristy6b3da3a2010-06-20 02:21:46 +00001738 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001739 if (*option == '+')
1740 {
1741 if ((*image)->geometry != (char *) NULL)
1742 (*image)->geometry=DestroyString((*image)->geometry);
1743 break;
1744 }
1745 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1746 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1747 (void) CloneString(&(*image)->geometry,argv[i+1]);
1748 else
anthonye9c27192011-03-27 08:07:06 +00001749 new_image=ResizeImage(*image,geometry.width,geometry.height,
1750 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00001751 break;
1752 }
1753 if (LocaleCompare("gravity",option+1) == 0)
1754 {
1755 if (*option == '+')
1756 {
1757 draw_info->gravity=UndefinedGravity;
1758 break;
1759 }
1760 draw_info->gravity=(GravityType) ParseMagickOption(
1761 MagickGravityOptions,MagickFalse,argv[i+1]);
1762 break;
1763 }
1764 break;
1765 }
1766 case 'h':
1767 {
1768 if (LocaleCompare("highlight-color",option+1) == 0)
1769 {
1770 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1771 break;
1772 }
1773 break;
1774 }
1775 case 'i':
1776 {
1777 if (LocaleCompare("identify",option+1) == 0)
1778 {
1779 char
1780 *text;
1781
cristy6b3da3a2010-06-20 02:21:46 +00001782 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001783 if (format == (char *) NULL)
1784 {
cristy6b3da3a2010-06-20 02:21:46 +00001785 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
cristy3ed852e2009-09-05 21:47:34 +00001786 InheritException(exception,&(*image)->exception);
1787 break;
1788 }
cristy6b3da3a2010-06-20 02:21:46 +00001789 text=InterpretImageProperties(mogrify_info,*image,format);
cristy3ed852e2009-09-05 21:47:34 +00001790 InheritException(exception,&(*image)->exception);
1791 if (text == (char *) NULL)
1792 break;
1793 (void) fputs(text,stdout);
1794 (void) fputc('\n',stdout);
1795 text=DestroyString(text);
1796 break;
1797 }
1798 if (LocaleCompare("implode",option+1) == 0)
1799 {
cristy3ed852e2009-09-05 21:47:34 +00001800 /*
1801 Implode image.
1802 */
cristy6b3da3a2010-06-20 02:21:46 +00001803 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001804 (void) ParseGeometry(argv[i+1],&geometry_info);
anthonye9c27192011-03-27 08:07:06 +00001805 new_image=ImplodeImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00001806 break;
1807 }
cristyb32b90a2009-09-07 21:45:48 +00001808 if (LocaleCompare("interline-spacing",option+1) == 0)
1809 {
1810 if (*option == '+')
1811 (void) ParseGeometry("0",&geometry_info);
1812 else
1813 (void) ParseGeometry(argv[i+1],&geometry_info);
1814 draw_info->interline_spacing=geometry_info.rho;
1815 break;
1816 }
cristy3ed852e2009-09-05 21:47:34 +00001817 if (LocaleCompare("interword-spacing",option+1) == 0)
1818 {
1819 if (*option == '+')
1820 (void) ParseGeometry("0",&geometry_info);
1821 else
1822 (void) ParseGeometry(argv[i+1],&geometry_info);
1823 draw_info->interword_spacing=geometry_info.rho;
1824 break;
1825 }
1826 break;
1827 }
1828 case 'k':
1829 {
1830 if (LocaleCompare("kerning",option+1) == 0)
1831 {
1832 if (*option == '+')
1833 (void) ParseGeometry("0",&geometry_info);
1834 else
1835 (void) ParseGeometry(argv[i+1],&geometry_info);
1836 draw_info->kerning=geometry_info.rho;
1837 break;
1838 }
1839 break;
1840 }
1841 case 'l':
1842 {
1843 if (LocaleCompare("lat",option+1) == 0)
1844 {
cristy3ed852e2009-09-05 21:47:34 +00001845 /*
1846 Local adaptive threshold image.
1847 */
cristy6b3da3a2010-06-20 02:21:46 +00001848 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001849 flags=ParseGeometry(argv[i+1],&geometry_info);
1850 if ((flags & PercentValue) != 0)
1851 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
anthonye9c27192011-03-27 08:07:06 +00001852 new_image=AdaptiveThresholdImage(*image,(size_t)
cristybb503372010-05-27 20:51:26 +00001853 geometry_info.rho,(size_t) geometry_info.sigma,
1854 (ssize_t) geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00001855 break;
1856 }
1857 if (LocaleCompare("level",option+1) == 0)
1858 {
cristy3ed852e2009-09-05 21:47:34 +00001859 MagickRealType
1860 black_point,
1861 gamma,
1862 white_point;
1863
1864 MagickStatusType
1865 flags;
1866
1867 /*
1868 Parse levels.
1869 */
cristy6b3da3a2010-06-20 02:21:46 +00001870 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001871 flags=ParseGeometry(argv[i+1],&geometry_info);
1872 black_point=geometry_info.rho;
1873 white_point=(MagickRealType) QuantumRange;
1874 if ((flags & SigmaValue) != 0)
1875 white_point=geometry_info.sigma;
1876 gamma=1.0;
1877 if ((flags & XiValue) != 0)
1878 gamma=geometry_info.xi;
1879 if ((flags & PercentValue) != 0)
1880 {
1881 black_point*=(MagickRealType) (QuantumRange/100.0);
1882 white_point*=(MagickRealType) (QuantumRange/100.0);
1883 }
1884 if ((flags & SigmaValue) == 0)
1885 white_point=(MagickRealType) QuantumRange-black_point;
1886 if ((*option == '+') || ((flags & AspectValue) != 0))
1887 (void) LevelizeImageChannel(*image,channel,black_point,
1888 white_point,gamma);
1889 else
1890 (void) LevelImageChannel(*image,channel,black_point,white_point,
1891 gamma);
1892 InheritException(exception,&(*image)->exception);
1893 break;
1894 }
1895 if (LocaleCompare("level-colors",option+1) == 0)
1896 {
1897 char
1898 token[MaxTextExtent];
1899
1900 const char
1901 *p;
1902
1903 MagickPixelPacket
1904 black_point,
1905 white_point;
1906
1907 p=(const char *) argv[i+1];
1908 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00001909 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001910 (void) QueryMagickColor(token,&black_point,exception);
1911 else
cristyee0f8d72009-09-19 00:58:29 +00001912 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001913 if (isalpha((int) token[0]) || (token[0] == '#'))
1914 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00001915 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00001916 white_point=black_point; /* set everything to that color */
1917 else
1918 {
cristyee0f8d72009-09-19 00:58:29 +00001919 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
anthonye9c27192011-03-27 08:07:06 +00001920 GetMagickToken(p,&p,token); /* Get white point color. */
cristyee0f8d72009-09-19 00:58:29 +00001921 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00001922 (void) QueryMagickColor(token,&white_point,exception);
1923 else
cristyee0f8d72009-09-19 00:58:29 +00001924 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00001925 }
cristy74fe8f12009-10-03 19:09:01 +00001926 (void) LevelColorsImageChannel(*image,channel,&black_point,
1927 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001928 break;
1929 }
1930 if (LocaleCompare("linear-stretch",option+1) == 0)
1931 {
1932 double
1933 black_point,
1934 white_point;
1935
cristy3ed852e2009-09-05 21:47:34 +00001936 MagickStatusType
1937 flags;
1938
cristy6b3da3a2010-06-20 02:21:46 +00001939 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001940 flags=ParseGeometry(argv[i+1],&geometry_info);
1941 black_point=geometry_info.rho;
1942 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1943 if ((flags & SigmaValue) != 0)
1944 white_point=geometry_info.sigma;
1945 if ((flags & PercentValue) != 0)
1946 {
1947 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1948 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1949 }
1950 if ((flags & SigmaValue) == 0)
1951 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1952 black_point;
1953 (void) LinearStretchImage(*image,black_point,white_point);
1954 InheritException(exception,&(*image)->exception);
1955 break;
1956 }
1957 if (LocaleCompare("linewidth",option+1) == 0)
1958 {
cristyf2f27272009-12-17 14:48:46 +00001959 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001960 break;
1961 }
1962 if (LocaleCompare("liquid-rescale",option+1) == 0)
1963 {
cristy3ed852e2009-09-05 21:47:34 +00001964 /*
1965 Liquid rescale image.
1966 */
cristy6b3da3a2010-06-20 02:21:46 +00001967 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001968 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1969 if ((flags & XValue) == 0)
1970 geometry.x=1;
1971 if ((flags & YValue) == 0)
1972 geometry.y=0;
anthonye9c27192011-03-27 08:07:06 +00001973 new_image=LiquidRescaleImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +00001974 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00001975 break;
1976 }
1977 if (LocaleCompare("lowlight-color",option+1) == 0)
1978 {
1979 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1980 break;
1981 }
1982 break;
1983 }
1984 case 'm':
1985 {
1986 if (LocaleCompare("map",option+1) == 0)
1987 {
1988 Image
1989 *remap_image;
1990
1991 /*
1992 Transform image colors to match this set of colors.
1993 */
cristy6b3da3a2010-06-20 02:21:46 +00001994 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00001995 if (*option == '+')
1996 break;
cristy6b3da3a2010-06-20 02:21:46 +00001997 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00001998 if (remap_image == (Image *) NULL)
1999 break;
2000 (void) RemapImage(quantize_info,*image,remap_image);
2001 InheritException(exception,&(*image)->exception);
2002 remap_image=DestroyImage(remap_image);
2003 break;
2004 }
2005 if (LocaleCompare("mask",option+1) == 0)
2006 {
2007 Image
2008 *mask;
2009
cristy6b3da3a2010-06-20 02:21:46 +00002010 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002011 if (*option == '+')
2012 {
2013 /*
2014 Remove a mask.
2015 */
2016 (void) SetImageMask(*image,(Image *) NULL);
2017 InheritException(exception,&(*image)->exception);
2018 break;
2019 }
2020 /*
2021 Set the image mask.
2022 */
cristy6b3da3a2010-06-20 02:21:46 +00002023 mask=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002024 if (mask == (Image *) NULL)
2025 break;
2026 (void) SetImageMask(*image,mask);
2027 mask=DestroyImage(mask);
2028 InheritException(exception,&(*image)->exception);
2029 break;
2030 }
2031 if (LocaleCompare("matte",option+1) == 0)
2032 {
2033 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2034 SetAlphaChannel : DeactivateAlphaChannel );
2035 InheritException(exception,&(*image)->exception);
2036 break;
2037 }
2038 if (LocaleCompare("median",option+1) == 0)
2039 {
cristy3ed852e2009-09-05 21:47:34 +00002040 /*
2041 Median filter image.
2042 */
cristy6b3da3a2010-06-20 02:21:46 +00002043 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002044 (void) ParseGeometry(argv[i+1],&geometry_info);
anthonye9c27192011-03-27 08:07:06 +00002045 new_image=StatisticImageChannel(*image,channel,MedianStatistic,
cristy95c38342011-03-18 22:39:51 +00002046 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002047 break;
2048 }
cristy69ec32d2011-02-27 23:57:09 +00002049 if (LocaleCompare("mode",option+1) == 0)
2050 {
cristy69ec32d2011-02-27 23:57:09 +00002051 /*
2052 Mode image.
2053 */
2054 (void) SyncImageSettings(mogrify_info,*image);
2055 (void) ParseGeometry(argv[i+1],&geometry_info);
anthonye9c27192011-03-27 08:07:06 +00002056 new_image=StatisticImageChannel(*image,channel,ModeStatistic,
cristy95c38342011-03-18 22:39:51 +00002057 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
cristy69ec32d2011-02-27 23:57:09 +00002058 break;
2059 }
cristy3ed852e2009-09-05 21:47:34 +00002060 if (LocaleCompare("modulate",option+1) == 0)
2061 {
cristy6b3da3a2010-06-20 02:21:46 +00002062 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002063 (void) ModulateImage(*image,argv[i+1]);
2064 InheritException(exception,&(*image)->exception);
2065 break;
2066 }
2067 if (LocaleCompare("monitor",option+1) == 0)
2068 {
cristy7d34ef22010-03-25 01:11:22 +00002069 if (*option == '+')
2070 {
2071 (void) SetImageProgressMonitor(*image,
2072 (MagickProgressMonitor) NULL,(void *) NULL);
2073 break;
2074 }
cristy3ed852e2009-09-05 21:47:34 +00002075 (void) SetImageProgressMonitor(*image,MonitorProgress,
2076 (void *) NULL);
2077 break;
2078 }
2079 if (LocaleCompare("monochrome",option+1) == 0)
2080 {
cristy6b3da3a2010-06-20 02:21:46 +00002081 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002082 (void) SetImageType(*image,BilevelType);
2083 InheritException(exception,&(*image)->exception);
2084 break;
2085 }
anthony29188a82010-01-22 10:12:34 +00002086 if (LocaleCompare("morphology",option+1) == 0)
2087 {
anthony29188a82010-01-22 10:12:34 +00002088 char
2089 token[MaxTextExtent];
2090
2091 const char
2092 *p;
2093
cristye96405a2010-05-19 02:24:31 +00002094 KernelInfo
2095 *kernel;
2096
cristye96405a2010-05-19 02:24:31 +00002097 MorphologyMethod
2098 method;
2099
cristy9d314ff2011-03-09 01:30:28 +00002100 ssize_t
2101 iterations;
2102
anthony29188a82010-01-22 10:12:34 +00002103 /*
2104 Morphological Image Operation
2105 */
cristy6b3da3a2010-06-20 02:21:46 +00002106 (void) SyncImageSettings(mogrify_info,*image);
anthony29188a82010-01-22 10:12:34 +00002107 p=argv[i+1];
2108 GetMagickToken(p,&p,token);
2109 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
cristyd2c1e1e2010-05-08 01:05:44 +00002110 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002111 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002112 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002113 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002114 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002115 if ((*p != '\0'))
cristy32c2aea2010-12-01 01:00:50 +00002116 iterations=(ssize_t) StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002117 kernel=AcquireKernelInfo(argv[i+2]);
2118 if (kernel == (KernelInfo *) NULL)
cristye96405a2010-05-19 02:24:31 +00002119 {
2120 (void) ThrowMagickException(exception,GetMagickModule(),
2121 OptionError,"UnabletoParseKernel","morphology");
2122 status=MagickFalse;
2123 break;
2124 }
anthonye9c27192011-03-27 08:07:06 +00002125 new_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002126 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002127 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002128 break;
2129 }
cristy3ed852e2009-09-05 21:47:34 +00002130 if (LocaleCompare("motion-blur",option+1) == 0)
2131 {
cristy3ed852e2009-09-05 21:47:34 +00002132 /*
2133 Motion blur image.
2134 */
cristy6b3da3a2010-06-20 02:21:46 +00002135 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002136 flags=ParseGeometry(argv[i+1],&geometry_info);
2137 if ((flags & SigmaValue) == 0)
2138 geometry_info.sigma=1.0;
anthonye9c27192011-03-27 08:07:06 +00002139 new_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002140 geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002141 break;
2142 }
2143 break;
2144 }
2145 case 'n':
2146 {
2147 if (LocaleCompare("negate",option+1) == 0)
2148 {
cristy6b3da3a2010-06-20 02:21:46 +00002149 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002150 (void) NegateImageChannel(*image,channel,*option == '+' ?
2151 MagickTrue : MagickFalse);
2152 InheritException(exception,&(*image)->exception);
2153 break;
2154 }
2155 if (LocaleCompare("noise",option+1) == 0)
2156 {
cristy6b3da3a2010-06-20 02:21:46 +00002157 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002158 if (*option == '-')
2159 {
2160 (void) ParseGeometry(argv[i+1],&geometry_info);
anthonye9c27192011-03-27 08:07:06 +00002161 new_image=StatisticImageChannel(*image,channel,
cristy95c38342011-03-18 22:39:51 +00002162 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2163 geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002164 }
2165 else
2166 {
2167 NoiseType
2168 noise;
2169
2170 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2171 MagickFalse,argv[i+1]);
anthonye9c27192011-03-27 08:07:06 +00002172 new_image=AddNoiseImageChannel(*image,channel,noise,
cristy3ed852e2009-09-05 21:47:34 +00002173 exception);
2174 }
cristy3ed852e2009-09-05 21:47:34 +00002175 break;
2176 }
2177 if (LocaleCompare("normalize",option+1) == 0)
2178 {
cristy6b3da3a2010-06-20 02:21:46 +00002179 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002180 (void) NormalizeImageChannel(*image,channel);
2181 InheritException(exception,&(*image)->exception);
2182 break;
2183 }
2184 break;
2185 }
2186 case 'o':
2187 {
2188 if (LocaleCompare("opaque",option+1) == 0)
2189 {
2190 MagickPixelPacket
2191 target;
2192
cristy6b3da3a2010-06-20 02:21:46 +00002193 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002194 (void) QueryMagickColor(argv[i+1],&target,exception);
2195 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2196 *option == '-' ? MagickFalse : MagickTrue);
2197 break;
2198 }
2199 if (LocaleCompare("ordered-dither",option+1) == 0)
2200 {
cristy6b3da3a2010-06-20 02:21:46 +00002201 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002202 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2203 exception);
2204 break;
2205 }
2206 break;
2207 }
2208 case 'p':
2209 {
2210 if (LocaleCompare("paint",option+1) == 0)
2211 {
2212 Image
2213 *paint_image;
2214
2215 /*
2216 Oil paint image.
2217 */
cristy6b3da3a2010-06-20 02:21:46 +00002218 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002219 (void) ParseGeometry(argv[i+1],&geometry_info);
2220 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2221 if (paint_image == (Image *) NULL)
2222 break;
2223 *image=DestroyImage(*image);
2224 *image=paint_image;
2225 break;
2226 }
2227 if (LocaleCompare("pen",option+1) == 0)
2228 {
2229 if (*option == '+')
2230 {
2231 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2232 break;
2233 }
2234 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2235 break;
2236 }
2237 if (LocaleCompare("pointsize",option+1) == 0)
2238 {
2239 if (*option == '+')
2240 (void) ParseGeometry("12",&geometry_info);
2241 else
2242 (void) ParseGeometry(argv[i+1],&geometry_info);
2243 draw_info->pointsize=geometry_info.rho;
2244 break;
2245 }
2246 if (LocaleCompare("polaroid",option+1) == 0)
2247 {
2248 double
2249 angle;
2250
cristy3ed852e2009-09-05 21:47:34 +00002251 RandomInfo
2252 *random_info;
2253
2254 /*
2255 Simulate a Polaroid picture.
2256 */
cristy6b3da3a2010-06-20 02:21:46 +00002257 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002258 random_info=AcquireRandomInfo();
2259 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2260 random_info=DestroyRandomInfo(random_info);
2261 if (*option == '-')
2262 {
2263 SetGeometryInfo(&geometry_info);
2264 flags=ParseGeometry(argv[i+1],&geometry_info);
2265 angle=geometry_info.rho;
2266 }
anthonye9c27192011-03-27 08:07:06 +00002267 new_image=PolaroidImage(*image,draw_info,angle,exception);
cristy3ed852e2009-09-05 21:47:34 +00002268 break;
2269 }
2270 if (LocaleCompare("posterize",option+1) == 0)
2271 {
2272 /*
2273 Posterize image.
2274 */
cristy6b3da3a2010-06-20 02:21:46 +00002275 (void) SyncImageSettings(mogrify_info,*image);
cristye27293e2009-12-18 02:53:20 +00002276 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002277 quantize_info->dither);
2278 InheritException(exception,&(*image)->exception);
2279 break;
2280 }
2281 if (LocaleCompare("preview",option+1) == 0)
2282 {
cristy3ed852e2009-09-05 21:47:34 +00002283 PreviewType
2284 preview_type;
2285
2286 /*
2287 Preview image.
2288 */
cristy6b3da3a2010-06-20 02:21:46 +00002289 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002290 if (*option == '+')
2291 preview_type=UndefinedPreview;
2292 else
2293 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2294 MagickFalse,argv[i+1]);
anthonye9c27192011-03-27 08:07:06 +00002295 new_image=PreviewImage(*image,preview_type,exception);
cristy3ed852e2009-09-05 21:47:34 +00002296 break;
2297 }
2298 if (LocaleCompare("profile",option+1) == 0)
2299 {
2300 const char
2301 *name;
2302
2303 const StringInfo
2304 *profile;
2305
2306 Image
2307 *profile_image;
2308
2309 ImageInfo
2310 *profile_info;
2311
cristy6b3da3a2010-06-20 02:21:46 +00002312 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002313 if (*option == '+')
2314 {
2315 /*
2316 Remove a profile from the image.
2317 */
2318 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2319 NULL,0,MagickTrue);
2320 InheritException(exception,&(*image)->exception);
2321 break;
2322 }
2323 /*
2324 Associate a profile with the image.
2325 */
cristy6b3da3a2010-06-20 02:21:46 +00002326 profile_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00002327 profile=GetImageProfile(*image,"iptc");
2328 if (profile != (StringInfo *) NULL)
2329 profile_info->profile=(void *) CloneStringInfo(profile);
2330 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2331 profile_info=DestroyImageInfo(profile_info);
2332 if (profile_image == (Image *) NULL)
2333 {
cristy3ed852e2009-09-05 21:47:34 +00002334 StringInfo
2335 *profile;
2336
cristy6b3da3a2010-06-20 02:21:46 +00002337 profile_info=CloneImageInfo(mogrify_info);
cristy071dd7b2010-04-09 13:04:54 +00002338 (void) CopyMagickString(profile_info->filename,argv[i+1],
2339 MaxTextExtent);
2340 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
cristy3ed852e2009-09-05 21:47:34 +00002341 if (profile != (StringInfo *) NULL)
2342 {
cristy071dd7b2010-04-09 13:04:54 +00002343 (void) ProfileImage(*image,profile_info->magick,
cristybb503372010-05-27 20:51:26 +00002344 GetStringInfoDatum(profile),(size_t)
cristy071dd7b2010-04-09 13:04:54 +00002345 GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002346 profile=DestroyStringInfo(profile);
2347 }
cristy071dd7b2010-04-09 13:04:54 +00002348 profile_info=DestroyImageInfo(profile_info);
cristy3ed852e2009-09-05 21:47:34 +00002349 break;
2350 }
2351 ResetImageProfileIterator(profile_image);
2352 name=GetNextImageProfile(profile_image);
2353 while (name != (const char *) NULL)
2354 {
2355 profile=GetImageProfile(profile_image,name);
2356 if (profile != (StringInfo *) NULL)
2357 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristybb503372010-05-27 20:51:26 +00002358 (size_t) GetStringInfoLength(profile),MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002359 name=GetNextImageProfile(profile_image);
2360 }
2361 profile_image=DestroyImage(profile_image);
2362 break;
2363 }
2364 break;
2365 }
2366 case 'q':
2367 {
2368 if (LocaleCompare("quantize",option+1) == 0)
2369 {
2370 if (*option == '+')
2371 {
2372 quantize_info->colorspace=UndefinedColorspace;
2373 break;
2374 }
2375 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2376 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2377 break;
2378 }
2379 break;
2380 }
2381 case 'r':
2382 {
2383 if (LocaleCompare("radial-blur",option+1) == 0)
2384 {
cristy3ed852e2009-09-05 21:47:34 +00002385 /*
2386 Radial blur image.
2387 */
cristy6b3da3a2010-06-20 02:21:46 +00002388 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00002389 new_image=RadialBlurImageChannel(*image,channel,
cristya5447be2010-01-11 00:20:51 +00002390 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002391 break;
2392 }
2393 if (LocaleCompare("raise",option+1) == 0)
2394 {
2395 /*
2396 Surround image with a raise of solid color.
2397 */
2398 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2399 if ((flags & SigmaValue) == 0)
2400 geometry.height=geometry.width;
2401 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2402 MagickFalse);
2403 InheritException(exception,&(*image)->exception);
2404 break;
2405 }
2406 if (LocaleCompare("random-threshold",option+1) == 0)
2407 {
2408 /*
2409 Threshold image.
2410 */
cristy6b3da3a2010-06-20 02:21:46 +00002411 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002412 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2413 exception);
2414 break;
2415 }
2416 if (LocaleCompare("recolor",option+1) == 0)
2417 {
cristyf055ae42010-04-02 23:01:38 +00002418 KernelInfo
2419 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00002420
cristy6b3da3a2010-06-20 02:21:46 +00002421 (void) SyncImageSettings(mogrify_info,*image);
cristyf055ae42010-04-02 23:01:38 +00002422 kernel=AcquireKernelInfo(argv[i+1]);
2423 if (kernel == (KernelInfo *) NULL)
2424 break;
anthonye9c27192011-03-27 08:07:06 +00002425 new_image=ColorMatrixImage(*image,kernel,exception);
cristyf055ae42010-04-02 23:01:38 +00002426 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00002427 break;
2428 }
2429 if (LocaleCompare("region",option+1) == 0)
2430 {
cristy6b3da3a2010-06-20 02:21:46 +00002431 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002432 if (region_image != (Image *) NULL)
2433 {
2434 /*
2435 Composite region.
2436 */
anthonye9c27192011-03-27 08:07:06 +00002437 (void) CompositeImage(region_image, CopyCompositeOp,*image,
cristy3ed852e2009-09-05 21:47:34 +00002438 region_geometry.x,region_geometry.y);
2439 InheritException(exception,&region_image->exception);
2440 *image=DestroyImage(*image);
2441 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00002442 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002443 }
2444 if (*option == '+')
anthonye9c27192011-03-27 08:07:06 +00002445 break;
cristy3ed852e2009-09-05 21:47:34 +00002446 /*
2447 Apply transformations to a selected region of the image.
2448 */
2449 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2450 exception);
anthonye9c27192011-03-27 08:07:06 +00002451 new_image=CropImage(*image,&region_geometry,exception);
2452 if (new_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002453 break;
2454 region_image=(*image);
anthonye9c27192011-03-27 08:07:06 +00002455 *image=new_image;
2456 new_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00002457 break;
2458 }
2459 if (LocaleCompare("render",option+1) == 0)
2460 {
cristy6b3da3a2010-06-20 02:21:46 +00002461 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002462 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2463 break;
2464 }
2465 if (LocaleCompare("remap",option+1) == 0)
2466 {
2467 Image
2468 *remap_image;
2469
2470 /*
2471 Transform image colors to match this set of colors.
2472 */
cristy6b3da3a2010-06-20 02:21:46 +00002473 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002474 if (*option == '+')
2475 break;
cristy6b3da3a2010-06-20 02:21:46 +00002476 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00002477 if (remap_image == (Image *) NULL)
2478 break;
2479 (void) RemapImage(quantize_info,*image,remap_image);
2480 InheritException(exception,&(*image)->exception);
2481 remap_image=DestroyImage(remap_image);
2482 break;
2483 }
2484 if (LocaleCompare("repage",option+1) == 0)
2485 {
2486 if (*option == '+')
2487 {
2488 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2489 break;
2490 }
2491 (void) ResetImagePage(*image,argv[i+1]);
2492 InheritException(exception,&(*image)->exception);
2493 break;
2494 }
2495 if (LocaleCompare("resample",option+1) == 0)
2496 {
cristy3ed852e2009-09-05 21:47:34 +00002497 /*
2498 Resample image.
2499 */
cristy6b3da3a2010-06-20 02:21:46 +00002500 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002501 flags=ParseGeometry(argv[i+1],&geometry_info);
2502 if ((flags & SigmaValue) == 0)
2503 geometry_info.sigma=geometry_info.rho;
anthonye9c27192011-03-27 08:07:06 +00002504 new_image=ResampleImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002505 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002506 break;
2507 }
2508 if (LocaleCompare("resize",option+1) == 0)
2509 {
cristy3ed852e2009-09-05 21:47:34 +00002510 /*
2511 Resize image.
2512 */
cristy6b3da3a2010-06-20 02:21:46 +00002513 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002514 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
anthonye9c27192011-03-27 08:07:06 +00002515 new_image=ResizeImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002516 (*image)->filter,(*image)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00002517 break;
2518 }
cristy3ed852e2009-09-05 21:47:34 +00002519 if (LocaleCompare("roll",option+1) == 0)
2520 {
cristy3ed852e2009-09-05 21:47:34 +00002521 /*
2522 Roll image.
2523 */
cristy6b3da3a2010-06-20 02:21:46 +00002524 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002525 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
anthonye9c27192011-03-27 08:07:06 +00002526 new_image=RollImage(*image,geometry.x,geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00002527 break;
2528 }
2529 if (LocaleCompare("rotate",option+1) == 0)
2530 {
2531 char
2532 *geometry;
2533
cristy3ed852e2009-09-05 21:47:34 +00002534 /*
2535 Check for conditional image rotation.
2536 */
cristy6b3da3a2010-06-20 02:21:46 +00002537 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002538 if (strchr(argv[i+1],'>') != (char *) NULL)
2539 if ((*image)->columns <= (*image)->rows)
2540 break;
2541 if (strchr(argv[i+1],'<') != (char *) NULL)
2542 if ((*image)->columns >= (*image)->rows)
2543 break;
2544 /*
2545 Rotate image.
2546 */
2547 geometry=ConstantString(argv[i+1]);
2548 (void) SubstituteString(&geometry,">","");
2549 (void) SubstituteString(&geometry,"<","");
2550 (void) ParseGeometry(geometry,&geometry_info);
2551 geometry=DestroyString(geometry);
anthonye9c27192011-03-27 08:07:06 +00002552 new_image=RotateImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002553 break;
2554 }
2555 break;
2556 }
2557 case 's':
2558 {
2559 if (LocaleCompare("sample",option+1) == 0)
2560 {
cristy3ed852e2009-09-05 21:47:34 +00002561 /*
2562 Sample image with pixel replication.
2563 */
cristy6b3da3a2010-06-20 02:21:46 +00002564 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002565 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
anthonye9c27192011-03-27 08:07:06 +00002566 new_image=SampleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002567 exception);
cristy3ed852e2009-09-05 21:47:34 +00002568 break;
2569 }
2570 if (LocaleCompare("scale",option+1) == 0)
2571 {
cristy3ed852e2009-09-05 21:47:34 +00002572 /*
2573 Resize image.
2574 */
cristy6b3da3a2010-06-20 02:21:46 +00002575 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002576 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
anthonye9c27192011-03-27 08:07:06 +00002577 new_image=ScaleImage(*image,geometry.width,geometry.height,
cristy3ed852e2009-09-05 21:47:34 +00002578 exception);
cristy3ed852e2009-09-05 21:47:34 +00002579 break;
2580 }
2581 if (LocaleCompare("selective-blur",option+1) == 0)
2582 {
cristy3ed852e2009-09-05 21:47:34 +00002583 /*
2584 Selectively blur pixels within a contrast threshold.
2585 */
cristy6b3da3a2010-06-20 02:21:46 +00002586 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002587 flags=ParseGeometry(argv[i+1],&geometry_info);
2588 if ((flags & PercentValue) != 0)
2589 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
anthonye9c27192011-03-27 08:07:06 +00002590 new_image=SelectiveBlurImageChannel(*image,channel,
cristy3ed852e2009-09-05 21:47:34 +00002591 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002592 break;
2593 }
2594 if (LocaleCompare("separate",option+1) == 0)
2595 {
cristy3ed852e2009-09-05 21:47:34 +00002596 /*
2597 Break channels into separate images.
anthonye9c27192011-03-27 08:07:06 +00002598 WARNING: This can generate multiple images!
cristy3ed852e2009-09-05 21:47:34 +00002599 */
cristy6b3da3a2010-06-20 02:21:46 +00002600 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00002601 new_image=SeparateImages(*image,channel,exception);
cristy3ed852e2009-09-05 21:47:34 +00002602 break;
2603 }
2604 if (LocaleCompare("sepia-tone",option+1) == 0)
2605 {
2606 double
2607 threshold;
2608
cristy3ed852e2009-09-05 21:47:34 +00002609 /*
2610 Sepia-tone image.
2611 */
cristy6b3da3a2010-06-20 02:21:46 +00002612 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002613 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
anthonye9c27192011-03-27 08:07:06 +00002614 new_image=SepiaToneImage(*image,threshold,exception);
cristy3ed852e2009-09-05 21:47:34 +00002615 break;
2616 }
2617 if (LocaleCompare("segment",option+1) == 0)
2618 {
2619 /*
2620 Segment image.
2621 */
cristy6b3da3a2010-06-20 02:21:46 +00002622 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002623 flags=ParseGeometry(argv[i+1],&geometry_info);
2624 if ((flags & SigmaValue) == 0)
2625 geometry_info.sigma=1.0;
cristy7e6164a2010-07-22 20:43:57 +00002626 (void) SegmentImage(*image,(*image)->colorspace,
2627 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
cristy3ed852e2009-09-05 21:47:34 +00002628 InheritException(exception,&(*image)->exception);
2629 break;
2630 }
2631 if (LocaleCompare("set",option+1) == 0)
2632 {
cristy6d9a1292010-05-31 14:17:06 +00002633 char
2634 *value;
2635
cristy3ed852e2009-09-05 21:47:34 +00002636 /*
2637 Set image option.
2638 */
cristy6d9a1292010-05-31 14:17:06 +00002639 if (*option == '+')
2640 {
2641 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2642 (void) DeleteImageRegistry(argv[i+1]+9);
2643 else
2644 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy7e109582010-06-01 12:56:44 +00002645 {
cristy6b3da3a2010-06-20 02:21:46 +00002646 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
cristy7e109582010-06-01 12:56:44 +00002647 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2648 }
cristy6d9a1292010-05-31 14:17:06 +00002649 else
2650 (void) DeleteImageProperty(*image,argv[i+1]);
2651 break;
2652 }
cristy6b3da3a2010-06-20 02:21:46 +00002653 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy6d9a1292010-05-31 14:17:06 +00002654 if (value == (char *) NULL)
2655 break;
cristy3ed852e2009-09-05 21:47:34 +00002656 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002657 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2658 exception);
cristy3ed852e2009-09-05 21:47:34 +00002659 else
2660 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
cristy6d9a1292010-05-31 14:17:06 +00002661 {
cristy7f02ba12010-09-21 12:39:28 +00002662 (void) SetImageOption(image_info,argv[i+1]+7,value);
cristy6b3da3a2010-06-20 02:21:46 +00002663 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
cristy6d9a1292010-05-31 14:17:06 +00002664 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2665 }
cristy3ed852e2009-09-05 21:47:34 +00002666 else
cristy6d9a1292010-05-31 14:17:06 +00002667 (void) SetImageProperty(*image,argv[i+1],value);
2668 value=DestroyString(value);
cristy3ed852e2009-09-05 21:47:34 +00002669 break;
2670 }
2671 if (LocaleCompare("shade",option+1) == 0)
2672 {
cristy3ed852e2009-09-05 21:47:34 +00002673 /*
2674 Shade image.
2675 */
cristy6b3da3a2010-06-20 02:21:46 +00002676 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002677 flags=ParseGeometry(argv[i+1],&geometry_info);
2678 if ((flags & SigmaValue) == 0)
2679 geometry_info.sigma=1.0;
anthonye9c27192011-03-27 08:07:06 +00002680 new_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
cristy3ed852e2009-09-05 21:47:34 +00002681 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002682 break;
2683 }
2684 if (LocaleCompare("shadow",option+1) == 0)
2685 {
cristy3ed852e2009-09-05 21:47:34 +00002686 /*
2687 Shadow image.
2688 */
cristy6b3da3a2010-06-20 02:21:46 +00002689 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002690 flags=ParseGeometry(argv[i+1],&geometry_info);
2691 if ((flags & SigmaValue) == 0)
2692 geometry_info.sigma=1.0;
2693 if ((flags & XiValue) == 0)
2694 geometry_info.xi=4.0;
2695 if ((flags & PsiValue) == 0)
2696 geometry_info.psi=4.0;
anthonye9c27192011-03-27 08:07:06 +00002697 new_image=ShadowImage(*image,geometry_info.rho,geometry_info.sigma,
2698 (ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2699 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00002700 break;
2701 }
2702 if (LocaleCompare("sharpen",option+1) == 0)
2703 {
cristy3ed852e2009-09-05 21:47:34 +00002704 /*
2705 Sharpen image.
2706 */
cristy6b3da3a2010-06-20 02:21:46 +00002707 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002708 flags=ParseGeometry(argv[i+1],&geometry_info);
2709 if ((flags & SigmaValue) == 0)
2710 geometry_info.sigma=1.0;
anthonye9c27192011-03-27 08:07:06 +00002711 new_image=SharpenImageChannel(*image,channel,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002712 geometry_info.sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00002713 break;
2714 }
2715 if (LocaleCompare("shave",option+1) == 0)
2716 {
cristy3ed852e2009-09-05 21:47:34 +00002717 /*
2718 Shave the image edges.
2719 */
cristy6b3da3a2010-06-20 02:21:46 +00002720 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002721 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
anthonye9c27192011-03-27 08:07:06 +00002722 new_image=ShaveImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002723 break;
2724 }
2725 if (LocaleCompare("shear",option+1) == 0)
2726 {
cristy3ed852e2009-09-05 21:47:34 +00002727 /*
2728 Shear image.
2729 */
cristy6b3da3a2010-06-20 02:21:46 +00002730 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002731 flags=ParseGeometry(argv[i+1],&geometry_info);
2732 if ((flags & SigmaValue) == 0)
2733 geometry_info.sigma=geometry_info.rho;
anthonye9c27192011-03-27 08:07:06 +00002734 new_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
cristy3ed852e2009-09-05 21:47:34 +00002735 exception);
cristy3ed852e2009-09-05 21:47:34 +00002736 break;
2737 }
2738 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2739 {
2740 /*
2741 Sigmoidal non-linearity contrast control.
2742 */
cristy6b3da3a2010-06-20 02:21:46 +00002743 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002744 flags=ParseGeometry(argv[i+1],&geometry_info);
2745 if ((flags & SigmaValue) == 0)
2746 geometry_info.sigma=(double) QuantumRange/2.0;
2747 if ((flags & PercentValue) != 0)
2748 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2749 100.0;
2750 (void) SigmoidalContrastImageChannel(*image,channel,
2751 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2752 geometry_info.sigma);
2753 InheritException(exception,&(*image)->exception);
2754 break;
2755 }
2756 if (LocaleCompare("sketch",option+1) == 0)
2757 {
cristy3ed852e2009-09-05 21:47:34 +00002758 /*
2759 Sketch image.
2760 */
cristy6b3da3a2010-06-20 02:21:46 +00002761 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002762 flags=ParseGeometry(argv[i+1],&geometry_info);
2763 if ((flags & SigmaValue) == 0)
2764 geometry_info.sigma=1.0;
anthonye9c27192011-03-27 08:07:06 +00002765 new_image=SketchImage(*image,geometry_info.rho,
cristy3ed852e2009-09-05 21:47:34 +00002766 geometry_info.sigma,geometry_info.xi,exception);
cristy3ed852e2009-09-05 21:47:34 +00002767 break;
2768 }
2769 if (LocaleCompare("solarize",option+1) == 0)
2770 {
2771 double
2772 threshold;
2773
cristy6b3da3a2010-06-20 02:21:46 +00002774 (void) SyncImageSettings(mogrify_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002775 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002776 (void) SolarizeImage(*image,threshold);
2777 InheritException(exception,&(*image)->exception);
2778 break;
2779 }
2780 if (LocaleCompare("sparse-color",option+1) == 0)
2781 {
cristy3ed852e2009-09-05 21:47:34 +00002782 SparseColorMethod
2783 method;
2784
2785 char
2786 *arguments;
2787
2788 /*
2789 Sparse Color Interpolated Gradient
2790 */
cristy6b3da3a2010-06-20 02:21:46 +00002791 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002792 method=(SparseColorMethod) ParseMagickOption(
2793 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy6b3da3a2010-06-20 02:21:46 +00002794 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
cristy3ed852e2009-09-05 21:47:34 +00002795 InheritException(exception,&(*image)->exception);
2796 if (arguments == (char *) NULL)
2797 break;
anthonye9c27192011-03-27 08:07:06 +00002798 new_image=SparseColorOption(*image,channel,method,arguments,
cristy3ed852e2009-09-05 21:47:34 +00002799 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2800 arguments=DestroyString(arguments);
cristy3ed852e2009-09-05 21:47:34 +00002801 break;
2802 }
2803 if (LocaleCompare("splice",option+1) == 0)
2804 {
cristy3ed852e2009-09-05 21:47:34 +00002805 /*
2806 Splice a solid color into the image.
2807 */
cristy6b3da3a2010-06-20 02:21:46 +00002808 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002809 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
anthonye9c27192011-03-27 08:07:06 +00002810 new_image=SpliceImage(*image,&geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00002811 break;
2812 }
2813 if (LocaleCompare("spread",option+1) == 0)
2814 {
cristy3ed852e2009-09-05 21:47:34 +00002815 /*
2816 Spread an image.
2817 */
cristy6b3da3a2010-06-20 02:21:46 +00002818 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002819 (void) ParseGeometry(argv[i+1],&geometry_info);
anthonye9c27192011-03-27 08:07:06 +00002820 new_image=SpreadImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002821 break;
2822 }
cristy0834d642011-03-18 18:26:08 +00002823 if (LocaleCompare("statistic",option+1) == 0)
2824 {
cristy0834d642011-03-18 18:26:08 +00002825 StatisticType
2826 type;
2827
2828 (void) SyncImageSettings(mogrify_info,*image);
2829 type=(StatisticType) ParseMagickOption(MagickStatisticOptions,
2830 MagickFalse,argv[i+1]);
2831 (void) ParseGeometry(argv[i+2],&geometry_info);
anthonye9c27192011-03-27 08:07:06 +00002832 new_image=StatisticImageChannel(*image,channel,type,
cristy95c38342011-03-18 22:39:51 +00002833 (size_t) geometry_info.rho,(size_t) geometry_info.sigma,
2834 exception);
cristy0834d642011-03-18 18:26:08 +00002835 break;
2836 }
cristy3ed852e2009-09-05 21:47:34 +00002837 if (LocaleCompare("stretch",option+1) == 0)
2838 {
2839 if (*option == '+')
2840 {
2841 draw_info->stretch=UndefinedStretch;
2842 break;
2843 }
2844 draw_info->stretch=(StretchType) ParseMagickOption(
2845 MagickStretchOptions,MagickFalse,argv[i+1]);
2846 break;
2847 }
2848 if (LocaleCompare("strip",option+1) == 0)
2849 {
2850 /*
2851 Strip image of profiles and comments.
2852 */
cristy6b3da3a2010-06-20 02:21:46 +00002853 (void) SyncImageSettings(mogrify_info,*image);
glennrp3dae5ae2010-12-23 22:42:52 +00002854 (void) StripImage(*image);
cristy3ed852e2009-09-05 21:47:34 +00002855 InheritException(exception,&(*image)->exception);
2856 break;
2857 }
2858 if (LocaleCompare("stroke",option+1) == 0)
2859 {
2860 ExceptionInfo
2861 *sans;
2862
2863 if (*option == '+')
2864 {
2865 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2866 if (draw_info->stroke_pattern != (Image *) NULL)
2867 draw_info->stroke_pattern=DestroyImage(
2868 draw_info->stroke_pattern);
2869 break;
2870 }
2871 sans=AcquireExceptionInfo();
2872 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2873 sans=DestroyExceptionInfo(sans);
2874 if (status == MagickFalse)
cristy6b3da3a2010-06-20 02:21:46 +00002875 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002876 exception);
2877 break;
2878 }
2879 if (LocaleCompare("strokewidth",option+1) == 0)
2880 {
cristyf2f27272009-12-17 14:48:46 +00002881 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002882 break;
2883 }
2884 if (LocaleCompare("style",option+1) == 0)
2885 {
2886 if (*option == '+')
2887 {
2888 draw_info->style=UndefinedStyle;
2889 break;
2890 }
2891 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
2892 MagickFalse,argv[i+1]);
2893 break;
2894 }
2895 if (LocaleCompare("swirl",option+1) == 0)
2896 {
cristy3ed852e2009-09-05 21:47:34 +00002897 /*
2898 Swirl image.
2899 */
cristy6b3da3a2010-06-20 02:21:46 +00002900 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002901 (void) ParseGeometry(argv[i+1],&geometry_info);
anthonye9c27192011-03-27 08:07:06 +00002902 new_image=SwirlImage(*image,geometry_info.rho,exception);
cristy3ed852e2009-09-05 21:47:34 +00002903 break;
2904 }
2905 break;
2906 }
2907 case 't':
2908 {
2909 if (LocaleCompare("threshold",option+1) == 0)
2910 {
2911 double
2912 threshold;
2913
2914 /*
2915 Threshold image.
2916 */
cristy6b3da3a2010-06-20 02:21:46 +00002917 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002918 if (*option == '+')
2919 threshold=(double) QuantumRange/2.5;
2920 else
cristyf2f27272009-12-17 14:48:46 +00002921 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002922 (void) BilevelImageChannel(*image,channel,threshold);
2923 InheritException(exception,&(*image)->exception);
2924 break;
2925 }
2926 if (LocaleCompare("thumbnail",option+1) == 0)
2927 {
cristy3ed852e2009-09-05 21:47:34 +00002928 /*
2929 Thumbnail image.
2930 */
cristy6b3da3a2010-06-20 02:21:46 +00002931 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002932 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
anthonye9c27192011-03-27 08:07:06 +00002933 new_image=ThumbnailImage(*image,geometry.width,
cristy3ed852e2009-09-05 21:47:34 +00002934 geometry.height,exception);
cristy3ed852e2009-09-05 21:47:34 +00002935 break;
2936 }
2937 if (LocaleCompare("tile",option+1) == 0)
2938 {
2939 if (*option == '+')
2940 {
2941 if (draw_info->fill_pattern != (Image *) NULL)
2942 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2943 break;
2944 }
cristy6b3da3a2010-06-20 02:21:46 +00002945 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
cristy3ed852e2009-09-05 21:47:34 +00002946 exception);
2947 break;
2948 }
2949 if (LocaleCompare("tint",option+1) == 0)
2950 {
cristy3ed852e2009-09-05 21:47:34 +00002951 /*
2952 Tint the image.
2953 */
cristy6b3da3a2010-06-20 02:21:46 +00002954 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00002955 new_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
cristy3ed852e2009-09-05 21:47:34 +00002956 break;
2957 }
2958 if (LocaleCompare("transform",option+1) == 0)
2959 {
cristy3ed852e2009-09-05 21:47:34 +00002960 /*
2961 Affine transform image.
2962 */
cristy6b3da3a2010-06-20 02:21:46 +00002963 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00002964 new_image=AffineTransformImage(*image,&draw_info->affine,
cristy3ed852e2009-09-05 21:47:34 +00002965 exception);
cristy3ed852e2009-09-05 21:47:34 +00002966 break;
2967 }
2968 if (LocaleCompare("transparent",option+1) == 0)
2969 {
2970 MagickPixelPacket
2971 target;
2972
cristy6b3da3a2010-06-20 02:21:46 +00002973 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00002974 (void) QueryMagickColor(argv[i+1],&target,exception);
2975 (void) TransparentPaintImage(*image,&target,(Quantum)
2976 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
2977 InheritException(exception,&(*image)->exception);
2978 break;
2979 }
2980 if (LocaleCompare("transpose",option+1) == 0)
2981 {
cristy3ed852e2009-09-05 21:47:34 +00002982 /*
2983 Transpose image scanlines.
2984 */
cristy6b3da3a2010-06-20 02:21:46 +00002985 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00002986 new_image=TransposeImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002987 break;
2988 }
2989 if (LocaleCompare("transverse",option+1) == 0)
2990 {
cristy3ed852e2009-09-05 21:47:34 +00002991 /*
2992 Transverse image scanlines.
2993 */
cristy6b3da3a2010-06-20 02:21:46 +00002994 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00002995 new_image=TransverseImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00002996 break;
2997 }
2998 if (LocaleCompare("treedepth",option+1) == 0)
2999 {
cristye27293e2009-12-18 02:53:20 +00003000 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003001 break;
3002 }
3003 if (LocaleCompare("trim",option+1) == 0)
3004 {
cristy3ed852e2009-09-05 21:47:34 +00003005 /*
3006 Trim image.
3007 */
cristy6b3da3a2010-06-20 02:21:46 +00003008 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00003009 new_image=TrimImage(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003010 break;
3011 }
3012 if (LocaleCompare("type",option+1) == 0)
3013 {
3014 ImageType
3015 type;
3016
cristy6b3da3a2010-06-20 02:21:46 +00003017 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003018 if (*option == '+')
cristy5f1c1ff2010-12-23 21:38:06 +00003019 type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003020 else
3021 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3022 argv[i+1]);
cristy5f1c1ff2010-12-23 21:38:06 +00003023 (*image)->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00003024 (void) SetImageType(*image,type);
3025 InheritException(exception,&(*image)->exception);
3026 break;
3027 }
3028 break;
3029 }
3030 case 'u':
3031 {
3032 if (LocaleCompare("undercolor",option+1) == 0)
3033 {
3034 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3035 exception);
3036 break;
3037 }
cristy045bd902010-01-30 18:56:24 +00003038 if (LocaleCompare("unique",option+1) == 0)
3039 {
3040 if (*option == '+')
3041 {
cristy83fae872010-04-22 15:04:16 +00003042 (void) DeleteImageArtifact(*image,"identify:unique-colors");
cristy045bd902010-01-30 18:56:24 +00003043 break;
3044 }
cristy83fae872010-04-22 15:04:16 +00003045 (void) SetImageArtifact(*image,"identify:unique-colors","true");
cristya01cbea2010-11-03 16:33:33 +00003046 (void) SetImageArtifact(*image,"verbose","true");
cristy045bd902010-01-30 18:56:24 +00003047 break;
3048 }
cristy3ed852e2009-09-05 21:47:34 +00003049 if (LocaleCompare("unique-colors",option+1) == 0)
3050 {
cristy3ed852e2009-09-05 21:47:34 +00003051 /*
3052 Unique image colors.
3053 */
cristy6b3da3a2010-06-20 02:21:46 +00003054 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00003055 new_image=UniqueImageColors(*image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003056 break;
3057 }
3058 if (LocaleCompare("unsharp",option+1) == 0)
3059 {
cristy3ed852e2009-09-05 21:47:34 +00003060 /*
3061 Unsharp mask image.
3062 */
cristy6b3da3a2010-06-20 02:21:46 +00003063 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003064 flags=ParseGeometry(argv[i+1],&geometry_info);
3065 if ((flags & SigmaValue) == 0)
3066 geometry_info.sigma=1.0;
3067 if ((flags & XiValue) == 0)
3068 geometry_info.xi=1.0;
3069 if ((flags & PsiValue) == 0)
3070 geometry_info.psi=0.05;
anthonye9c27192011-03-27 08:07:06 +00003071 new_image=UnsharpMaskImageChannel(*image,channel,geometry_info.rho,
3072 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
3073 exception);
cristy3ed852e2009-09-05 21:47:34 +00003074 break;
3075 }
3076 break;
3077 }
3078 case 'v':
3079 {
3080 if (LocaleCompare("verbose",option+1) == 0)
3081 {
3082 (void) SetImageArtifact(*image,option+1,
3083 *option == '+' ? "false" : "true");
3084 break;
3085 }
3086 if (LocaleCompare("vignette",option+1) == 0)
3087 {
cristy3ed852e2009-09-05 21:47:34 +00003088 /*
3089 Vignette image.
3090 */
cristy6b3da3a2010-06-20 02:21:46 +00003091 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003092 flags=ParseGeometry(argv[i+1],&geometry_info);
3093 if ((flags & SigmaValue) == 0)
3094 geometry_info.sigma=1.0;
3095 if ((flags & XiValue) == 0)
3096 geometry_info.xi=0.1*(*image)->columns;
3097 if ((flags & PsiValue) == 0)
3098 geometry_info.psi=0.1*(*image)->rows;
anthonye9c27192011-03-27 08:07:06 +00003099 new_image=VignetteImage(*image,geometry_info.rho,
cristybb503372010-05-27 20:51:26 +00003100 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
cristy0534a6b2010-03-18 01:19:38 +00003101 ceil(geometry_info.psi-0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003102 break;
3103 }
3104 if (LocaleCompare("virtual-pixel",option+1) == 0)
3105 {
3106 if (*option == '+')
3107 {
3108 (void) SetImageVirtualPixelMethod(*image,
3109 UndefinedVirtualPixelMethod);
3110 break;
3111 }
3112 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3113 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3114 argv[i+1]));
3115 break;
3116 }
3117 break;
3118 }
3119 case 'w':
3120 {
3121 if (LocaleCompare("wave",option+1) == 0)
3122 {
cristy3ed852e2009-09-05 21:47:34 +00003123 /*
3124 Wave image.
3125 */
cristy6b3da3a2010-06-20 02:21:46 +00003126 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003127 flags=ParseGeometry(argv[i+1],&geometry_info);
3128 if ((flags & SigmaValue) == 0)
3129 geometry_info.sigma=1.0;
anthonye9c27192011-03-27 08:07:06 +00003130 new_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
cristy3ed852e2009-09-05 21:47:34 +00003131 exception);
cristy3ed852e2009-09-05 21:47:34 +00003132 break;
3133 }
3134 if (LocaleCompare("weight",option+1) == 0)
3135 {
cristye27293e2009-12-18 02:53:20 +00003136 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003137 if (LocaleCompare(argv[i+1],"all") == 0)
3138 draw_info->weight=0;
3139 if (LocaleCompare(argv[i+1],"bold") == 0)
3140 draw_info->weight=700;
3141 if (LocaleCompare(argv[i+1],"bolder") == 0)
3142 if (draw_info->weight <= 800)
3143 draw_info->weight+=100;
3144 if (LocaleCompare(argv[i+1],"lighter") == 0)
3145 if (draw_info->weight >= 100)
3146 draw_info->weight-=100;
3147 if (LocaleCompare(argv[i+1],"normal") == 0)
3148 draw_info->weight=400;
3149 break;
3150 }
3151 if (LocaleCompare("white-threshold",option+1) == 0)
3152 {
3153 /*
3154 White threshold image.
3155 */
cristy6b3da3a2010-06-20 02:21:46 +00003156 (void) SyncImageSettings(mogrify_info,*image);
cristy3ed852e2009-09-05 21:47:34 +00003157 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3158 exception);
3159 InheritException(exception,&(*image)->exception);
3160 break;
3161 }
3162 break;
3163 }
3164 default:
3165 break;
3166 }
anthonye9c27192011-03-27 08:07:06 +00003167 /*
3168 Replace current image with any image that was generated
3169 */
3170 if (new_image != (Image *) NULL)
3171 ReplaceImageInListReturnLast(image,new_image);
cristy3ed852e2009-09-05 21:47:34 +00003172 i+=count;
3173 }
3174 if (region_image != (Image *) NULL)
3175 {
3176 /*
3177 Composite transformed region onto image.
3178 */
cristy6b3da3a2010-06-20 02:21:46 +00003179 (void) SyncImageSettings(mogrify_info,*image);
anthonye9c27192011-03-27 08:07:06 +00003180 (void) CompositeImage(region_image,CopyCompositeOp,*image,
3181 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003182 InheritException(exception,&region_image->exception);
3183 *image=DestroyImage(*image);
3184 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003185 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003186 }
3187 /*
3188 Free resources.
3189 */
3190 quantize_info=DestroyQuantizeInfo(quantize_info);
3191 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003192 mogrify_info=DestroyImageInfo(mogrify_info);
3193 status=(*image)->exception.severity == UndefinedException ? MagickTrue :
3194 MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003195 return(status);
3196}
3197
3198/*
3199%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3200% %
3201% %
3202% %
cristy5063d812010-10-19 16:28:10 +00003203+ 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 +00003204% %
3205% %
3206% %
3207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3208%
3209% MogrifyImageCommand() transforms an image or a sequence of images. These
3210% transforms include image scaling, image rotation, color reduction, and
3211% others. The transmogrified image overwrites the original image.
3212%
3213% The format of the MogrifyImageCommand method is:
3214%
3215% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3216% const char **argv,char **metadata,ExceptionInfo *exception)
3217%
3218% A description of each parameter follows:
3219%
3220% o image_info: the image info.
3221%
3222% o argc: the number of elements in the argument vector.
3223%
3224% o argv: A text array containing the command line arguments.
3225%
3226% o metadata: any metadata is returned here.
3227%
3228% o exception: return any errors or warnings in this structure.
3229%
3230*/
3231
3232static MagickBooleanType MogrifyUsage(void)
3233{
3234 static const char
3235 *miscellaneous[]=
3236 {
3237 "-debug events display copious debugging information",
3238 "-help print program options",
3239 "-list type print a list of supported option arguments",
3240 "-log format format of debugging information",
3241 "-version print version information",
3242 (char *) NULL
3243 },
3244 *operators[]=
3245 {
3246 "-adaptive-blur geometry",
3247 " adaptively blur pixels; decrease effect near edges",
3248 "-adaptive-resize geometry",
3249 " adaptively resize image using 'mesh' interpolation",
3250 "-adaptive-sharpen geometry",
3251 " adaptively sharpen pixels; increase effect near edges",
3252 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3253 " transparent, extract, background, or shape",
3254 "-annotate geometry text",
3255 " annotate the image with text",
3256 "-auto-gamma automagically adjust gamma level of image",
3257 "-auto-level automagically adjust color levels of image",
3258 "-auto-orient automagically orient (rotate) image",
3259 "-bench iterations measure performance",
3260 "-black-threshold value",
3261 " force all pixels below the threshold into black",
3262 "-blue-shift simulate a scene at nighttime in the moonlight",
3263 "-blur geometry reduce image noise and reduce detail levels",
3264 "-border geometry surround image with a border of color",
3265 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003266 "-brightness-contrast geometry",
3267 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003268 "-cdl filename color correct with a color decision list",
3269 "-charcoal radius simulate a charcoal drawing",
3270 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003271 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003272 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003273 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003274 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003275 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003276 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003277 "-contrast enhance or reduce the image contrast",
3278 "-contrast-stretch geometry",
3279 " improve contrast by `stretching' the intensity range",
3280 "-convolve coefficients",
3281 " apply a convolution kernel to the image",
3282 "-cycle amount cycle the image colormap",
3283 "-decipher filename convert cipher pixels to plain pixels",
3284 "-deskew threshold straighten an image",
3285 "-despeckle reduce the speckles within an image",
3286 "-distort method args",
3287 " distort images according to given method ad args",
3288 "-draw string annotate the image with a graphic primitive",
3289 "-edge radius apply a filter to detect edges in the image",
3290 "-encipher filename convert plain pixels to cipher pixels",
3291 "-emboss radius emboss an image",
3292 "-enhance apply a digital filter to enhance a noisy image",
3293 "-equalize perform histogram equalization to an image",
3294 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003295 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003296 "-extent geometry set the image size",
3297 "-extract geometry extract area from image",
3298 "-fft implements the discrete Fourier transform (DFT)",
3299 "-flip flip image vertically",
3300 "-floodfill geometry color",
3301 " floodfill the image with color",
3302 "-flop flop image horizontally",
3303 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003304 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003305 " apply function over image values",
3306 "-gamma value level of gamma correction",
3307 "-gaussian-blur geometry",
3308 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003309 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003310 "-identify identify the format and characteristics of the image",
3311 "-ift implements the inverse discrete Fourier transform (DFT)",
3312 "-implode amount implode image pixels about the center",
3313 "-lat geometry local adaptive thresholding",
3314 "-layers method optimize, merge, or compare image layers",
3315 "-level value adjust the level of image contrast",
3316 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003317 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003318 "-linear-stretch geometry",
3319 " improve contrast by `stretching with saturation'",
3320 "-liquid-rescale geometry",
3321 " rescale image with seam-carving",
3322 "-median radius apply a median filter to the image",
cristy2ecd9be2011-02-28 01:17:26 +00003323 "-mode radius make each pixel the 'predominate color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003324 "-modulate value vary the brightness, saturation, and hue",
3325 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003326 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003327 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003328 "-motion-blur geometry",
3329 " simulate motion blur",
3330 "-negate replace every pixel with its complementary color ",
3331 "-noise radius add or reduce noise in an image",
3332 "-normalize transform image to span the full range of colors",
3333 "-opaque color change this color to the fill color",
3334 "-ordered-dither NxN",
3335 " add a noise pattern to the image with specific",
3336 " amplitudes",
3337 "-paint radius simulate an oil painting",
3338 "-polaroid angle simulate a Polaroid picture",
3339 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003340 "-profile filename add, delete, or apply an image profile",
3341 "-quantize colorspace reduce colors in this colorspace",
3342 "-radial-blur angle radial blur the image",
3343 "-raise value lighten/darken image edges to create a 3-D effect",
3344 "-random-threshold low,high",
3345 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003346 "-region geometry apply options to a portion of the image",
3347 "-render render vector graphics",
3348 "-repage geometry size and location of an image canvas",
3349 "-resample geometry change the resolution of an image",
3350 "-resize geometry resize the image",
3351 "-roll geometry roll an image vertically or horizontally",
3352 "-rotate degrees apply Paeth rotation to the image",
3353 "-sample geometry scale image with pixel sampling",
3354 "-scale geometry scale the image",
3355 "-segment values segment an image",
3356 "-selective-blur geometry",
3357 " selectively blur pixels within a contrast threshold",
3358 "-sepia-tone threshold",
3359 " simulate a sepia-toned photo",
3360 "-set property value set an image property",
3361 "-shade degrees shade the image using a distant light source",
3362 "-shadow geometry simulate an image shadow",
3363 "-sharpen geometry sharpen the image",
3364 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003365 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003366 "-sigmoidal-contrast geometry",
3367 " increase the contrast without saturating highlights or shadows",
3368 "-sketch geometry simulate a pencil sketch",
3369 "-solarize threshold negate all pixels above the threshold level",
3370 "-sparse-color method args",
3371 " fill in a image based on a few color points",
3372 "-splice geometry splice the background color into the image",
3373 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003374 "-statistic type radius",
3375 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003376 "-strip strip image of all profiles and comments",
3377 "-swirl degrees swirl image pixels about the center",
3378 "-threshold value threshold the image",
3379 "-thumbnail geometry create a thumbnail of the image",
3380 "-tile filename tile image when filling a graphic primitive",
3381 "-tint value tint the image with the fill color",
3382 "-transform affine transform image",
3383 "-transparent color make this color transparent within the image",
3384 "-transpose flip image vertically and rotate 90 degrees",
3385 "-transverse flop image horizontally and rotate 270 degrees",
3386 "-trim trim image edges",
3387 "-type type image type",
3388 "-unique-colors discard all but one of any pixel color",
3389 "-unsharp geometry sharpen the image",
3390 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003391 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003392 "-white-threshold value",
3393 " force all pixels above the threshold into white",
3394 (char *) NULL
3395 },
3396 *sequence_operators[]=
3397 {
cristy4285d782011-02-09 20:12:28 +00003398 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003399 "-clut apply a color lookup table to the image",
3400 "-coalesce merge a sequence of images",
3401 "-combine combine a sequence of images",
3402 "-composite composite image",
3403 "-crop geometry cut out a rectangular region of the image",
3404 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003405 "-evaluate-sequence operator",
3406 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003407 "-flatten flatten a sequence of images",
3408 "-fx expression apply mathematical expression to an image channel(s)",
3409 "-hald-clut apply a Hald color lookup table to the image",
3410 "-morph value morph an image sequence",
3411 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003412 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003413 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003414 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003415 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003416 "-write filename write images to this file",
3417 (char *) NULL
3418 },
3419 *settings[]=
3420 {
3421 "-adjoin join images into a single multi-image file",
3422 "-affine matrix affine transform matrix",
3423 "-alpha option activate, deactivate, reset, or set the alpha channel",
3424 "-antialias remove pixel-aliasing",
3425 "-authenticate password",
3426 " decipher image with this password",
3427 "-attenuate value lessen (or intensify) when adding noise to an image",
3428 "-background color background color",
3429 "-bias value add bias when convolving an image",
3430 "-black-point-compensation",
3431 " use black point compensation",
3432 "-blue-primary point chromaticity blue primary point",
3433 "-bordercolor color border color",
3434 "-caption string assign a caption to an image",
3435 "-channel type apply option to select image channels",
3436 "-colors value preferred number of colors in the image",
3437 "-colorspace type alternate image colorspace",
3438 "-comment string annotate image with comment",
3439 "-compose operator set image composite operator",
3440 "-compress type type of pixel compression when writing the image",
3441 "-define format:option",
3442 " define one or more image format options",
3443 "-delay value display the next image after pausing",
3444 "-density geometry horizontal and vertical density of the image",
3445 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003446 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003447 "-display server get image or font from this X server",
3448 "-dispose method layer disposal method",
3449 "-dither method apply error diffusion to image",
3450 "-encoding type text encoding type",
3451 "-endian type endianness (MSB or LSB) of the image",
3452 "-family name render text with this font family",
3453 "-fill color color to use when filling a graphic primitive",
3454 "-filter type use this filter when resizing an image",
3455 "-font name render text with this font",
3456 "-format \"string\" output formatted image characteristics",
3457 "-fuzz distance colors within this distance are considered equal",
3458 "-gravity type horizontal and vertical text placement",
3459 "-green-primary point chromaticity green primary point",
3460 "-intent type type of rendering intent when managing the image color",
3461 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003462 "-interline-spacing value",
3463 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003464 "-interpolate method pixel color interpolation method",
3465 "-interword-spacing value",
3466 " set the space between two words",
3467 "-kerning value set the space between two letters",
3468 "-label string assign a label to an image",
3469 "-limit type value pixel cache resource limit",
3470 "-loop iterations add Netscape loop extension to your GIF animation",
3471 "-mask filename associate a mask with the image",
3472 "-mattecolor color frame color",
3473 "-monitor monitor progress",
3474 "-orient type image orientation",
3475 "-page geometry size and location of an image canvas (setting)",
3476 "-ping efficiently determine image attributes",
3477 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003478 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003479 "-preview type image preview type",
3480 "-quality value JPEG/MIFF/PNG compression level",
3481 "-quiet suppress all warning messages",
3482 "-red-primary point chromaticity red primary point",
3483 "-regard-warnings pay attention to warning messages",
3484 "-remap filename transform image colors to match this set of colors",
3485 "-respect-parentheses settings remain in effect until parenthesis boundary",
3486 "-sampling-factor geometry",
3487 " horizontal and vertical sampling factor",
3488 "-scene value image scene number",
3489 "-seed value seed a new sequence of pseudo-random numbers",
3490 "-size geometry width and height of image",
3491 "-stretch type render text with this font stretch",
3492 "-stroke color graphic primitive stroke color",
3493 "-strokewidth value graphic primitive stroke width",
3494 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003495 "-synchronize synchronize image to storage device",
3496 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003497 "-texture filename name of texture to tile onto the image background",
3498 "-tile-offset geometry",
3499 " tile offset",
3500 "-treedepth value color tree depth",
3501 "-transparent-color color",
3502 " transparent color",
3503 "-undercolor color annotation bounding box color",
3504 "-units type the units of image resolution",
3505 "-verbose print detailed information about the image",
3506 "-view FlashPix viewing transforms",
3507 "-virtual-pixel method",
3508 " virtual pixel access method",
3509 "-weight type render text with this font weight",
3510 "-white-point point chromaticity white point",
3511 (char *) NULL
3512 },
3513 *stack_operators[]=
3514 {
anthonyb69c4b32011-03-23 04:37:44 +00003515 "-delete indexes delete the image from the image sequence",
3516 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003517 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003518 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003519 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003520 "-swap indexes swap two images in the image sequence",
3521 (char *) NULL
3522 };
3523
3524 const char
3525 **p;
3526
cristybb503372010-05-27 20:51:26 +00003527 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003528 (void) printf("Copyright: %s\n",GetMagickCopyright());
3529 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003530 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3531 GetClientName());
3532 (void) printf("\nImage Settings:\n");
3533 for (p=settings; *p != (char *) NULL; p++)
3534 (void) printf(" %s\n",*p);
3535 (void) printf("\nImage Operators:\n");
3536 for (p=operators; *p != (char *) NULL; p++)
3537 (void) printf(" %s\n",*p);
3538 (void) printf("\nImage Sequence Operators:\n");
3539 for (p=sequence_operators; *p != (char *) NULL; p++)
3540 (void) printf(" %s\n",*p);
3541 (void) printf("\nImage Stack Operators:\n");
3542 for (p=stack_operators; *p != (char *) NULL; p++)
3543 (void) printf(" %s\n",*p);
3544 (void) printf("\nMiscellaneous Options:\n");
3545 for (p=miscellaneous; *p != (char *) NULL; p++)
3546 (void) printf(" %s\n",*p);
3547 (void) printf(
3548 "\nBy default, the image format of `file' is determined by its magic\n");
3549 (void) printf(
3550 "number. To specify a particular image format, precede the filename\n");
3551 (void) printf(
3552 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3553 (void) printf(
3554 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3555 (void) printf("'-' for standard input or output.\n");
3556 return(MagickFalse);
3557}
3558
3559WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3560 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3561{
3562#define DestroyMogrify() \
3563{ \
3564 if (format != (char *) NULL) \
3565 format=DestroyString(format); \
3566 if (path != (char *) NULL) \
3567 path=DestroyString(path); \
3568 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003569 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003570 argv[i]=DestroyString(argv[i]); \
3571 argv=(char **) RelinquishMagickMemory(argv); \
3572}
3573#define ThrowMogrifyException(asperity,tag,option) \
3574{ \
3575 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3576 option); \
3577 DestroyMogrify(); \
3578 return(MagickFalse); \
3579}
3580#define ThrowMogrifyInvalidArgumentException(option,argument) \
3581{ \
3582 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3583 "InvalidArgument","`%s': %s",argument,option); \
3584 DestroyMogrify(); \
3585 return(MagickFalse); \
3586}
3587
3588 char
3589 *format,
3590 *option,
3591 *path;
3592
3593 Image
3594 *image;
3595
3596 ImageStack
3597 image_stack[MaxImageStackDepth+1];
3598
cristy3ed852e2009-09-05 21:47:34 +00003599 MagickBooleanType
3600 global_colormap;
3601
3602 MagickBooleanType
3603 fire,
cristyebbcfea2011-02-25 02:43:54 +00003604 pend,
3605 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003606
3607 MagickStatusType
3608 status;
3609
cristyebbcfea2011-02-25 02:43:54 +00003610 register ssize_t
3611 i;
3612
3613 ssize_t
3614 j,
3615 k;
3616
cristy3ed852e2009-09-05 21:47:34 +00003617 /*
3618 Set defaults.
3619 */
3620 assert(image_info != (ImageInfo *) NULL);
3621 assert(image_info->signature == MagickSignature);
3622 if (image_info->debug != MagickFalse)
3623 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3624 assert(exception != (ExceptionInfo *) NULL);
3625 if (argc == 2)
3626 {
3627 option=argv[1];
3628 if ((LocaleCompare("version",option+1) == 0) ||
3629 (LocaleCompare("-version",option+1) == 0))
3630 {
3631 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003632 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003633 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
3634 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003635 return(MagickFalse);
3636 }
3637 }
3638 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003639 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003640 format=(char *) NULL;
3641 path=(char *) NULL;
3642 global_colormap=MagickFalse;
3643 k=0;
3644 j=1;
3645 NewImageStack();
3646 option=(char *) NULL;
3647 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003648 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003649 status=MagickTrue;
3650 /*
3651 Parse command line.
3652 */
3653 ReadCommandlLine(argc,&argv);
3654 status=ExpandFilenames(&argc,&argv);
3655 if (status == MagickFalse)
3656 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3657 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003658 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003659 {
3660 option=argv[i];
3661 if (LocaleCompare(option,"(") == 0)
3662 {
3663 FireImageStack(MagickFalse,MagickTrue,pend);
3664 if (k == MaxImageStackDepth)
3665 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3666 option);
3667 PushImageStack();
3668 continue;
3669 }
3670 if (LocaleCompare(option,")") == 0)
3671 {
3672 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3673 if (k == 0)
3674 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3675 PopImageStack();
3676 continue;
3677 }
3678 if (IsMagickOption(option) == MagickFalse)
3679 {
3680 char
3681 backup_filename[MaxTextExtent],
3682 *filename;
3683
3684 Image
3685 *images;
3686
3687 /*
3688 Option is a file name: begin by reading image from specified file.
3689 */
3690 FireImageStack(MagickFalse,MagickFalse,pend);
3691 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003692 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003693 filename=argv[++i];
3694 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3695 images=ReadImages(image_info,exception);
3696 status&=(images != (Image *) NULL) &&
3697 (exception->severity < ErrorException);
3698 if (images == (Image *) NULL)
3699 continue;
cristydaa76602010-06-30 13:05:11 +00003700 if (format != (char *) NULL)
3701 (void) CopyMagickString(images->filename,images->magick_filename,
3702 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003703 if (path != (char *) NULL)
3704 {
3705 GetPathComponent(option,TailPath,filename);
3706 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
3707 path,*DirectorySeparator,filename);
3708 }
3709 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003710 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003711 AppendImageStack(images);
3712 FinalizeImageSettings(image_info,image,MagickFalse);
3713 if (global_colormap != MagickFalse)
3714 {
3715 QuantizeInfo
3716 *quantize_info;
3717
3718 quantize_info=AcquireQuantizeInfo(image_info);
3719 (void) RemapImages(quantize_info,images,(Image *) NULL);
3720 quantize_info=DestroyQuantizeInfo(quantize_info);
3721 }
3722 *backup_filename='\0';
3723 if ((LocaleCompare(image->filename,"-") != 0) &&
3724 (IsPathWritable(image->filename) != MagickFalse))
3725 {
cristybb503372010-05-27 20:51:26 +00003726 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003727 i;
3728
3729 /*
3730 Rename image file as backup.
3731 */
3732 (void) CopyMagickString(backup_filename,image->filename,
3733 MaxTextExtent);
3734 for (i=0; i < 6; i++)
3735 {
3736 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3737 if (IsPathAccessible(backup_filename) == MagickFalse)
3738 break;
3739 }
3740 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3741 (rename(image->filename,backup_filename) != 0))
3742 *backup_filename='\0';
3743 }
3744 /*
3745 Write transmogrified image to disk.
3746 */
3747 image_info->synchronize=MagickTrue;
3748 status&=WriteImages(image_info,image,image->filename,exception);
3749 if ((status == MagickFalse) && (*backup_filename != '\0'))
3750 (void) remove(backup_filename);
3751 RemoveAllImageStack();
3752 continue;
3753 }
3754 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3755 switch (*(option+1))
3756 {
3757 case 'a':
3758 {
3759 if (LocaleCompare("adaptive-blur",option+1) == 0)
3760 {
3761 i++;
cristybb503372010-05-27 20:51:26 +00003762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003763 ThrowMogrifyException(OptionError,"MissingArgument",option);
3764 if (IsGeometry(argv[i]) == MagickFalse)
3765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3766 break;
3767 }
3768 if (LocaleCompare("adaptive-resize",option+1) == 0)
3769 {
3770 i++;
cristybb503372010-05-27 20:51:26 +00003771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003772 ThrowMogrifyException(OptionError,"MissingArgument",option);
3773 if (IsGeometry(argv[i]) == MagickFalse)
3774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3775 break;
3776 }
3777 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3778 {
3779 i++;
cristybb503372010-05-27 20:51:26 +00003780 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003781 ThrowMogrifyException(OptionError,"MissingArgument",option);
3782 if (IsGeometry(argv[i]) == MagickFalse)
3783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3784 break;
3785 }
3786 if (LocaleCompare("affine",option+1) == 0)
3787 {
3788 if (*option == '+')
3789 break;
3790 i++;
cristybb503372010-05-27 20:51:26 +00003791 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003792 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003793 break;
3794 }
3795 if (LocaleCompare("alpha",option+1) == 0)
3796 {
cristybb503372010-05-27 20:51:26 +00003797 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003798 type;
3799
3800 if (*option == '+')
3801 break;
3802 i++;
cristybb503372010-05-27 20:51:26 +00003803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003804 ThrowMogrifyException(OptionError,"MissingArgument",option);
3805 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
3806 if (type < 0)
3807 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3808 argv[i]);
3809 break;
3810 }
3811 if (LocaleCompare("annotate",option+1) == 0)
3812 {
3813 if (*option == '+')
3814 break;
3815 i++;
cristybb503372010-05-27 20:51:26 +00003816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003817 ThrowMogrifyException(OptionError,"MissingArgument",option);
3818 if (IsGeometry(argv[i]) == MagickFalse)
3819 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003821 ThrowMogrifyException(OptionError,"MissingArgument",option);
3822 i++;
3823 break;
3824 }
3825 if (LocaleCompare("antialias",option+1) == 0)
3826 break;
3827 if (LocaleCompare("append",option+1) == 0)
3828 break;
3829 if (LocaleCompare("attenuate",option+1) == 0)
3830 {
3831 if (*option == '+')
3832 break;
3833 i++;
cristybb503372010-05-27 20:51:26 +00003834 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003835 ThrowMogrifyException(OptionError,"MissingArgument",option);
3836 if (IsGeometry(argv[i]) == MagickFalse)
3837 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3838 break;
3839 }
3840 if (LocaleCompare("authenticate",option+1) == 0)
3841 {
3842 if (*option == '+')
3843 break;
3844 i++;
cristybb503372010-05-27 20:51:26 +00003845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003846 ThrowMogrifyException(OptionError,"MissingArgument",option);
3847 break;
3848 }
3849 if (LocaleCompare("auto-gamma",option+1) == 0)
3850 break;
3851 if (LocaleCompare("auto-level",option+1) == 0)
3852 break;
3853 if (LocaleCompare("auto-orient",option+1) == 0)
3854 break;
3855 if (LocaleCompare("average",option+1) == 0)
3856 break;
3857 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3858 }
3859 case 'b':
3860 {
3861 if (LocaleCompare("background",option+1) == 0)
3862 {
3863 if (*option == '+')
3864 break;
3865 i++;
cristybb503372010-05-27 20:51:26 +00003866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003867 ThrowMogrifyException(OptionError,"MissingArgument",option);
3868 break;
3869 }
3870 if (LocaleCompare("bias",option+1) == 0)
3871 {
3872 if (*option == '+')
3873 break;
3874 i++;
cristybb503372010-05-27 20:51:26 +00003875 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003876 ThrowMogrifyException(OptionError,"MissingArgument",option);
3877 if (IsGeometry(argv[i]) == MagickFalse)
3878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3879 break;
3880 }
3881 if (LocaleCompare("black-point-compensation",option+1) == 0)
3882 break;
3883 if (LocaleCompare("black-threshold",option+1) == 0)
3884 {
3885 if (*option == '+')
3886 break;
3887 i++;
cristybb503372010-05-27 20:51:26 +00003888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003889 ThrowMogrifyException(OptionError,"MissingArgument",option);
3890 if (IsGeometry(argv[i]) == MagickFalse)
3891 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3892 break;
3893 }
3894 if (LocaleCompare("blue-primary",option+1) == 0)
3895 {
3896 if (*option == '+')
3897 break;
3898 i++;
cristybb503372010-05-27 20:51:26 +00003899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003900 ThrowMogrifyException(OptionError,"MissingArgument",option);
3901 if (IsGeometry(argv[i]) == MagickFalse)
3902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3903 break;
3904 }
3905 if (LocaleCompare("blue-shift",option+1) == 0)
3906 {
3907 i++;
cristybb503372010-05-27 20:51:26 +00003908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003909 ThrowMogrifyException(OptionError,"MissingArgument",option);
3910 if (IsGeometry(argv[i]) == MagickFalse)
3911 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3912 break;
3913 }
3914 if (LocaleCompare("blur",option+1) == 0)
3915 {
3916 i++;
cristybb503372010-05-27 20:51:26 +00003917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003918 ThrowMogrifyException(OptionError,"MissingArgument",option);
3919 if (IsGeometry(argv[i]) == MagickFalse)
3920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3921 break;
3922 }
3923 if (LocaleCompare("border",option+1) == 0)
3924 {
3925 if (*option == '+')
3926 break;
3927 i++;
cristybb503372010-05-27 20:51:26 +00003928 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003929 ThrowMogrifyException(OptionError,"MissingArgument",option);
3930 if (IsGeometry(argv[i]) == MagickFalse)
3931 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3932 break;
3933 }
3934 if (LocaleCompare("bordercolor",option+1) == 0)
3935 {
3936 if (*option == '+')
3937 break;
3938 i++;
cristybb503372010-05-27 20:51:26 +00003939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003940 ThrowMogrifyException(OptionError,"MissingArgument",option);
3941 break;
3942 }
3943 if (LocaleCompare("box",option+1) == 0)
3944 {
3945 if (*option == '+')
3946 break;
3947 i++;
cristybb503372010-05-27 20:51:26 +00003948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003949 ThrowMogrifyException(OptionError,"MissingArgument",option);
3950 break;
3951 }
cristya28d6b82010-01-11 20:03:47 +00003952 if (LocaleCompare("brightness-contrast",option+1) == 0)
3953 {
3954 i++;
cristybb503372010-05-27 20:51:26 +00003955 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003956 ThrowMogrifyException(OptionError,"MissingArgument",option);
3957 if (IsGeometry(argv[i]) == MagickFalse)
3958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3959 break;
3960 }
cristy3ed852e2009-09-05 21:47:34 +00003961 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3962 }
3963 case 'c':
3964 {
3965 if (LocaleCompare("cache",option+1) == 0)
3966 {
3967 if (*option == '+')
3968 break;
3969 i++;
cristybb503372010-05-27 20:51:26 +00003970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003971 ThrowMogrifyException(OptionError,"MissingArgument",option);
3972 if (IsGeometry(argv[i]) == MagickFalse)
3973 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3974 break;
3975 }
3976 if (LocaleCompare("caption",option+1) == 0)
3977 {
3978 if (*option == '+')
3979 break;
3980 i++;
cristybb503372010-05-27 20:51:26 +00003981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003982 ThrowMogrifyException(OptionError,"MissingArgument",option);
3983 break;
3984 }
3985 if (LocaleCompare("channel",option+1) == 0)
3986 {
cristybb503372010-05-27 20:51:26 +00003987 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003988 channel;
3989
3990 if (*option == '+')
3991 break;
3992 i++;
cristybb503372010-05-27 20:51:26 +00003993 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003994 ThrowMogrifyException(OptionError,"MissingArgument",option);
3995 channel=ParseChannelOption(argv[i]);
3996 if (channel < 0)
3997 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3998 argv[i]);
3999 break;
4000 }
4001 if (LocaleCompare("cdl",option+1) == 0)
4002 {
4003 if (*option == '+')
4004 break;
4005 i++;
cristybb503372010-05-27 20:51:26 +00004006 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004007 ThrowMogrifyException(OptionError,"MissingArgument",option);
4008 break;
4009 }
4010 if (LocaleCompare("charcoal",option+1) == 0)
4011 {
4012 if (*option == '+')
4013 break;
4014 i++;
cristybb503372010-05-27 20:51:26 +00004015 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004016 ThrowMogrifyException(OptionError,"MissingArgument",option);
4017 if (IsGeometry(argv[i]) == MagickFalse)
4018 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4019 break;
4020 }
4021 if (LocaleCompare("chop",option+1) == 0)
4022 {
4023 if (*option == '+')
4024 break;
4025 i++;
cristybb503372010-05-27 20:51:26 +00004026 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004027 ThrowMogrifyException(OptionError,"MissingArgument",option);
4028 if (IsGeometry(argv[i]) == MagickFalse)
4029 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4030 break;
4031 }
cristy1eb45dd2009-09-25 16:38:06 +00004032 if (LocaleCompare("clamp",option+1) == 0)
4033 break;
4034 if (LocaleCompare("clip",option+1) == 0)
4035 break;
cristy3ed852e2009-09-05 21:47:34 +00004036 if (LocaleCompare("clip-mask",option+1) == 0)
4037 {
4038 if (*option == '+')
4039 break;
4040 i++;
cristybb503372010-05-27 20:51:26 +00004041 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004042 ThrowMogrifyException(OptionError,"MissingArgument",option);
4043 break;
4044 }
4045 if (LocaleCompare("clut",option+1) == 0)
4046 break;
4047 if (LocaleCompare("coalesce",option+1) == 0)
4048 break;
4049 if (LocaleCompare("colorize",option+1) == 0)
4050 {
4051 if (*option == '+')
4052 break;
4053 i++;
cristybb503372010-05-27 20:51:26 +00004054 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004055 ThrowMogrifyException(OptionError,"MissingArgument",option);
4056 if (IsGeometry(argv[i]) == MagickFalse)
4057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4058 break;
4059 }
cristye6365592010-04-02 17:31:23 +00004060 if (LocaleCompare("color-matrix",option+1) == 0)
4061 {
cristyb6bd4ad2010-08-08 01:12:27 +00004062 KernelInfo
4063 *kernel_info;
4064
cristye6365592010-04-02 17:31:23 +00004065 if (*option == '+')
4066 break;
4067 i++;
cristybb503372010-05-27 20:51:26 +00004068 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004069 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004070 kernel_info=AcquireKernelInfo(argv[i]);
4071 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004072 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004073 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004074 break;
4075 }
cristy3ed852e2009-09-05 21:47:34 +00004076 if (LocaleCompare("colors",option+1) == 0)
4077 {
4078 if (*option == '+')
4079 break;
4080 i++;
cristybb503372010-05-27 20:51:26 +00004081 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004082 ThrowMogrifyException(OptionError,"MissingArgument",option);
4083 if (IsGeometry(argv[i]) == MagickFalse)
4084 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4085 break;
4086 }
4087 if (LocaleCompare("colorspace",option+1) == 0)
4088 {
cristybb503372010-05-27 20:51:26 +00004089 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004090 colorspace;
4091
4092 if (*option == '+')
4093 break;
4094 i++;
cristybb503372010-05-27 20:51:26 +00004095 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004096 ThrowMogrifyException(OptionError,"MissingArgument",option);
4097 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4098 argv[i]);
4099 if (colorspace < 0)
4100 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4101 argv[i]);
4102 break;
4103 }
4104 if (LocaleCompare("combine",option+1) == 0)
4105 break;
4106 if (LocaleCompare("comment",option+1) == 0)
4107 {
4108 if (*option == '+')
4109 break;
4110 i++;
cristybb503372010-05-27 20:51:26 +00004111 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004112 ThrowMogrifyException(OptionError,"MissingArgument",option);
4113 break;
4114 }
4115 if (LocaleCompare("composite",option+1) == 0)
4116 break;
4117 if (LocaleCompare("compress",option+1) == 0)
4118 {
cristybb503372010-05-27 20:51:26 +00004119 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004120 compress;
4121
4122 if (*option == '+')
4123 break;
4124 i++;
cristybb503372010-05-27 20:51:26 +00004125 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004126 ThrowMogrifyException(OptionError,"MissingArgument",option);
4127 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4128 argv[i]);
4129 if (compress < 0)
4130 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4131 argv[i]);
4132 break;
4133 }
cristy22879752009-10-25 23:55:40 +00004134 if (LocaleCompare("concurrent",option+1) == 0)
4135 break;
cristy3ed852e2009-09-05 21:47:34 +00004136 if (LocaleCompare("contrast",option+1) == 0)
4137 break;
4138 if (LocaleCompare("contrast-stretch",option+1) == 0)
4139 {
4140 i++;
cristybb503372010-05-27 20:51:26 +00004141 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004142 ThrowMogrifyException(OptionError,"MissingArgument",option);
4143 if (IsGeometry(argv[i]) == MagickFalse)
4144 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4145 break;
4146 }
4147 if (LocaleCompare("convolve",option+1) == 0)
4148 {
cristyb6bd4ad2010-08-08 01:12:27 +00004149 KernelInfo
4150 *kernel_info;
4151
cristy3ed852e2009-09-05 21:47:34 +00004152 if (*option == '+')
4153 break;
4154 i++;
cristybb503372010-05-27 20:51:26 +00004155 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004156 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004157 kernel_info=AcquireKernelInfo(argv[i]);
4158 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004160 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004161 break;
4162 }
4163 if (LocaleCompare("crop",option+1) == 0)
4164 {
4165 if (*option == '+')
4166 break;
4167 i++;
cristybb503372010-05-27 20:51:26 +00004168 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004169 ThrowMogrifyException(OptionError,"MissingArgument",option);
4170 if (IsGeometry(argv[i]) == MagickFalse)
4171 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4172 break;
4173 }
4174 if (LocaleCompare("cycle",option+1) == 0)
4175 {
4176 if (*option == '+')
4177 break;
4178 i++;
cristybb503372010-05-27 20:51:26 +00004179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004180 ThrowMogrifyException(OptionError,"MissingArgument",option);
4181 if (IsGeometry(argv[i]) == MagickFalse)
4182 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4183 break;
4184 }
4185 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4186 }
4187 case 'd':
4188 {
4189 if (LocaleCompare("decipher",option+1) == 0)
4190 {
4191 if (*option == '+')
4192 break;
4193 i++;
cristybb503372010-05-27 20:51:26 +00004194 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004195 ThrowMogrifyException(OptionError,"MissingArgument",option);
4196 break;
4197 }
4198 if (LocaleCompare("deconstruct",option+1) == 0)
4199 break;
4200 if (LocaleCompare("debug",option+1) == 0)
4201 {
cristybb503372010-05-27 20:51:26 +00004202 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004203 event;
4204
4205 if (*option == '+')
4206 break;
4207 i++;
cristybb503372010-05-27 20:51:26 +00004208 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004209 ThrowMogrifyException(OptionError,"MissingArgument",option);
4210 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4211 if (event < 0)
4212 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4213 argv[i]);
4214 (void) SetLogEventMask(argv[i]);
4215 break;
4216 }
4217 if (LocaleCompare("define",option+1) == 0)
4218 {
4219 i++;
cristybb503372010-05-27 20:51:26 +00004220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004221 ThrowMogrifyException(OptionError,"MissingArgument",option);
4222 if (*option == '+')
4223 {
4224 const char
4225 *define;
4226
4227 define=GetImageOption(image_info,argv[i]);
4228 if (define == (const char *) NULL)
4229 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4230 break;
4231 }
4232 break;
4233 }
4234 if (LocaleCompare("delay",option+1) == 0)
4235 {
4236 if (*option == '+')
4237 break;
4238 i++;
cristybb503372010-05-27 20:51:26 +00004239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004240 ThrowMogrifyException(OptionError,"MissingArgument",option);
4241 if (IsGeometry(argv[i]) == MagickFalse)
4242 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4243 break;
4244 }
cristyecb10ff2011-03-22 13:14:03 +00004245 if (LocaleCompare("delete",option+1) == 0)
4246 {
4247 if (*option == '+')
4248 break;
4249 i++;
4250 if (i == (ssize_t) (argc-1))
4251 ThrowMogrifyException(OptionError,"MissingArgument",option);
4252 if (IsGeometry(argv[i]) == MagickFalse)
4253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4254 break;
4255 }
cristy3ed852e2009-09-05 21:47:34 +00004256 if (LocaleCompare("density",option+1) == 0)
4257 {
4258 if (*option == '+')
4259 break;
4260 i++;
cristybb503372010-05-27 20:51:26 +00004261 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004262 ThrowMogrifyException(OptionError,"MissingArgument",option);
4263 if (IsGeometry(argv[i]) == MagickFalse)
4264 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4265 break;
4266 }
4267 if (LocaleCompare("depth",option+1) == 0)
4268 {
4269 if (*option == '+')
4270 break;
4271 i++;
cristybb503372010-05-27 20:51:26 +00004272 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004273 ThrowMogrifyException(OptionError,"MissingArgument",option);
4274 if (IsGeometry(argv[i]) == MagickFalse)
4275 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4276 break;
4277 }
4278 if (LocaleCompare("deskew",option+1) == 0)
4279 {
4280 if (*option == '+')
4281 break;
4282 i++;
cristybb503372010-05-27 20:51:26 +00004283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004284 ThrowMogrifyException(OptionError,"MissingArgument",option);
4285 if (IsGeometry(argv[i]) == MagickFalse)
4286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4287 break;
4288 }
4289 if (LocaleCompare("despeckle",option+1) == 0)
4290 break;
4291 if (LocaleCompare("dft",option+1) == 0)
4292 break;
cristyc9b12952010-03-28 01:12:28 +00004293 if (LocaleCompare("direction",option+1) == 0)
4294 {
cristybb503372010-05-27 20:51:26 +00004295 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004296 direction;
4297
4298 if (*option == '+')
4299 break;
4300 i++;
cristybb503372010-05-27 20:51:26 +00004301 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004302 ThrowMogrifyException(OptionError,"MissingArgument",option);
4303 direction=ParseMagickOption(MagickDirectionOptions,MagickFalse,
4304 argv[i]);
4305 if (direction < 0)
4306 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4307 argv[i]);
4308 break;
4309 }
cristy3ed852e2009-09-05 21:47:34 +00004310 if (LocaleCompare("display",option+1) == 0)
4311 {
4312 if (*option == '+')
4313 break;
4314 i++;
cristybb503372010-05-27 20:51:26 +00004315 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004316 ThrowMogrifyException(OptionError,"MissingArgument",option);
4317 break;
4318 }
4319 if (LocaleCompare("dispose",option+1) == 0)
4320 {
cristybb503372010-05-27 20:51:26 +00004321 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004322 dispose;
4323
4324 if (*option == '+')
4325 break;
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
4329 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4330 if (dispose < 0)
4331 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4332 argv[i]);
4333 break;
4334 }
4335 if (LocaleCompare("distort",option+1) == 0)
4336 {
cristybb503372010-05-27 20:51:26 +00004337 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004338 op;
4339
4340 i++;
cristybb503372010-05-27 20:51:26 +00004341 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004342 ThrowMogrifyException(OptionError,"MissingArgument",option);
4343 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4344 if (op < 0)
4345 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4346 argv[i]);
4347 i++;
cristybb503372010-05-27 20:51:26 +00004348 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004349 ThrowMogrifyException(OptionError,"MissingArgument",option);
4350 break;
4351 }
4352 if (LocaleCompare("dither",option+1) == 0)
4353 {
cristybb503372010-05-27 20:51:26 +00004354 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004355 method;
4356
4357 if (*option == '+')
4358 break;
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
4362 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4363 if (method < 0)
4364 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4365 argv[i]);
4366 break;
4367 }
4368 if (LocaleCompare("draw",option+1) == 0)
4369 {
4370 if (*option == '+')
4371 break;
4372 i++;
cristybb503372010-05-27 20:51:26 +00004373 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004374 ThrowMogrifyException(OptionError,"MissingArgument",option);
4375 break;
4376 }
cristyecb10ff2011-03-22 13:14:03 +00004377 if (LocaleCompare("duplicate",option+1) == 0)
4378 {
4379 if (*option == '+')
4380 break;
4381 i++;
4382 if (i == (ssize_t) (argc-1))
4383 ThrowMogrifyException(OptionError,"MissingArgument",option);
4384 if (IsGeometry(argv[i]) == MagickFalse)
4385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4386 break;
4387 }
cristy22879752009-10-25 23:55:40 +00004388 if (LocaleCompare("duration",option+1) == 0)
4389 {
4390 if (*option == '+')
4391 break;
4392 i++;
cristybb503372010-05-27 20:51:26 +00004393 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004394 ThrowMogrifyException(OptionError,"MissingArgument",option);
4395 if (IsGeometry(argv[i]) == MagickFalse)
4396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4397 break;
4398 }
cristy3ed852e2009-09-05 21:47:34 +00004399 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4400 }
4401 case 'e':
4402 {
4403 if (LocaleCompare("edge",option+1) == 0)
4404 {
4405 if (*option == '+')
4406 break;
4407 i++;
cristybb503372010-05-27 20:51:26 +00004408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004409 ThrowMogrifyException(OptionError,"MissingArgument",option);
4410 if (IsGeometry(argv[i]) == MagickFalse)
4411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4412 break;
4413 }
4414 if (LocaleCompare("emboss",option+1) == 0)
4415 {
4416 if (*option == '+')
4417 break;
4418 i++;
cristybb503372010-05-27 20:51:26 +00004419 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004420 ThrowMogrifyException(OptionError,"MissingArgument",option);
4421 if (IsGeometry(argv[i]) == MagickFalse)
4422 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4423 break;
4424 }
4425 if (LocaleCompare("encipher",option+1) == 0)
4426 {
4427 if (*option == '+')
4428 break;
4429 i++;
cristybb503372010-05-27 20:51:26 +00004430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004431 ThrowMogrifyException(OptionError,"MissingArgument",option);
4432 break;
4433 }
4434 if (LocaleCompare("encoding",option+1) == 0)
4435 {
4436 if (*option == '+')
4437 break;
4438 i++;
cristybb503372010-05-27 20:51:26 +00004439 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004440 ThrowMogrifyException(OptionError,"MissingArgument",option);
4441 break;
4442 }
4443 if (LocaleCompare("endian",option+1) == 0)
4444 {
cristybb503372010-05-27 20:51:26 +00004445 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004446 endian;
4447
4448 if (*option == '+')
4449 break;
4450 i++;
cristybb503372010-05-27 20:51:26 +00004451 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004452 ThrowMogrifyException(OptionError,"MissingArgument",option);
4453 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4454 if (endian < 0)
4455 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4456 argv[i]);
4457 break;
4458 }
4459 if (LocaleCompare("enhance",option+1) == 0)
4460 break;
4461 if (LocaleCompare("equalize",option+1) == 0)
4462 break;
4463 if (LocaleCompare("evaluate",option+1) == 0)
4464 {
cristybb503372010-05-27 20:51:26 +00004465 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004466 op;
4467
4468 if (*option == '+')
4469 break;
4470 i++;
cristybb503372010-05-27 20:51:26 +00004471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004472 ThrowMogrifyException(OptionError,"MissingArgument",option);
4473 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4474 if (op < 0)
4475 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4476 argv[i]);
4477 i++;
cristybb503372010-05-27 20:51:26 +00004478 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004479 ThrowMogrifyException(OptionError,"MissingArgument",option);
4480 if (IsGeometry(argv[i]) == MagickFalse)
4481 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4482 break;
4483 }
cristyd18ae7c2010-03-07 17:39:52 +00004484 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4485 {
cristybb503372010-05-27 20:51:26 +00004486 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004487 op;
4488
4489 if (*option == '+')
4490 break;
4491 i++;
cristybb503372010-05-27 20:51:26 +00004492 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004493 ThrowMogrifyException(OptionError,"MissingArgument",option);
4494 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4495 if (op < 0)
4496 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4497 argv[i]);
4498 break;
4499 }
cristy3ed852e2009-09-05 21:47:34 +00004500 if (LocaleCompare("extent",option+1) == 0)
4501 {
4502 if (*option == '+')
4503 break;
4504 i++;
cristybb503372010-05-27 20:51:26 +00004505 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004506 ThrowMogrifyException(OptionError,"MissingArgument",option);
4507 if (IsGeometry(argv[i]) == MagickFalse)
4508 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4509 break;
4510 }
4511 if (LocaleCompare("extract",option+1) == 0)
4512 {
4513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
4518 if (IsGeometry(argv[i]) == MagickFalse)
4519 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4520 break;
4521 }
4522 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4523 }
4524 case 'f':
4525 {
4526 if (LocaleCompare("family",option+1) == 0)
4527 {
4528 if (*option == '+')
4529 break;
4530 i++;
cristybb503372010-05-27 20:51:26 +00004531 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004532 ThrowMogrifyException(OptionError,"MissingArgument",option);
4533 break;
4534 }
4535 if (LocaleCompare("fill",option+1) == 0)
4536 {
4537 if (*option == '+')
4538 break;
4539 i++;
cristybb503372010-05-27 20:51:26 +00004540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004541 ThrowMogrifyException(OptionError,"MissingArgument",option);
4542 break;
4543 }
4544 if (LocaleCompare("filter",option+1) == 0)
4545 {
cristybb503372010-05-27 20:51:26 +00004546 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004547 filter;
4548
4549 if (*option == '+')
4550 break;
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4555 if (filter < 0)
4556 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4557 argv[i]);
4558 break;
4559 }
4560 if (LocaleCompare("flatten",option+1) == 0)
4561 break;
4562 if (LocaleCompare("flip",option+1) == 0)
4563 break;
4564 if (LocaleCompare("flop",option+1) == 0)
4565 break;
4566 if (LocaleCompare("floodfill",option+1) == 0)
4567 {
4568 if (*option == '+')
4569 break;
4570 i++;
cristybb503372010-05-27 20:51:26 +00004571 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004572 ThrowMogrifyException(OptionError,"MissingArgument",option);
4573 if (IsGeometry(argv[i]) == MagickFalse)
4574 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4575 i++;
cristybb503372010-05-27 20:51:26 +00004576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004577 ThrowMogrifyException(OptionError,"MissingArgument",option);
4578 break;
4579 }
4580 if (LocaleCompare("font",option+1) == 0)
4581 {
4582 if (*option == '+')
4583 break;
4584 i++;
cristybb503372010-05-27 20:51:26 +00004585 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004586 ThrowMogrifyException(OptionError,"MissingArgument",option);
4587 break;
4588 }
4589 if (LocaleCompare("format",option+1) == 0)
4590 {
4591 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4592 (void) CloneString(&format,(char *) NULL);
4593 if (*option == '+')
4594 break;
4595 i++;
cristybb503372010-05-27 20:51:26 +00004596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004597 ThrowMogrifyException(OptionError,"MissingArgument",option);
4598 (void) CloneString(&format,argv[i]);
4599 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4600 (void) ConcatenateMagickString(image_info->filename,":",
4601 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004602 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004603 if (*image_info->magick == '\0')
4604 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4605 format);
4606 break;
4607 }
4608 if (LocaleCompare("frame",option+1) == 0)
4609 {
4610 if (*option == '+')
4611 break;
4612 i++;
cristybb503372010-05-27 20:51:26 +00004613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004614 ThrowMogrifyException(OptionError,"MissingArgument",option);
4615 if (IsGeometry(argv[i]) == MagickFalse)
4616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4617 break;
4618 }
4619 if (LocaleCompare("function",option+1) == 0)
4620 {
cristybb503372010-05-27 20:51:26 +00004621 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004622 op;
4623
4624 if (*option == '+')
4625 break;
4626 i++;
cristybb503372010-05-27 20:51:26 +00004627 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004628 ThrowMogrifyException(OptionError,"MissingArgument",option);
4629 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4630 if (op < 0)
4631 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4632 i++;
cristybb503372010-05-27 20:51:26 +00004633 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004634 ThrowMogrifyException(OptionError,"MissingArgument",option);
4635 break;
4636 }
4637 if (LocaleCompare("fuzz",option+1) == 0)
4638 {
4639 if (*option == '+')
4640 break;
4641 i++;
cristybb503372010-05-27 20:51:26 +00004642 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004643 ThrowMogrifyException(OptionError,"MissingArgument",option);
4644 if (IsGeometry(argv[i]) == MagickFalse)
4645 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4646 break;
4647 }
4648 if (LocaleCompare("fx",option+1) == 0)
4649 {
4650 if (*option == '+')
4651 break;
4652 i++;
cristybb503372010-05-27 20:51:26 +00004653 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004654 ThrowMogrifyException(OptionError,"MissingArgument",option);
4655 break;
4656 }
4657 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4658 }
4659 case 'g':
4660 {
4661 if (LocaleCompare("gamma",option+1) == 0)
4662 {
4663 i++;
cristybb503372010-05-27 20:51:26 +00004664 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004665 ThrowMogrifyException(OptionError,"MissingArgument",option);
4666 if (IsGeometry(argv[i]) == MagickFalse)
4667 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4668 break;
4669 }
4670 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4671 (LocaleCompare("gaussian",option+1) == 0))
4672 {
4673 i++;
cristybb503372010-05-27 20:51:26 +00004674 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004675 ThrowMogrifyException(OptionError,"MissingArgument",option);
4676 if (IsGeometry(argv[i]) == MagickFalse)
4677 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4678 break;
4679 }
4680 if (LocaleCompare("geometry",option+1) == 0)
4681 {
4682 if (*option == '+')
4683 break;
4684 i++;
cristybb503372010-05-27 20:51:26 +00004685 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004686 ThrowMogrifyException(OptionError,"MissingArgument",option);
4687 if (IsGeometry(argv[i]) == MagickFalse)
4688 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4689 break;
4690 }
4691 if (LocaleCompare("gravity",option+1) == 0)
4692 {
cristybb503372010-05-27 20:51:26 +00004693 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004694 gravity;
4695
4696 if (*option == '+')
4697 break;
4698 i++;
cristybb503372010-05-27 20:51:26 +00004699 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004700 ThrowMogrifyException(OptionError,"MissingArgument",option);
4701 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
4702 if (gravity < 0)
4703 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4704 argv[i]);
4705 break;
4706 }
4707 if (LocaleCompare("green-primary",option+1) == 0)
4708 {
4709 if (*option == '+')
4710 break;
4711 i++;
cristybb503372010-05-27 20:51:26 +00004712 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004713 ThrowMogrifyException(OptionError,"MissingArgument",option);
4714 if (IsGeometry(argv[i]) == MagickFalse)
4715 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4716 break;
4717 }
4718 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4719 }
4720 case 'h':
4721 {
4722 if (LocaleCompare("hald-clut",option+1) == 0)
4723 break;
4724 if ((LocaleCompare("help",option+1) == 0) ||
4725 (LocaleCompare("-help",option+1) == 0))
4726 return(MogrifyUsage());
4727 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4728 }
4729 case 'i':
4730 {
4731 if (LocaleCompare("identify",option+1) == 0)
4732 break;
4733 if (LocaleCompare("idft",option+1) == 0)
4734 break;
4735 if (LocaleCompare("implode",option+1) == 0)
4736 {
4737 if (*option == '+')
4738 break;
4739 i++;
cristybb503372010-05-27 20:51:26 +00004740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004741 ThrowMogrifyException(OptionError,"MissingArgument",option);
4742 if (IsGeometry(argv[i]) == MagickFalse)
4743 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4744 break;
4745 }
4746 if (LocaleCompare("intent",option+1) == 0)
4747 {
cristybb503372010-05-27 20:51:26 +00004748 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004749 intent;
4750
4751 if (*option == '+')
4752 break;
4753 i++;
cristybb503372010-05-27 20:51:26 +00004754 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004755 ThrowMogrifyException(OptionError,"MissingArgument",option);
4756 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
4757 if (intent < 0)
4758 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4759 argv[i]);
4760 break;
4761 }
4762 if (LocaleCompare("interlace",option+1) == 0)
4763 {
cristybb503372010-05-27 20:51:26 +00004764 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004765 interlace;
4766
4767 if (*option == '+')
4768 break;
4769 i++;
cristybb503372010-05-27 20:51:26 +00004770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004771 ThrowMogrifyException(OptionError,"MissingArgument",option);
4772 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
4773 argv[i]);
4774 if (interlace < 0)
4775 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4776 argv[i]);
4777 break;
4778 }
cristyb32b90a2009-09-07 21:45:48 +00004779 if (LocaleCompare("interline-spacing",option+1) == 0)
4780 {
4781 if (*option == '+')
4782 break;
4783 i++;
cristybb503372010-05-27 20:51:26 +00004784 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004785 ThrowMogrifyException(OptionError,"MissingArgument",option);
4786 if (IsGeometry(argv[i]) == MagickFalse)
4787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4788 break;
4789 }
cristy3ed852e2009-09-05 21:47:34 +00004790 if (LocaleCompare("interpolate",option+1) == 0)
4791 {
cristybb503372010-05-27 20:51:26 +00004792 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004793 interpolate;
4794
4795 if (*option == '+')
4796 break;
4797 i++;
cristybb503372010-05-27 20:51:26 +00004798 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004799 ThrowMogrifyException(OptionError,"MissingArgument",option);
4800 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
4801 argv[i]);
4802 if (interpolate < 0)
4803 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4804 argv[i]);
4805 break;
4806 }
4807 if (LocaleCompare("interword-spacing",option+1) == 0)
4808 {
4809 if (*option == '+')
4810 break;
4811 i++;
cristybb503372010-05-27 20:51:26 +00004812 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004813 ThrowMogrifyException(OptionError,"MissingArgument",option);
4814 if (IsGeometry(argv[i]) == MagickFalse)
4815 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4816 break;
4817 }
4818 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4819 }
4820 case 'k':
4821 {
4822 if (LocaleCompare("kerning",option+1) == 0)
4823 {
4824 if (*option == '+')
4825 break;
4826 i++;
cristybb503372010-05-27 20:51:26 +00004827 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004828 ThrowMogrifyException(OptionError,"MissingArgument",option);
4829 if (IsGeometry(argv[i]) == MagickFalse)
4830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4831 break;
4832 }
4833 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4834 }
4835 case 'l':
4836 {
4837 if (LocaleCompare("label",option+1) == 0)
4838 {
4839 if (*option == '+')
4840 break;
4841 i++;
cristybb503372010-05-27 20:51:26 +00004842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004843 ThrowMogrifyException(OptionError,"MissingArgument",option);
4844 break;
4845 }
4846 if (LocaleCompare("lat",option+1) == 0)
4847 {
4848 if (*option == '+')
4849 break;
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 if (IsGeometry(argv[i]) == MagickFalse)
4854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4855 }
4856 if (LocaleCompare("layers",option+1) == 0)
4857 {
cristybb503372010-05-27 20:51:26 +00004858 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004859 type;
4860
4861 if (*option == '+')
4862 break;
4863 i++;
cristybb503372010-05-27 20:51:26 +00004864 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004865 ThrowMogrifyException(OptionError,"MissingArgument",option);
4866 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
4867 if (type < 0)
4868 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4869 argv[i]);
4870 break;
4871 }
4872 if (LocaleCompare("level",option+1) == 0)
4873 {
4874 i++;
cristybb503372010-05-27 20:51:26 +00004875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004876 ThrowMogrifyException(OptionError,"MissingArgument",option);
4877 if (IsGeometry(argv[i]) == MagickFalse)
4878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4879 break;
4880 }
4881 if (LocaleCompare("level-colors",option+1) == 0)
4882 {
4883 i++;
cristybb503372010-05-27 20:51:26 +00004884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004885 ThrowMogrifyException(OptionError,"MissingArgument",option);
4886 break;
4887 }
4888 if (LocaleCompare("linewidth",option+1) == 0)
4889 {
4890 if (*option == '+')
4891 break;
4892 i++;
cristybb503372010-05-27 20:51:26 +00004893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004894 ThrowMogrifyException(OptionError,"MissingArgument",option);
4895 if (IsGeometry(argv[i]) == MagickFalse)
4896 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4897 break;
4898 }
4899 if (LocaleCompare("limit",option+1) == 0)
4900 {
4901 char
4902 *p;
4903
4904 double
4905 value;
4906
cristybb503372010-05-27 20:51:26 +00004907 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004908 resource;
4909
4910 if (*option == '+')
4911 break;
4912 i++;
cristybb503372010-05-27 20:51:26 +00004913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004914 ThrowMogrifyException(OptionError,"MissingArgument",option);
4915 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
4916 argv[i]);
4917 if (resource < 0)
4918 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4919 argv[i]);
4920 i++;
cristybb503372010-05-27 20:51:26 +00004921 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004922 ThrowMogrifyException(OptionError,"MissingArgument",option);
4923 value=strtod(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004924 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004925 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4926 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4927 break;
4928 }
4929 if (LocaleCompare("liquid-rescale",option+1) == 0)
4930 {
4931 i++;
cristybb503372010-05-27 20:51:26 +00004932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004933 ThrowMogrifyException(OptionError,"MissingArgument",option);
4934 if (IsGeometry(argv[i]) == MagickFalse)
4935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4936 break;
4937 }
4938 if (LocaleCompare("list",option+1) == 0)
4939 {
cristybb503372010-05-27 20:51:26 +00004940 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004941 list;
4942
4943 if (*option == '+')
4944 break;
4945 i++;
cristybb503372010-05-27 20:51:26 +00004946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004947 ThrowMogrifyException(OptionError,"MissingArgument",option);
4948 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
4949 if (list < 0)
4950 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004951 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004952 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004953 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004954 }
4955 if (LocaleCompare("log",option+1) == 0)
4956 {
4957 if (*option == '+')
4958 break;
4959 i++;
cristybb503372010-05-27 20:51:26 +00004960 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004961 (strchr(argv[i],'%') == (char *) NULL))
4962 ThrowMogrifyException(OptionError,"MissingArgument",option);
4963 break;
4964 }
4965 if (LocaleCompare("loop",option+1) == 0)
4966 {
4967 if (*option == '+')
4968 break;
4969 i++;
cristybb503372010-05-27 20:51:26 +00004970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004971 ThrowMogrifyException(OptionError,"MissingArgument",option);
4972 if (IsGeometry(argv[i]) == MagickFalse)
4973 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4974 break;
4975 }
4976 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4977 }
4978 case 'm':
4979 {
4980 if (LocaleCompare("map",option+1) == 0)
4981 {
4982 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4983 if (*option == '+')
4984 break;
4985 i++;
cristybb503372010-05-27 20:51:26 +00004986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004987 ThrowMogrifyException(OptionError,"MissingArgument",option);
4988 break;
4989 }
4990 if (LocaleCompare("mask",option+1) == 0)
4991 {
4992 if (*option == '+')
4993 break;
4994 i++;
cristybb503372010-05-27 20:51:26 +00004995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004996 ThrowMogrifyException(OptionError,"MissingArgument",option);
4997 break;
4998 }
4999 if (LocaleCompare("matte",option+1) == 0)
5000 break;
5001 if (LocaleCompare("mattecolor",option+1) == 0)
5002 {
5003 if (*option == '+')
5004 break;
5005 i++;
cristybb503372010-05-27 20:51:26 +00005006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005007 ThrowMogrifyException(OptionError,"MissingArgument",option);
5008 break;
5009 }
cristyf40785b2010-03-06 02:27:27 +00005010 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005011 break;
cristyf40785b2010-03-06 02:27:27 +00005012 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005013 break;
cristy3ed852e2009-09-05 21:47:34 +00005014 if (LocaleCompare("modulate",option+1) == 0)
5015 {
5016 if (*option == '+')
5017 break;
5018 i++;
cristybb503372010-05-27 20:51:26 +00005019 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005020 ThrowMogrifyException(OptionError,"MissingArgument",option);
5021 if (IsGeometry(argv[i]) == MagickFalse)
5022 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5023 break;
5024 }
5025 if (LocaleCompare("median",option+1) == 0)
5026 {
5027 if (*option == '+')
5028 break;
5029 i++;
cristybb503372010-05-27 20:51:26 +00005030 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005031 ThrowMogrifyException(OptionError,"MissingArgument",option);
5032 if (IsGeometry(argv[i]) == MagickFalse)
5033 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5034 break;
5035 }
cristy69ec32d2011-02-27 23:57:09 +00005036 if (LocaleCompare("mode",option+1) == 0)
5037 {
5038 if (*option == '+')
5039 break;
5040 i++;
5041 if (i == (ssize_t) argc)
5042 ThrowMogrifyException(OptionError,"MissingArgument",option);
5043 if (IsGeometry(argv[i]) == MagickFalse)
5044 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5045 break;
5046 }
cristy3ed852e2009-09-05 21:47:34 +00005047 if (LocaleCompare("monitor",option+1) == 0)
5048 break;
5049 if (LocaleCompare("monochrome",option+1) == 0)
5050 break;
5051 if (LocaleCompare("morph",option+1) == 0)
5052 {
5053 if (*option == '+')
5054 break;
5055 i++;
cristybb503372010-05-27 20:51:26 +00005056 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005057 ThrowMogrifyException(OptionError,"MissingArgument",option);
5058 if (IsGeometry(argv[i]) == MagickFalse)
5059 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5060 break;
5061 }
anthony29188a82010-01-22 10:12:34 +00005062 if (LocaleCompare("morphology",option+1) == 0)
5063 {
anthony29188a82010-01-22 10:12:34 +00005064 char
5065 token[MaxTextExtent];
5066
cristyb6bd4ad2010-08-08 01:12:27 +00005067 KernelInfo
5068 *kernel_info;
5069
5070 ssize_t
5071 op;
5072
anthony29188a82010-01-22 10:12:34 +00005073 i++;
cristybb503372010-05-27 20:51:26 +00005074 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005075 ThrowMogrifyException(OptionError,"MissingArgument",option);
5076 GetMagickToken(argv[i],NULL,token);
5077 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5078 if (op < 0)
5079 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005080 token);
anthony29188a82010-01-22 10:12:34 +00005081 i++;
cristybb503372010-05-27 20:51:26 +00005082 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005083 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005084 kernel_info=AcquireKernelInfo(argv[i]);
5085 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005086 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005087 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005088 break;
5089 }
cristy3ed852e2009-09-05 21:47:34 +00005090 if (LocaleCompare("mosaic",option+1) == 0)
5091 break;
5092 if (LocaleCompare("motion-blur",option+1) == 0)
5093 {
5094 if (*option == '+')
5095 break;
5096 i++;
cristybb503372010-05-27 20:51:26 +00005097 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005098 ThrowMogrifyException(OptionError,"MissingArgument",option);
5099 if (IsGeometry(argv[i]) == MagickFalse)
5100 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5101 break;
5102 }
5103 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5104 }
5105 case 'n':
5106 {
5107 if (LocaleCompare("negate",option+1) == 0)
5108 break;
5109 if (LocaleCompare("noise",option+1) == 0)
5110 {
5111 i++;
cristybb503372010-05-27 20:51:26 +00005112 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005113 ThrowMogrifyException(OptionError,"MissingArgument",option);
5114 if (*option == '+')
5115 {
cristybb503372010-05-27 20:51:26 +00005116 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005117 noise;
5118
5119 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5120 if (noise < 0)
5121 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5122 argv[i]);
5123 break;
5124 }
5125 if (IsGeometry(argv[i]) == MagickFalse)
5126 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5127 break;
5128 }
5129 if (LocaleCompare("noop",option+1) == 0)
5130 break;
5131 if (LocaleCompare("normalize",option+1) == 0)
5132 break;
5133 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5134 }
5135 case 'o':
5136 {
5137 if (LocaleCompare("opaque",option+1) == 0)
5138 {
cristy3ed852e2009-09-05 21:47:34 +00005139 i++;
cristybb503372010-05-27 20:51:26 +00005140 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005141 ThrowMogrifyException(OptionError,"MissingArgument",option);
5142 break;
5143 }
5144 if (LocaleCompare("ordered-dither",option+1) == 0)
5145 {
5146 if (*option == '+')
5147 break;
5148 i++;
cristybb503372010-05-27 20:51:26 +00005149 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005150 ThrowMogrifyException(OptionError,"MissingArgument",option);
5151 break;
5152 }
5153 if (LocaleCompare("orient",option+1) == 0)
5154 {
cristybb503372010-05-27 20:51:26 +00005155 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005156 orientation;
5157
5158 orientation=UndefinedOrientation;
5159 if (*option == '+')
5160 break;
5161 i++;
cristybb503372010-05-27 20:51:26 +00005162 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005163 ThrowMogrifyException(OptionError,"MissingArgument",option);
5164 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5165 argv[i]);
5166 if (orientation < 0)
5167 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5168 argv[i]);
5169 break;
5170 }
5171 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5172 }
5173 case 'p':
5174 {
5175 if (LocaleCompare("page",option+1) == 0)
5176 {
5177 if (*option == '+')
5178 break;
5179 i++;
cristybb503372010-05-27 20:51:26 +00005180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005181 ThrowMogrifyException(OptionError,"MissingArgument",option);
5182 break;
5183 }
5184 if (LocaleCompare("paint",option+1) == 0)
5185 {
5186 if (*option == '+')
5187 break;
5188 i++;
cristybb503372010-05-27 20:51:26 +00005189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005190 ThrowMogrifyException(OptionError,"MissingArgument",option);
5191 if (IsGeometry(argv[i]) == MagickFalse)
5192 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5193 break;
5194 }
5195 if (LocaleCompare("path",option+1) == 0)
5196 {
5197 (void) CloneString(&path,(char *) NULL);
5198 if (*option == '+')
5199 break;
5200 i++;
cristybb503372010-05-27 20:51:26 +00005201 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005202 ThrowMogrifyException(OptionError,"MissingArgument",option);
5203 (void) CloneString(&path,argv[i]);
5204 break;
5205 }
5206 if (LocaleCompare("pointsize",option+1) == 0)
5207 {
5208 if (*option == '+')
5209 break;
5210 i++;
cristybb503372010-05-27 20:51:26 +00005211 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005212 ThrowMogrifyException(OptionError,"MissingArgument",option);
5213 if (IsGeometry(argv[i]) == MagickFalse)
5214 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5215 break;
5216 }
5217 if (LocaleCompare("polaroid",option+1) == 0)
5218 {
5219 if (*option == '+')
5220 break;
5221 i++;
cristybb503372010-05-27 20:51:26 +00005222 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005223 ThrowMogrifyException(OptionError,"MissingArgument",option);
5224 if (IsGeometry(argv[i]) == MagickFalse)
5225 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5226 break;
5227 }
5228 if (LocaleCompare("posterize",option+1) == 0)
5229 {
5230 if (*option == '+')
5231 break;
5232 i++;
cristybb503372010-05-27 20:51:26 +00005233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005234 ThrowMogrifyException(OptionError,"MissingArgument",option);
5235 if (IsGeometry(argv[i]) == MagickFalse)
5236 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5237 break;
5238 }
cristye7f51092010-01-17 00:39:37 +00005239 if (LocaleCompare("precision",option+1) == 0)
5240 {
5241 if (*option == '+')
5242 break;
5243 i++;
cristybb503372010-05-27 20:51:26 +00005244 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005245 ThrowMogrifyException(OptionError,"MissingArgument",option);
5246 if (IsGeometry(argv[i]) == MagickFalse)
5247 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5248 break;
5249 }
cristy3ed852e2009-09-05 21:47:34 +00005250 if (LocaleCompare("print",option+1) == 0)
5251 {
5252 if (*option == '+')
5253 break;
5254 i++;
cristybb503372010-05-27 20:51:26 +00005255 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005256 ThrowMogrifyException(OptionError,"MissingArgument",option);
5257 break;
5258 }
5259 if (LocaleCompare("process",option+1) == 0)
5260 {
5261 if (*option == '+')
5262 break;
5263 i++;
cristybb503372010-05-27 20:51:26 +00005264 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005265 ThrowMogrifyException(OptionError,"MissingArgument",option);
5266 break;
5267 }
5268 if (LocaleCompare("profile",option+1) == 0)
5269 {
5270 i++;
cristybb503372010-05-27 20:51:26 +00005271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005272 ThrowMogrifyException(OptionError,"MissingArgument",option);
5273 break;
5274 }
5275 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5276 }
5277 case 'q':
5278 {
5279 if (LocaleCompare("quality",option+1) == 0)
5280 {
5281 if (*option == '+')
5282 break;
5283 i++;
cristybb503372010-05-27 20:51:26 +00005284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005285 ThrowMogrifyException(OptionError,"MissingArgument",option);
5286 if (IsGeometry(argv[i]) == MagickFalse)
5287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5288 break;
5289 }
5290 if (LocaleCompare("quantize",option+1) == 0)
5291 {
cristybb503372010-05-27 20:51:26 +00005292 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005293 colorspace;
5294
5295 if (*option == '+')
5296 break;
5297 i++;
cristybb503372010-05-27 20:51:26 +00005298 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005299 ThrowMogrifyException(OptionError,"MissingArgument",option);
5300 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5301 argv[i]);
5302 if (colorspace < 0)
5303 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5304 argv[i]);
5305 break;
5306 }
5307 if (LocaleCompare("quiet",option+1) == 0)
5308 break;
5309 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5310 }
5311 case 'r':
5312 {
5313 if (LocaleCompare("radial-blur",option+1) == 0)
5314 {
5315 i++;
cristybb503372010-05-27 20:51:26 +00005316 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005317 ThrowMogrifyException(OptionError,"MissingArgument",option);
5318 if (IsGeometry(argv[i]) == MagickFalse)
5319 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5320 break;
5321 }
5322 if (LocaleCompare("raise",option+1) == 0)
5323 {
5324 i++;
cristybb503372010-05-27 20:51:26 +00005325 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005326 ThrowMogrifyException(OptionError,"MissingArgument",option);
5327 if (IsGeometry(argv[i]) == MagickFalse)
5328 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5329 break;
5330 }
5331 if (LocaleCompare("random-threshold",option+1) == 0)
5332 {
5333 if (*option == '+')
5334 break;
5335 i++;
cristybb503372010-05-27 20:51:26 +00005336 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005337 ThrowMogrifyException(OptionError,"MissingArgument",option);
5338 if (IsGeometry(argv[i]) == MagickFalse)
5339 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5340 break;
5341 }
cristye6365592010-04-02 17:31:23 +00005342 if (LocaleCompare("recolor",option+1) == 0)
5343 {
5344 if (*option == '+')
5345 break;
5346 i++;
cristybb503372010-05-27 20:51:26 +00005347 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005348 ThrowMogrifyException(OptionError,"MissingArgument",option);
5349 if (IsGeometry(argv[i]) == MagickFalse)
5350 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5351 break;
5352 }
cristy3ed852e2009-09-05 21:47:34 +00005353 if (LocaleCompare("red-primary",option+1) == 0)
5354 {
5355 if (*option == '+')
5356 break;
5357 i++;
cristybb503372010-05-27 20:51:26 +00005358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005359 ThrowMogrifyException(OptionError,"MissingArgument",option);
5360 if (IsGeometry(argv[i]) == MagickFalse)
5361 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5362 }
cristy9f2083a2010-04-22 19:48:05 +00005363 if (LocaleCompare("regard-warnings",option+1) == 0)
5364 break;
cristy3ed852e2009-09-05 21:47:34 +00005365 if (LocaleCompare("region",option+1) == 0)
5366 {
5367 if (*option == '+')
5368 break;
5369 i++;
cristybb503372010-05-27 20:51:26 +00005370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005371 ThrowMogrifyException(OptionError,"MissingArgument",option);
5372 if (IsGeometry(argv[i]) == MagickFalse)
5373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5374 break;
5375 }
cristyf0c78232010-03-15 12:53:40 +00005376 if (LocaleCompare("remap",option+1) == 0)
5377 {
5378 if (*option == '+')
5379 break;
5380 i++;
cristybb503372010-05-27 20:51:26 +00005381 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005382 ThrowMogrifyException(OptionError,"MissingArgument",option);
5383 break;
5384 }
cristy3ed852e2009-09-05 21:47:34 +00005385 if (LocaleCompare("render",option+1) == 0)
5386 break;
5387 if (LocaleCompare("repage",option+1) == 0)
5388 {
5389 if (*option == '+')
5390 break;
5391 i++;
cristybb503372010-05-27 20:51:26 +00005392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005393 ThrowMogrifyException(OptionError,"MissingArgument",option);
5394 if (IsGeometry(argv[i]) == MagickFalse)
5395 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5396 break;
5397 }
5398 if (LocaleCompare("resample",option+1) == 0)
5399 {
5400 if (*option == '+')
5401 break;
5402 i++;
cristybb503372010-05-27 20:51:26 +00005403 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005404 ThrowMogrifyException(OptionError,"MissingArgument",option);
5405 if (IsGeometry(argv[i]) == MagickFalse)
5406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5407 break;
5408 }
5409 if (LocaleCompare("resize",option+1) == 0)
5410 {
5411 if (*option == '+')
5412 break;
5413 i++;
cristybb503372010-05-27 20:51:26 +00005414 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005415 ThrowMogrifyException(OptionError,"MissingArgument",option);
5416 if (IsGeometry(argv[i]) == MagickFalse)
5417 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5418 break;
5419 }
cristyebbcfea2011-02-25 02:43:54 +00005420 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5421 {
5422 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5423 break;
5424 }
cristy3ed852e2009-09-05 21:47:34 +00005425 if (LocaleCompare("reverse",option+1) == 0)
5426 break;
5427 if (LocaleCompare("roll",option+1) == 0)
5428 {
5429 if (*option == '+')
5430 break;
5431 i++;
cristybb503372010-05-27 20:51:26 +00005432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005433 ThrowMogrifyException(OptionError,"MissingArgument",option);
5434 if (IsGeometry(argv[i]) == MagickFalse)
5435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5436 break;
5437 }
5438 if (LocaleCompare("rotate",option+1) == 0)
5439 {
5440 i++;
cristybb503372010-05-27 20:51:26 +00005441 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005442 ThrowMogrifyException(OptionError,"MissingArgument",option);
5443 if (IsGeometry(argv[i]) == MagickFalse)
5444 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5445 break;
5446 }
5447 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5448 }
5449 case 's':
5450 {
5451 if (LocaleCompare("sample",option+1) == 0)
5452 {
5453 if (*option == '+')
5454 break;
5455 i++;
cristybb503372010-05-27 20:51:26 +00005456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005457 ThrowMogrifyException(OptionError,"MissingArgument",option);
5458 if (IsGeometry(argv[i]) == MagickFalse)
5459 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5460 break;
5461 }
5462 if (LocaleCompare("sampling-factor",option+1) == 0)
5463 {
5464 if (*option == '+')
5465 break;
5466 i++;
cristybb503372010-05-27 20:51:26 +00005467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005468 ThrowMogrifyException(OptionError,"MissingArgument",option);
5469 if (IsGeometry(argv[i]) == MagickFalse)
5470 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5471 break;
5472 }
5473 if (LocaleCompare("scale",option+1) == 0)
5474 {
5475 if (*option == '+')
5476 break;
5477 i++;
cristybb503372010-05-27 20:51:26 +00005478 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005479 ThrowMogrifyException(OptionError,"MissingArgument",option);
5480 if (IsGeometry(argv[i]) == MagickFalse)
5481 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5482 break;
5483 }
5484 if (LocaleCompare("scene",option+1) == 0)
5485 {
5486 if (*option == '+')
5487 break;
5488 i++;
cristybb503372010-05-27 20:51:26 +00005489 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005490 ThrowMogrifyException(OptionError,"MissingArgument",option);
5491 if (IsGeometry(argv[i]) == MagickFalse)
5492 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5493 break;
5494 }
5495 if (LocaleCompare("seed",option+1) == 0)
5496 {
5497 if (*option == '+')
5498 break;
5499 i++;
cristybb503372010-05-27 20:51:26 +00005500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005501 ThrowMogrifyException(OptionError,"MissingArgument",option);
5502 if (IsGeometry(argv[i]) == MagickFalse)
5503 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5504 break;
5505 }
5506 if (LocaleCompare("segment",option+1) == 0)
5507 {
5508 if (*option == '+')
5509 break;
5510 i++;
cristybb503372010-05-27 20:51:26 +00005511 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005512 ThrowMogrifyException(OptionError,"MissingArgument",option);
5513 if (IsGeometry(argv[i]) == MagickFalse)
5514 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5515 break;
5516 }
5517 if (LocaleCompare("selective-blur",option+1) == 0)
5518 {
5519 i++;
cristybb503372010-05-27 20:51:26 +00005520 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005521 ThrowMogrifyException(OptionError,"MissingArgument",option);
5522 if (IsGeometry(argv[i]) == MagickFalse)
5523 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5524 break;
5525 }
5526 if (LocaleCompare("separate",option+1) == 0)
5527 break;
5528 if (LocaleCompare("sepia-tone",option+1) == 0)
5529 {
5530 if (*option == '+')
5531 break;
5532 i++;
cristybb503372010-05-27 20:51:26 +00005533 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005534 ThrowMogrifyException(OptionError,"MissingArgument",option);
5535 if (IsGeometry(argv[i]) == MagickFalse)
5536 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5537 break;
5538 }
5539 if (LocaleCompare("set",option+1) == 0)
5540 {
5541 i++;
cristybb503372010-05-27 20:51:26 +00005542 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005543 ThrowMogrifyException(OptionError,"MissingArgument",option);
5544 if (*option == '+')
5545 break;
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 break;
5550 }
5551 if (LocaleCompare("shade",option+1) == 0)
5552 {
5553 i++;
cristybb503372010-05-27 20:51:26 +00005554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 if (IsGeometry(argv[i]) == MagickFalse)
5557 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5558 break;
5559 }
5560 if (LocaleCompare("shadow",option+1) == 0)
5561 {
5562 if (*option == '+')
5563 break;
5564 i++;
cristybb503372010-05-27 20:51:26 +00005565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005566 ThrowMogrifyException(OptionError,"MissingArgument",option);
5567 if (IsGeometry(argv[i]) == MagickFalse)
5568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5569 break;
5570 }
5571 if (LocaleCompare("sharpen",option+1) == 0)
5572 {
5573 i++;
cristybb503372010-05-27 20:51:26 +00005574 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005575 ThrowMogrifyException(OptionError,"MissingArgument",option);
5576 if (IsGeometry(argv[i]) == MagickFalse)
5577 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5578 break;
5579 }
5580 if (LocaleCompare("shave",option+1) == 0)
5581 {
5582 if (*option == '+')
5583 break;
5584 i++;
cristybb503372010-05-27 20:51:26 +00005585 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 if (IsGeometry(argv[i]) == MagickFalse)
5588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5589 break;
5590 }
5591 if (LocaleCompare("shear",option+1) == 0)
5592 {
5593 i++;
cristybb503372010-05-27 20:51:26 +00005594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5598 break;
5599 }
5600 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5601 {
5602 i++;
cristybb503372010-05-27 20:51:26 +00005603 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005604 ThrowMogrifyException(OptionError,"MissingArgument",option);
5605 if (IsGeometry(argv[i]) == MagickFalse)
5606 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5607 break;
5608 }
5609 if (LocaleCompare("size",option+1) == 0)
5610 {
5611 if (*option == '+')
5612 break;
5613 i++;
cristybb503372010-05-27 20:51:26 +00005614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005615 ThrowMogrifyException(OptionError,"MissingArgument",option);
5616 if (IsGeometry(argv[i]) == MagickFalse)
5617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5618 break;
5619 }
5620 if (LocaleCompare("sketch",option+1) == 0)
5621 {
5622 if (*option == '+')
5623 break;
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 if (IsGeometry(argv[i]) == MagickFalse)
5628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5629 break;
5630 }
cristy4285d782011-02-09 20:12:28 +00005631 if (LocaleCompare("smush",option+1) == 0)
5632 {
cristy4285d782011-02-09 20:12:28 +00005633 i++;
5634 if (i == (ssize_t) argc)
5635 ThrowMogrifyException(OptionError,"MissingArgument",option);
5636 if (IsGeometry(argv[i]) == MagickFalse)
5637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005638 i++;
5639 break;
5640 }
cristy3ed852e2009-09-05 21:47:34 +00005641 if (LocaleCompare("solarize",option+1) == 0)
5642 {
5643 if (*option == '+')
5644 break;
5645 i++;
cristybb503372010-05-27 20:51:26 +00005646 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005647 ThrowMogrifyException(OptionError,"MissingArgument",option);
5648 if (IsGeometry(argv[i]) == MagickFalse)
5649 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5650 break;
5651 }
5652 if (LocaleCompare("sparse-color",option+1) == 0)
5653 {
cristybb503372010-05-27 20:51:26 +00005654 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005655 op;
5656
5657 i++;
cristybb503372010-05-27 20:51:26 +00005658 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005659 ThrowMogrifyException(OptionError,"MissingArgument",option);
5660 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5661 if (op < 0)
5662 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5663 argv[i]);
5664 i++;
cristybb503372010-05-27 20:51:26 +00005665 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005666 ThrowMogrifyException(OptionError,"MissingArgument",option);
5667 break;
5668 }
5669 if (LocaleCompare("spread",option+1) == 0)
5670 {
5671 if (*option == '+')
5672 break;
5673 i++;
cristybb503372010-05-27 20:51:26 +00005674 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005675 ThrowMogrifyException(OptionError,"MissingArgument",option);
5676 if (IsGeometry(argv[i]) == MagickFalse)
5677 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5678 break;
5679 }
cristy0834d642011-03-18 18:26:08 +00005680 if (LocaleCompare("statistic",option+1) == 0)
5681 {
5682 ssize_t
5683 op;
5684
5685 if (*option == '+')
5686 break;
5687 i++;
5688 if (i == (ssize_t) argc)
5689 ThrowMogrifyException(OptionError,"MissingArgument",option);
5690 op=ParseMagickOption(MagickStatisticOptions,MagickFalse,argv[i]);
5691 if (op < 0)
5692 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5693 argv[i]);
5694 i++;
5695 if (i == (ssize_t) (argc-1))
5696 ThrowMogrifyException(OptionError,"MissingArgument",option);
5697 if (IsGeometry(argv[i]) == MagickFalse)
5698 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5699 break;
5700 }
cristy3ed852e2009-09-05 21:47:34 +00005701 if (LocaleCompare("stretch",option+1) == 0)
5702 {
cristybb503372010-05-27 20:51:26 +00005703 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005704 stretch;
5705
5706 if (*option == '+')
5707 break;
5708 i++;
cristybb503372010-05-27 20:51:26 +00005709 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005710 ThrowMogrifyException(OptionError,"MissingArgument",option);
5711 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
5712 if (stretch < 0)
5713 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5714 argv[i]);
5715 break;
5716 }
5717 if (LocaleCompare("strip",option+1) == 0)
5718 break;
5719 if (LocaleCompare("stroke",option+1) == 0)
5720 {
5721 if (*option == '+')
5722 break;
5723 i++;
cristybb503372010-05-27 20:51:26 +00005724 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005725 ThrowMogrifyException(OptionError,"MissingArgument",option);
5726 break;
5727 }
5728 if (LocaleCompare("strokewidth",option+1) == 0)
5729 {
5730 if (*option == '+')
5731 break;
5732 i++;
cristybb503372010-05-27 20:51:26 +00005733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005734 ThrowMogrifyException(OptionError,"MissingArgument",option);
5735 if (IsGeometry(argv[i]) == MagickFalse)
5736 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5737 break;
5738 }
5739 if (LocaleCompare("style",option+1) == 0)
5740 {
cristybb503372010-05-27 20:51:26 +00005741 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005742 style;
5743
5744 if (*option == '+')
5745 break;
5746 i++;
cristybb503372010-05-27 20:51:26 +00005747 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005748 ThrowMogrifyException(OptionError,"MissingArgument",option);
5749 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
5750 if (style < 0)
5751 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5752 argv[i]);
5753 break;
5754 }
cristyecb10ff2011-03-22 13:14:03 +00005755 if (LocaleCompare("swap",option+1) == 0)
5756 {
5757 if (*option == '+')
5758 break;
5759 i++;
5760 if (i == (ssize_t) (argc-1))
5761 ThrowMogrifyException(OptionError,"MissingArgument",option);
5762 if (IsGeometry(argv[i]) == MagickFalse)
5763 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5764 break;
5765 }
cristy3ed852e2009-09-05 21:47:34 +00005766 if (LocaleCompare("swirl",option+1) == 0)
5767 {
5768 if (*option == '+')
5769 break;
5770 i++;
cristybb503372010-05-27 20:51:26 +00005771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005772 ThrowMogrifyException(OptionError,"MissingArgument",option);
5773 if (IsGeometry(argv[i]) == MagickFalse)
5774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5775 break;
5776 }
cristyd9a29192010-10-16 16:49:53 +00005777 if (LocaleCompare("synchronize",option+1) == 0)
5778 break;
cristy3ed852e2009-09-05 21:47:34 +00005779 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5780 }
5781 case 't':
5782 {
5783 if (LocaleCompare("taint",option+1) == 0)
5784 break;
5785 if (LocaleCompare("texture",option+1) == 0)
5786 {
5787 if (*option == '+')
5788 break;
5789 i++;
cristybb503372010-05-27 20:51:26 +00005790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005791 ThrowMogrifyException(OptionError,"MissingArgument",option);
5792 break;
5793 }
5794 if (LocaleCompare("tile",option+1) == 0)
5795 {
5796 if (*option == '+')
5797 break;
5798 i++;
cristybb503372010-05-27 20:51:26 +00005799 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005800 ThrowMogrifyException(OptionError,"MissingArgument",option);
5801 break;
5802 }
5803 if (LocaleCompare("tile-offset",option+1) == 0)
5804 {
5805 if (*option == '+')
5806 break;
5807 i++;
cristybb503372010-05-27 20:51:26 +00005808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005809 ThrowMogrifyException(OptionError,"MissingArgument",option);
5810 if (IsGeometry(argv[i]) == MagickFalse)
5811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5812 break;
5813 }
5814 if (LocaleCompare("tint",option+1) == 0)
5815 {
5816 if (*option == '+')
5817 break;
5818 i++;
cristybb503372010-05-27 20:51:26 +00005819 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005820 ThrowMogrifyException(OptionError,"MissingArgument",option);
5821 if (IsGeometry(argv[i]) == MagickFalse)
5822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5823 break;
5824 }
5825 if (LocaleCompare("transform",option+1) == 0)
5826 break;
5827 if (LocaleCompare("transpose",option+1) == 0)
5828 break;
5829 if (LocaleCompare("transverse",option+1) == 0)
5830 break;
5831 if (LocaleCompare("threshold",option+1) == 0)
5832 {
5833 if (*option == '+')
5834 break;
5835 i++;
cristybb503372010-05-27 20:51:26 +00005836 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005837 ThrowMogrifyException(OptionError,"MissingArgument",option);
5838 if (IsGeometry(argv[i]) == MagickFalse)
5839 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5840 break;
5841 }
5842 if (LocaleCompare("thumbnail",option+1) == 0)
5843 {
5844 if (*option == '+')
5845 break;
5846 i++;
cristybb503372010-05-27 20:51:26 +00005847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005848 ThrowMogrifyException(OptionError,"MissingArgument",option);
5849 if (IsGeometry(argv[i]) == MagickFalse)
5850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5851 break;
5852 }
5853 if (LocaleCompare("transparent",option+1) == 0)
5854 {
5855 i++;
cristybb503372010-05-27 20:51:26 +00005856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005857 ThrowMogrifyException(OptionError,"MissingArgument",option);
5858 break;
5859 }
5860 if (LocaleCompare("transparent-color",option+1) == 0)
5861 {
5862 if (*option == '+')
5863 break;
5864 i++;
cristybb503372010-05-27 20:51:26 +00005865 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 break;
5868 }
5869 if (LocaleCompare("treedepth",option+1) == 0)
5870 {
5871 if (*option == '+')
5872 break;
5873 i++;
cristybb503372010-05-27 20:51:26 +00005874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005875 ThrowMogrifyException(OptionError,"MissingArgument",option);
5876 if (IsGeometry(argv[i]) == MagickFalse)
5877 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5878 break;
5879 }
5880 if (LocaleCompare("trim",option+1) == 0)
5881 break;
5882 if (LocaleCompare("type",option+1) == 0)
5883 {
cristybb503372010-05-27 20:51:26 +00005884 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005885 type;
5886
5887 if (*option == '+')
5888 break;
5889 i++;
cristybb503372010-05-27 20:51:26 +00005890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005891 ThrowMogrifyException(OptionError,"MissingArgument",option);
5892 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
5893 if (type < 0)
5894 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5895 argv[i]);
5896 break;
5897 }
5898 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5899 }
5900 case 'u':
5901 {
5902 if (LocaleCompare("undercolor",option+1) == 0)
5903 {
5904 if (*option == '+')
5905 break;
5906 i++;
cristybb503372010-05-27 20:51:26 +00005907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005908 ThrowMogrifyException(OptionError,"MissingArgument",option);
5909 break;
5910 }
5911 if (LocaleCompare("unique-colors",option+1) == 0)
5912 break;
5913 if (LocaleCompare("units",option+1) == 0)
5914 {
cristybb503372010-05-27 20:51:26 +00005915 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005916 units;
5917
5918 if (*option == '+')
5919 break;
5920 i++;
cristybb503372010-05-27 20:51:26 +00005921 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005922 ThrowMogrifyException(OptionError,"MissingArgument",option);
5923 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
5924 argv[i]);
5925 if (units < 0)
5926 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5927 argv[i]);
5928 break;
5929 }
5930 if (LocaleCompare("unsharp",option+1) == 0)
5931 {
5932 i++;
cristybb503372010-05-27 20:51:26 +00005933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005934 ThrowMogrifyException(OptionError,"MissingArgument",option);
5935 if (IsGeometry(argv[i]) == MagickFalse)
5936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5937 break;
5938 }
5939 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5940 }
5941 case 'v':
5942 {
5943 if (LocaleCompare("verbose",option+1) == 0)
5944 {
5945 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5946 break;
5947 }
5948 if ((LocaleCompare("version",option+1) == 0) ||
5949 (LocaleCompare("-version",option+1) == 0))
5950 {
5951 (void) fprintf(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005952 GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00005953 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
5954 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005955 break;
5956 }
5957 if (LocaleCompare("view",option+1) == 0)
5958 {
5959 if (*option == '+')
5960 break;
5961 i++;
cristybb503372010-05-27 20:51:26 +00005962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005963 ThrowMogrifyException(OptionError,"MissingArgument",option);
5964 break;
5965 }
5966 if (LocaleCompare("vignette",option+1) == 0)
5967 {
5968 if (*option == '+')
5969 break;
5970 i++;
cristybb503372010-05-27 20:51:26 +00005971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005972 ThrowMogrifyException(OptionError,"MissingArgument",option);
5973 if (IsGeometry(argv[i]) == MagickFalse)
5974 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5975 break;
5976 }
5977 if (LocaleCompare("virtual-pixel",option+1) == 0)
5978 {
cristybb503372010-05-27 20:51:26 +00005979 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005980 method;
5981
5982 if (*option == '+')
5983 break;
5984 i++;
cristybb503372010-05-27 20:51:26 +00005985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005986 ThrowMogrifyException(OptionError,"MissingArgument",option);
5987 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
5988 argv[i]);
5989 if (method < 0)
5990 ThrowMogrifyException(OptionError,
5991 "UnrecognizedVirtualPixelMethod",argv[i]);
5992 break;
5993 }
5994 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5995 }
5996 case 'w':
5997 {
5998 if (LocaleCompare("wave",option+1) == 0)
5999 {
6000 i++;
cristybb503372010-05-27 20:51:26 +00006001 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006002 ThrowMogrifyException(OptionError,"MissingArgument",option);
6003 if (IsGeometry(argv[i]) == MagickFalse)
6004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6005 break;
6006 }
6007 if (LocaleCompare("weight",option+1) == 0)
6008 {
6009 if (*option == '+')
6010 break;
6011 i++;
cristybb503372010-05-27 20:51:26 +00006012 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006013 ThrowMogrifyException(OptionError,"MissingArgument",option);
6014 break;
6015 }
6016 if (LocaleCompare("white-point",option+1) == 0)
6017 {
6018 if (*option == '+')
6019 break;
6020 i++;
cristybb503372010-05-27 20:51:26 +00006021 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006022 ThrowMogrifyException(OptionError,"MissingArgument",option);
6023 if (IsGeometry(argv[i]) == MagickFalse)
6024 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6025 break;
6026 }
6027 if (LocaleCompare("white-threshold",option+1) == 0)
6028 {
6029 if (*option == '+')
6030 break;
6031 i++;
cristybb503372010-05-27 20:51:26 +00006032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006033 ThrowMogrifyException(OptionError,"MissingArgument",option);
6034 if (IsGeometry(argv[i]) == MagickFalse)
6035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036 break;
6037 }
6038 if (LocaleCompare("write",option+1) == 0)
6039 {
6040 i++;
cristybb503372010-05-27 20:51:26 +00006041 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006042 ThrowMogrifyException(OptionError,"MissingArgument",option);
6043 break;
6044 }
6045 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6046 }
6047 case '?':
6048 break;
6049 default:
6050 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6051 }
6052 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6053 MagickFalse : MagickTrue;
6054 if (fire != MagickFalse)
6055 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6056 }
6057 if (k != 0)
6058 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006059 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006060 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6061 DestroyMogrify();
6062 return(status != 0 ? MagickTrue : MagickFalse);
6063}
6064
6065/*
6066%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6067% %
6068% %
6069% %
6070+ M o g r i f y I m a g e I n f o %
6071% %
6072% %
6073% %
6074%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6075%
6076% MogrifyImageInfo() applies image processing settings to the image as
6077% prescribed by command line options.
6078%
6079% The format of the MogrifyImageInfo method is:
6080%
6081% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6082% const char **argv,ExceptionInfo *exception)
6083%
6084% A description of each parameter follows:
6085%
6086% o image_info: the image info..
6087%
6088% o argc: Specifies a pointer to an integer describing the number of
6089% elements in the argument vector.
6090%
6091% o argv: Specifies a pointer to a text array containing the command line
6092% arguments.
6093%
6094% o exception: return any errors or warnings in this structure.
6095%
6096*/
6097WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6098 const int argc,const char **argv,ExceptionInfo *exception)
6099{
6100 const char
6101 *option;
6102
6103 GeometryInfo
6104 geometry_info;
6105
cristybb503372010-05-27 20:51:26 +00006106 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006107 count;
6108
cristybb503372010-05-27 20:51:26 +00006109 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006110 i;
6111
6112 /*
6113 Initialize method variables.
6114 */
6115 assert(image_info != (ImageInfo *) NULL);
6116 assert(image_info->signature == MagickSignature);
6117 if (image_info->debug != MagickFalse)
6118 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6119 image_info->filename);
6120 if (argc < 0)
6121 return(MagickTrue);
6122 /*
6123 Set the image settings.
6124 */
cristybb503372010-05-27 20:51:26 +00006125 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006126 {
6127 option=argv[i];
6128 if (IsMagickOption(option) == MagickFalse)
6129 continue;
6130 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6131 0L);
cristycee97112010-05-28 00:44:52 +00006132 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006133 break;
6134 switch (*(option+1))
6135 {
6136 case 'a':
6137 {
6138 if (LocaleCompare("adjoin",option+1) == 0)
6139 {
6140 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6141 break;
6142 }
6143 if (LocaleCompare("antialias",option+1) == 0)
6144 {
6145 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6146 break;
6147 }
6148 if (LocaleCompare("attenuate",option+1) == 0)
6149 {
6150 if (*option == '+')
6151 {
6152 (void) DeleteImageOption(image_info,option+1);
6153 break;
6154 }
6155 (void) SetImageOption(image_info,option+1,argv[i+1]);
6156 break;
6157 }
6158 if (LocaleCompare("authenticate",option+1) == 0)
6159 {
6160 if (*option == '+')
6161 (void) CloneString(&image_info->authenticate,(char *) NULL);
6162 else
6163 (void) CloneString(&image_info->authenticate,argv[i+1]);
6164 break;
6165 }
6166 break;
6167 }
6168 case 'b':
6169 {
6170 if (LocaleCompare("background",option+1) == 0)
6171 {
6172 if (*option == '+')
6173 {
6174 (void) DeleteImageOption(image_info,option+1);
6175 (void) QueryColorDatabase(BackgroundColor,
6176 &image_info->background_color,exception);
6177 break;
6178 }
6179 (void) SetImageOption(image_info,option+1,argv[i+1]);
6180 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6181 exception);
6182 break;
6183 }
6184 if (LocaleCompare("bias",option+1) == 0)
6185 {
6186 if (*option == '+')
6187 {
6188 (void) SetImageOption(image_info,option+1,"0.0");
6189 break;
6190 }
6191 (void) SetImageOption(image_info,option+1,argv[i+1]);
6192 break;
6193 }
6194 if (LocaleCompare("black-point-compensation",option+1) == 0)
6195 {
6196 if (*option == '+')
6197 {
6198 (void) SetImageOption(image_info,option+1,"false");
6199 break;
6200 }
6201 (void) SetImageOption(image_info,option+1,"true");
6202 break;
6203 }
6204 if (LocaleCompare("blue-primary",option+1) == 0)
6205 {
6206 if (*option == '+')
6207 {
6208 (void) SetImageOption(image_info,option+1,"0.0");
6209 break;
6210 }
6211 (void) SetImageOption(image_info,option+1,argv[i+1]);
6212 break;
6213 }
6214 if (LocaleCompare("bordercolor",option+1) == 0)
6215 {
6216 if (*option == '+')
6217 {
6218 (void) DeleteImageOption(image_info,option+1);
6219 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6220 exception);
6221 break;
6222 }
6223 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6224 exception);
6225 (void) SetImageOption(image_info,option+1,argv[i+1]);
6226 break;
6227 }
6228 if (LocaleCompare("box",option+1) == 0)
6229 {
6230 if (*option == '+')
6231 {
6232 (void) SetImageOption(image_info,"undercolor","none");
6233 break;
6234 }
6235 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6236 break;
6237 }
6238 break;
6239 }
6240 case 'c':
6241 {
6242 if (LocaleCompare("cache",option+1) == 0)
6243 {
6244 MagickSizeType
6245 limit;
6246
6247 limit=MagickResourceInfinity;
6248 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006249 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006250 (void) SetMagickResourceLimit(MemoryResource,limit);
6251 (void) SetMagickResourceLimit(MapResource,2*limit);
6252 break;
6253 }
6254 if (LocaleCompare("caption",option+1) == 0)
6255 {
6256 if (*option == '+')
6257 {
6258 (void) DeleteImageOption(image_info,option+1);
6259 break;
6260 }
6261 (void) SetImageOption(image_info,option+1,argv[i+1]);
6262 break;
6263 }
6264 if (LocaleCompare("channel",option+1) == 0)
6265 {
6266 if (*option == '+')
6267 {
6268 image_info->channel=DefaultChannels;
6269 break;
6270 }
6271 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6272 break;
6273 }
6274 if (LocaleCompare("colors",option+1) == 0)
6275 {
cristye27293e2009-12-18 02:53:20 +00006276 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006277 break;
6278 }
6279 if (LocaleCompare("colorspace",option+1) == 0)
6280 {
6281 if (*option == '+')
6282 {
6283 image_info->colorspace=UndefinedColorspace;
6284 (void) SetImageOption(image_info,option+1,"undefined");
6285 break;
6286 }
6287 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6288 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6289 (void) SetImageOption(image_info,option+1,argv[i+1]);
6290 break;
6291 }
6292 if (LocaleCompare("compress",option+1) == 0)
6293 {
6294 if (*option == '+')
6295 {
6296 image_info->compression=UndefinedCompression;
6297 (void) SetImageOption(image_info,option+1,"undefined");
6298 break;
6299 }
6300 image_info->compression=(CompressionType) ParseMagickOption(
6301 MagickCompressOptions,MagickFalse,argv[i+1]);
6302 (void) SetImageOption(image_info,option+1,argv[i+1]);
6303 break;
6304 }
6305 if (LocaleCompare("comment",option+1) == 0)
6306 {
6307 if (*option == '+')
6308 {
6309 (void) DeleteImageOption(image_info,option+1);
6310 break;
6311 }
6312 (void) SetImageOption(image_info,option+1,argv[i+1]);
6313 break;
6314 }
6315 if (LocaleCompare("compose",option+1) == 0)
6316 {
6317 if (*option == '+')
6318 {
6319 (void) SetImageOption(image_info,option+1,"undefined");
6320 break;
6321 }
6322 (void) SetImageOption(image_info,option+1,argv[i+1]);
6323 break;
6324 }
6325 if (LocaleCompare("compress",option+1) == 0)
6326 {
6327 if (*option == '+')
6328 {
6329 image_info->compression=UndefinedCompression;
6330 (void) SetImageOption(image_info,option+1,"undefined");
6331 break;
6332 }
6333 image_info->compression=(CompressionType) ParseMagickOption(
6334 MagickCompressOptions,MagickFalse,argv[i+1]);
6335 (void) SetImageOption(image_info,option+1,argv[i+1]);
6336 break;
6337 }
6338 break;
6339 }
6340 case 'd':
6341 {
6342 if (LocaleCompare("debug",option+1) == 0)
6343 {
6344 if (*option == '+')
6345 (void) SetLogEventMask("none");
6346 else
6347 (void) SetLogEventMask(argv[i+1]);
6348 image_info->debug=IsEventLogging();
6349 break;
6350 }
6351 if (LocaleCompare("define",option+1) == 0)
6352 {
6353 if (*option == '+')
6354 {
6355 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6356 (void) DeleteImageRegistry(argv[i+1]+9);
6357 else
6358 (void) DeleteImageOption(image_info,argv[i+1]);
6359 break;
6360 }
6361 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6362 {
6363 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6364 exception);
6365 break;
6366 }
6367 (void) DefineImageOption(image_info,argv[i+1]);
6368 break;
6369 }
6370 if (LocaleCompare("delay",option+1) == 0)
6371 {
6372 if (*option == '+')
6373 {
6374 (void) SetImageOption(image_info,option+1,"0");
6375 break;
6376 }
6377 (void) SetImageOption(image_info,option+1,argv[i+1]);
6378 break;
6379 }
6380 if (LocaleCompare("density",option+1) == 0)
6381 {
6382 /*
6383 Set image density.
6384 */
6385 if (*option == '+')
6386 {
6387 if (image_info->density != (char *) NULL)
6388 image_info->density=DestroyString(image_info->density);
6389 (void) SetImageOption(image_info,option+1,"72");
6390 break;
6391 }
6392 (void) CloneString(&image_info->density,argv[i+1]);
6393 (void) SetImageOption(image_info,option+1,argv[i+1]);
6394 break;
6395 }
6396 if (LocaleCompare("depth",option+1) == 0)
6397 {
6398 if (*option == '+')
6399 {
6400 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6401 break;
6402 }
cristye27293e2009-12-18 02:53:20 +00006403 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006404 break;
6405 }
cristyc9b12952010-03-28 01:12:28 +00006406 if (LocaleCompare("direction",option+1) == 0)
6407 {
6408 if (*option == '+')
6409 {
6410 (void) SetImageOption(image_info,option+1,"undefined");
6411 break;
6412 }
6413 (void) SetImageOption(image_info,option+1,argv[i+1]);
6414 break;
6415 }
cristy3ed852e2009-09-05 21:47:34 +00006416 if (LocaleCompare("display",option+1) == 0)
6417 {
6418 if (*option == '+')
6419 {
6420 if (image_info->server_name != (char *) NULL)
6421 image_info->server_name=DestroyString(
6422 image_info->server_name);
6423 break;
6424 }
6425 (void) CloneString(&image_info->server_name,argv[i+1]);
6426 break;
6427 }
6428 if (LocaleCompare("dispose",option+1) == 0)
6429 {
6430 if (*option == '+')
6431 {
6432 (void) SetImageOption(image_info,option+1,"undefined");
6433 break;
6434 }
6435 (void) SetImageOption(image_info,option+1,argv[i+1]);
6436 break;
6437 }
6438 if (LocaleCompare("dither",option+1) == 0)
6439 {
6440 if (*option == '+')
6441 {
6442 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006443 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006444 break;
6445 }
6446 (void) SetImageOption(image_info,option+1,argv[i+1]);
6447 image_info->dither=MagickTrue;
6448 break;
6449 }
6450 break;
6451 }
6452 case 'e':
6453 {
6454 if (LocaleCompare("encoding",option+1) == 0)
6455 {
6456 if (*option == '+')
6457 {
6458 (void) SetImageOption(image_info,option+1,"undefined");
6459 break;
6460 }
6461 (void) SetImageOption(image_info,option+1,argv[i+1]);
6462 break;
6463 }
6464 if (LocaleCompare("endian",option+1) == 0)
6465 {
6466 if (*option == '+')
6467 {
6468 image_info->endian=UndefinedEndian;
6469 (void) SetImageOption(image_info,option+1,"undefined");
6470 break;
6471 }
6472 image_info->endian=(EndianType) ParseMagickOption(
6473 MagickEndianOptions,MagickFalse,argv[i+1]);
6474 (void) SetImageOption(image_info,option+1,argv[i+1]);
6475 break;
6476 }
6477 if (LocaleCompare("extract",option+1) == 0)
6478 {
6479 /*
6480 Set image extract geometry.
6481 */
6482 if (*option == '+')
6483 {
6484 if (image_info->extract != (char *) NULL)
6485 image_info->extract=DestroyString(image_info->extract);
6486 break;
6487 }
6488 (void) CloneString(&image_info->extract,argv[i+1]);
6489 break;
6490 }
6491 break;
6492 }
6493 case 'f':
6494 {
6495 if (LocaleCompare("fill",option+1) == 0)
6496 {
6497 if (*option == '+')
6498 {
6499 (void) SetImageOption(image_info,option+1,"none");
6500 break;
6501 }
6502 (void) SetImageOption(image_info,option+1,argv[i+1]);
6503 break;
6504 }
6505 if (LocaleCompare("filter",option+1) == 0)
6506 {
6507 if (*option == '+')
6508 {
6509 (void) SetImageOption(image_info,option+1,"undefined");
6510 break;
6511 }
6512 (void) SetImageOption(image_info,option+1,argv[i+1]);
6513 break;
6514 }
6515 if (LocaleCompare("font",option+1) == 0)
6516 {
6517 if (*option == '+')
6518 {
6519 if (image_info->font != (char *) NULL)
6520 image_info->font=DestroyString(image_info->font);
6521 break;
6522 }
6523 (void) CloneString(&image_info->font,argv[i+1]);
6524 break;
6525 }
6526 if (LocaleCompare("format",option+1) == 0)
6527 {
6528 register const char
6529 *q;
6530
6531 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006532 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006533 image_info->ping=MagickFalse;
6534 (void) SetImageOption(image_info,option+1,argv[i+1]);
6535 break;
6536 }
6537 if (LocaleCompare("fuzz",option+1) == 0)
6538 {
6539 if (*option == '+')
6540 {
6541 image_info->fuzz=0.0;
6542 (void) SetImageOption(image_info,option+1,"0");
6543 break;
6544 }
cristyf2f27272009-12-17 14:48:46 +00006545 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006546 1.0);
6547 (void) SetImageOption(image_info,option+1,argv[i+1]);
6548 break;
6549 }
6550 break;
6551 }
6552 case 'g':
6553 {
6554 if (LocaleCompare("gravity",option+1) == 0)
6555 {
6556 if (*option == '+')
6557 {
6558 (void) SetImageOption(image_info,option+1,"undefined");
6559 break;
6560 }
6561 (void) SetImageOption(image_info,option+1,argv[i+1]);
6562 break;
6563 }
6564 if (LocaleCompare("green-primary",option+1) == 0)
6565 {
6566 if (*option == '+')
6567 {
6568 (void) SetImageOption(image_info,option+1,"0.0");
6569 break;
6570 }
6571 (void) SetImageOption(image_info,option+1,argv[i+1]);
6572 break;
6573 }
6574 break;
6575 }
6576 case 'i':
6577 {
6578 if (LocaleCompare("intent",option+1) == 0)
6579 {
6580 if (*option == '+')
6581 {
6582 (void) SetImageOption(image_info,option+1,"undefined");
6583 break;
6584 }
6585 (void) SetImageOption(image_info,option+1,argv[i+1]);
6586 break;
6587 }
6588 if (LocaleCompare("interlace",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 image_info->interlace=UndefinedInterlace;
6593 (void) SetImageOption(image_info,option+1,"undefined");
6594 break;
6595 }
6596 image_info->interlace=(InterlaceType) ParseMagickOption(
6597 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
cristyb32b90a2009-09-07 21:45:48 +00006601 if (LocaleCompare("interline-spacing",option+1) == 0)
6602 {
6603 if (*option == '+')
6604 {
6605 (void) SetImageOption(image_info,option+1,"undefined");
6606 break;
6607 }
6608 (void) SetImageOption(image_info,option+1,argv[i+1]);
6609 break;
6610 }
cristy3ed852e2009-09-05 21:47:34 +00006611 if (LocaleCompare("interpolate",option+1) == 0)
6612 {
6613 if (*option == '+')
6614 {
6615 (void) SetImageOption(image_info,option+1,"undefined");
6616 break;
6617 }
6618 (void) SetImageOption(image_info,option+1,argv[i+1]);
6619 break;
6620 }
6621 if (LocaleCompare("interword-spacing",option+1) == 0)
6622 {
6623 if (*option == '+')
6624 {
6625 (void) SetImageOption(image_info,option+1,"undefined");
6626 break;
6627 }
6628 (void) SetImageOption(image_info,option+1,argv[i+1]);
6629 break;
6630 }
6631 break;
6632 }
6633 case 'k':
6634 {
6635 if (LocaleCompare("kerning",option+1) == 0)
6636 {
6637 if (*option == '+')
6638 {
6639 (void) SetImageOption(image_info,option+1,"undefined");
6640 break;
6641 }
6642 (void) SetImageOption(image_info,option+1,argv[i+1]);
6643 break;
6644 }
6645 break;
6646 }
6647 case 'l':
6648 {
6649 if (LocaleCompare("label",option+1) == 0)
6650 {
6651 if (*option == '+')
6652 {
6653 (void) DeleteImageOption(image_info,option+1);
6654 break;
6655 }
6656 (void) SetImageOption(image_info,option+1,argv[i+1]);
6657 break;
6658 }
6659 if (LocaleCompare("limit",option+1) == 0)
6660 {
6661 MagickSizeType
6662 limit;
6663
6664 ResourceType
6665 type;
6666
6667 if (*option == '+')
6668 break;
6669 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6670 MagickFalse,argv[i+1]);
6671 limit=MagickResourceInfinity;
6672 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006673 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006674 (void) SetMagickResourceLimit(type,limit);
6675 break;
6676 }
6677 if (LocaleCompare("list",option+1) == 0)
6678 {
cristybb503372010-05-27 20:51:26 +00006679 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006680 list;
6681
6682 /*
6683 Display configuration list.
6684 */
6685 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6686 switch (list)
6687 {
6688 case MagickCoderOptions:
6689 {
6690 (void) ListCoderInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickColorOptions:
6694 {
6695 (void) ListColorInfo((FILE *) NULL,exception);
6696 break;
6697 }
6698 case MagickConfigureOptions:
6699 {
6700 (void) ListConfigureInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickDelegateOptions:
6704 {
6705 (void) ListDelegateInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickFontOptions:
6709 {
6710 (void) ListTypeInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickFormatOptions:
6714 {
6715 (void) ListMagickInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickLocaleOptions:
6719 {
6720 (void) ListLocaleInfo((FILE *) NULL,exception);
6721 break;
6722 }
6723 case MagickLogOptions:
6724 {
6725 (void) ListLogInfo((FILE *) NULL,exception);
6726 break;
6727 }
6728 case MagickMagicOptions:
6729 {
6730 (void) ListMagicInfo((FILE *) NULL,exception);
6731 break;
6732 }
6733 case MagickMimeOptions:
6734 {
6735 (void) ListMimeInfo((FILE *) NULL,exception);
6736 break;
6737 }
6738 case MagickModuleOptions:
6739 {
6740 (void) ListModuleInfo((FILE *) NULL,exception);
6741 break;
6742 }
6743 case MagickPolicyOptions:
6744 {
6745 (void) ListPolicyInfo((FILE *) NULL,exception);
6746 break;
6747 }
6748 case MagickResourceOptions:
6749 {
6750 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6751 break;
6752 }
6753 case MagickThresholdOptions:
6754 {
6755 (void) ListThresholdMaps((FILE *) NULL,exception);
6756 break;
6757 }
6758 default:
6759 {
6760 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
6761 exception);
6762 break;
6763 }
6764 }
cristyaeb2cbc2010-05-07 13:28:58 +00006765 break;
cristy3ed852e2009-09-05 21:47:34 +00006766 }
6767 if (LocaleCompare("log",option+1) == 0)
6768 {
6769 if (*option == '+')
6770 break;
6771 (void) SetLogFormat(argv[i+1]);
6772 break;
6773 }
6774 if (LocaleCompare("loop",option+1) == 0)
6775 {
6776 if (*option == '+')
6777 {
6778 (void) SetImageOption(image_info,option+1,"0");
6779 break;
6780 }
6781 (void) SetImageOption(image_info,option+1,argv[i+1]);
6782 break;
6783 }
6784 break;
6785 }
6786 case 'm':
6787 {
6788 if (LocaleCompare("matte",option+1) == 0)
6789 {
6790 if (*option == '+')
6791 {
6792 (void) SetImageOption(image_info,option+1,"false");
6793 break;
6794 }
6795 (void) SetImageOption(image_info,option+1,"true");
6796 break;
6797 }
6798 if (LocaleCompare("mattecolor",option+1) == 0)
6799 {
6800 if (*option == '+')
6801 {
6802 (void) SetImageOption(image_info,option+1,argv[i+1]);
6803 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6804 exception);
6805 break;
6806 }
6807 (void) SetImageOption(image_info,option+1,argv[i+1]);
6808 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6809 exception);
6810 break;
6811 }
6812 if (LocaleCompare("monitor",option+1) == 0)
6813 {
6814 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6815 (void *) NULL);
6816 break;
6817 }
6818 if (LocaleCompare("monochrome",option+1) == 0)
6819 {
6820 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6821 break;
6822 }
6823 break;
6824 }
6825 case 'o':
6826 {
6827 if (LocaleCompare("orient",option+1) == 0)
6828 {
6829 if (*option == '+')
6830 {
6831 image_info->orientation=UndefinedOrientation;
6832 (void) SetImageOption(image_info,option+1,"undefined");
6833 break;
6834 }
6835 image_info->orientation=(OrientationType) ParseMagickOption(
6836 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006837 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006838 break;
6839 }
6840 }
6841 case 'p':
6842 {
6843 if (LocaleCompare("page",option+1) == 0)
6844 {
6845 char
6846 *canonical_page,
6847 page[MaxTextExtent];
6848
6849 const char
6850 *image_option;
6851
6852 MagickStatusType
6853 flags;
6854
6855 RectangleInfo
6856 geometry;
6857
6858 if (*option == '+')
6859 {
6860 (void) DeleteImageOption(image_info,option+1);
6861 (void) CloneString(&image_info->page,(char *) NULL);
6862 break;
6863 }
6864 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6865 image_option=GetImageOption(image_info,"page");
6866 if (image_option != (const char *) NULL)
6867 flags=ParseAbsoluteGeometry(image_option,&geometry);
6868 canonical_page=GetPageGeometry(argv[i+1]);
6869 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6870 canonical_page=DestroyString(canonical_page);
6871 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006872 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006873 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6874 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006875 (unsigned long) geometry.width,(unsigned long) geometry.height,
6876 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006877 (void) SetImageOption(image_info,option+1,page);
6878 (void) CloneString(&image_info->page,page);
6879 break;
6880 }
6881 if (LocaleCompare("pen",option+1) == 0)
6882 {
6883 if (*option == '+')
6884 {
6885 (void) SetImageOption(image_info,option+1,"none");
6886 break;
6887 }
6888 (void) SetImageOption(image_info,option+1,argv[i+1]);
6889 break;
6890 }
6891 if (LocaleCompare("ping",option+1) == 0)
6892 {
6893 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6894 break;
6895 }
6896 if (LocaleCompare("pointsize",option+1) == 0)
6897 {
6898 if (*option == '+')
6899 geometry_info.rho=0.0;
6900 else
6901 (void) ParseGeometry(argv[i+1],&geometry_info);
6902 image_info->pointsize=geometry_info.rho;
6903 break;
6904 }
cristye7f51092010-01-17 00:39:37 +00006905 if (LocaleCompare("precision",option+1) == 0)
6906 {
cristybf2766a2010-01-17 03:33:23 +00006907 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006908 break;
6909 }
cristy3ed852e2009-09-05 21:47:34 +00006910 if (LocaleCompare("preview",option+1) == 0)
6911 {
6912 /*
6913 Preview image.
6914 */
6915 if (*option == '+')
6916 {
6917 image_info->preview_type=UndefinedPreview;
6918 break;
6919 }
6920 image_info->preview_type=(PreviewType) ParseMagickOption(
6921 MagickPreviewOptions,MagickFalse,argv[i+1]);
6922 break;
6923 }
6924 break;
6925 }
6926 case 'q':
6927 {
6928 if (LocaleCompare("quality",option+1) == 0)
6929 {
6930 /*
6931 Set image compression quality.
6932 */
6933 if (*option == '+')
6934 {
6935 image_info->quality=UndefinedCompressionQuality;
6936 (void) SetImageOption(image_info,option+1,"0");
6937 break;
6938 }
cristye27293e2009-12-18 02:53:20 +00006939 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006940 (void) SetImageOption(image_info,option+1,argv[i+1]);
6941 break;
6942 }
6943 if (LocaleCompare("quiet",option+1) == 0)
6944 {
6945 static WarningHandler
6946 warning_handler = (WarningHandler) NULL;
6947
6948 if (*option == '+')
6949 {
6950 /*
6951 Restore error or warning messages.
6952 */
6953 warning_handler=SetWarningHandler(warning_handler);
6954 break;
6955 }
6956 /*
6957 Suppress error or warning messages.
6958 */
6959 warning_handler=SetWarningHandler((WarningHandler) NULL);
6960 break;
6961 }
6962 break;
6963 }
6964 case 'r':
6965 {
6966 if (LocaleCompare("red-primary",option+1) == 0)
6967 {
6968 if (*option == '+')
6969 {
6970 (void) SetImageOption(image_info,option+1,"0.0");
6971 break;
6972 }
6973 (void) SetImageOption(image_info,option+1,argv[i+1]);
6974 break;
6975 }
6976 break;
6977 }
6978 case 's':
6979 {
6980 if (LocaleCompare("sampling-factor",option+1) == 0)
6981 {
6982 /*
6983 Set image sampling factor.
6984 */
6985 if (*option == '+')
6986 {
6987 if (image_info->sampling_factor != (char *) NULL)
6988 image_info->sampling_factor=DestroyString(
6989 image_info->sampling_factor);
6990 break;
6991 }
6992 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6993 break;
6994 }
6995 if (LocaleCompare("scene",option+1) == 0)
6996 {
6997 /*
6998 Set image scene.
6999 */
7000 if (*option == '+')
7001 {
7002 image_info->scene=0;
7003 (void) SetImageOption(image_info,option+1,"0");
7004 break;
7005 }
cristye27293e2009-12-18 02:53:20 +00007006 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007007 (void) SetImageOption(image_info,option+1,argv[i+1]);
7008 break;
7009 }
7010 if (LocaleCompare("seed",option+1) == 0)
7011 {
cristybb503372010-05-27 20:51:26 +00007012 size_t
cristy3ed852e2009-09-05 21:47:34 +00007013 seed;
7014
7015 if (*option == '+')
7016 {
cristybb503372010-05-27 20:51:26 +00007017 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007018 SeedPseudoRandomGenerator(seed);
7019 break;
7020 }
cristye27293e2009-12-18 02:53:20 +00007021 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007022 SeedPseudoRandomGenerator(seed);
7023 break;
7024 }
7025 if (LocaleCompare("size",option+1) == 0)
7026 {
7027 if (*option == '+')
7028 {
7029 if (image_info->size != (char *) NULL)
7030 image_info->size=DestroyString(image_info->size);
7031 break;
7032 }
7033 (void) CloneString(&image_info->size,argv[i+1]);
7034 break;
7035 }
7036 if (LocaleCompare("stroke",option+1) == 0)
7037 {
7038 if (*option == '+')
7039 {
7040 (void) SetImageOption(image_info,option+1,"none");
7041 break;
7042 }
7043 (void) SetImageOption(image_info,option+1,argv[i+1]);
7044 break;
7045 }
7046 if (LocaleCompare("strokewidth",option+1) == 0)
7047 {
7048 if (*option == '+')
7049 {
7050 (void) SetImageOption(image_info,option+1,"0");
7051 break;
7052 }
7053 (void) SetImageOption(image_info,option+1,argv[i+1]);
7054 break;
7055 }
cristyd9a29192010-10-16 16:49:53 +00007056 if (LocaleCompare("synchronize",option+1) == 0)
7057 {
7058 if (*option == '+')
7059 {
7060 image_info->synchronize=MagickFalse;
7061 break;
7062 }
7063 image_info->synchronize=MagickTrue;
7064 break;
7065 }
cristy3ed852e2009-09-05 21:47:34 +00007066 break;
7067 }
7068 case 't':
7069 {
7070 if (LocaleCompare("taint",option+1) == 0)
7071 {
7072 if (*option == '+')
7073 {
7074 (void) SetImageOption(image_info,option+1,"false");
7075 break;
7076 }
7077 (void) SetImageOption(image_info,option+1,"true");
7078 break;
7079 }
7080 if (LocaleCompare("texture",option+1) == 0)
7081 {
7082 if (*option == '+')
7083 {
7084 if (image_info->texture != (char *) NULL)
7085 image_info->texture=DestroyString(image_info->texture);
7086 break;
7087 }
7088 (void) CloneString(&image_info->texture,argv[i+1]);
7089 break;
7090 }
7091 if (LocaleCompare("tile-offset",option+1) == 0)
7092 {
7093 if (*option == '+')
7094 {
7095 (void) SetImageOption(image_info,option+1,"0");
7096 break;
7097 }
7098 (void) SetImageOption(image_info,option+1,argv[i+1]);
7099 break;
7100 }
7101 if (LocaleCompare("transparent-color",option+1) == 0)
7102 {
7103 if (*option == '+')
7104 {
7105 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7106 (void) SetImageOption(image_info,option+1,"none");
7107 break;
7108 }
7109 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7110 exception);
7111 (void) SetImageOption(image_info,option+1,argv[i+1]);
7112 break;
7113 }
7114 if (LocaleCompare("type",option+1) == 0)
7115 {
7116 if (*option == '+')
7117 {
cristy5f1c1ff2010-12-23 21:38:06 +00007118 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007119 (void) SetImageOption(image_info,option+1,"undefined");
7120 break;
7121 }
7122 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7123 MagickFalse,argv[i+1]);
7124 (void) SetImageOption(image_info,option+1,argv[i+1]);
7125 break;
7126 }
7127 break;
7128 }
7129 case 'u':
7130 {
7131 if (LocaleCompare("undercolor",option+1) == 0)
7132 {
7133 if (*option == '+')
7134 {
7135 (void) DeleteImageOption(image_info,option+1);
7136 break;
7137 }
7138 (void) SetImageOption(image_info,option+1,argv[i+1]);
7139 break;
7140 }
7141 if (LocaleCompare("units",option+1) == 0)
7142 {
7143 if (*option == '+')
7144 {
7145 image_info->units=UndefinedResolution;
7146 (void) SetImageOption(image_info,option+1,"undefined");
7147 break;
7148 }
7149 image_info->units=(ResolutionType) ParseMagickOption(
7150 MagickResolutionOptions,MagickFalse,argv[i+1]);
7151 (void) SetImageOption(image_info,option+1,argv[i+1]);
7152 break;
7153 }
7154 break;
7155 }
7156 case 'v':
7157 {
7158 if (LocaleCompare("verbose",option+1) == 0)
7159 {
7160 if (*option == '+')
7161 {
7162 image_info->verbose=MagickFalse;
7163 break;
7164 }
7165 image_info->verbose=MagickTrue;
7166 image_info->ping=MagickFalse;
7167 break;
7168 }
7169 if (LocaleCompare("view",option+1) == 0)
7170 {
7171 if (*option == '+')
7172 {
7173 if (image_info->view != (char *) NULL)
7174 image_info->view=DestroyString(image_info->view);
7175 break;
7176 }
7177 (void) CloneString(&image_info->view,argv[i+1]);
7178 break;
7179 }
7180 if (LocaleCompare("virtual-pixel",option+1) == 0)
7181 {
7182 if (*option == '+')
7183 {
7184 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7185 (void) SetImageOption(image_info,option+1,"undefined");
7186 break;
7187 }
7188 image_info->virtual_pixel_method=(VirtualPixelMethod)
7189 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7190 argv[i+1]);
7191 (void) SetImageOption(image_info,option+1,argv[i+1]);
7192 break;
7193 }
7194 break;
7195 }
7196 case 'w':
7197 {
7198 if (LocaleCompare("white-point",option+1) == 0)
7199 {
7200 if (*option == '+')
7201 {
7202 (void) SetImageOption(image_info,option+1,"0.0");
7203 break;
7204 }
7205 (void) SetImageOption(image_info,option+1,argv[i+1]);
7206 break;
7207 }
7208 break;
7209 }
7210 default:
7211 break;
7212 }
7213 i+=count;
7214 }
7215 return(MagickTrue);
7216}
7217
7218/*
7219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7220% %
7221% %
7222% %
7223+ M o g r i f y I m a g e L i s t %
7224% %
7225% %
7226% %
7227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7228%
7229% MogrifyImageList() applies any command line options that might affect the
7230% entire image list (e.g. -append, -coalesce, etc.).
7231%
7232% The format of the MogrifyImage method is:
7233%
7234% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7235% const char **argv,Image **images,ExceptionInfo *exception)
7236%
7237% A description of each parameter follows:
7238%
7239% o image_info: the image info..
7240%
7241% o argc: Specifies a pointer to an integer describing the number of
7242% elements in the argument vector.
7243%
7244% o argv: Specifies a pointer to a text array containing the command line
7245% arguments.
7246%
anthonye9c27192011-03-27 08:07:06 +00007247% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007248%
7249% o exception: return any errors or warnings in this structure.
7250%
7251*/
7252WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7253 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7254{
7255 ChannelType
7256 channel;
7257
7258 const char
7259 *option;
7260
cristy6b3da3a2010-06-20 02:21:46 +00007261 ImageInfo
7262 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007263
7264 MagickStatusType
7265 status;
7266
7267 QuantizeInfo
7268 *quantize_info;
7269
cristybb503372010-05-27 20:51:26 +00007270 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007271 i;
7272
cristy6b3da3a2010-06-20 02:21:46 +00007273 ssize_t
7274 count,
7275 index;
7276
cristy3ed852e2009-09-05 21:47:34 +00007277 /*
7278 Apply options to the image list.
7279 */
7280 assert(image_info != (ImageInfo *) NULL);
7281 assert(image_info->signature == MagickSignature);
7282 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007283 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007284 assert((*images)->signature == MagickSignature);
7285 if ((*images)->debug != MagickFalse)
7286 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7287 (*images)->filename);
7288 if ((argc <= 0) || (*argv == (char *) NULL))
7289 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007290 mogrify_info=CloneImageInfo(image_info);
7291 quantize_info=AcquireQuantizeInfo(mogrify_info);
7292 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007293 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007294 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007295 {
cristy74fe8f12009-10-03 19:09:01 +00007296 if (*images == (Image *) NULL)
7297 break;
cristy3ed852e2009-09-05 21:47:34 +00007298 option=argv[i];
7299 if (IsMagickOption(option) == MagickFalse)
7300 continue;
7301 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7302 0L);
cristycee97112010-05-28 00:44:52 +00007303 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007304 break;
cristy6b3da3a2010-06-20 02:21:46 +00007305 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007306 switch (*(option+1))
7307 {
7308 case 'a':
7309 {
7310 if (LocaleCompare("affinity",option+1) == 0)
7311 {
cristy6b3da3a2010-06-20 02:21:46 +00007312 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007313 if (*option == '+')
7314 {
7315 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7316 InheritException(exception,&(*images)->exception);
7317 break;
7318 }
7319 i++;
7320 break;
7321 }
7322 if (LocaleCompare("append",option+1) == 0)
7323 {
7324 Image
7325 *append_image;
7326
cristy6b3da3a2010-06-20 02:21:46 +00007327 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007328 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7329 MagickFalse,exception);
7330 if (append_image == (Image *) NULL)
7331 {
7332 status=MagickFalse;
7333 break;
7334 }
7335 *images=DestroyImageList(*images);
7336 *images=append_image;
7337 break;
7338 }
7339 if (LocaleCompare("average",option+1) == 0)
7340 {
7341 Image
7342 *average_image;
7343
cristyd18ae7c2010-03-07 17:39:52 +00007344 /*
7345 Average an image sequence (deprecated).
7346 */
cristy6b3da3a2010-06-20 02:21:46 +00007347 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007348 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7349 exception);
cristy3ed852e2009-09-05 21:47:34 +00007350 if (average_image == (Image *) NULL)
7351 {
7352 status=MagickFalse;
7353 break;
7354 }
7355 *images=DestroyImageList(*images);
7356 *images=average_image;
7357 break;
7358 }
7359 break;
7360 }
7361 case 'c':
7362 {
7363 if (LocaleCompare("channel",option+1) == 0)
7364 {
7365 if (*option == '+')
7366 {
7367 channel=DefaultChannels;
7368 break;
7369 }
7370 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7371 break;
7372 }
7373 if (LocaleCompare("clut",option+1) == 0)
7374 {
7375 Image
7376 *clut_image,
7377 *image;
7378
cristy6b3da3a2010-06-20 02:21:46 +00007379 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007380 image=RemoveFirstImageFromList(images);
7381 clut_image=RemoveFirstImageFromList(images);
7382 if (clut_image == (Image *) NULL)
7383 {
7384 status=MagickFalse;
7385 break;
7386 }
7387 (void) ClutImageChannel(image,channel,clut_image);
7388 clut_image=DestroyImage(clut_image);
7389 InheritException(exception,&image->exception);
7390 *images=DestroyImageList(*images);
7391 *images=image;
7392 break;
7393 }
7394 if (LocaleCompare("coalesce",option+1) == 0)
7395 {
7396 Image
7397 *coalesce_image;
7398
cristy6b3da3a2010-06-20 02:21:46 +00007399 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007400 coalesce_image=CoalesceImages(*images,exception);
7401 if (coalesce_image == (Image *) NULL)
7402 {
7403 status=MagickFalse;
7404 break;
7405 }
7406 *images=DestroyImageList(*images);
7407 *images=coalesce_image;
7408 break;
7409 }
7410 if (LocaleCompare("combine",option+1) == 0)
7411 {
7412 Image
7413 *combine_image;
7414
cristy6b3da3a2010-06-20 02:21:46 +00007415 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007416 combine_image=CombineImages(*images,channel,exception);
7417 if (combine_image == (Image *) NULL)
7418 {
7419 status=MagickFalse;
7420 break;
7421 }
7422 *images=DestroyImageList(*images);
7423 *images=combine_image;
7424 break;
7425 }
7426 if (LocaleCompare("composite",option+1) == 0)
7427 {
7428 Image
7429 *mask_image,
7430 *composite_image,
7431 *image;
7432
7433 RectangleInfo
7434 geometry;
7435
cristy6b3da3a2010-06-20 02:21:46 +00007436 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007437 image=RemoveFirstImageFromList(images);
7438 composite_image=RemoveFirstImageFromList(images);
7439 if (composite_image == (Image *) NULL)
7440 {
7441 status=MagickFalse;
7442 break;
7443 }
7444 (void) TransformImage(&composite_image,(char *) NULL,
7445 composite_image->geometry);
7446 SetGeometry(composite_image,&geometry);
7447 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7448 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7449 &geometry);
7450 mask_image=RemoveFirstImageFromList(images);
7451 if (mask_image != (Image *) NULL)
7452 {
7453 if ((image->compose == DisplaceCompositeOp) ||
7454 (image->compose == DistortCompositeOp))
7455 {
7456 /*
7457 Merge Y displacement into X displacement image.
7458 */
7459 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7460 mask_image,0,0);
7461 mask_image=DestroyImage(mask_image);
7462 }
7463 else
7464 {
7465 /*
7466 Set a blending mask for the composition.
7467 */
7468 image->mask=mask_image;
7469 (void) NegateImage(image->mask,MagickFalse);
7470 }
7471 }
7472 (void) CompositeImageChannel(image,channel,image->compose,
7473 composite_image,geometry.x,geometry.y);
7474 if (image->mask != (Image *) NULL)
7475 image->mask=DestroyImage(image->mask);
7476 composite_image=DestroyImage(composite_image);
7477 InheritException(exception,&image->exception);
7478 *images=DestroyImageList(*images);
7479 *images=image;
7480 break;
7481 }
7482 if (LocaleCompare("crop",option+1) == 0)
7483 {
7484 MagickStatusType
7485 flags;
7486
7487 RectangleInfo
7488 geometry;
7489
anthonye9c27192011-03-27 08:07:06 +00007490 /*
7491 Crop Image (when offsets given - tile crop)
7492
7493 Note this does not include 'equal area division' which is
7494 flaged by a '@' symbol.
7495
7496 This could be merged completely into MogrifyImage()
7497 */
cristy6b3da3a2010-06-20 02:21:46 +00007498 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007499 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7500 if (((geometry.width == 0) && (geometry.height == 0)) ||
7501 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7502 break;
7503 (void) TransformImages(images,argv[i+1],(char *) NULL);
7504 InheritException(exception,&(*images)->exception);
7505 break;
7506 }
7507 break;
7508 }
7509 case 'd':
7510 {
7511 if (LocaleCompare("deconstruct",option+1) == 0)
7512 {
7513 Image
7514 *deconstruct_image;
7515
cristy6b3da3a2010-06-20 02:21:46 +00007516 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007517 deconstruct_image=DeconstructImages(*images,exception);
7518 if (deconstruct_image == (Image *) NULL)
7519 {
7520 status=MagickFalse;
7521 break;
7522 }
7523 *images=DestroyImageList(*images);
7524 *images=deconstruct_image;
7525 break;
7526 }
7527 if (LocaleCompare("delete",option+1) == 0)
7528 {
7529 if (*option == '+')
7530 DeleteImages(images,"-1",exception);
7531 else
7532 DeleteImages(images,argv[i+1],exception);
7533 break;
7534 }
7535 if (LocaleCompare("dither",option+1) == 0)
7536 {
7537 if (*option == '+')
7538 {
7539 quantize_info->dither=MagickFalse;
7540 break;
7541 }
7542 quantize_info->dither=MagickTrue;
7543 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7544 MagickDitherOptions,MagickFalse,argv[i+1]);
7545 break;
7546 }
cristyecb10ff2011-03-22 13:14:03 +00007547 if (LocaleCompare("duplicate",option+1) == 0)
7548 {
anthony2b6bcae2011-03-23 13:05:34 +00007549 Image *
7550 duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007551
anthony2b6bcae2011-03-23 13:05:34 +00007552 if (*option == '+')
7553 duplicate_images = DuplicateImages(*images,1,"-1",
7554 exception);
7555 else {
7556 size_t
7557 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007558
anthony2b6bcae2011-03-23 13:05:34 +00007559 char
7560 *p;
7561
7562 number_duplicates=(size_t) StringToLong(argv[i+1]);
7563 if ( (p=strchr(argv[i+1],',')) != (char *)NULL )
7564 duplicate_images = DuplicateImages(*images,
7565 number_duplicates,p,exception);
7566 else
7567 duplicate_images = DuplicateImages(*images,
7568 number_duplicates,"-1",exception);
7569 }
7570 AppendImageToList(images, duplicate_images);
7571 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007572 break;
7573 }
cristy3ed852e2009-09-05 21:47:34 +00007574 break;
7575 }
cristyd18ae7c2010-03-07 17:39:52 +00007576 case 'e':
7577 {
7578 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7579 {
7580 Image
7581 *evaluate_image;
7582
7583 MagickEvaluateOperator
7584 op;
7585
cristy6b3da3a2010-06-20 02:21:46 +00007586 (void) SyncImageSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007587 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7588 MagickFalse,argv[i+1]);
7589 evaluate_image=EvaluateImages(*images,op,exception);
7590 if (evaluate_image == (Image *) NULL)
7591 {
7592 status=MagickFalse;
7593 break;
7594 }
7595 *images=DestroyImageList(*images);
7596 *images=evaluate_image;
7597 break;
7598 }
7599 break;
7600 }
cristy3ed852e2009-09-05 21:47:34 +00007601 case 'f':
7602 {
cristyf0a247f2009-10-04 00:20:03 +00007603 if (LocaleCompare("fft",option+1) == 0)
7604 {
7605 Image
7606 *fourier_image;
7607
7608 /*
7609 Implements the discrete Fourier transform (DFT).
7610 */
cristy6b3da3a2010-06-20 02:21:46 +00007611 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007612 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7613 MagickTrue : MagickFalse,exception);
7614 if (fourier_image == (Image *) NULL)
7615 break;
7616 *images=DestroyImage(*images);
7617 *images=fourier_image;
7618 break;
7619 }
cristy3ed852e2009-09-05 21:47:34 +00007620 if (LocaleCompare("flatten",option+1) == 0)
7621 {
7622 Image
7623 *flatten_image;
7624
cristy6b3da3a2010-06-20 02:21:46 +00007625 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007626 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7627 if (flatten_image == (Image *) NULL)
7628 break;
7629 *images=DestroyImageList(*images);
7630 *images=flatten_image;
7631 break;
7632 }
7633 if (LocaleCompare("fx",option+1) == 0)
7634 {
7635 Image
7636 *fx_image;
7637
cristy6b3da3a2010-06-20 02:21:46 +00007638 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007639 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7640 if (fx_image == (Image *) NULL)
7641 {
7642 status=MagickFalse;
7643 break;
7644 }
7645 *images=DestroyImageList(*images);
7646 *images=fx_image;
7647 break;
7648 }
7649 break;
7650 }
7651 case 'h':
7652 {
7653 if (LocaleCompare("hald-clut",option+1) == 0)
7654 {
7655 Image
7656 *hald_image,
7657 *image;
7658
cristy6b3da3a2010-06-20 02:21:46 +00007659 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007660 image=RemoveFirstImageFromList(images);
7661 hald_image=RemoveFirstImageFromList(images);
7662 if (hald_image == (Image *) NULL)
7663 {
7664 status=MagickFalse;
7665 break;
7666 }
7667 (void) HaldClutImageChannel(image,channel,hald_image);
7668 hald_image=DestroyImage(hald_image);
7669 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007670 if (*images != (Image *) NULL)
7671 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007672 *images=image;
7673 break;
7674 }
7675 break;
7676 }
7677 case 'i':
7678 {
7679 if (LocaleCompare("ift",option+1) == 0)
7680 {
7681 Image
cristy8587f882009-11-13 20:28:49 +00007682 *fourier_image,
7683 *magnitude_image,
7684 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007685
7686 /*
7687 Implements the inverse fourier discrete Fourier transform (DFT).
7688 */
cristy6b3da3a2010-06-20 02:21:46 +00007689 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007690 magnitude_image=RemoveFirstImageFromList(images);
7691 phase_image=RemoveFirstImageFromList(images);
7692 if (phase_image == (Image *) NULL)
7693 {
7694 status=MagickFalse;
7695 break;
7696 }
7697 fourier_image=InverseFourierTransformImage(magnitude_image,
7698 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007699 if (fourier_image == (Image *) NULL)
7700 break;
cristy0aff6ea2009-11-14 01:40:53 +00007701 if (*images != (Image *) NULL)
7702 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007703 *images=fourier_image;
7704 break;
7705 }
7706 if (LocaleCompare("insert",option+1) == 0)
7707 {
7708 Image
7709 *p,
7710 *q;
7711
7712 index=0;
7713 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007714 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007715 p=RemoveLastImageFromList(images);
7716 if (p == (Image *) NULL)
7717 {
7718 (void) ThrowMagickException(exception,GetMagickModule(),
7719 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7720 status=MagickFalse;
7721 break;
7722 }
7723 q=p;
7724 if (index == 0)
7725 PrependImageToList(images,q);
7726 else
cristybb503372010-05-27 20:51:26 +00007727 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007728 AppendImageToList(images,q);
7729 else
7730 {
7731 q=GetImageFromList(*images,index-1);
7732 if (q == (Image *) NULL)
7733 {
7734 (void) ThrowMagickException(exception,GetMagickModule(),
7735 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7736 status=MagickFalse;
7737 break;
7738 }
7739 InsertImageInList(&q,p);
7740 }
7741 *images=GetFirstImageInList(q);
7742 break;
7743 }
7744 break;
7745 }
7746 case 'l':
7747 {
7748 if (LocaleCompare("layers",option+1) == 0)
7749 {
7750 Image
7751 *layers;
7752
7753 ImageLayerMethod
7754 method;
7755
cristy6b3da3a2010-06-20 02:21:46 +00007756 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007757 layers=(Image *) NULL;
7758 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7759 MagickFalse,argv[i+1]);
7760 switch (method)
7761 {
7762 case CoalesceLayer:
7763 {
7764 layers=CoalesceImages(*images,exception);
7765 break;
7766 }
7767 case CompareAnyLayer:
7768 case CompareClearLayer:
7769 case CompareOverlayLayer:
7770 default:
7771 {
7772 layers=CompareImageLayers(*images,method,exception);
7773 break;
7774 }
7775 case MergeLayer:
7776 case FlattenLayer:
7777 case MosaicLayer:
7778 case TrimBoundsLayer:
7779 {
7780 layers=MergeImageLayers(*images,method,exception);
7781 break;
7782 }
7783 case DisposeLayer:
7784 {
7785 layers=DisposeImages(*images,exception);
7786 break;
7787 }
7788 case OptimizeImageLayer:
7789 {
7790 layers=OptimizeImageLayers(*images,exception);
7791 break;
7792 }
7793 case OptimizePlusLayer:
7794 {
7795 layers=OptimizePlusImageLayers(*images,exception);
7796 break;
7797 }
7798 case OptimizeTransLayer:
7799 {
7800 OptimizeImageTransparency(*images,exception);
7801 break;
7802 }
7803 case RemoveDupsLayer:
7804 {
7805 RemoveDuplicateLayers(images,exception);
7806 break;
7807 }
7808 case RemoveZeroLayer:
7809 {
7810 RemoveZeroDelayLayers(images,exception);
7811 break;
7812 }
7813 case OptimizeLayer:
7814 {
7815 /*
7816 General Purpose, GIF Animation Optimizer.
7817 */
7818 layers=CoalesceImages(*images,exception);
7819 if (layers == (Image *) NULL)
7820 {
7821 status=MagickFalse;
7822 break;
7823 }
7824 InheritException(exception,&layers->exception);
7825 *images=DestroyImageList(*images);
7826 *images=layers;
7827 layers=OptimizeImageLayers(*images,exception);
7828 if (layers == (Image *) NULL)
7829 {
7830 status=MagickFalse;
7831 break;
7832 }
7833 InheritException(exception,&layers->exception);
7834 *images=DestroyImageList(*images);
7835 *images=layers;
7836 layers=(Image *) NULL;
7837 OptimizeImageTransparency(*images,exception);
7838 InheritException(exception,&(*images)->exception);
7839 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7840 break;
7841 }
7842 case CompositeLayer:
7843 {
7844 CompositeOperator
7845 compose;
7846
7847 Image
7848 *source;
7849
7850 RectangleInfo
7851 geometry;
7852
7853 /*
7854 Split image sequence at the first 'NULL:' image.
7855 */
7856 source=(*images);
7857 while (source != (Image *) NULL)
7858 {
7859 source=GetNextImageInList(source);
7860 if ((source != (Image *) NULL) &&
7861 (LocaleCompare(source->magick,"NULL") == 0))
7862 break;
7863 }
7864 if (source != (Image *) NULL)
7865 {
7866 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7867 (GetNextImageInList(source) == (Image *) NULL))
7868 source=(Image *) NULL;
7869 else
7870 {
7871 /*
7872 Separate the two lists, junk the null: image.
7873 */
7874 source=SplitImageList(source->previous);
7875 DeleteImageFromList(&source);
7876 }
7877 }
7878 if (source == (Image *) NULL)
7879 {
7880 (void) ThrowMagickException(exception,GetMagickModule(),
7881 OptionError,"MissingNullSeparator","layers Composite");
7882 status=MagickFalse;
7883 break;
7884 }
7885 /*
7886 Adjust offset with gravity and virtual canvas.
7887 */
7888 SetGeometry(*images,&geometry);
7889 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7890 geometry.width=source->page.width != 0 ?
7891 source->page.width : source->columns;
7892 geometry.height=source->page.height != 0 ?
7893 source->page.height : source->rows;
7894 GravityAdjustGeometry((*images)->page.width != 0 ?
7895 (*images)->page.width : (*images)->columns,
7896 (*images)->page.height != 0 ? (*images)->page.height :
7897 (*images)->rows,(*images)->gravity,&geometry);
7898 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007899 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007900 if (option != (const char *) NULL)
7901 compose=(CompositeOperator) ParseMagickOption(
7902 MagickComposeOptions,MagickFalse,option);
7903 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7904 exception);
7905 source=DestroyImageList(source);
7906 break;
7907 }
7908 }
7909 if (layers == (Image *) NULL)
7910 break;
7911 InheritException(exception,&layers->exception);
7912 *images=DestroyImageList(*images);
7913 *images=layers;
7914 break;
7915 }
7916 break;
7917 }
7918 case 'm':
7919 {
7920 if (LocaleCompare("map",option+1) == 0)
7921 {
cristy6b3da3a2010-06-20 02:21:46 +00007922 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007923 if (*option == '+')
7924 {
7925 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7926 InheritException(exception,&(*images)->exception);
7927 break;
7928 }
7929 i++;
7930 break;
7931 }
cristyf40785b2010-03-06 02:27:27 +00007932 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007933 {
7934 Image
cristyf40785b2010-03-06 02:27:27 +00007935 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007936
cristyd18ae7c2010-03-07 17:39:52 +00007937 /*
7938 Maximum image sequence (deprecated).
7939 */
cristy6b3da3a2010-06-20 02:21:46 +00007940 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007941 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007942 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007943 {
7944 status=MagickFalse;
7945 break;
7946 }
7947 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007948 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007949 break;
7950 }
cristyf40785b2010-03-06 02:27:27 +00007951 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007952 {
7953 Image
cristyf40785b2010-03-06 02:27:27 +00007954 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007955
cristyd18ae7c2010-03-07 17:39:52 +00007956 /*
7957 Minimum image sequence (deprecated).
7958 */
cristy6b3da3a2010-06-20 02:21:46 +00007959 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007960 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007961 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007962 {
7963 status=MagickFalse;
7964 break;
7965 }
7966 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007967 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007968 break;
7969 }
cristy3ed852e2009-09-05 21:47:34 +00007970 if (LocaleCompare("morph",option+1) == 0)
7971 {
7972 Image
7973 *morph_image;
7974
cristy6b3da3a2010-06-20 02:21:46 +00007975 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007976 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007977 exception);
7978 if (morph_image == (Image *) NULL)
7979 {
7980 status=MagickFalse;
7981 break;
7982 }
7983 *images=DestroyImageList(*images);
7984 *images=morph_image;
7985 break;
7986 }
7987 if (LocaleCompare("mosaic",option+1) == 0)
7988 {
7989 Image
7990 *mosaic_image;
7991
cristy6b3da3a2010-06-20 02:21:46 +00007992 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007993 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7994 if (mosaic_image == (Image *) NULL)
7995 {
7996 status=MagickFalse;
7997 break;
7998 }
7999 *images=DestroyImageList(*images);
8000 *images=mosaic_image;
8001 break;
8002 }
8003 break;
8004 }
8005 case 'p':
8006 {
8007 if (LocaleCompare("print",option+1) == 0)
8008 {
8009 char
8010 *string;
8011
cristy6b3da3a2010-06-20 02:21:46 +00008012 (void) SyncImagesSettings(mogrify_info,*images);
8013 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008014 if (string == (char *) NULL)
8015 break;
8016 InheritException(exception,&(*images)->exception);
8017 (void) fprintf(stdout,"%s",string);
8018 string=DestroyString(string);
8019 }
8020 if (LocaleCompare("process",option+1) == 0)
8021 {
8022 char
8023 **arguments;
8024
8025 int
8026 j,
8027 number_arguments;
8028
cristy6b3da3a2010-06-20 02:21:46 +00008029 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008030 arguments=StringToArgv(argv[i+1],&number_arguments);
8031 if (arguments == (char **) NULL)
8032 break;
8033 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8034 {
8035 char
8036 breaker,
8037 quote,
8038 *token;
8039
8040 const char
8041 *arguments;
8042
8043 int
8044 next,
8045 status;
8046
8047 size_t
8048 length;
8049
8050 TokenInfo
8051 *token_info;
8052
8053 /*
8054 Support old style syntax, filter="-option arg".
8055 */
8056 length=strlen(argv[i+1]);
8057 token=(char *) NULL;
8058 if (~length >= MaxTextExtent)
8059 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8060 sizeof(*token));
8061 if (token == (char *) NULL)
8062 break;
8063 next=0;
8064 arguments=argv[i+1];
8065 token_info=AcquireTokenInfo();
8066 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8067 "\"",'\0',&breaker,&next,&quote);
8068 token_info=DestroyTokenInfo(token_info);
8069 if (status == 0)
8070 {
8071 const char
8072 *argv;
8073
8074 argv=(&(arguments[next]));
8075 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8076 exception);
8077 }
8078 token=DestroyString(token);
8079 break;
8080 }
cristy91c0da22010-05-02 01:44:07 +00008081 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008082 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8083 number_arguments-2,(const char **) arguments+2,exception);
8084 for (j=0; j < number_arguments; j++)
8085 arguments[j]=DestroyString(arguments[j]);
8086 arguments=(char **) RelinquishMagickMemory(arguments);
8087 break;
8088 }
8089 break;
8090 }
8091 case 'r':
8092 {
8093 if (LocaleCompare("reverse",option+1) == 0)
8094 {
8095 ReverseImageList(images);
8096 InheritException(exception,&(*images)->exception);
8097 break;
8098 }
8099 break;
8100 }
8101 case 's':
8102 {
cristy4285d782011-02-09 20:12:28 +00008103 if (LocaleCompare("smush",option+1) == 0)
8104 {
8105 Image
8106 *smush_image;
8107
8108 ssize_t
8109 offset;
8110
8111 (void) SyncImagesSettings(mogrify_info,*images);
8112 offset=(ssize_t) StringToLong(argv[i+1]);
8113 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8114 MagickFalse,offset,exception);
8115 if (smush_image == (Image *) NULL)
8116 {
8117 status=MagickFalse;
8118 break;
8119 }
8120 *images=DestroyImageList(*images);
8121 *images=smush_image;
8122 break;
8123 }
cristy3ed852e2009-09-05 21:47:34 +00008124 if (LocaleCompare("swap",option+1) == 0)
8125 {
8126 Image
8127 *p,
8128 *q,
8129 *swap;
8130
cristybb503372010-05-27 20:51:26 +00008131 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008132 swap_index;
8133
8134 index=(-1);
8135 swap_index=(-2);
8136 if (*option != '+')
8137 {
8138 GeometryInfo
8139 geometry_info;
8140
8141 MagickStatusType
8142 flags;
8143
8144 swap_index=(-1);
8145 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008146 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008147 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008148 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008149 }
8150 p=GetImageFromList(*images,index);
8151 q=GetImageFromList(*images,swap_index);
8152 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8153 {
8154 (void) ThrowMagickException(exception,GetMagickModule(),
8155 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8156 status=MagickFalse;
8157 break;
8158 }
8159 if (p == q)
8160 break;
8161 swap=CloneImage(p,0,0,MagickTrue,exception);
8162 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8163 ReplaceImageInList(&q,swap);
8164 *images=GetFirstImageInList(q);
8165 break;
8166 }
8167 break;
8168 }
8169 case 'w':
8170 {
8171 if (LocaleCompare("write",option+1) == 0)
8172 {
cristy071dd7b2010-04-09 13:04:54 +00008173 char
cristy06609ee2010-03-17 20:21:27 +00008174 key[MaxTextExtent];
8175
cristy3ed852e2009-09-05 21:47:34 +00008176 Image
8177 *write_images;
8178
8179 ImageInfo
8180 *write_info;
8181
cristy6b3da3a2010-06-20 02:21:46 +00008182 (void) SyncImagesSettings(mogrify_info,*images);
cristy06609ee2010-03-17 20:21:27 +00008183 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8184 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008185 write_images=(*images);
8186 if (*option == '+')
8187 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008188 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008189 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8190 write_info=DestroyImageInfo(write_info);
8191 if (*option == '+')
8192 write_images=DestroyImageList(write_images);
8193 break;
8194 }
8195 break;
8196 }
8197 default:
8198 break;
8199 }
8200 i+=count;
8201 }
8202 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008203 mogrify_info=DestroyImageInfo(mogrify_info);
8204 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008205 return(status != 0 ? MagickTrue : MagickFalse);
8206}
8207
8208/*
8209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8210% %
8211% %
8212% %
8213+ M o g r i f y I m a g e s %
8214% %
8215% %
8216% %
8217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8218%
8219% MogrifyImages() applies image processing options to a sequence of images as
8220% prescribed by command line options.
8221%
8222% The format of the MogrifyImage method is:
8223%
8224% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8225% const MagickBooleanType post,const int argc,const char **argv,
8226% Image **images,Exceptioninfo *exception)
8227%
8228% A description of each parameter follows:
8229%
8230% o image_info: the image info..
8231%
8232% o post: If true, post process image list operators otherwise pre-process.
8233%
8234% o argc: Specifies a pointer to an integer describing the number of
8235% elements in the argument vector.
8236%
8237% o argv: Specifies a pointer to a text array containing the command line
8238% arguments.
8239%
anthonye9c27192011-03-27 08:07:06 +00008240% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008241%
8242% o exception: return any errors or warnings in this structure.
8243%
8244*/
8245WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8246 const MagickBooleanType post,const int argc,const char **argv,
8247 Image **images,ExceptionInfo *exception)
8248{
8249#define MogrifyImageTag "Mogrify/Image"
8250
anthonye9c27192011-03-27 08:07:06 +00008251 MagickStatusType
8252 status;
cristy3ed852e2009-09-05 21:47:34 +00008253
cristy0e9f9c12010-02-11 03:00:47 +00008254 MagickBooleanType
8255 proceed;
8256
anthonye9c27192011-03-27 08:07:06 +00008257 size_t
8258 n;
cristy3ed852e2009-09-05 21:47:34 +00008259
cristybb503372010-05-27 20:51:26 +00008260 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008261 i;
8262
cristy3ed852e2009-09-05 21:47:34 +00008263 assert(image_info != (ImageInfo *) NULL);
8264 assert(image_info->signature == MagickSignature);
8265 if (images == (Image **) NULL)
8266 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008267 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008268 assert((*images)->signature == MagickSignature);
8269 if ((*images)->debug != MagickFalse)
8270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8271 (*images)->filename);
8272 if ((argc <= 0) || (*argv == (char *) NULL))
8273 return(MagickTrue);
8274 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8275 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008276 status=0;
anthonye9c27192011-03-27 08:07:06 +00008277
8278 /*
8279 Pre-process multi-image sequence operators
8280 */
cristy3ed852e2009-09-05 21:47:34 +00008281 if (post == MagickFalse)
8282 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008283
8284 /*
8285 For each image, process simple single image operators
8286 */
8287 i=0;
8288 n=GetImageListLength(*images);
8289 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008290 {
anthonye9c27192011-03-27 08:07:06 +00008291 status&=MogrifyImage(image_info,argc,argv,images,exception);
8292 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008293 if (proceed == MagickFalse)
8294 break;
anthonye9c27192011-03-27 08:07:06 +00008295 if ( (*images)->next == (Image *) NULL )
8296 break;
8297 *images=(*images)->next;
8298 i++;
cristy3ed852e2009-09-05 21:47:34 +00008299 }
anthonye9c27192011-03-27 08:07:06 +00008300 assert( *images != (Image *) NULL );
8301
8302 /*
8303 Post-process, multi-image sequence operators
8304 */
8305 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008306 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008307 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008308 return(status != 0 ? MagickTrue : MagickFalse);
8309}