blob: 236837ef8209a7a35329f9b57e803b6eeb1ece47 [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% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 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% %
cristy3980b0d2009-10-25 14:37:13 +000072+ M a g i c k C o m m a n d G e n e s i s %
73% %
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,
84% MagickCommand command,const int argc,const char **argv,Image **image)
85%
86% A description of each parameter follows:
87%
88% o image_info: the image info.
89%
90% o command: the magick command.
91%
92% o argc: Specifies a pointer to an integer describing the number of
93% elements in the argument vector.
94%
95% o argv: Specifies a pointer to a text array containing the command line
96% arguments.
97%
98% o image: the image.
99%
100% o exception: return any errors or warnings in this structure.
101%
102*/
103WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
104 MagickCommand command,int argc,char **argv,char **metadata,
105 ExceptionInfo *exception)
106{
107 char
108 *option;
109
110 double
111 duration,
112 elapsed_time,
113 user_time;
114
cristy3980b0d2009-10-25 14:37:13 +0000115 MagickBooleanType
116 concurrent,
117 regard_warnings,
118 status;
119
120 register long
121 i;
122
123 TimerInfo
124 *timer;
125
126 unsigned long
127 iterations;
128
cristyd0a94fa2010-03-12 14:18:11 +0000129 (void) setlocale(LC_ALL,"");
130 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000131 concurrent=MagickFalse;
132 duration=(-1.0);
133 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000134 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000135 regard_warnings=MagickFalse;
136 for (i=1; i < (long) (argc-1); i++)
137 {
138 option=argv[i];
139 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
140 continue;
141 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000142 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000143 if (LocaleCompare("concurrent",option+1) == 0)
144 concurrent=MagickTrue;
145 if (LocaleCompare("debug",option+1) == 0)
146 (void) SetLogEventMask(argv[++i]);
147 if (LocaleCompare("duration",option+1) == 0)
cristyf2f27272009-12-17 14:48:46 +0000148 duration=StringToDouble(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000149 if (LocaleCompare("regard-warnings",option+1) == 0)
150 regard_warnings=MagickTrue;
151 }
152 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000153 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000154 {
cristyceae09d2009-10-28 17:18:47 +0000155 for (i=0; i < (long) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000156 {
cristy33557d72009-11-06 00:54:33 +0000157 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000158 continue;
159 if (duration > 0)
160 {
161 if (GetElapsedTime(timer) > duration)
162 continue;
163 (void) ContinueTimer(timer);
164 }
165 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000166 if (exception->severity != UndefinedException)
167 {
168 if ((exception->severity > ErrorException) ||
169 (regard_warnings != MagickFalse))
170 status=MagickTrue;
171 CatchException(exception);
172 }
cristy3d1a5512009-10-25 21:23:27 +0000173 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000174 {
175 (void) fputs(*metadata,stdout);
176 (void) fputc('\n',stdout);
177 *metadata=DestroyString(*metadata);
178 }
179 }
180 }
cristyceae09d2009-10-28 17:18:47 +0000181 else
182 {
183 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000184#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000185 # pragma omp parallel for shared(status)
186#endif
187 for (i=0; i < (long) iterations; i++)
188 {
cristy33557d72009-11-06 00:54:33 +0000189 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000190 continue;
191 if (duration > 0)
192 {
193 if (GetElapsedTime(timer) > duration)
194 continue;
195 (void) ContinueTimer(timer);
196 }
197 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000198#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000199 # pragma omp critical (MagickCore_Launch_Command)
200#endif
201 {
202 if (exception->severity != UndefinedException)
203 {
204 if ((exception->severity > ErrorException) ||
205 (regard_warnings != MagickFalse))
206 status=MagickTrue;
207 CatchException(exception);
208 }
209 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
210 {
211 (void) fputs(*metadata,stdout);
212 (void) fputc('\n',stdout);
213 *metadata=DestroyString(*metadata);
214 }
215 }
216 }
217 }
cristy3980b0d2009-10-25 14:37:13 +0000218 if (iterations > 1)
219 {
220 elapsed_time=GetElapsedTime(timer);
221 user_time=GetUserTime(timer);
cristy8cd5b312010-01-07 01:10:24 +0000222 (void) fprintf(stderr,
cristye7f51092010-01-17 00:39:37 +0000223 "Performance: %lui %gips %0.3fu %ld:%02ld.%03ld\n",
cristy3980b0d2009-10-25 14:37:13 +0000224 iterations,1.0*iterations/elapsed_time,user_time,(long)
225 (elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
226 (long) (1000.0*(elapsed_time-floor(elapsed_time))));
227 }
228 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000229 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000230}
231
232/*
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234% %
235% %
236% %
cristy3ed852e2009-09-05 21:47:34 +0000237+ M o g r i f y I m a g e %
238% %
239% %
240% %
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242%
243% MogrifyImage() applies image processing options to an image as prescribed
244% by command line options.
245%
246% The format of the MogrifyImage method is:
247%
248% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
249% const char **argv,Image **image)
250%
251% A description of each parameter follows:
252%
253% o image_info: the image info..
254%
255% o argc: Specifies a pointer to an integer describing the number of
256% elements in the argument vector.
257%
258% o argv: Specifies a pointer to a text array containing the command line
259% arguments.
260%
261% o image: the image.
262%
263% o exception: return any errors or warnings in this structure.
264%
265*/
266
267static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
268 ExceptionInfo *exception)
269{
270 char
271 key[MaxTextExtent];
272
273 ExceptionInfo
274 *sans_exception;
275
276 Image
277 *image;
278
279 ImageInfo
280 *read_info;
281
282 (void) FormatMagickString(key,MaxTextExtent,"cache:%s",path);
283 sans_exception=AcquireExceptionInfo();
284 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
285 sans_exception=DestroyExceptionInfo(sans_exception);
286 if (image != (Image *) NULL)
287 return(image);
288 read_info=CloneImageInfo(image_info);
289 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
290 image=ReadImage(read_info,exception);
291 read_info=DestroyImageInfo(read_info);
292 if (image != (Image *) NULL)
293 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
294 return(image);
295}
296
297static int IsPathDirectory(const char *path)
298{
299 MagickBooleanType
300 status;
301
302 struct stat
303 attributes;
304
305 if ((path == (const char *) NULL) || (*path == '\0'))
306 return(MagickFalse);
307 status=GetPathAttributes(path,&attributes);
308 if (status == MagickFalse)
309 return(-1);
310 if (S_ISDIR(attributes.st_mode) == 0)
311 return(0);
312 return(1);
313}
314
315static MagickBooleanType IsPathWritable(const char *path)
316{
317 if (IsPathAccessible(path) == MagickFalse)
318 return(MagickFalse);
319 if (access(path,W_OK) != 0)
320 return(MagickFalse);
321 return(MagickTrue);
322}
323
324static inline long MagickMax(const long x,const long y)
325{
326 if (x > y)
327 return(x);
328 return(y);
329}
330
331static MagickBooleanType MonitorProgress(const char *text,
cristyb32b90a2009-09-07 21:45:48 +0000332 const MagickOffsetType offset,const MagickSizeType extent,
cristy3ed852e2009-09-05 21:47:34 +0000333 void *wand_unused(client_data))
334{
335 char
336 message[MaxTextExtent],
337 tag[MaxTextExtent];
338
339 const char
340 *locale_message;
341
342 register char
343 *p;
344
cristyb32b90a2009-09-07 21:45:48 +0000345 if (extent < 2)
cristy3ed852e2009-09-05 21:47:34 +0000346 return(MagickTrue);
347 (void) CopyMagickMemory(tag,text,MaxTextExtent);
348 p=strrchr(tag,'/');
349 if (p != (char *) NULL)
350 *p='\0';
351 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
352 locale_message=GetLocaleMessage(message);
353 if (locale_message == message)
354 locale_message=tag;
355 if (p == (char *) NULL)
cristyb32b90a2009-09-07 21:45:48 +0000356 (void) fprintf(stderr,"%s: %ld of %lu, %02ld%% complete\r",locale_message,
357 (long) offset,(unsigned long) extent,(long) (100L*offset/(extent-1)));
cristy3ed852e2009-09-05 21:47:34 +0000358 else
cristyb32b90a2009-09-07 21:45:48 +0000359 (void) fprintf(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
360 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
361 (100L*offset/(extent-1)));
362 if (offset == (MagickOffsetType) (extent-1))
cristy3ed852e2009-09-05 21:47:34 +0000363 (void) fprintf(stderr,"\n");
364 (void) fflush(stderr);
365 return(MagickTrue);
366}
367
368static Image *SparseColorOption(const Image *image,const ChannelType channel,
369 const SparseColorMethod method,const char *arguments,
370 const MagickBooleanType color_from_image,ExceptionInfo *exception)
371{
372 ChannelType
373 channels;
374
375 char
376 token[MaxTextExtent];
377
378 const char
379 *p;
380
381 double
382 *sparse_arguments;
383
384 register unsigned long
385 x;
386
387 unsigned long
388 number_arguments;
389
390 unsigned long
391 number_colors;
392
393 Image
394 *sparse_image;
395
396 MagickPixelPacket
397 color;
398
399 MagickBooleanType
400 error;
401
402 assert(image != (Image *) NULL);
403 assert(image->signature == MagickSignature);
404 if (image->debug != MagickFalse)
405 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
406 assert(exception != (ExceptionInfo *) NULL);
407 assert(exception->signature == MagickSignature);
408 /*
409 Limit channels according to image - and add up number of color channel.
410 */
411 channels=channel;
412 if (image->colorspace != CMYKColorspace)
413 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
414 if (image->matte == MagickFalse)
415 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
416 number_colors=0;
417 if ((channels & RedChannel) != 0)
418 number_colors++;
419 if ((channels & GreenChannel) != 0)
420 number_colors++;
421 if ((channels & BlueChannel) != 0)
422 number_colors++;
423 if ((channels & IndexChannel) != 0)
424 number_colors++;
425 if ((channels & OpacityChannel) != 0)
426 number_colors++;
427 /*
428 Read string, to determine number of arguments needed,
429 */
430 p=arguments;
431 x=0;
432 while( *p != '\0' )
433 {
434 GetMagickToken(p,&p,token);
435 if ( token[0] == ',' ) continue;
436 if ( isalpha((int) token[0]) || token[0] == '#' ) {
437 if ( color_from_image ) {
438 (void) ThrowMagickException(exception,GetMagickModule(),
439 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
440 "Color arg given, when colors are coming from image");
441 return( (Image *)NULL);
442 }
443 x += number_colors; /* color argument */
444 }
445 else {
446 x++; /* floating point argument */
447 }
448 }
449 error=MagickTrue;
450 if ( color_from_image ) {
451 /* just the control points are being given */
452 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
453 number_arguments=(x/2)*(2+number_colors);
454 }
455 else {
456 /* control points and color values */
457 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
458 number_arguments=x;
459 }
460 if ( error ) {
461 (void) ThrowMagickException(exception,GetMagickModule(),
462 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
463 "Invalid number of Arguments");
464 return( (Image *)NULL);
465 }
466
467 /* Allocate and fill in the floating point arguments */
468 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
469 sizeof(*sparse_arguments));
470 if (sparse_arguments == (double *) NULL) {
471 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
472 "MemoryAllocationFailed","%s","SparseColorOption");
473 return( (Image *)NULL);
474 }
475 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
476 sizeof(*sparse_arguments));
477 p=arguments;
478 x=0;
479 while( *p != '\0' && x < number_arguments ) {
480 /* X coordinate */
481 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
482 if ( token[0] == '\0' ) break;
483 if ( isalpha((int) token[0]) || token[0] == '#' ) {
484 (void) ThrowMagickException(exception,GetMagickModule(),
485 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
486 "Color found, instead of X-coord");
487 error = MagickTrue;
488 break;
489 }
cristyf2f27272009-12-17 14:48:46 +0000490 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000491 /* Y coordinate */
492 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
493 if ( token[0] == '\0' ) break;
494 if ( isalpha((int) token[0]) || token[0] == '#' ) {
495 (void) ThrowMagickException(exception,GetMagickModule(),
496 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
497 "Color found, instead of Y-coord");
498 error = MagickTrue;
499 break;
500 }
cristyf2f27272009-12-17 14:48:46 +0000501 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000502 /* color values for this control point */
503#if 0
504 if ( (color_from_image ) {
505 /* get color from image */
506 /* HOW??? */
507 }
508 else
509#endif
510 {
511 /* color name or function given in string argument */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 /* Color string given */
516 (void) QueryMagickColor(token,&color,exception);
517 if ( channels & RedChannel )
518 sparse_arguments[x++] = QuantumScale*color.red;
519 if ( channels & GreenChannel )
520 sparse_arguments[x++] = QuantumScale*color.green;
521 if ( channels & BlueChannel )
522 sparse_arguments[x++] = QuantumScale*color.blue;
523 if ( channels & IndexChannel )
524 sparse_arguments[x++] = QuantumScale*color.index;
525 if ( channels & OpacityChannel )
526 sparse_arguments[x++] = QuantumScale*color.opacity;
527 }
528 else {
529#if 0
530 /* the color name/function/value was not found - error */
531 break;
532#else
533 /* Colors given as a set of floating point values - experimental */
534 /* NB: token contains the first floating point value to use! */
535 if ( channels & RedChannel ) {
536 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
537 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
538 break;
cristy0f19e682009-12-17 14:55:51 +0000539 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000540 token[0] = ','; /* used this token - get another */
541 }
542 if ( channels & GreenChannel ) {
543 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
544 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
545 break;
cristy0f19e682009-12-17 14:55:51 +0000546 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000547 token[0] = ','; /* used this token - get another */
548 }
549 if ( channels & BlueChannel ) {
550 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
551 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
552 break;
cristy0f19e682009-12-17 14:55:51 +0000553 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000554 token[0] = ','; /* used this token - get another */
555 }
556 if ( channels & IndexChannel ) {
557 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
558 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
559 break;
cristy0f19e682009-12-17 14:55:51 +0000560 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000561 token[0] = ','; /* used this token - get another */
562 }
563 if ( channels & OpacityChannel ) {
564 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
565 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
566 break;
cristy0f19e682009-12-17 14:55:51 +0000567 sparse_arguments[x++]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +0000568 token[0] = ','; /* used this token - get another */
569 }
570#endif
571 }
572 }
573 }
574 if ( number_arguments != x && !error ) {
575 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
576 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
577 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
578 return( (Image *)NULL);
579 }
580 if ( error )
581 return( (Image *)NULL);
582
583 /* Call the Interpolation function with the parsed arguments */
584 sparse_image=SparseColorImage(image,channels,method,number_arguments,
585 sparse_arguments,exception);
586 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
587 return( sparse_image );
588}
589
590WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
591 const char **argv,Image **image,ExceptionInfo *exception)
592{
593 ChannelType
594 channel;
595
596 const char
597 *format,
598 *option;
599
600 DrawInfo
601 *draw_info;
602
603 GeometryInfo
604 geometry_info;
605
606 Image
607 *region_image;
608
609 long
610 count;
611
612 MagickBooleanType
613 status;
614
615 MagickPixelPacket
616 fill;
617
618 MagickStatusType
619 flags;
620
621 QuantizeInfo
622 *quantize_info;
623
624 RectangleInfo
625 geometry,
626 region_geometry;
627
628 register long
629 i;
630
631 /*
632 Initialize method variables.
633 */
634 assert(image_info != (const ImageInfo *) NULL);
635 assert(image_info->signature == MagickSignature);
636 assert(image != (Image **) NULL);
637 assert((*image)->signature == MagickSignature);
638 if ((*image)->debug != MagickFalse)
639 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
640 if (argc < 0)
641 return(MagickTrue);
642 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
643 quantize_info=AcquireQuantizeInfo(image_info);
644 SetGeometryInfo(&geometry_info);
645 GetMagickPixelPacket(*image,&fill);
646 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
647 &fill);
648 channel=image_info->channel;
649 format=GetImageOption(image_info,"format");
650 SetGeometry(*image,&region_geometry);
651 region_image=NewImageList();
652 /*
653 Transmogrify the image.
654 */
655 for (i=0; i < (long) argc; i++)
656 {
657 option=argv[i];
658 if (IsMagickOption(option) == MagickFalse)
659 continue;
660 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
661 0L);
662 if ((i+count) >= argc)
663 break;
664 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
665 switch (*(option+1))
666 {
667 case 'a':
668 {
669 if (LocaleCompare("adaptive-blur",option+1) == 0)
670 {
671 Image
672 *blur_image;
673
674 /*
675 Adaptive blur image.
676 */
677 (void) SyncImageSettings(image_info,*image);
678 flags=ParseGeometry(argv[i+1],&geometry_info);
679 if ((flags & SigmaValue) == 0)
680 geometry_info.sigma=1.0;
681 blur_image=AdaptiveBlurImageChannel(*image,channel,
682 geometry_info.rho,geometry_info.sigma,exception);
683 if (blur_image == (Image *) NULL)
684 break;
685 *image=DestroyImage(*image);
686 *image=blur_image;
687 break;
688 }
689 if (LocaleCompare("adaptive-resize",option+1) == 0)
690 {
691 Image
692 *resize_image;
693
694 /*
695 Adaptive resize image.
696 */
697 (void) SyncImageSettings(image_info,*image);
698 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
699 resize_image=AdaptiveResizeImage(*image,geometry.width,
700 geometry.height,exception);
701 if (resize_image == (Image *) NULL)
702 break;
703 *image=DestroyImage(*image);
704 *image=resize_image;
705 break;
706 }
707 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
708 {
709 Image
710 *sharp_image;
711
712 /*
713 Adaptive sharpen image.
714 */
715 (void) SyncImageSettings(image_info,*image);
716 flags=ParseGeometry(argv[i+1],&geometry_info);
717 if ((flags & SigmaValue) == 0)
718 geometry_info.sigma=1.0;
719 sharp_image=AdaptiveSharpenImageChannel(*image,channel,
720 geometry_info.rho,geometry_info.sigma,exception);
721 if (sharp_image == (Image *) NULL)
722 break;
723 *image=DestroyImage(*image);
724 *image=sharp_image;
725 break;
726 }
727 if (LocaleCompare("affine",option+1) == 0)
728 {
729 /*
730 Affine matrix.
731 */
732 if (*option == '+')
733 {
734 GetAffineMatrix(&draw_info->affine);
735 break;
736 }
737 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
738 break;
739 }
740 if (LocaleCompare("alpha",option+1) == 0)
741 {
742 AlphaChannelType
743 alpha_type;
744
745 (void) SyncImageSettings(image_info,*image);
746 alpha_type=(AlphaChannelType) ParseMagickOption(MagickAlphaOptions,
747 MagickFalse,argv[i+1]);
748 (void) SetImageAlphaChannel(*image,alpha_type);
749 InheritException(exception,&(*image)->exception);
750 break;
751 }
752 if (LocaleCompare("annotate",option+1) == 0)
753 {
754 char
755 *text,
756 geometry[MaxTextExtent];
757
758 /*
759 Annotate image.
760 */
761 (void) SyncImageSettings(image_info,*image);
762 SetGeometryInfo(&geometry_info);
763 flags=ParseGeometry(argv[i+1],&geometry_info);
764 if ((flags & SigmaValue) == 0)
765 geometry_info.sigma=geometry_info.rho;
766 text=InterpretImageProperties(image_info,*image,argv[i+2]);
767 InheritException(exception,&(*image)->exception);
768 if (text == (char *) NULL)
769 break;
770 (void) CloneString(&draw_info->text,text);
771 text=DestroyString(text);
772 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
773 geometry_info.xi,geometry_info.psi);
774 (void) CloneString(&draw_info->geometry,geometry);
775 draw_info->affine.sx=cos(DegreesToRadians(
776 fmod(geometry_info.rho,360.0)));
777 draw_info->affine.rx=sin(DegreesToRadians(
778 fmod(geometry_info.rho,360.0)));
779 draw_info->affine.ry=(-sin(DegreesToRadians(
780 fmod(geometry_info.sigma,360.0))));
781 draw_info->affine.sy=cos(DegreesToRadians(
782 fmod(geometry_info.sigma,360.0)));
783 (void) AnnotateImage(*image,draw_info);
784 InheritException(exception,&(*image)->exception);
785 break;
786 }
787 if (LocaleCompare("antialias",option+1) == 0)
788 {
789 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
790 MagickFalse;
791 draw_info->text_antialias=(*option == '-') ? MagickTrue :
792 MagickFalse;
793 break;
794 }
795 if (LocaleCompare("auto-gamma",option+1) == 0)
796 {
797 /*
798 Auto Adjust Gamma of image based on its mean
799 */
800 (void) SyncImageSettings(image_info,*image);
801 (void) AutoGammaImageChannel(*image,channel);
802 break;
803 }
804 if (LocaleCompare("auto-level",option+1) == 0)
805 {
806 /*
807 Perfectly Normalize (max/min stretch) the image
808 */
809 (void) SyncImageSettings(image_info,*image);
810 (void) AutoLevelImageChannel(*image,channel);
811 break;
812 }
813 if (LocaleCompare("auto-orient",option+1) == 0)
814 {
815 Image
816 *orient_image;
817
818 (void) SyncImageSettings(image_info,*image);
819 orient_image=NewImageList();
820 switch ((*image)->orientation)
821 {
822 case TopRightOrientation:
823 {
824 orient_image=FlopImage(*image,exception);
825 break;
826 }
827 case BottomRightOrientation:
828 {
829 orient_image=RotateImage(*image,180.0,exception);
830 break;
831 }
832 case BottomLeftOrientation:
833 {
834 orient_image=FlipImage(*image,exception);
835 break;
836 }
837 case LeftTopOrientation:
838 {
839 orient_image=TransposeImage(*image,exception);
840 break;
841 }
842 case RightTopOrientation:
843 {
844 orient_image=RotateImage(*image,90.0,exception);
845 break;
846 }
847 case RightBottomOrientation:
848 {
849 orient_image=TransverseImage(*image,exception);
850 break;
851 }
852 case LeftBottomOrientation:
853 {
854 orient_image=RotateImage(*image,270.0,exception);
855 break;
856 }
857 default:
858 break;
859 }
860 if (orient_image == (Image *) NULL)
861 break;
862 orient_image->orientation=TopLeftOrientation;
863 *image=DestroyImage(*image);
864 *image=orient_image;
865 break;
866 }
867 break;
868 }
869 case 'b':
870 {
871 if (LocaleCompare("black-threshold",option+1) == 0)
872 {
873 /*
874 Black threshold image.
875 */
876 (void) SyncImageSettings(image_info,*image);
877 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
878 exception);
879 InheritException(exception,&(*image)->exception);
880 break;
881 }
882 if (LocaleCompare("blue-shift",option+1) == 0)
883 {
884 Image
885 *shift_image;
886
887 /*
888 Blue shift image.
889 */
890 (void) SyncImageSettings(image_info,*image);
891 geometry_info.rho=1.5;
892 if (*option == '-')
893 flags=ParseGeometry(argv[i+1],&geometry_info);
894 shift_image=BlueShiftImage(*image,geometry_info.rho,exception);
895 if (shift_image == (Image *) NULL)
896 break;
897 *image=DestroyImage(*image);
898 *image=shift_image;
899 break;
900 }
901 if (LocaleCompare("blur",option+1) == 0)
902 {
903 Image
904 *blur_image;
905
906 /*
907 Gaussian blur image.
908 */
909 (void) SyncImageSettings(image_info,*image);
910 flags=ParseGeometry(argv[i+1],&geometry_info);
911 if ((flags & SigmaValue) == 0)
912 geometry_info.sigma=1.0;
913 blur_image=BlurImageChannel(*image,channel,geometry_info.rho,
914 geometry_info.sigma,exception);
915 if (blur_image == (Image *) NULL)
916 break;
917 *image=DestroyImage(*image);
918 *image=blur_image;
919 break;
920 }
921 if (LocaleCompare("border",option+1) == 0)
922 {
923 Image
924 *border_image;
925
926 /*
927 Surround image with a border of solid color.
928 */
929 (void) SyncImageSettings(image_info,*image);
930 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
931 if ((flags & SigmaValue) == 0)
932 geometry.height=geometry.width;
933 border_image=BorderImage(*image,&geometry,exception);
934 if (border_image == (Image *) NULL)
935 break;
936 *image=DestroyImage(*image);
937 *image=border_image;
938 break;
939 }
940 if (LocaleCompare("bordercolor",option+1) == 0)
941 {
942 if (*option == '+')
943 {
944 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
945 exception);
946 break;
947 }
948 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
949 exception);
950 break;
951 }
952 if (LocaleCompare("box",option+1) == 0)
953 {
954 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
955 exception);
956 break;
957 }
cristya28d6b82010-01-11 20:03:47 +0000958 if (LocaleCompare("brightness-contrast",option+1) == 0)
959 {
960 double
961 brightness,
962 contrast;
963
964 GeometryInfo
965 geometry_info;
966
967 MagickStatusType
968 flags;
969
970 /*
971 Brightness / contrast image.
972 */
973 (void) SyncImageSettings(image_info,*image);
974 flags=ParseGeometry(argv[i+1],&geometry_info);
975 brightness=geometry_info.rho;
cristy81fbc8b2010-01-11 20:04:07 +0000976 contrast=0.0;
cristya28d6b82010-01-11 20:03:47 +0000977 if ((flags & SigmaValue) != 0)
978 contrast=geometry_info.sigma;
cristy02cc0f22010-01-12 00:02:32 +0000979 (void) BrightnessContrastImageChannel(*image,channel,brightness,
980 contrast);
cristya28d6b82010-01-11 20:03:47 +0000981 InheritException(exception,&(*image)->exception);
982 break;
983 }
cristy3ed852e2009-09-05 21:47:34 +0000984 break;
985 }
986 case 'c':
987 {
988 if (LocaleCompare("cdl",option+1) == 0)
989 {
990 char
991 *color_correction_collection;
992
993 /*
994 Color correct with a color decision list.
995 */
996 (void) SyncImageSettings(image_info,*image);
997 color_correction_collection=FileToString(argv[i+1],~0,exception);
998 if (color_correction_collection == (char *) NULL)
999 break;
1000 (void) ColorDecisionListImage(*image,color_correction_collection);
1001 InheritException(exception,&(*image)->exception);
1002 break;
1003 }
1004 if (LocaleCompare("channel",option+1) == 0)
1005 {
1006 if (*option == '+')
1007 {
1008 channel=DefaultChannels;
1009 break;
1010 }
1011 channel=(ChannelType) ParseChannelOption(argv[i+1]);
1012 break;
1013 }
1014 if (LocaleCompare("charcoal",option+1) == 0)
1015 {
1016 Image
1017 *charcoal_image;
1018
1019 /*
1020 Charcoal image.
1021 */
1022 (void) SyncImageSettings(image_info,*image);
1023 flags=ParseGeometry(argv[i+1],&geometry_info);
1024 if ((flags & SigmaValue) == 0)
1025 geometry_info.sigma=1.0;
1026 charcoal_image=CharcoalImage(*image,geometry_info.rho,
1027 geometry_info.sigma,exception);
1028 if (charcoal_image == (Image *) NULL)
1029 break;
1030 *image=DestroyImage(*image);
1031 *image=charcoal_image;
1032 break;
1033 }
1034 if (LocaleCompare("chop",option+1) == 0)
1035 {
1036 Image
1037 *chop_image;
1038
1039 /*
1040 Chop the image.
1041 */
1042 (void) SyncImageSettings(image_info,*image);
1043 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1044 chop_image=ChopImage(*image,&geometry,exception);
1045 if (chop_image == (Image *) NULL)
1046 break;
1047 *image=DestroyImage(*image);
1048 *image=chop_image;
1049 break;
1050 }
cristy1eb45dd2009-09-25 16:38:06 +00001051 if (LocaleCompare("clamp",option+1) == 0)
1052 {
1053 /*
1054 Clamp image.
1055 */
1056 (void) SyncImageSettings(image_info,*image);
1057 (void) ClampImageChannel(*image,channel);
1058 InheritException(exception,&(*image)->exception);
1059 break;
1060 }
cristy3ed852e2009-09-05 21:47:34 +00001061 if (LocaleCompare("clip",option+1) == 0)
1062 {
1063 (void) SyncImageSettings(image_info,*image);
1064 if (*option == '+')
1065 {
1066 (void) SetImageClipMask(*image,(Image *) NULL);
1067 InheritException(exception,&(*image)->exception);
1068 break;
1069 }
1070 (void) ClipImage(*image);
1071 InheritException(exception,&(*image)->exception);
1072 break;
1073 }
1074 if (LocaleCompare("clip-mask",option+1) == 0)
1075 {
1076 Image
1077 *mask;
1078
1079 long
1080 y;
1081
1082 register long
1083 x;
1084
1085 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001086 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001087
1088 (void) SyncImageSettings(image_info,*image);
1089 if (*option == '+')
1090 {
1091 /*
1092 Remove a mask.
1093 */
1094 (void) SetImageMask(*image,(Image *) NULL);
1095 InheritException(exception,&(*image)->exception);
1096 break;
1097 }
1098 /*
1099 Set the image mask.
1100 */
1101 mask=GetImageCache(image_info,argv[i+1],exception);
1102 if (mask == (Image *) NULL)
1103 break;
1104 for (y=0; y < (long) mask->rows; y++)
1105 {
1106 q=GetAuthenticPixels(mask,0,y,mask->columns,1,exception);
1107 if (q == (PixelPacket *) NULL)
1108 break;
1109 for (x=0; x < (long) mask->columns; x++)
1110 {
1111 if (mask->matte == MagickFalse)
1112 q->opacity=PixelIntensityToQuantum(q);
1113 q->red=q->opacity;
1114 q->green=q->opacity;
1115 q->blue=q->opacity;
1116 q++;
1117 }
1118 if (SyncAuthenticPixels(mask,exception) == MagickFalse)
1119 break;
1120 }
1121 if (SetImageStorageClass(mask,DirectClass) == MagickFalse)
1122 return(MagickFalse);
1123 mask->matte=MagickTrue;
1124 (void) SetImageClipMask(*image,mask);
1125 mask=DestroyImage(mask);
1126 InheritException(exception,&(*image)->exception);
1127 break;
1128 }
1129 if (LocaleCompare("clip-path",option+1) == 0)
1130 {
1131 (void) SyncImageSettings(image_info,*image);
1132 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1133 MagickFalse);
1134 InheritException(exception,&(*image)->exception);
1135 break;
1136 }
1137 if (LocaleCompare("colorize",option+1) == 0)
1138 {
1139 Image
1140 *colorize_image;
1141
1142 /*
1143 Colorize the image.
1144 */
1145 (void) SyncImageSettings(image_info,*image);
1146 colorize_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1147 exception);
1148 if (colorize_image == (Image *) NULL)
1149 break;
1150 *image=DestroyImage(*image);
1151 *image=colorize_image;
1152 break;
1153 }
1154 if (LocaleCompare("colors",option+1) == 0)
1155 {
1156 /*
1157 Reduce the number of colors in the image.
1158 */
1159 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00001160 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001161 if (quantize_info->number_colors == 0)
1162 break;
1163 if (((*image)->storage_class == DirectClass) ||
1164 (*image)->colors > quantize_info->number_colors)
1165 (void) QuantizeImage(quantize_info,*image);
1166 else
1167 (void) CompressImageColormap(*image);
1168 InheritException(exception,&(*image)->exception);
1169 break;
1170 }
1171 if (LocaleCompare("colorspace",option+1) == 0)
1172 {
1173 ColorspaceType
1174 colorspace;
1175
1176 (void) SyncImageSettings(image_info,*image);
1177 if (*option == '+')
1178 {
1179 (void) TransformImageColorspace(*image,RGBColorspace);
1180 InheritException(exception,&(*image)->exception);
1181 break;
1182 }
1183 colorspace=(ColorspaceType) ParseMagickOption(
1184 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1185 (void) TransformImageColorspace(*image,colorspace);
1186 InheritException(exception,&(*image)->exception);
1187 break;
1188 }
1189 if (LocaleCompare("contrast",option+1) == 0)
1190 {
1191 (void) SyncImageSettings(image_info,*image);
1192 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1193 MagickFalse);
1194 InheritException(exception,&(*image)->exception);
1195 break;
1196 }
1197 if (LocaleCompare("contrast-stretch",option+1) == 0)
1198 {
1199 double
1200 black_point,
1201 white_point;
1202
cristy3ed852e2009-09-05 21:47:34 +00001203 MagickStatusType
1204 flags;
1205
1206 /*
1207 Contrast stretch image.
1208 */
1209 (void) SyncImageSettings(image_info,*image);
1210 flags=ParseGeometry(argv[i+1],&geometry_info);
1211 black_point=geometry_info.rho;
1212 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1213 black_point;
1214 if ((flags & PercentValue) != 0)
1215 {
1216 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1217 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1218 }
1219 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1220 white_point;
1221 (void) ContrastStretchImageChannel(*image,channel,black_point,
1222 white_point);
1223 InheritException(exception,&(*image)->exception);
1224 break;
1225 }
1226 if (LocaleCompare("convolve",option+1) == 0)
1227 {
cristy36826ab2010-03-06 01:29:30 +00001228 double
1229 gamma;
1230
cristy3ed852e2009-09-05 21:47:34 +00001231 Image
1232 *convolve_image;
1233
cristy2be15382010-01-21 02:38:03 +00001234 KernelInfo
cristy56a9e512010-01-06 18:18:55 +00001235 *kernel;
cristy3ed852e2009-09-05 21:47:34 +00001236
cristy36826ab2010-03-06 01:29:30 +00001237 register long
1238 j;
1239
cristya6510532010-03-06 13:09:30 +00001240 (void) SyncImageSettings(image_info,*image);
cristy2be15382010-01-21 02:38:03 +00001241 kernel=AcquireKernelInfo(argv[i+1]);
1242 if (kernel == (KernelInfo *) NULL)
cristy56a9e512010-01-06 18:18:55 +00001243 break;
cristy36826ab2010-03-06 01:29:30 +00001244 gamma=0.0;
1245 for (j=0; j < (long) (kernel->width*kernel->height); j++)
1246 gamma+=kernel->values[j];
1247 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
cristyd2baf7d2010-03-06 04:26:44 +00001248 for (j=0; j < (long) (kernel->width*kernel->height); j++)
cristy36826ab2010-03-06 01:29:30 +00001249 kernel->values[j]*=gamma;
cristy6771f1e2010-03-05 19:43:39 +00001250 convolve_image=FilterImageChannel(*image,channel,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00001251 kernel=DestroyKernelInfo(kernel);
cristy3ed852e2009-09-05 21:47:34 +00001252 if (convolve_image == (Image *) NULL)
1253 break;
1254 *image=DestroyImage(*image);
1255 *image=convolve_image;
1256 break;
1257 }
1258 if (LocaleCompare("crop",option+1) == 0)
1259 {
1260 (void) SyncImageSettings(image_info,*image);
1261 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1262 if (((geometry.width != 0) || (geometry.height != 0)) &&
1263 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1264 break;
1265 (void) TransformImage(image,argv[i+1],(char *) NULL);
1266 InheritException(exception,&(*image)->exception);
1267 break;
1268 }
1269 if (LocaleCompare("cycle",option+1) == 0)
1270 {
1271 /*
1272 Cycle an image colormap.
1273 */
1274 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00001275 (void) CycleColormapImage(*image,StringToLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001276 InheritException(exception,&(*image)->exception);
1277 break;
1278 }
1279 break;
1280 }
1281 case 'd':
1282 {
1283 if (LocaleCompare("decipher",option+1) == 0)
1284 {
1285 StringInfo
1286 *passkey;
1287
1288 /*
1289 Decipher pixels.
1290 */
1291 (void) SyncImageSettings(image_info,*image);
1292 passkey=FileToStringInfo(argv[i+1],~0,exception);
1293 if (passkey != (StringInfo *) NULL)
1294 {
1295 (void) PasskeyDecipherImage(*image,passkey,exception);
1296 passkey=DestroyStringInfo(passkey);
1297 }
1298 break;
1299 }
1300 if (LocaleCompare("density",option+1) == 0)
1301 {
1302 /*
1303 Set image density.
1304 */
1305 (void) CloneString(&draw_info->density,argv[i+1]);
1306 break;
1307 }
1308 if (LocaleCompare("depth",option+1) == 0)
1309 {
1310 (void) SyncImageSettings(image_info,*image);
1311 if (*option == '+')
1312 {
1313 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1314 break;
1315 }
cristye27293e2009-12-18 02:53:20 +00001316 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001317 break;
1318 }
1319 if (LocaleCompare("deskew",option+1) == 0)
1320 {
1321 double
1322 threshold;
1323
1324 Image
1325 *deskew_image;
1326
1327 /*
1328 Straighten the image.
1329 */
1330 (void) SyncImageSettings(image_info,*image);
1331 if (*option == '+')
1332 threshold=40.0*QuantumRange/100.0;
1333 else
cristyf2f27272009-12-17 14:48:46 +00001334 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001335 deskew_image=DeskewImage(*image,threshold,exception);
1336 if (deskew_image == (Image *) NULL)
1337 break;
1338 *image=DestroyImage(*image);
1339 *image=deskew_image;
1340 break;
1341 }
1342 if (LocaleCompare("despeckle",option+1) == 0)
1343 {
1344 Image
1345 *despeckle_image;
1346
1347 /*
1348 Reduce the speckles within an image.
1349 */
1350 (void) SyncImageSettings(image_info,*image);
1351 despeckle_image=DespeckleImage(*image,exception);
1352 if (despeckle_image == (Image *) NULL)
1353 break;
1354 *image=DestroyImage(*image);
1355 *image=despeckle_image;
1356 break;
1357 }
1358 if (LocaleCompare("display",option+1) == 0)
1359 {
1360 (void) CloneString(&draw_info->server_name,argv[i+1]);
1361 break;
1362 }
cristy3ed852e2009-09-05 21:47:34 +00001363 if (LocaleCompare("distort",option+1) == 0)
1364 {
1365 char
1366 *args,
1367 token[MaxTextExtent];
1368
1369 const char
1370 *p;
1371
1372 DistortImageMethod
1373 method;
1374
1375 double
1376 *arguments;
1377
1378 Image
1379 *distort_image;
1380
1381 register long
1382 x;
1383
1384 unsigned long
1385 number_arguments;
1386
1387 /*
1388 Distort image.
1389 */
1390 (void) SyncImageSettings(image_info,*image);
1391 method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions,
1392 MagickFalse,argv[i+1]);
1393 args=InterpretImageProperties(image_info,*image,argv[i+2]);
1394 InheritException(exception,&(*image)->exception);
1395 if (args == (char *) NULL)
1396 break;
1397 p=(char *) args;
1398 for (x=0; *p != '\0'; x++)
1399 {
1400 GetMagickToken(p,&p,token);
1401 if (*token == ',')
1402 GetMagickToken(p,&p,token);
1403 }
1404 number_arguments=(unsigned long) x;
1405 arguments=(double *) AcquireQuantumMemory(number_arguments,
1406 sizeof(*arguments));
1407 if (arguments == (double *) NULL)
1408 ThrowWandFatalException(ResourceLimitFatalError,
1409 "MemoryAllocationFailed",(*image)->filename);
1410 (void) ResetMagickMemory(arguments,0,number_arguments*
1411 sizeof(*arguments));
1412 p=(char *) args;
1413 for (x=0; (x < (long) number_arguments) && (*p != '\0'); x++)
1414 {
1415 GetMagickToken(p,&p,token);
1416 if (*token == ',')
1417 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001418 arguments[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001419 }
1420 args=DestroyString(args);
1421 distort_image=DistortImage(*image,method,number_arguments,arguments,
1422 (*option == '+') ? MagickTrue : MagickFalse,exception);
1423 arguments=(double *) RelinquishMagickMemory(arguments);
1424 if (distort_image == (Image *) NULL)
1425 break;
1426 *image=DestroyImage(*image);
1427 *image=distort_image;
1428 break;
1429 }
1430 if (LocaleCompare("dither",option+1) == 0)
1431 {
1432 if (*option == '+')
1433 {
1434 quantize_info->dither=MagickFalse;
1435 break;
1436 }
1437 quantize_info->dither=MagickTrue;
1438 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
1439 MagickDitherOptions,MagickFalse,argv[i+1]);
1440 if (quantize_info->dither_method == NoDitherMethod)
1441 quantize_info->dither=MagickFalse;
1442 break;
1443 }
1444 if (LocaleCompare("draw",option+1) == 0)
1445 {
1446 /*
1447 Draw image.
1448 */
1449 (void) SyncImageSettings(image_info,*image);
1450 (void) CloneString(&draw_info->primitive,argv[i+1]);
1451 (void) DrawImage(*image,draw_info);
1452 InheritException(exception,&(*image)->exception);
1453 break;
1454 }
1455 break;
1456 }
1457 case 'e':
1458 {
1459 if (LocaleCompare("edge",option+1) == 0)
1460 {
1461 Image
1462 *edge_image;
1463
1464 /*
1465 Enhance edges in the image.
1466 */
1467 (void) SyncImageSettings(image_info,*image);
1468 flags=ParseGeometry(argv[i+1],&geometry_info);
1469 if ((flags & SigmaValue) == 0)
1470 geometry_info.sigma=1.0;
1471 edge_image=EdgeImage(*image,geometry_info.rho,exception);
1472 if (edge_image == (Image *) NULL)
1473 break;
1474 *image=DestroyImage(*image);
1475 *image=edge_image;
1476 break;
1477 }
1478 if (LocaleCompare("emboss",option+1) == 0)
1479 {
1480 Image
1481 *emboss_image;
1482
1483 /*
1484 Gaussian embossen image.
1485 */
1486 (void) SyncImageSettings(image_info,*image);
1487 flags=ParseGeometry(argv[i+1],&geometry_info);
1488 if ((flags & SigmaValue) == 0)
1489 geometry_info.sigma=1.0;
1490 emboss_image=EmbossImage(*image,geometry_info.rho,
1491 geometry_info.sigma,exception);
1492 if (emboss_image == (Image *) NULL)
1493 break;
1494 *image=DestroyImage(*image);
1495 *image=emboss_image;
1496 break;
1497 }
1498 if (LocaleCompare("encipher",option+1) == 0)
1499 {
1500 StringInfo
1501 *passkey;
1502
1503 /*
1504 Encipher pixels.
1505 */
1506 (void) SyncImageSettings(image_info,*image);
1507 passkey=FileToStringInfo(argv[i+1],~0,exception);
1508 if (passkey != (StringInfo *) NULL)
1509 {
1510 (void) PasskeyEncipherImage(*image,passkey,exception);
1511 passkey=DestroyStringInfo(passkey);
1512 }
1513 break;
1514 }
1515 if (LocaleCompare("encoding",option+1) == 0)
1516 {
1517 (void) CloneString(&draw_info->encoding,argv[i+1]);
1518 break;
1519 }
1520 if (LocaleCompare("enhance",option+1) == 0)
1521 {
1522 Image
1523 *enhance_image;
1524
1525 /*
1526 Enhance image.
1527 */
1528 (void) SyncImageSettings(image_info,*image);
1529 enhance_image=EnhanceImage(*image,exception);
1530 if (enhance_image == (Image *) NULL)
1531 break;
1532 *image=DestroyImage(*image);
1533 *image=enhance_image;
1534 break;
1535 }
1536 if (LocaleCompare("equalize",option+1) == 0)
1537 {
1538 /*
1539 Equalize image.
1540 */
1541 (void) SyncImageSettings(image_info,*image);
1542 (void) EqualizeImageChannel(*image,channel);
1543 InheritException(exception,&(*image)->exception);
1544 break;
1545 }
1546 if (LocaleCompare("evaluate",option+1) == 0)
1547 {
1548 double
1549 constant;
1550
1551 MagickEvaluateOperator
1552 op;
1553
1554 (void) SyncImageSettings(image_info,*image);
1555 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
1556 MagickFalse,argv[i+1]);
cristyf2f27272009-12-17 14:48:46 +00001557 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001558 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1559 break;
1560 }
1561 if (LocaleCompare("extent",option+1) == 0)
1562 {
1563 Image
1564 *extent_image;
1565
1566 /*
1567 Set the image extent.
1568 */
1569 (void) SyncImageSettings(image_info,*image);
1570 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
cristyf0bbfd92009-11-25 14:12:31 +00001571 if (geometry.width == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001572 geometry.width=(*image)->columns;
cristyf0bbfd92009-11-25 14:12:31 +00001573 if (geometry.height == 0)
cristy2ea9a4e2009-11-25 14:30:22 +00001574 geometry.height=(*image)->rows;
cristy3ed852e2009-09-05 21:47:34 +00001575 geometry.x=(-geometry.x);
1576 geometry.y=(-geometry.y);
1577 extent_image=ExtentImage(*image,&geometry,exception);
1578 if (extent_image == (Image *) NULL)
1579 break;
1580 *image=DestroyImage(*image);
1581 *image=extent_image;
1582 break;
1583 }
1584 break;
1585 }
1586 case 'f':
1587 {
1588 if (LocaleCompare("family",option+1) == 0)
1589 {
1590 if (*option == '+')
1591 {
1592 if (draw_info->family != (char *) NULL)
1593 draw_info->family=DestroyString(draw_info->family);
1594 break;
1595 }
1596 (void) CloneString(&draw_info->family,argv[i+1]);
1597 break;
1598 }
cristy0fe961c2010-01-30 03:09:54 +00001599 if (LocaleCompare("features",option+1) == 0)
1600 {
1601 if (*option == '+')
1602 {
1603 (void) DeleteImageArtifact(*image,"identify:features");
1604 break;
1605 }
1606 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1607 break;
1608 }
cristy3ed852e2009-09-05 21:47:34 +00001609 if (LocaleCompare("fill",option+1) == 0)
1610 {
1611 ExceptionInfo
1612 *sans;
1613
1614 GetMagickPixelPacket(*image,&fill);
1615 if (*option == '+')
1616 {
1617 (void) QueryMagickColor("none",&fill,exception);
1618 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1619 if (draw_info->fill_pattern != (Image *) NULL)
1620 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1621 break;
1622 }
1623 sans=AcquireExceptionInfo();
1624 (void) QueryMagickColor(argv[i+1],&fill,sans);
1625 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1626 sans=DestroyExceptionInfo(sans);
1627 if (status == MagickFalse)
1628 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
1629 exception);
1630 break;
1631 }
1632 if (LocaleCompare("flip",option+1) == 0)
1633 {
1634 Image
1635 *flip_image;
1636
1637 /*
1638 Flip image scanlines.
1639 */
1640 (void) SyncImageSettings(image_info,*image);
1641 flip_image=FlipImage(*image,exception);
1642 if (flip_image == (Image *) NULL)
1643 break;
1644 *image=DestroyImage(*image);
1645 *image=flip_image;
1646 break;
1647 }
1648 if (LocaleCompare("flop",option+1) == 0)
1649 {
1650 Image
1651 *flop_image;
1652
1653 /*
1654 Flop image scanlines.
1655 */
1656 (void) SyncImageSettings(image_info,*image);
1657 flop_image=FlopImage(*image,exception);
1658 if (flop_image == (Image *) NULL)
1659 break;
1660 *image=DestroyImage(*image);
1661 *image=flop_image;
1662 break;
1663 }
1664 if (LocaleCompare("floodfill",option+1) == 0)
1665 {
1666 MagickPixelPacket
1667 target;
1668
1669 /*
1670 Floodfill image.
1671 */
1672 (void) SyncImageSettings(image_info,*image);
1673 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1674 (void) QueryMagickColor(argv[i+2],&target,exception);
1675 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1676 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1677 InheritException(exception,&(*image)->exception);
1678 break;
1679 }
1680 if (LocaleCompare("font",option+1) == 0)
1681 {
1682 if (*option == '+')
1683 {
1684 if (draw_info->font != (char *) NULL)
1685 draw_info->font=DestroyString(draw_info->font);
1686 break;
1687 }
1688 (void) CloneString(&draw_info->font,argv[i+1]);
1689 break;
1690 }
1691 if (LocaleCompare("format",option+1) == 0)
1692 {
1693 format=argv[i+1];
1694 break;
1695 }
1696 if (LocaleCompare("frame",option+1) == 0)
1697 {
1698 FrameInfo
1699 frame_info;
1700
1701 Image
1702 *frame_image;
1703
1704 /*
1705 Surround image with an ornamental border.
1706 */
1707 (void) SyncImageSettings(image_info,*image);
1708 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1709 frame_info.width=geometry.width;
1710 frame_info.height=geometry.height;
1711 if ((flags & HeightValue) == 0)
1712 frame_info.height=geometry.width;
1713 frame_info.outer_bevel=geometry.x;
1714 frame_info.inner_bevel=geometry.y;
1715 frame_info.x=(long) frame_info.width;
1716 frame_info.y=(long) frame_info.height;
1717 frame_info.width=(*image)->columns+2*frame_info.width;
1718 frame_info.height=(*image)->rows+2*frame_info.height;
1719 frame_image=FrameImage(*image,&frame_info,exception);
1720 if (frame_image == (Image *) NULL)
1721 break;
1722 *image=DestroyImage(*image);
1723 *image=frame_image;
1724 break;
1725 }
1726 if (LocaleCompare("function",option+1) == 0)
1727 {
1728 char
1729 *arguments,
1730 token[MaxTextExtent];
1731
1732 const char
1733 *p;
1734
1735 double
1736 *parameters;
1737
1738 MagickFunction
1739 function;
1740
1741 register long
1742 x;
1743
1744 unsigned long
1745 number_parameters;
1746
1747 /*
1748 Function Modify Image Values
1749 */
1750 (void) SyncImageSettings(image_info,*image);
1751 function=(MagickFunction) ParseMagickOption(MagickFunctionOptions,
1752 MagickFalse,argv[i+1]);
1753 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
1754 InheritException(exception,&(*image)->exception);
1755 if (arguments == (char *) NULL)
1756 break;
1757 p=(char *) arguments;
1758 for (x=0; *p != '\0'; x++)
1759 {
1760 GetMagickToken(p,&p,token);
1761 if (*token == ',')
1762 GetMagickToken(p,&p,token);
1763 }
1764 number_parameters=(unsigned long) x;
1765 parameters=(double *) AcquireQuantumMemory(number_parameters,
1766 sizeof(*parameters));
1767 if (parameters == (double *) NULL)
1768 ThrowWandFatalException(ResourceLimitFatalError,
1769 "MemoryAllocationFailed",(*image)->filename);
1770 (void) ResetMagickMemory(parameters,0,number_parameters*
1771 sizeof(*parameters));
1772 p=(char *) arguments;
1773 for (x=0; (x < (long) number_parameters) && (*p != '\0'); x++)
1774 {
1775 GetMagickToken(p,&p,token);
1776 if (*token == ',')
1777 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00001778 parameters[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00001779 }
1780 arguments=DestroyString(arguments);
1781 (void) FunctionImageChannel(*image,channel,function,
1782 number_parameters,parameters,exception);
1783 parameters=(double *) RelinquishMagickMemory(parameters);
1784 break;
1785 }
1786 break;
1787 }
1788 case 'g':
1789 {
1790 if (LocaleCompare("gamma",option+1) == 0)
1791 {
1792 /*
1793 Gamma image.
1794 */
1795 (void) SyncImageSettings(image_info,*image);
1796 if (*option == '+')
cristyf2f27272009-12-17 14:48:46 +00001797 (*image)->gamma=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00001798 else
1799 {
1800 if (strchr(argv[i+1],',') != (char *) NULL)
1801 (void) GammaImage(*image,argv[i+1]);
1802 else
cristya5447be2010-01-11 00:20:51 +00001803 (void) GammaImageChannel(*image,channel,
1804 StringToDouble(argv[i+1]));
cristy3ed852e2009-09-05 21:47:34 +00001805 InheritException(exception,&(*image)->exception);
1806 }
1807 break;
1808 }
1809 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1810 (LocaleCompare("gaussian",option+1) == 0))
1811 {
1812 Image
1813 *gaussian_image;
1814
1815 /*
1816 Gaussian blur image.
1817 */
1818 (void) SyncImageSettings(image_info,*image);
1819 flags=ParseGeometry(argv[i+1],&geometry_info);
1820 if ((flags & SigmaValue) == 0)
1821 geometry_info.sigma=1.0;
1822 gaussian_image=GaussianBlurImageChannel(*image,channel,
1823 geometry_info.rho,geometry_info.sigma,exception);
1824 if (gaussian_image == (Image *) NULL)
1825 break;
1826 *image=DestroyImage(*image);
1827 *image=gaussian_image;
1828 break;
1829 }
1830 if (LocaleCompare("geometry",option+1) == 0)
1831 {
1832 (void) SyncImageSettings(image_info,*image);
1833 if (*option == '+')
1834 {
1835 if ((*image)->geometry != (char *) NULL)
1836 (*image)->geometry=DestroyString((*image)->geometry);
1837 break;
1838 }
1839 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1840 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1841 (void) CloneString(&(*image)->geometry,argv[i+1]);
1842 else
1843 {
1844 Image
1845 *zoom_image;
1846
1847 /*
1848 Resize image.
1849 */
1850 zoom_image=ZoomImage(*image,geometry.width,geometry.height,
1851 exception);
1852 if (zoom_image == (Image *) NULL)
1853 break;
1854 *image=DestroyImage(*image);
1855 *image=zoom_image;
1856 }
1857 break;
1858 }
1859 if (LocaleCompare("gravity",option+1) == 0)
1860 {
1861 if (*option == '+')
1862 {
1863 draw_info->gravity=UndefinedGravity;
1864 break;
1865 }
1866 draw_info->gravity=(GravityType) ParseMagickOption(
1867 MagickGravityOptions,MagickFalse,argv[i+1]);
1868 break;
1869 }
1870 break;
1871 }
1872 case 'h':
1873 {
1874 if (LocaleCompare("highlight-color",option+1) == 0)
1875 {
1876 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1877 break;
1878 }
1879 break;
1880 }
1881 case 'i':
1882 {
1883 if (LocaleCompare("identify",option+1) == 0)
1884 {
1885 char
1886 *text;
1887
1888 (void) SyncImageSettings(image_info,*image);
1889 if (format == (char *) NULL)
1890 {
1891 (void) IdentifyImage(*image,stdout,image_info->verbose);
1892 InheritException(exception,&(*image)->exception);
1893 break;
1894 }
1895 text=InterpretImageProperties(image_info,*image,format);
1896 InheritException(exception,&(*image)->exception);
1897 if (text == (char *) NULL)
1898 break;
1899 (void) fputs(text,stdout);
1900 (void) fputc('\n',stdout);
1901 text=DestroyString(text);
1902 break;
1903 }
1904 if (LocaleCompare("implode",option+1) == 0)
1905 {
1906 Image
1907 *implode_image;
1908
1909 /*
1910 Implode image.
1911 */
1912 (void) SyncImageSettings(image_info,*image);
1913 (void) ParseGeometry(argv[i+1],&geometry_info);
1914 implode_image=ImplodeImage(*image,geometry_info.rho,exception);
1915 if (implode_image == (Image *) NULL)
1916 break;
1917 *image=DestroyImage(*image);
1918 *image=implode_image;
1919 break;
1920 }
cristyb32b90a2009-09-07 21:45:48 +00001921 if (LocaleCompare("interline-spacing",option+1) == 0)
1922 {
1923 if (*option == '+')
1924 (void) ParseGeometry("0",&geometry_info);
1925 else
1926 (void) ParseGeometry(argv[i+1],&geometry_info);
1927 draw_info->interline_spacing=geometry_info.rho;
1928 break;
1929 }
cristy3ed852e2009-09-05 21:47:34 +00001930 if (LocaleCompare("interword-spacing",option+1) == 0)
1931 {
1932 if (*option == '+')
1933 (void) ParseGeometry("0",&geometry_info);
1934 else
1935 (void) ParseGeometry(argv[i+1],&geometry_info);
1936 draw_info->interword_spacing=geometry_info.rho;
1937 break;
1938 }
1939 break;
1940 }
1941 case 'k':
1942 {
1943 if (LocaleCompare("kerning",option+1) == 0)
1944 {
1945 if (*option == '+')
1946 (void) ParseGeometry("0",&geometry_info);
1947 else
1948 (void) ParseGeometry(argv[i+1],&geometry_info);
1949 draw_info->kerning=geometry_info.rho;
1950 break;
1951 }
1952 break;
1953 }
1954 case 'l':
1955 {
1956 if (LocaleCompare("lat",option+1) == 0)
1957 {
1958 Image
1959 *threshold_image;
1960
1961 /*
1962 Local adaptive threshold image.
1963 */
1964 (void) SyncImageSettings(image_info,*image);
1965 flags=ParseGeometry(argv[i+1],&geometry_info);
1966 if ((flags & PercentValue) != 0)
1967 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1968 threshold_image=AdaptiveThresholdImage(*image,(unsigned long)
1969 geometry_info.rho,(unsigned long) geometry_info.sigma,
1970 (long) geometry_info.xi,exception);
1971 if (threshold_image == (Image *) NULL)
1972 break;
1973 *image=DestroyImage(*image);
1974 *image=threshold_image;
1975 break;
1976 }
1977 if (LocaleCompare("level",option+1) == 0)
1978 {
cristy3ed852e2009-09-05 21:47:34 +00001979 MagickRealType
1980 black_point,
1981 gamma,
1982 white_point;
1983
1984 MagickStatusType
1985 flags;
1986
1987 /*
1988 Parse levels.
1989 */
1990 (void) SyncImageSettings(image_info,*image);
1991 flags=ParseGeometry(argv[i+1],&geometry_info);
1992 black_point=geometry_info.rho;
1993 white_point=(MagickRealType) QuantumRange;
1994 if ((flags & SigmaValue) != 0)
1995 white_point=geometry_info.sigma;
1996 gamma=1.0;
1997 if ((flags & XiValue) != 0)
1998 gamma=geometry_info.xi;
1999 if ((flags & PercentValue) != 0)
2000 {
2001 black_point*=(MagickRealType) (QuantumRange/100.0);
2002 white_point*=(MagickRealType) (QuantumRange/100.0);
2003 }
2004 if ((flags & SigmaValue) == 0)
2005 white_point=(MagickRealType) QuantumRange-black_point;
2006 if ((*option == '+') || ((flags & AspectValue) != 0))
2007 (void) LevelizeImageChannel(*image,channel,black_point,
2008 white_point,gamma);
2009 else
2010 (void) LevelImageChannel(*image,channel,black_point,white_point,
2011 gamma);
2012 InheritException(exception,&(*image)->exception);
2013 break;
2014 }
2015 if (LocaleCompare("level-colors",option+1) == 0)
2016 {
2017 char
2018 token[MaxTextExtent];
2019
2020 const char
2021 *p;
2022
2023 MagickPixelPacket
2024 black_point,
2025 white_point;
2026
2027 p=(const char *) argv[i+1];
2028 GetMagickToken(p,&p,token); /* get black point color */
cristyee0f8d72009-09-19 00:58:29 +00002029 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002030 (void) QueryMagickColor(token,&black_point,exception);
2031 else
cristyee0f8d72009-09-19 00:58:29 +00002032 (void) QueryMagickColor("#000000",&black_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002033 if (isalpha((int) token[0]) || (token[0] == '#'))
2034 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002035 if (*token == '\0')
cristy3ed852e2009-09-05 21:47:34 +00002036 white_point=black_point; /* set everything to that color */
2037 else
2038 {
2039 /*
2040 Get white point color.
2041 */
cristyee0f8d72009-09-19 00:58:29 +00002042 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
cristy3ed852e2009-09-05 21:47:34 +00002043 GetMagickToken(p,&p,token);
cristyee0f8d72009-09-19 00:58:29 +00002044 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy3ed852e2009-09-05 21:47:34 +00002045 (void) QueryMagickColor(token,&white_point,exception);
2046 else
cristyee0f8d72009-09-19 00:58:29 +00002047 (void) QueryMagickColor("#ffffff",&white_point,exception);
cristy3ed852e2009-09-05 21:47:34 +00002048 }
cristy74fe8f12009-10-03 19:09:01 +00002049 (void) LevelColorsImageChannel(*image,channel,&black_point,
2050 &white_point,*option == '+' ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00002051 break;
2052 }
2053 if (LocaleCompare("linear-stretch",option+1) == 0)
2054 {
2055 double
2056 black_point,
2057 white_point;
2058
cristy3ed852e2009-09-05 21:47:34 +00002059 MagickStatusType
2060 flags;
2061
2062 (void) SyncImageSettings(image_info,*image);
2063 flags=ParseGeometry(argv[i+1],&geometry_info);
2064 black_point=geometry_info.rho;
2065 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2066 if ((flags & SigmaValue) != 0)
2067 white_point=geometry_info.sigma;
2068 if ((flags & PercentValue) != 0)
2069 {
2070 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2071 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2072 }
2073 if ((flags & SigmaValue) == 0)
2074 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2075 black_point;
2076 (void) LinearStretchImage(*image,black_point,white_point);
2077 InheritException(exception,&(*image)->exception);
2078 break;
2079 }
2080 if (LocaleCompare("linewidth",option+1) == 0)
2081 {
cristyf2f27272009-12-17 14:48:46 +00002082 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00002083 break;
2084 }
2085 if (LocaleCompare("liquid-rescale",option+1) == 0)
2086 {
2087 Image
2088 *resize_image;
2089
2090 /*
2091 Liquid rescale image.
2092 */
2093 (void) SyncImageSettings(image_info,*image);
2094 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2095 if ((flags & XValue) == 0)
2096 geometry.x=1;
2097 if ((flags & YValue) == 0)
2098 geometry.y=0;
2099 resize_image=LiquidRescaleImage(*image,geometry.width,
2100 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2101 if (resize_image == (Image *) NULL)
2102 break;
2103 *image=DestroyImage(*image);
2104 *image=resize_image;
2105 break;
2106 }
2107 if (LocaleCompare("lowlight-color",option+1) == 0)
2108 {
2109 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2110 break;
2111 }
2112 break;
2113 }
2114 case 'm':
2115 {
2116 if (LocaleCompare("map",option+1) == 0)
2117 {
2118 Image
2119 *remap_image;
2120
2121 /*
2122 Transform image colors to match this set of colors.
2123 */
2124 (void) SyncImageSettings(image_info,*image);
2125 if (*option == '+')
2126 break;
2127 remap_image=GetImageCache(image_info,argv[i+1],exception);
2128 if (remap_image == (Image *) NULL)
2129 break;
2130 (void) RemapImage(quantize_info,*image,remap_image);
2131 InheritException(exception,&(*image)->exception);
2132 remap_image=DestroyImage(remap_image);
2133 break;
2134 }
2135 if (LocaleCompare("mask",option+1) == 0)
2136 {
2137 Image
2138 *mask;
2139
2140 (void) SyncImageSettings(image_info,*image);
2141 if (*option == '+')
2142 {
2143 /*
2144 Remove a mask.
2145 */
2146 (void) SetImageMask(*image,(Image *) NULL);
2147 InheritException(exception,&(*image)->exception);
2148 break;
2149 }
2150 /*
2151 Set the image mask.
2152 */
2153 mask=GetImageCache(image_info,argv[i+1],exception);
2154 if (mask == (Image *) NULL)
2155 break;
2156 (void) SetImageMask(*image,mask);
2157 mask=DestroyImage(mask);
2158 InheritException(exception,&(*image)->exception);
2159 break;
2160 }
2161 if (LocaleCompare("matte",option+1) == 0)
2162 {
2163 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2164 SetAlphaChannel : DeactivateAlphaChannel );
2165 InheritException(exception,&(*image)->exception);
2166 break;
2167 }
2168 if (LocaleCompare("median",option+1) == 0)
2169 {
2170 Image
2171 *median_image;
2172
2173 /*
2174 Median filter image.
2175 */
2176 (void) SyncImageSettings(image_info,*image);
2177 (void) ParseGeometry(argv[i+1],&geometry_info);
2178 median_image=MedianFilterImage(*image,geometry_info.rho,exception);
2179 if (median_image == (Image *) NULL)
2180 break;
2181 *image=DestroyImage(*image);
2182 *image=median_image;
2183 break;
2184 }
2185 if (LocaleCompare("modulate",option+1) == 0)
2186 {
2187 (void) SyncImageSettings(image_info,*image);
2188 (void) ModulateImage(*image,argv[i+1]);
2189 InheritException(exception,&(*image)->exception);
2190 break;
2191 }
2192 if (LocaleCompare("monitor",option+1) == 0)
2193 {
2194 (void) SetImageProgressMonitor(*image,MonitorProgress,
2195 (void *) NULL);
2196 break;
2197 }
2198 if (LocaleCompare("monochrome",option+1) == 0)
2199 {
2200 (void) SyncImageSettings(image_info,*image);
2201 (void) SetImageType(*image,BilevelType);
2202 InheritException(exception,&(*image)->exception);
2203 break;
2204 }
anthony29188a82010-01-22 10:12:34 +00002205 if (LocaleCompare("morphology",option+1) == 0)
2206 {
2207 MorphologyMethod
2208 method;
2209
2210 KernelInfo
2211 *kernel;
2212
2213 char
2214 token[MaxTextExtent];
2215
2216 const char
2217 *p;
2218
cristyef656912010-03-05 19:54:59 +00002219 long
anthony29188a82010-01-22 10:12:34 +00002220 iterations;
2221
2222 Image
2223 *morphology_image;
2224 /*
2225 Morphological Image Operation
2226 */
2227 (void) SyncImageSettings(image_info,*image);
2228 p=argv[i+1];
2229 GetMagickToken(p,&p,token);
2230 method=(MorphologyMethod) ParseMagickOption(MagickMorphologyOptions,
2231 MagickFalse,token);
cristyef656912010-03-05 19:54:59 +00002232 iterations=1L;
anthony29188a82010-01-22 10:12:34 +00002233 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002234 if ((*p == ':') || (*p == ','))
anthony29188a82010-01-22 10:12:34 +00002235 GetMagickToken(p,&p,token);
cristyef656912010-03-05 19:54:59 +00002236 if ((*p != '\0'))
2237 iterations=StringToLong(p);
anthony29188a82010-01-22 10:12:34 +00002238 kernel=AcquireKernelInfo(argv[i+2]);
2239 if (kernel == (KernelInfo *) NULL)
2240 ThrowWandFatalException(ResourceLimitFatalError,
2241 "MemoryAllocationFailed",(*image)->filename);
anthony930be612010-02-08 04:26:15 +00002242 if ( GetImageArtifact(*image,"showkernel") != (const char *) NULL)
2243 ShowKernelInfo(kernel); /* display the kernel to stderr */
anthony29188a82010-01-22 10:12:34 +00002244 morphology_image=MorphologyImageChannel(*image,channel,method,
cristy02d5b4f2010-02-01 01:08:27 +00002245 iterations,kernel,exception);
anthony83ba99b2010-01-24 08:48:15 +00002246 kernel=DestroyKernelInfo(kernel);
anthony29188a82010-01-22 10:12:34 +00002247 if (morphology_image == (Image *) NULL)
2248 break;
2249 *image=DestroyImage(*image);
2250 *image=morphology_image;
2251 break;
2252 }
cristy3ed852e2009-09-05 21:47:34 +00002253 if (LocaleCompare("motion-blur",option+1) == 0)
2254 {
2255 Image
2256 *blur_image;
2257
2258 /*
2259 Motion blur image.
2260 */
2261 (void) SyncImageSettings(image_info,*image);
2262 flags=ParseGeometry(argv[i+1],&geometry_info);
2263 if ((flags & SigmaValue) == 0)
2264 geometry_info.sigma=1.0;
2265 blur_image=MotionBlurImageChannel(*image,channel,geometry_info.rho,
2266 geometry_info.sigma,geometry_info.xi,exception);
2267 if (blur_image == (Image *) NULL)
2268 break;
2269 *image=DestroyImage(*image);
2270 *image=blur_image;
2271 break;
2272 }
2273 break;
2274 }
2275 case 'n':
2276 {
2277 if (LocaleCompare("negate",option+1) == 0)
2278 {
2279 (void) SyncImageSettings(image_info,*image);
2280 (void) NegateImageChannel(*image,channel,*option == '+' ?
2281 MagickTrue : MagickFalse);
2282 InheritException(exception,&(*image)->exception);
2283 break;
2284 }
2285 if (LocaleCompare("noise",option+1) == 0)
2286 {
2287 Image
2288 *noisy_image;
2289
2290 (void) SyncImageSettings(image_info,*image);
2291 if (*option == '-')
2292 {
2293 (void) ParseGeometry(argv[i+1],&geometry_info);
2294 noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
2295 exception);
2296 }
2297 else
2298 {
2299 NoiseType
2300 noise;
2301
2302 noise=(NoiseType) ParseMagickOption(MagickNoiseOptions,
2303 MagickFalse,argv[i+1]);
2304 noisy_image=AddNoiseImageChannel(*image,channel,noise,
2305 exception);
2306 }
2307 if (noisy_image == (Image *) NULL)
2308 break;
2309 *image=DestroyImage(*image);
2310 *image=noisy_image;
2311 break;
2312 }
2313 if (LocaleCompare("normalize",option+1) == 0)
2314 {
2315 (void) SyncImageSettings(image_info,*image);
2316 (void) NormalizeImageChannel(*image,channel);
2317 InheritException(exception,&(*image)->exception);
2318 break;
2319 }
2320 break;
2321 }
2322 case 'o':
2323 {
2324 if (LocaleCompare("opaque",option+1) == 0)
2325 {
2326 MagickPixelPacket
2327 target;
2328
2329 (void) SyncImageSettings(image_info,*image);
2330 (void) QueryMagickColor(argv[i+1],&target,exception);
2331 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2332 *option == '-' ? MagickFalse : MagickTrue);
2333 break;
2334 }
2335 if (LocaleCompare("ordered-dither",option+1) == 0)
2336 {
2337 (void) SyncImageSettings(image_info,*image);
2338 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2339 exception);
2340 break;
2341 }
2342 break;
2343 }
2344 case 'p':
2345 {
2346 if (LocaleCompare("paint",option+1) == 0)
2347 {
2348 Image
2349 *paint_image;
2350
2351 /*
2352 Oil paint image.
2353 */
2354 (void) SyncImageSettings(image_info,*image);
2355 (void) ParseGeometry(argv[i+1],&geometry_info);
2356 paint_image=OilPaintImage(*image,geometry_info.rho,exception);
2357 if (paint_image == (Image *) NULL)
2358 break;
2359 *image=DestroyImage(*image);
2360 *image=paint_image;
2361 break;
2362 }
2363 if (LocaleCompare("pen",option+1) == 0)
2364 {
2365 if (*option == '+')
2366 {
2367 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2368 break;
2369 }
2370 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2371 break;
2372 }
2373 if (LocaleCompare("pointsize",option+1) == 0)
2374 {
2375 if (*option == '+')
2376 (void) ParseGeometry("12",&geometry_info);
2377 else
2378 (void) ParseGeometry(argv[i+1],&geometry_info);
2379 draw_info->pointsize=geometry_info.rho;
2380 break;
2381 }
2382 if (LocaleCompare("polaroid",option+1) == 0)
2383 {
2384 double
2385 angle;
2386
2387 Image
2388 *polaroid_image;
2389
2390 RandomInfo
2391 *random_info;
2392
2393 /*
2394 Simulate a Polaroid picture.
2395 */
2396 (void) SyncImageSettings(image_info,*image);
2397 random_info=AcquireRandomInfo();
2398 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2399 random_info=DestroyRandomInfo(random_info);
2400 if (*option == '-')
2401 {
2402 SetGeometryInfo(&geometry_info);
2403 flags=ParseGeometry(argv[i+1],&geometry_info);
2404 angle=geometry_info.rho;
2405 }
2406 polaroid_image=PolaroidImage(*image,draw_info,angle,exception);
2407 if (polaroid_image == (Image *) NULL)
2408 break;
2409 *image=DestroyImage(*image);
2410 *image=polaroid_image;
2411 break;
2412 }
2413 if (LocaleCompare("posterize",option+1) == 0)
2414 {
2415 /*
2416 Posterize image.
2417 */
2418 (void) SyncImageSettings(image_info,*image);
cristye27293e2009-12-18 02:53:20 +00002419 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00002420 quantize_info->dither);
2421 InheritException(exception,&(*image)->exception);
2422 break;
2423 }
2424 if (LocaleCompare("preview",option+1) == 0)
2425 {
2426 Image
2427 *preview_image;
2428
2429 PreviewType
2430 preview_type;
2431
2432 /*
2433 Preview image.
2434 */
2435 (void) SyncImageSettings(image_info,*image);
2436 if (*option == '+')
2437 preview_type=UndefinedPreview;
2438 else
2439 preview_type=(PreviewType) ParseMagickOption(MagickPreviewOptions,
2440 MagickFalse,argv[i+1]);
2441 preview_image=PreviewImage(*image,preview_type,exception);
2442 if (preview_image == (Image *) NULL)
2443 break;
2444 *image=DestroyImage(*image);
2445 *image=preview_image;
2446 break;
2447 }
2448 if (LocaleCompare("profile",option+1) == 0)
2449 {
2450 const char
2451 *name;
2452
2453 const StringInfo
2454 *profile;
2455
2456 Image
2457 *profile_image;
2458
2459 ImageInfo
2460 *profile_info;
2461
2462 (void) SyncImageSettings(image_info,*image);
2463 if (*option == '+')
2464 {
2465 /*
2466 Remove a profile from the image.
2467 */
2468 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2469 NULL,0,MagickTrue);
2470 InheritException(exception,&(*image)->exception);
2471 break;
2472 }
2473 /*
2474 Associate a profile with the image.
2475 */
2476 profile_info=CloneImageInfo(image_info);
2477 profile=GetImageProfile(*image,"iptc");
2478 if (profile != (StringInfo *) NULL)
2479 profile_info->profile=(void *) CloneStringInfo(profile);
2480 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2481 profile_info=DestroyImageInfo(profile_info);
2482 if (profile_image == (Image *) NULL)
2483 {
2484 char
2485 name[MaxTextExtent],
2486 filename[MaxTextExtent];
2487
2488 register char
2489 *p;
2490
2491 StringInfo
2492 *profile;
2493
2494 (void) CopyMagickString(filename,argv[i+1],MaxTextExtent);
2495 (void) CopyMagickString(name,argv[i+1],MaxTextExtent);
2496 for (p=filename; *p != '\0'; p++)
2497 if ((*p == ':') && (IsPathDirectory(argv[i+1]) < 0) &&
2498 (IsPathAccessible(argv[i+1]) == MagickFalse))
2499 {
2500 register char
2501 *q;
2502
2503 /*
2504 Look for profile name (e.g. name:profile).
2505 */
2506 (void) CopyMagickString(name,filename,(size_t)
2507 (p-filename+1));
2508 for (q=filename; *q != '\0'; q++)
2509 *q=(*++p);
2510 break;
2511 }
2512 profile=FileToStringInfo(filename,~0UL,exception);
2513 if (profile != (StringInfo *) NULL)
2514 {
2515 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2516 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2517 profile=DestroyStringInfo(profile);
2518 }
2519 break;
2520 }
2521 ResetImageProfileIterator(profile_image);
2522 name=GetNextImageProfile(profile_image);
2523 while (name != (const char *) NULL)
2524 {
2525 profile=GetImageProfile(profile_image,name);
2526 if (profile != (StringInfo *) NULL)
2527 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2528 (unsigned long) GetStringInfoLength(profile),MagickFalse);
2529 name=GetNextImageProfile(profile_image);
2530 }
2531 profile_image=DestroyImage(profile_image);
2532 break;
2533 }
2534 break;
2535 }
2536 case 'q':
2537 {
2538 if (LocaleCompare("quantize",option+1) == 0)
2539 {
2540 if (*option == '+')
2541 {
2542 quantize_info->colorspace=UndefinedColorspace;
2543 break;
2544 }
2545 quantize_info->colorspace=(ColorspaceType) ParseMagickOption(
2546 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2547 break;
2548 }
2549 break;
2550 }
2551 case 'r':
2552 {
2553 if (LocaleCompare("radial-blur",option+1) == 0)
2554 {
2555 Image
2556 *blur_image;
2557
2558 /*
2559 Radial blur image.
2560 */
2561 (void) SyncImageSettings(image_info,*image);
cristya5447be2010-01-11 00:20:51 +00002562 blur_image=RadialBlurImageChannel(*image,channel,
2563 StringToDouble(argv[i+1]),exception);
cristy3ed852e2009-09-05 21:47:34 +00002564 if (blur_image == (Image *) NULL)
2565 break;
2566 *image=DestroyImage(*image);
2567 *image=blur_image;
2568 break;
2569 }
2570 if (LocaleCompare("raise",option+1) == 0)
2571 {
2572 /*
2573 Surround image with a raise of solid color.
2574 */
2575 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2576 if ((flags & SigmaValue) == 0)
2577 geometry.height=geometry.width;
2578 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2579 MagickFalse);
2580 InheritException(exception,&(*image)->exception);
2581 break;
2582 }
2583 if (LocaleCompare("random-threshold",option+1) == 0)
2584 {
2585 /*
2586 Threshold image.
2587 */
2588 (void) SyncImageSettings(image_info,*image);
2589 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2590 exception);
2591 break;
2592 }
2593 if (LocaleCompare("recolor",option+1) == 0)
2594 {
2595 char
2596 token[MaxTextExtent];
2597
2598 const char
2599 *p;
2600
2601 double
2602 *color_matrix;
2603
2604 Image
2605 *recolor_image;
2606
2607 register long
2608 x;
2609
2610 unsigned long
2611 order;
2612
2613 /*
2614 Transform color image.
2615 */
2616 (void) SyncImageSettings(image_info,*image);
2617 p=argv[i+1];
2618 for (x=0; *p != '\0'; x++)
2619 {
2620 GetMagickToken(p,&p,token);
2621 if (*token == ',')
2622 GetMagickToken(p,&p,token);
2623 }
2624 order=(unsigned long) sqrt((double) x+1.0);
2625 color_matrix=(double *) AcquireQuantumMemory(order,order*
2626 sizeof(*color_matrix));
2627 if (color_matrix == (double *) NULL)
2628 ThrowWandFatalException(ResourceLimitFatalError,
2629 "MemoryAllocationFailed",(*image)->filename);
2630 p=argv[i+1];
2631 for (x=0; (x < (long) (order*order)) && (*p != '\0'); x++)
2632 {
2633 GetMagickToken(p,&p,token);
2634 if (*token == ',')
2635 GetMagickToken(p,&p,token);
cristyf2f27272009-12-17 14:48:46 +00002636 color_matrix[x]=StringToDouble(token);
cristy3ed852e2009-09-05 21:47:34 +00002637 }
2638 for ( ; x < (long) (order*order); x++)
2639 color_matrix[x]=0.0;
2640 recolor_image=RecolorImage(*image,order,color_matrix,exception);
2641 color_matrix=(double *) RelinquishMagickMemory(color_matrix);
2642 if (recolor_image == (Image *) NULL)
2643 break;
2644 *image=DestroyImage(*image);
2645 *image=recolor_image;
2646 break;
2647 }
2648 if (LocaleCompare("region",option+1) == 0)
2649 {
2650 Image
2651 *crop_image;
2652
2653 (void) SyncImageSettings(image_info,*image);
2654 if (region_image != (Image *) NULL)
2655 {
2656 /*
2657 Composite region.
2658 */
2659 (void) CompositeImage(region_image,(*image)->matte !=
2660 MagickFalse ? OverCompositeOp : CopyCompositeOp,*image,
2661 region_geometry.x,region_geometry.y);
2662 InheritException(exception,&region_image->exception);
2663 *image=DestroyImage(*image);
2664 *image=region_image;
2665 }
2666 if (*option == '+')
2667 {
2668 if (region_image != (Image *) NULL)
2669 region_image=DestroyImage(region_image);
2670 break;
2671 }
2672 /*
2673 Apply transformations to a selected region of the image.
2674 */
2675 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2676 exception);
2677 crop_image=CropImage(*image,&region_geometry,exception);
2678 if (crop_image == (Image *) NULL)
2679 break;
2680 region_image=(*image);
2681 *image=crop_image;
2682 break;
2683 }
2684 if (LocaleCompare("render",option+1) == 0)
2685 {
2686 (void) SyncImageSettings(image_info,*image);
2687 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2688 break;
2689 }
2690 if (LocaleCompare("remap",option+1) == 0)
2691 {
2692 Image
2693 *remap_image;
2694
2695 /*
2696 Transform image colors to match this set of colors.
2697 */
2698 (void) SyncImageSettings(image_info,*image);
2699 if (*option == '+')
2700 break;
2701 remap_image=GetImageCache(image_info,argv[i+1],exception);
2702 if (remap_image == (Image *) NULL)
2703 break;
2704 (void) RemapImage(quantize_info,*image,remap_image);
2705 InheritException(exception,&(*image)->exception);
2706 remap_image=DestroyImage(remap_image);
2707 break;
2708 }
2709 if (LocaleCompare("repage",option+1) == 0)
2710 {
2711 if (*option == '+')
2712 {
2713 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2714 break;
2715 }
2716 (void) ResetImagePage(*image,argv[i+1]);
2717 InheritException(exception,&(*image)->exception);
2718 break;
2719 }
2720 if (LocaleCompare("resample",option+1) == 0)
2721 {
2722 Image
2723 *resample_image;
2724
2725 /*
2726 Resample image.
2727 */
2728 (void) SyncImageSettings(image_info,*image);
2729 flags=ParseGeometry(argv[i+1],&geometry_info);
2730 if ((flags & SigmaValue) == 0)
2731 geometry_info.sigma=geometry_info.rho;
2732 resample_image=ResampleImage(*image,geometry_info.rho,
2733 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2734 if (resample_image == (Image *) NULL)
2735 break;
2736 *image=DestroyImage(*image);
2737 *image=resample_image;
2738 break;
2739 }
2740 if (LocaleCompare("resize",option+1) == 0)
2741 {
2742 Image
2743 *resize_image;
2744
2745 /*
2746 Resize image.
2747 */
2748 (void) SyncImageSettings(image_info,*image);
2749 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2750 resize_image=ResizeImage(*image,geometry.width,geometry.height,
2751 (*image)->filter,(*image)->blur,exception);
2752 if (resize_image == (Image *) NULL)
2753 break;
2754 *image=DestroyImage(*image);
2755 *image=resize_image;
2756 break;
2757 }
2758 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
2759 {
2760 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
2761 break;
2762 }
2763 if (LocaleCompare("roll",option+1) == 0)
2764 {
2765 Image
2766 *roll_image;
2767
2768 /*
2769 Roll image.
2770 */
2771 (void) SyncImageSettings(image_info,*image);
2772 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2773 roll_image=RollImage(*image,geometry.x,geometry.y,exception);
2774 if (roll_image == (Image *) NULL)
2775 break;
2776 *image=DestroyImage(*image);
2777 *image=roll_image;
2778 break;
2779 }
2780 if (LocaleCompare("rotate",option+1) == 0)
2781 {
2782 char
2783 *geometry;
2784
2785 Image
2786 *rotate_image;
2787
2788 /*
2789 Check for conditional image rotation.
2790 */
2791 (void) SyncImageSettings(image_info,*image);
2792 if (strchr(argv[i+1],'>') != (char *) NULL)
2793 if ((*image)->columns <= (*image)->rows)
2794 break;
2795 if (strchr(argv[i+1],'<') != (char *) NULL)
2796 if ((*image)->columns >= (*image)->rows)
2797 break;
2798 /*
2799 Rotate image.
2800 */
2801 geometry=ConstantString(argv[i+1]);
2802 (void) SubstituteString(&geometry,">","");
2803 (void) SubstituteString(&geometry,"<","");
2804 (void) ParseGeometry(geometry,&geometry_info);
2805 geometry=DestroyString(geometry);
2806 rotate_image=RotateImage(*image,geometry_info.rho,exception);
2807 if (rotate_image == (Image *) NULL)
2808 break;
2809 *image=DestroyImage(*image);
2810 *image=rotate_image;
2811 break;
2812 }
2813 break;
2814 }
2815 case 's':
2816 {
2817 if (LocaleCompare("sample",option+1) == 0)
2818 {
2819 Image
2820 *sample_image;
2821
2822 /*
2823 Sample image with pixel replication.
2824 */
2825 (void) SyncImageSettings(image_info,*image);
2826 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2827 sample_image=SampleImage(*image,geometry.width,geometry.height,
2828 exception);
2829 if (sample_image == (Image *) NULL)
2830 break;
2831 *image=DestroyImage(*image);
2832 *image=sample_image;
2833 break;
2834 }
2835 if (LocaleCompare("scale",option+1) == 0)
2836 {
2837 Image
2838 *scale_image;
2839
2840 /*
2841 Resize image.
2842 */
2843 (void) SyncImageSettings(image_info,*image);
2844 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2845 scale_image=ScaleImage(*image,geometry.width,geometry.height,
2846 exception);
2847 if (scale_image == (Image *) NULL)
2848 break;
2849 *image=DestroyImage(*image);
2850 *image=scale_image;
2851 break;
2852 }
2853 if (LocaleCompare("selective-blur",option+1) == 0)
2854 {
2855 Image
2856 *blur_image;
2857
2858 /*
2859 Selectively blur pixels within a contrast threshold.
2860 */
2861 (void) SyncImageSettings(image_info,*image);
2862 flags=ParseGeometry(argv[i+1],&geometry_info);
2863 if ((flags & PercentValue) != 0)
2864 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2865 blur_image=SelectiveBlurImageChannel(*image,channel,
2866 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2867 if (blur_image == (Image *) NULL)
2868 break;
2869 *image=DestroyImage(*image);
2870 *image=blur_image;
2871 break;
2872 }
2873 if (LocaleCompare("separate",option+1) == 0)
2874 {
2875 Image
2876 *separate_images;
2877
2878 /*
2879 Break channels into separate images.
2880 */
2881 (void) SyncImageSettings(image_info,*image);
2882 separate_images=SeparateImages(*image,channel,exception);
2883 if (separate_images == (Image *) NULL)
2884 break;
2885 *image=DestroyImage(*image);
2886 *image=separate_images;
2887 break;
2888 }
2889 if (LocaleCompare("sepia-tone",option+1) == 0)
2890 {
2891 double
2892 threshold;
2893
2894 Image
2895 *sepia_image;
2896
2897 /*
2898 Sepia-tone image.
2899 */
2900 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00002901 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002902 sepia_image=SepiaToneImage(*image,threshold,exception);
2903 if (sepia_image == (Image *) NULL)
2904 break;
2905 *image=DestroyImage(*image);
2906 *image=sepia_image;
2907 break;
2908 }
2909 if (LocaleCompare("segment",option+1) == 0)
2910 {
2911 /*
2912 Segment image.
2913 */
2914 (void) SyncImageSettings(image_info,*image);
2915 flags=ParseGeometry(argv[i+1],&geometry_info);
2916 if ((flags & SigmaValue) == 0)
2917 geometry_info.sigma=1.0;
2918 (void) SegmentImage(*image,(*image)->colorspace,image_info->verbose,
2919 geometry_info.rho,geometry_info.sigma);
2920 InheritException(exception,&(*image)->exception);
2921 break;
2922 }
2923 if (LocaleCompare("set",option+1) == 0)
2924 {
2925 /*
2926 Set image option.
2927 */
2928 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2929 (void) DeleteImageRegistry(argv[i+1]+9);
2930 else
2931 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2932 (void) DeleteImageOption(image_info,argv[i+1]+7);
2933 else
2934 (void) DeleteImageProperty(*image,argv[i+1]);
2935 if (*option == '-')
2936 {
2937 char
2938 *value;
2939
2940 value=InterpretImageProperties(image_info,*image,argv[i+2]);
2941 if (value != (char *) NULL)
2942 {
2943 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2944 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,
2945 value,exception);
2946 else
2947 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2948 {
2949 (void) SetImageOption(image_info,argv[i+1]+7,value);
2950 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2951 }
2952 else
2953 (void) SetImageProperty(*image,argv[i+1],value);
2954 value=DestroyString(value);
2955 }
2956 }
2957 break;
2958 }
2959 if (LocaleCompare("shade",option+1) == 0)
2960 {
2961 Image
2962 *shade_image;
2963
2964 /*
2965 Shade image.
2966 */
2967 (void) SyncImageSettings(image_info,*image);
2968 flags=ParseGeometry(argv[i+1],&geometry_info);
2969 if ((flags & SigmaValue) == 0)
2970 geometry_info.sigma=1.0;
2971 shade_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2972 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2973 if (shade_image == (Image *) NULL)
2974 break;
2975 *image=DestroyImage(*image);
2976 *image=shade_image;
2977 break;
2978 }
2979 if (LocaleCompare("shadow",option+1) == 0)
2980 {
2981 Image
2982 *shadow_image;
2983
2984 /*
2985 Shadow image.
2986 */
2987 (void) SyncImageSettings(image_info,*image);
2988 flags=ParseGeometry(argv[i+1],&geometry_info);
2989 if ((flags & SigmaValue) == 0)
2990 geometry_info.sigma=1.0;
2991 if ((flags & XiValue) == 0)
2992 geometry_info.xi=4.0;
2993 if ((flags & PsiValue) == 0)
2994 geometry_info.psi=4.0;
2995 shadow_image=ShadowImage(*image,geometry_info.rho,
2996 geometry_info.sigma,(long) (geometry_info.xi+0.5),(long)
2997 (geometry_info.psi+0.5),exception);
2998 if (shadow_image == (Image *) NULL)
2999 break;
3000 *image=DestroyImage(*image);
3001 *image=shadow_image;
3002 break;
3003 }
3004 if (LocaleCompare("sharpen",option+1) == 0)
3005 {
3006 Image
3007 *sharp_image;
3008
3009 /*
3010 Sharpen image.
3011 */
3012 (void) SyncImageSettings(image_info,*image);
3013 flags=ParseGeometry(argv[i+1],&geometry_info);
3014 if ((flags & SigmaValue) == 0)
3015 geometry_info.sigma=1.0;
3016 sharp_image=SharpenImageChannel(*image,channel,geometry_info.rho,
3017 geometry_info.sigma,exception);
3018 if (sharp_image == (Image *) NULL)
3019 break;
3020 *image=DestroyImage(*image);
3021 *image=sharp_image;
3022 break;
3023 }
3024 if (LocaleCompare("shave",option+1) == 0)
3025 {
3026 Image
3027 *shave_image;
3028
3029 /*
3030 Shave the image edges.
3031 */
3032 (void) SyncImageSettings(image_info,*image);
3033 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
3034 shave_image=ShaveImage(*image,&geometry,exception);
3035 if (shave_image == (Image *) NULL)
3036 break;
3037 *image=DestroyImage(*image);
3038 *image=shave_image;
3039 break;
3040 }
3041 if (LocaleCompare("shear",option+1) == 0)
3042 {
3043 Image
3044 *shear_image;
3045
3046 /*
3047 Shear image.
3048 */
3049 (void) SyncImageSettings(image_info,*image);
3050 flags=ParseGeometry(argv[i+1],&geometry_info);
3051 if ((flags & SigmaValue) == 0)
3052 geometry_info.sigma=geometry_info.rho;
3053 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
3054 exception);
3055 if (shear_image == (Image *) NULL)
3056 break;
3057 *image=DestroyImage(*image);
3058 *image=shear_image;
3059 break;
3060 }
3061 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
3062 {
3063 /*
3064 Sigmoidal non-linearity contrast control.
3065 */
3066 (void) SyncImageSettings(image_info,*image);
3067 flags=ParseGeometry(argv[i+1],&geometry_info);
3068 if ((flags & SigmaValue) == 0)
3069 geometry_info.sigma=(double) QuantumRange/2.0;
3070 if ((flags & PercentValue) != 0)
3071 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3072 100.0;
3073 (void) SigmoidalContrastImageChannel(*image,channel,
3074 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
3075 geometry_info.sigma);
3076 InheritException(exception,&(*image)->exception);
3077 break;
3078 }
3079 if (LocaleCompare("sketch",option+1) == 0)
3080 {
3081 Image
3082 *sketch_image;
3083
3084 /*
3085 Sketch image.
3086 */
3087 (void) SyncImageSettings(image_info,*image);
3088 flags=ParseGeometry(argv[i+1],&geometry_info);
3089 if ((flags & SigmaValue) == 0)
3090 geometry_info.sigma=1.0;
3091 sketch_image=SketchImage(*image,geometry_info.rho,
3092 geometry_info.sigma,geometry_info.xi,exception);
3093 if (sketch_image == (Image *) NULL)
3094 break;
3095 *image=DestroyImage(*image);
3096 *image=sketch_image;
3097 break;
3098 }
3099 if (LocaleCompare("solarize",option+1) == 0)
3100 {
3101 double
3102 threshold;
3103
3104 (void) SyncImageSettings(image_info,*image);
cristyf2f27272009-12-17 14:48:46 +00003105 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003106 (void) SolarizeImage(*image,threshold);
3107 InheritException(exception,&(*image)->exception);
3108 break;
3109 }
3110 if (LocaleCompare("sparse-color",option+1) == 0)
3111 {
3112 Image
3113 *sparse_image;
3114
3115 SparseColorMethod
3116 method;
3117
3118 char
3119 *arguments;
3120
3121 /*
3122 Sparse Color Interpolated Gradient
3123 */
3124 (void) SyncImageSettings(image_info,*image);
3125 method=(SparseColorMethod) ParseMagickOption(
3126 MagickSparseColorOptions,MagickFalse,argv[i+1]);
3127 arguments=InterpretImageProperties(image_info,*image,argv[i+2]);
3128 InheritException(exception,&(*image)->exception);
3129 if (arguments == (char *) NULL)
3130 break;
3131 sparse_image=SparseColorOption(*image,channel,method,arguments,
3132 option[0] == '+' ? MagickTrue : MagickFalse,exception);
3133 arguments=DestroyString(arguments);
3134 if (sparse_image == (Image *) NULL)
3135 break;
3136 *image=DestroyImage(*image);
3137 *image=sparse_image;
3138 break;
3139 }
3140 if (LocaleCompare("splice",option+1) == 0)
3141 {
3142 Image
3143 *splice_image;
3144
3145 /*
3146 Splice a solid color into the image.
3147 */
3148 (void) SyncImageSettings(image_info,*image);
3149 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
3150 splice_image=SpliceImage(*image,&geometry,exception);
3151 if (splice_image == (Image *) NULL)
3152 break;
3153 *image=DestroyImage(*image);
3154 *image=splice_image;
3155 break;
3156 }
3157 if (LocaleCompare("spread",option+1) == 0)
3158 {
3159 Image
3160 *spread_image;
3161
3162 /*
3163 Spread an image.
3164 */
3165 (void) SyncImageSettings(image_info,*image);
3166 (void) ParseGeometry(argv[i+1],&geometry_info);
3167 spread_image=SpreadImage(*image,geometry_info.rho,exception);
3168 if (spread_image == (Image *) NULL)
3169 break;
3170 *image=DestroyImage(*image);
3171 *image=spread_image;
3172 break;
3173 }
3174 if (LocaleCompare("stretch",option+1) == 0)
3175 {
3176 if (*option == '+')
3177 {
3178 draw_info->stretch=UndefinedStretch;
3179 break;
3180 }
3181 draw_info->stretch=(StretchType) ParseMagickOption(
3182 MagickStretchOptions,MagickFalse,argv[i+1]);
3183 break;
3184 }
3185 if (LocaleCompare("strip",option+1) == 0)
3186 {
3187 /*
3188 Strip image of profiles and comments.
3189 */
3190 (void) SyncImageSettings(image_info,*image);
3191 (void) StripImage(*image);
3192 InheritException(exception,&(*image)->exception);
3193 break;
3194 }
3195 if (LocaleCompare("stroke",option+1) == 0)
3196 {
3197 ExceptionInfo
3198 *sans;
3199
3200 if (*option == '+')
3201 {
3202 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3203 if (draw_info->stroke_pattern != (Image *) NULL)
3204 draw_info->stroke_pattern=DestroyImage(
3205 draw_info->stroke_pattern);
3206 break;
3207 }
3208 sans=AcquireExceptionInfo();
3209 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3210 sans=DestroyExceptionInfo(sans);
3211 if (status == MagickFalse)
3212 draw_info->stroke_pattern=GetImageCache(image_info,argv[i+1],
3213 exception);
3214 break;
3215 }
3216 if (LocaleCompare("strokewidth",option+1) == 0)
3217 {
cristyf2f27272009-12-17 14:48:46 +00003218 draw_info->stroke_width=StringToDouble(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003219 break;
3220 }
3221 if (LocaleCompare("style",option+1) == 0)
3222 {
3223 if (*option == '+')
3224 {
3225 draw_info->style=UndefinedStyle;
3226 break;
3227 }
3228 draw_info->style=(StyleType) ParseMagickOption(MagickStyleOptions,
3229 MagickFalse,argv[i+1]);
3230 break;
3231 }
3232 if (LocaleCompare("swirl",option+1) == 0)
3233 {
3234 Image
3235 *swirl_image;
3236
3237 /*
3238 Swirl image.
3239 */
3240 (void) SyncImageSettings(image_info,*image);
3241 (void) ParseGeometry(argv[i+1],&geometry_info);
3242 swirl_image=SwirlImage(*image,geometry_info.rho,exception);
3243 if (swirl_image == (Image *) NULL)
3244 break;
3245 *image=DestroyImage(*image);
3246 *image=swirl_image;
3247 break;
3248 }
3249 break;
3250 }
3251 case 't':
3252 {
3253 if (LocaleCompare("threshold",option+1) == 0)
3254 {
3255 double
3256 threshold;
3257
3258 /*
3259 Threshold image.
3260 */
3261 (void) SyncImageSettings(image_info,*image);
3262 if (*option == '+')
3263 threshold=(double) QuantumRange/2.5;
3264 else
cristyf2f27272009-12-17 14:48:46 +00003265 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00003266 (void) BilevelImageChannel(*image,channel,threshold);
3267 InheritException(exception,&(*image)->exception);
3268 break;
3269 }
3270 if (LocaleCompare("thumbnail",option+1) == 0)
3271 {
3272 Image
3273 *thumbnail_image;
3274
3275 /*
3276 Thumbnail image.
3277 */
3278 (void) SyncImageSettings(image_info,*image);
3279 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3280 thumbnail_image=ThumbnailImage(*image,geometry.width,
3281 geometry.height,exception);
3282 if (thumbnail_image == (Image *) NULL)
3283 break;
3284 *image=DestroyImage(*image);
3285 *image=thumbnail_image;
3286 break;
3287 }
3288 if (LocaleCompare("tile",option+1) == 0)
3289 {
3290 if (*option == '+')
3291 {
3292 if (draw_info->fill_pattern != (Image *) NULL)
3293 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3294 break;
3295 }
3296 draw_info->fill_pattern=GetImageCache(image_info,argv[i+1],
3297 exception);
3298 break;
3299 }
3300 if (LocaleCompare("tint",option+1) == 0)
3301 {
3302 Image
3303 *tint_image;
3304
3305 /*
3306 Tint the image.
3307 */
3308 (void) SyncImageSettings(image_info,*image);
3309 tint_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3310 if (tint_image == (Image *) NULL)
3311 break;
3312 *image=DestroyImage(*image);
3313 *image=tint_image;
3314 break;
3315 }
3316 if (LocaleCompare("transform",option+1) == 0)
3317 {
3318 Image
3319 *transform_image;
3320
3321 /*
3322 Affine transform image.
3323 */
3324 (void) SyncImageSettings(image_info,*image);
3325 transform_image=AffineTransformImage(*image,&draw_info->affine,
3326 exception);
3327 if (transform_image == (Image *) NULL)
3328 break;
3329 *image=DestroyImage(*image);
3330 *image=transform_image;
3331 break;
3332 }
3333 if (LocaleCompare("transparent",option+1) == 0)
3334 {
3335 MagickPixelPacket
3336 target;
3337
3338 (void) SyncImageSettings(image_info,*image);
3339 (void) QueryMagickColor(argv[i+1],&target,exception);
3340 (void) TransparentPaintImage(*image,&target,(Quantum)
3341 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3342 InheritException(exception,&(*image)->exception);
3343 break;
3344 }
3345 if (LocaleCompare("transpose",option+1) == 0)
3346 {
3347 Image
3348 *transpose_image;
3349
3350 /*
3351 Transpose image scanlines.
3352 */
3353 (void) SyncImageSettings(image_info,*image);
3354 transpose_image=TransposeImage(*image,exception);
3355 if (transpose_image == (Image *) NULL)
3356 break;
3357 *image=DestroyImage(*image);
3358 *image=transpose_image;
3359 break;
3360 }
3361 if (LocaleCompare("transverse",option+1) == 0)
3362 {
3363 Image
3364 *transverse_image;
3365
3366 /*
3367 Transverse image scanlines.
3368 */
3369 (void) SyncImageSettings(image_info,*image);
3370 transverse_image=TransverseImage(*image,exception);
3371 if (transverse_image == (Image *) NULL)
3372 break;
3373 *image=DestroyImage(*image);
3374 *image=transverse_image;
3375 break;
3376 }
3377 if (LocaleCompare("treedepth",option+1) == 0)
3378 {
cristye27293e2009-12-18 02:53:20 +00003379 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003380 break;
3381 }
3382 if (LocaleCompare("trim",option+1) == 0)
3383 {
3384 Image
3385 *trim_image;
3386
3387 /*
3388 Trim image.
3389 */
3390 (void) SyncImageSettings(image_info,*image);
3391 trim_image=TrimImage(*image,exception);
3392 if (trim_image == (Image *) NULL)
3393 break;
3394 *image=DestroyImage(*image);
3395 *image=trim_image;
3396 break;
3397 }
3398 if (LocaleCompare("type",option+1) == 0)
3399 {
3400 ImageType
3401 type;
3402
3403 (void) SyncImageSettings(image_info,*image);
3404 if (*option == '+')
3405 type=UndefinedType;
3406 else
3407 type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
3408 argv[i+1]);
3409 (*image)->type=UndefinedType;
3410 (void) SetImageType(*image,type);
3411 InheritException(exception,&(*image)->exception);
3412 break;
3413 }
3414 break;
3415 }
3416 case 'u':
3417 {
3418 if (LocaleCompare("undercolor",option+1) == 0)
3419 {
3420 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3421 exception);
3422 break;
3423 }
cristy045bd902010-01-30 18:56:24 +00003424 if (LocaleCompare("unique",option+1) == 0)
3425 {
3426 if (*option == '+')
3427 {
3428 (void) DeleteImageArtifact(*image,"identify:unique");
3429 break;
3430 }
3431 (void) SetImageArtifact(*image,"identify:unique","true");
3432 break;
3433 }
cristy3ed852e2009-09-05 21:47:34 +00003434 if (LocaleCompare("unique-colors",option+1) == 0)
3435 {
3436 Image
3437 *unique_image;
3438
3439 /*
3440 Unique image colors.
3441 */
3442 (void) SyncImageSettings(image_info,*image);
3443 unique_image=UniqueImageColors(*image,exception);
3444 if (unique_image == (Image *) NULL)
3445 break;
3446 *image=DestroyImage(*image);
3447 *image=unique_image;
3448 break;
3449 }
3450 if (LocaleCompare("unsharp",option+1) == 0)
3451 {
3452 Image
3453 *unsharp_image;
3454
3455 /*
3456 Unsharp mask image.
3457 */
3458 (void) SyncImageSettings(image_info,*image);
3459 flags=ParseGeometry(argv[i+1],&geometry_info);
3460 if ((flags & SigmaValue) == 0)
3461 geometry_info.sigma=1.0;
3462 if ((flags & XiValue) == 0)
3463 geometry_info.xi=1.0;
3464 if ((flags & PsiValue) == 0)
3465 geometry_info.psi=0.05;
3466 unsharp_image=UnsharpMaskImageChannel(*image,channel,
3467 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3468 geometry_info.psi,exception);
3469 if (unsharp_image == (Image *) NULL)
3470 break;
3471 *image=DestroyImage(*image);
3472 *image=unsharp_image;
3473 break;
3474 }
3475 break;
3476 }
3477 case 'v':
3478 {
3479 if (LocaleCompare("verbose",option+1) == 0)
3480 {
3481 (void) SetImageArtifact(*image,option+1,
3482 *option == '+' ? "false" : "true");
3483 break;
3484 }
3485 if (LocaleCompare("vignette",option+1) == 0)
3486 {
3487 Image
3488 *vignette_image;
3489
3490 /*
3491 Vignette image.
3492 */
3493 (void) SyncImageSettings(image_info,*image);
3494 flags=ParseGeometry(argv[i+1],&geometry_info);
3495 if ((flags & SigmaValue) == 0)
3496 geometry_info.sigma=1.0;
3497 if ((flags & XiValue) == 0)
3498 geometry_info.xi=0.1*(*image)->columns;
3499 if ((flags & PsiValue) == 0)
3500 geometry_info.psi=0.1*(*image)->rows;
3501 vignette_image=VignetteImage(*image,geometry_info.rho,
3502 geometry_info.sigma,(long) (geometry_info.xi+0.5),(long)
3503 (geometry_info.psi+0.5),exception);
3504 if (vignette_image == (Image *) NULL)
3505 break;
3506 *image=DestroyImage(*image);
3507 *image=vignette_image;
3508 break;
3509 }
3510 if (LocaleCompare("virtual-pixel",option+1) == 0)
3511 {
3512 if (*option == '+')
3513 {
3514 (void) SetImageVirtualPixelMethod(*image,
3515 UndefinedVirtualPixelMethod);
3516 break;
3517 }
3518 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3519 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
3520 argv[i+1]));
3521 break;
3522 }
3523 break;
3524 }
3525 case 'w':
3526 {
3527 if (LocaleCompare("wave",option+1) == 0)
3528 {
3529 Image
3530 *wave_image;
3531
3532 /*
3533 Wave image.
3534 */
3535 (void) SyncImageSettings(image_info,*image);
3536 flags=ParseGeometry(argv[i+1],&geometry_info);
3537 if ((flags & SigmaValue) == 0)
3538 geometry_info.sigma=1.0;
3539 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
3540 exception);
3541 if (wave_image == (Image *) NULL)
3542 break;
3543 *image=DestroyImage(*image);
3544 *image=wave_image;
3545 break;
3546 }
3547 if (LocaleCompare("weight",option+1) == 0)
3548 {
cristye27293e2009-12-18 02:53:20 +00003549 draw_info->weight=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00003550 if (LocaleCompare(argv[i+1],"all") == 0)
3551 draw_info->weight=0;
3552 if (LocaleCompare(argv[i+1],"bold") == 0)
3553 draw_info->weight=700;
3554 if (LocaleCompare(argv[i+1],"bolder") == 0)
3555 if (draw_info->weight <= 800)
3556 draw_info->weight+=100;
3557 if (LocaleCompare(argv[i+1],"lighter") == 0)
3558 if (draw_info->weight >= 100)
3559 draw_info->weight-=100;
3560 if (LocaleCompare(argv[i+1],"normal") == 0)
3561 draw_info->weight=400;
3562 break;
3563 }
3564 if (LocaleCompare("white-threshold",option+1) == 0)
3565 {
3566 /*
3567 White threshold image.
3568 */
3569 (void) SyncImageSettings(image_info,*image);
3570 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3571 exception);
3572 InheritException(exception,&(*image)->exception);
3573 break;
3574 }
3575 break;
3576 }
3577 default:
3578 break;
3579 }
3580 i+=count;
3581 }
3582 if (region_image != (Image *) NULL)
3583 {
3584 /*
3585 Composite transformed region onto image.
3586 */
3587 (void) SyncImageSettings(image_info,*image);
3588 (void) CompositeImage(region_image,(*image)->matte != MagickFalse ?
3589 OverCompositeOp : CopyCompositeOp,*image,region_geometry.x,
3590 region_geometry.y);
3591 InheritException(exception,&region_image->exception);
3592 *image=DestroyImage(*image);
3593 *image=region_image;
3594 }
3595 /*
3596 Free resources.
3597 */
3598 quantize_info=DestroyQuantizeInfo(quantize_info);
3599 draw_info=DestroyDrawInfo(draw_info);
3600 status=(*image)->exception.severity == UndefinedException ?
3601 MagickTrue : MagickFalse;
3602 return(status);
3603}
3604
3605/*
3606%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3607% %
3608% %
3609% %
3610% M o g r i f y I m a g e C o m m a n d %
3611% %
3612% %
3613% %
3614%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3615%
3616% MogrifyImageCommand() transforms an image or a sequence of images. These
3617% transforms include image scaling, image rotation, color reduction, and
3618% others. The transmogrified image overwrites the original image.
3619%
3620% The format of the MogrifyImageCommand method is:
3621%
3622% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3623% const char **argv,char **metadata,ExceptionInfo *exception)
3624%
3625% A description of each parameter follows:
3626%
3627% o image_info: the image info.
3628%
3629% o argc: the number of elements in the argument vector.
3630%
3631% o argv: A text array containing the command line arguments.
3632%
3633% o metadata: any metadata is returned here.
3634%
3635% o exception: return any errors or warnings in this structure.
3636%
3637*/
3638
3639static MagickBooleanType MogrifyUsage(void)
3640{
3641 static const char
3642 *miscellaneous[]=
3643 {
3644 "-debug events display copious debugging information",
3645 "-help print program options",
3646 "-list type print a list of supported option arguments",
3647 "-log format format of debugging information",
3648 "-version print version information",
3649 (char *) NULL
3650 },
3651 *operators[]=
3652 {
3653 "-adaptive-blur geometry",
3654 " adaptively blur pixels; decrease effect near edges",
3655 "-adaptive-resize geometry",
3656 " adaptively resize image using 'mesh' interpolation",
3657 "-adaptive-sharpen geometry",
3658 " adaptively sharpen pixels; increase effect near edges",
3659 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3660 " transparent, extract, background, or shape",
3661 "-annotate geometry text",
3662 " annotate the image with text",
3663 "-auto-gamma automagically adjust gamma level of image",
3664 "-auto-level automagically adjust color levels of image",
3665 "-auto-orient automagically orient (rotate) image",
3666 "-bench iterations measure performance",
3667 "-black-threshold value",
3668 " force all pixels below the threshold into black",
3669 "-blue-shift simulate a scene at nighttime in the moonlight",
3670 "-blur geometry reduce image noise and reduce detail levels",
3671 "-border geometry surround image with a border of color",
3672 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003673 "-brightness-contrast geometry",
3674 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003675 "-cdl filename color correct with a color decision list",
3676 "-charcoal radius simulate a charcoal drawing",
3677 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003678 "-clamp restrict pixel range from 0 to the quantum depth",
cristy3ed852e2009-09-05 21:47:34 +00003679 "-clip clip along the first path from the 8BIM profile",
3680 "-clip-mask filename associate a clip mask with the image",
3681 "-clip-path id clip along a named path from the 8BIM profile",
3682 "-colorize value colorize the image with the fill color",
3683 "-contrast enhance or reduce the image contrast",
3684 "-contrast-stretch geometry",
3685 " improve contrast by `stretching' the intensity range",
3686 "-convolve coefficients",
3687 " apply a convolution kernel to the image",
3688 "-cycle amount cycle the image colormap",
3689 "-decipher filename convert cipher pixels to plain pixels",
3690 "-deskew threshold straighten an image",
3691 "-despeckle reduce the speckles within an image",
3692 "-distort method args",
3693 " distort images according to given method ad args",
3694 "-draw string annotate the image with a graphic primitive",
3695 "-edge radius apply a filter to detect edges in the image",
3696 "-encipher filename convert plain pixels to cipher pixels",
3697 "-emboss radius emboss an image",
3698 "-enhance apply a digital filter to enhance a noisy image",
3699 "-equalize perform histogram equalization to an image",
3700 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003701 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003702 "-extent geometry set the image size",
3703 "-extract geometry extract area from image",
3704 "-fft implements the discrete Fourier transform (DFT)",
3705 "-flip flip image vertically",
3706 "-floodfill geometry color",
3707 " floodfill the image with color",
3708 "-flop flop image horizontally",
3709 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003710 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003711 " apply function over image values",
3712 "-gamma value level of gamma correction",
3713 "-gaussian-blur geometry",
3714 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003715 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003716 "-identify identify the format and characteristics of the image",
3717 "-ift implements the inverse discrete Fourier transform (DFT)",
3718 "-implode amount implode image pixels about the center",
3719 "-lat geometry local adaptive thresholding",
3720 "-layers method optimize, merge, or compare image layers",
3721 "-level value adjust the level of image contrast",
3722 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003723 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003724 "-linear-stretch geometry",
3725 " improve contrast by `stretching with saturation'",
3726 "-liquid-rescale geometry",
3727 " rescale image with seam-carving",
3728 "-median radius apply a median filter to the image",
3729 "-modulate value vary the brightness, saturation, and hue",
3730 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003731 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003732 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003733 "-motion-blur geometry",
3734 " simulate motion blur",
3735 "-negate replace every pixel with its complementary color ",
3736 "-noise radius add or reduce noise in an image",
3737 "-normalize transform image to span the full range of colors",
3738 "-opaque color change this color to the fill color",
3739 "-ordered-dither NxN",
3740 " add a noise pattern to the image with specific",
3741 " amplitudes",
3742 "-paint radius simulate an oil painting",
3743 "-polaroid angle simulate a Polaroid picture",
3744 "-posterize levels reduce the image to a limited number of color levels",
3745 "-print string interpret string and print to console",
3746 "-profile filename add, delete, or apply an image profile",
3747 "-quantize colorspace reduce colors in this colorspace",
3748 "-radial-blur angle radial blur the image",
3749 "-raise value lighten/darken image edges to create a 3-D effect",
3750 "-random-threshold low,high",
3751 " random threshold the image",
3752 "-recolor matrix translate, scale, shear, or rotate image colors",
3753 "-region geometry apply options to a portion of the image",
3754 "-render render vector graphics",
3755 "-repage geometry size and location of an image canvas",
3756 "-resample geometry change the resolution of an image",
3757 "-resize geometry resize the image",
3758 "-roll geometry roll an image vertically or horizontally",
3759 "-rotate degrees apply Paeth rotation to the image",
3760 "-sample geometry scale image with pixel sampling",
3761 "-scale geometry scale the image",
3762 "-segment values segment an image",
3763 "-selective-blur geometry",
3764 " selectively blur pixels within a contrast threshold",
3765 "-sepia-tone threshold",
3766 " simulate a sepia-toned photo",
3767 "-set property value set an image property",
3768 "-shade degrees shade the image using a distant light source",
3769 "-shadow geometry simulate an image shadow",
3770 "-sharpen geometry sharpen the image",
3771 "-shave geometry shave pixels from the image edges",
3772 "-shear geometry slide one edge of the image along the X or Y axis",
3773 "-sigmoidal-contrast geometry",
3774 " increase the contrast without saturating highlights or shadows",
3775 "-sketch geometry simulate a pencil sketch",
3776 "-solarize threshold negate all pixels above the threshold level",
3777 "-sparse-color method args",
3778 " fill in a image based on a few color points",
3779 "-splice geometry splice the background color into the image",
3780 "-spread radius displace image pixels by a random amount",
3781 "-strip strip image of all profiles and comments",
3782 "-swirl degrees swirl image pixels about the center",
3783 "-threshold value threshold the image",
3784 "-thumbnail geometry create a thumbnail of the image",
3785 "-tile filename tile image when filling a graphic primitive",
3786 "-tint value tint the image with the fill color",
3787 "-transform affine transform image",
3788 "-transparent color make this color transparent within the image",
3789 "-transpose flip image vertically and rotate 90 degrees",
3790 "-transverse flop image horizontally and rotate 270 degrees",
3791 "-trim trim image edges",
3792 "-type type image type",
3793 "-unique-colors discard all but one of any pixel color",
3794 "-unsharp geometry sharpen the image",
3795 "-vignette geometry soften the edges of the image in vignette style",
3796 "-wave geometry alter an image along a sine wave",
3797 "-white-threshold value",
3798 " force all pixels above the threshold into white",
3799 (char *) NULL
3800 },
3801 *sequence_operators[]=
3802 {
3803 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003804 "-clut apply a color lookup table to the image",
3805 "-coalesce merge a sequence of images",
3806 "-combine combine a sequence of images",
3807 "-composite composite image",
3808 "-crop geometry cut out a rectangular region of the image",
3809 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003810 "-evaluate-sequence operator",
3811 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003812 "-flatten flatten a sequence of images",
3813 "-fx expression apply mathematical expression to an image channel(s)",
3814 "-hald-clut apply a Hald color lookup table to the image",
3815 "-morph value morph an image sequence",
3816 "-mosaic create a mosaic from an image sequence",
3817 "-process arguments process the image with a custom image filter",
3818 "-reverse reverse image sequence",
3819 "-separate separate an image channel into a grayscale image",
3820 "-write filename write images to this file",
3821 (char *) NULL
3822 },
3823 *settings[]=
3824 {
3825 "-adjoin join images into a single multi-image file",
3826 "-affine matrix affine transform matrix",
3827 "-alpha option activate, deactivate, reset, or set the alpha channel",
3828 "-antialias remove pixel-aliasing",
3829 "-authenticate password",
3830 " decipher image with this password",
3831 "-attenuate value lessen (or intensify) when adding noise to an image",
3832 "-background color background color",
3833 "-bias value add bias when convolving an image",
3834 "-black-point-compensation",
3835 " use black point compensation",
3836 "-blue-primary point chromaticity blue primary point",
3837 "-bordercolor color border color",
3838 "-caption string assign a caption to an image",
3839 "-channel type apply option to select image channels",
3840 "-colors value preferred number of colors in the image",
3841 "-colorspace type alternate image colorspace",
3842 "-comment string annotate image with comment",
3843 "-compose operator set image composite operator",
3844 "-compress type type of pixel compression when writing the image",
3845 "-define format:option",
3846 " define one or more image format options",
3847 "-delay value display the next image after pausing",
3848 "-density geometry horizontal and vertical density of the image",
3849 "-depth value image depth",
3850 "-display server get image or font from this X server",
3851 "-dispose method layer disposal method",
3852 "-dither method apply error diffusion to image",
3853 "-encoding type text encoding type",
3854 "-endian type endianness (MSB or LSB) of the image",
3855 "-family name render text with this font family",
3856 "-fill color color to use when filling a graphic primitive",
3857 "-filter type use this filter when resizing an image",
3858 "-font name render text with this font",
3859 "-format \"string\" output formatted image characteristics",
3860 "-fuzz distance colors within this distance are considered equal",
3861 "-gravity type horizontal and vertical text placement",
3862 "-green-primary point chromaticity green primary point",
3863 "-intent type type of rendering intent when managing the image color",
3864 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003865 "-interline-spacing value",
3866 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003867 "-interpolate method pixel color interpolation method",
3868 "-interword-spacing value",
3869 " set the space between two words",
3870 "-kerning value set the space between two letters",
3871 "-label string assign a label to an image",
3872 "-limit type value pixel cache resource limit",
3873 "-loop iterations add Netscape loop extension to your GIF animation",
3874 "-mask filename associate a mask with the image",
3875 "-mattecolor color frame color",
3876 "-monitor monitor progress",
3877 "-orient type image orientation",
3878 "-page geometry size and location of an image canvas (setting)",
3879 "-ping efficiently determine image attributes",
3880 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003881 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003882 "-preview type image preview type",
3883 "-quality value JPEG/MIFF/PNG compression level",
3884 "-quiet suppress all warning messages",
3885 "-red-primary point chromaticity red primary point",
3886 "-regard-warnings pay attention to warning messages",
3887 "-remap filename transform image colors to match this set of colors",
3888 "-respect-parentheses settings remain in effect until parenthesis boundary",
3889 "-sampling-factor geometry",
3890 " horizontal and vertical sampling factor",
3891 "-scene value image scene number",
3892 "-seed value seed a new sequence of pseudo-random numbers",
3893 "-size geometry width and height of image",
3894 "-stretch type render text with this font stretch",
3895 "-stroke color graphic primitive stroke color",
3896 "-strokewidth value graphic primitive stroke width",
3897 "-style type render text with this font style",
3898 "-taint image as ineligible for bi-modal delegate",
3899 "-texture filename name of texture to tile onto the image background",
3900 "-tile-offset geometry",
3901 " tile offset",
3902 "-treedepth value color tree depth",
3903 "-transparent-color color",
3904 " transparent color",
3905 "-undercolor color annotation bounding box color",
3906 "-units type the units of image resolution",
3907 "-verbose print detailed information about the image",
3908 "-view FlashPix viewing transforms",
3909 "-virtual-pixel method",
3910 " virtual pixel access method",
3911 "-weight type render text with this font weight",
3912 "-white-point point chromaticity white point",
3913 (char *) NULL
3914 },
3915 *stack_operators[]=
3916 {
3917 "-clone index clone an image",
3918 "-delete index delete the image from the image sequence",
3919 "-insert index insert last image into the image sequence",
3920 "-swap indexes swap two images in the image sequence",
3921 (char *) NULL
3922 };
3923
3924 const char
3925 **p;
3926
3927 (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003928 (void) printf("Copyright: %s\n",GetMagickCopyright());
3929 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003930 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3931 GetClientName());
3932 (void) printf("\nImage Settings:\n");
3933 for (p=settings; *p != (char *) NULL; p++)
3934 (void) printf(" %s\n",*p);
3935 (void) printf("\nImage Operators:\n");
3936 for (p=operators; *p != (char *) NULL; p++)
3937 (void) printf(" %s\n",*p);
3938 (void) printf("\nImage Sequence Operators:\n");
3939 for (p=sequence_operators; *p != (char *) NULL; p++)
3940 (void) printf(" %s\n",*p);
3941 (void) printf("\nImage Stack Operators:\n");
3942 for (p=stack_operators; *p != (char *) NULL; p++)
3943 (void) printf(" %s\n",*p);
3944 (void) printf("\nMiscellaneous Options:\n");
3945 for (p=miscellaneous; *p != (char *) NULL; p++)
3946 (void) printf(" %s\n",*p);
3947 (void) printf(
3948 "\nBy default, the image format of `file' is determined by its magic\n");
3949 (void) printf(
3950 "number. To specify a particular image format, precede the filename\n");
3951 (void) printf(
3952 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3953 (void) printf(
3954 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3955 (void) printf("'-' for standard input or output.\n");
3956 return(MagickFalse);
3957}
3958
3959WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3960 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3961{
3962#define DestroyMogrify() \
3963{ \
3964 if (format != (char *) NULL) \
3965 format=DestroyString(format); \
3966 if (path != (char *) NULL) \
3967 path=DestroyString(path); \
3968 DestroyImageStack(); \
3969 for (i=0; i < (long) argc; i++) \
3970 argv[i]=DestroyString(argv[i]); \
3971 argv=(char **) RelinquishMagickMemory(argv); \
3972}
3973#define ThrowMogrifyException(asperity,tag,option) \
3974{ \
3975 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3976 option); \
3977 DestroyMogrify(); \
3978 return(MagickFalse); \
3979}
3980#define ThrowMogrifyInvalidArgumentException(option,argument) \
3981{ \
3982 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3983 "InvalidArgument","`%s': %s",argument,option); \
3984 DestroyMogrify(); \
3985 return(MagickFalse); \
3986}
3987
3988 char
3989 *format,
3990 *option,
3991 *path;
3992
3993 Image
3994 *image;
3995
3996 ImageStack
3997 image_stack[MaxImageStackDepth+1];
3998
3999 long
4000 j,
4001 k;
4002
4003 register long
4004 i;
4005
4006 MagickBooleanType
4007 global_colormap;
4008
4009 MagickBooleanType
4010 fire,
4011 pend;
4012
4013 MagickStatusType
4014 status;
4015
4016 /*
4017 Set defaults.
4018 */
4019 assert(image_info != (ImageInfo *) NULL);
4020 assert(image_info->signature == MagickSignature);
4021 if (image_info->debug != MagickFalse)
4022 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4023 assert(exception != (ExceptionInfo *) NULL);
4024 if (argc == 2)
4025 {
4026 option=argv[1];
4027 if ((LocaleCompare("version",option+1) == 0) ||
4028 (LocaleCompare("-version",option+1) == 0))
4029 {
4030 (void) fprintf(stdout,"Version: %s\n",
4031 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00004032 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
4033 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00004034 return(MagickFalse);
4035 }
4036 }
4037 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00004038 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00004039 format=(char *) NULL;
4040 path=(char *) NULL;
4041 global_colormap=MagickFalse;
4042 k=0;
4043 j=1;
4044 NewImageStack();
4045 option=(char *) NULL;
4046 pend=MagickFalse;
4047 status=MagickTrue;
4048 /*
4049 Parse command line.
4050 */
4051 ReadCommandlLine(argc,&argv);
4052 status=ExpandFilenames(&argc,&argv);
4053 if (status == MagickFalse)
4054 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
4055 GetExceptionMessage(errno));
4056 for (i=1; i < (long) argc; i++)
4057 {
4058 option=argv[i];
4059 if (LocaleCompare(option,"(") == 0)
4060 {
4061 FireImageStack(MagickFalse,MagickTrue,pend);
4062 if (k == MaxImageStackDepth)
4063 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
4064 option);
4065 PushImageStack();
4066 continue;
4067 }
4068 if (LocaleCompare(option,")") == 0)
4069 {
4070 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
4071 if (k == 0)
4072 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
4073 PopImageStack();
4074 continue;
4075 }
4076 if (IsMagickOption(option) == MagickFalse)
4077 {
4078 char
4079 backup_filename[MaxTextExtent],
4080 *filename;
4081
4082 Image
4083 *images;
4084
4085 /*
4086 Option is a file name: begin by reading image from specified file.
4087 */
4088 FireImageStack(MagickFalse,MagickFalse,pend);
4089 filename=argv[i];
4090 if ((LocaleCompare(filename,"--") == 0) && (i < (argc-1)))
4091 filename=argv[++i];
4092 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
4093 images=ReadImages(image_info,exception);
4094 status&=(images != (Image *) NULL) &&
4095 (exception->severity < ErrorException);
4096 if (images == (Image *) NULL)
4097 continue;
4098 if (path != (char *) NULL)
4099 {
4100 GetPathComponent(option,TailPath,filename);
4101 (void) FormatMagickString(images->filename,MaxTextExtent,"%s%c%s",
4102 path,*DirectorySeparator,filename);
4103 }
4104 if (format != (char *) NULL)
4105 AppendImageFormat(format,images->filename);
4106 AppendImageStack(images);
4107 FinalizeImageSettings(image_info,image,MagickFalse);
4108 if (global_colormap != MagickFalse)
4109 {
4110 QuantizeInfo
4111 *quantize_info;
4112
4113 quantize_info=AcquireQuantizeInfo(image_info);
4114 (void) RemapImages(quantize_info,images,(Image *) NULL);
4115 quantize_info=DestroyQuantizeInfo(quantize_info);
4116 }
4117 *backup_filename='\0';
4118 if ((LocaleCompare(image->filename,"-") != 0) &&
4119 (IsPathWritable(image->filename) != MagickFalse))
4120 {
4121 register long
4122 i;
4123
4124 /*
4125 Rename image file as backup.
4126 */
4127 (void) CopyMagickString(backup_filename,image->filename,
4128 MaxTextExtent);
4129 for (i=0; i < 6; i++)
4130 {
4131 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
4132 if (IsPathAccessible(backup_filename) == MagickFalse)
4133 break;
4134 }
4135 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
4136 (rename(image->filename,backup_filename) != 0))
4137 *backup_filename='\0';
4138 }
4139 /*
4140 Write transmogrified image to disk.
4141 */
4142 image_info->synchronize=MagickTrue;
4143 status&=WriteImages(image_info,image,image->filename,exception);
4144 if ((status == MagickFalse) && (*backup_filename != '\0'))
4145 (void) remove(backup_filename);
4146 RemoveAllImageStack();
4147 continue;
4148 }
4149 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4150 switch (*(option+1))
4151 {
4152 case 'a':
4153 {
4154 if (LocaleCompare("adaptive-blur",option+1) == 0)
4155 {
4156 i++;
4157 if (i == (long) argc)
4158 ThrowMogrifyException(OptionError,"MissingArgument",option);
4159 if (IsGeometry(argv[i]) == MagickFalse)
4160 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4161 break;
4162 }
4163 if (LocaleCompare("adaptive-resize",option+1) == 0)
4164 {
4165 i++;
4166 if (i == (long) argc)
4167 ThrowMogrifyException(OptionError,"MissingArgument",option);
4168 if (IsGeometry(argv[i]) == MagickFalse)
4169 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4170 break;
4171 }
4172 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4173 {
4174 i++;
4175 if (i == (long) argc)
4176 ThrowMogrifyException(OptionError,"MissingArgument",option);
4177 if (IsGeometry(argv[i]) == MagickFalse)
4178 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4179 break;
4180 }
4181 if (LocaleCompare("affine",option+1) == 0)
4182 {
4183 if (*option == '+')
4184 break;
4185 i++;
4186 if (i == (long) argc)
4187 ThrowMogrifyException(OptionError,"MissingArgument",option);
4188 if (IsGeometry(argv[i]) == MagickFalse)
4189 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4190 break;
4191 }
4192 if (LocaleCompare("alpha",option+1) == 0)
4193 {
4194 long
4195 type;
4196
4197 if (*option == '+')
4198 break;
4199 i++;
4200 if (i == (long) argc)
4201 ThrowMogrifyException(OptionError,"MissingArgument",option);
4202 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
4203 if (type < 0)
4204 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4205 argv[i]);
4206 break;
4207 }
4208 if (LocaleCompare("annotate",option+1) == 0)
4209 {
4210 if (*option == '+')
4211 break;
4212 i++;
4213 if (i == (long) argc)
4214 ThrowMogrifyException(OptionError,"MissingArgument",option);
4215 if (IsGeometry(argv[i]) == MagickFalse)
4216 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4217 if (i == (long) argc)
4218 ThrowMogrifyException(OptionError,"MissingArgument",option);
4219 i++;
4220 break;
4221 }
4222 if (LocaleCompare("antialias",option+1) == 0)
4223 break;
4224 if (LocaleCompare("append",option+1) == 0)
4225 break;
4226 if (LocaleCompare("attenuate",option+1) == 0)
4227 {
4228 if (*option == '+')
4229 break;
4230 i++;
4231 if (i == (long) (argc-1))
4232 ThrowMogrifyException(OptionError,"MissingArgument",option);
4233 if (IsGeometry(argv[i]) == MagickFalse)
4234 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4235 break;
4236 }
4237 if (LocaleCompare("authenticate",option+1) == 0)
4238 {
4239 if (*option == '+')
4240 break;
4241 i++;
4242 if (i == (long) argc)
4243 ThrowMogrifyException(OptionError,"MissingArgument",option);
4244 break;
4245 }
4246 if (LocaleCompare("auto-gamma",option+1) == 0)
4247 break;
4248 if (LocaleCompare("auto-level",option+1) == 0)
4249 break;
4250 if (LocaleCompare("auto-orient",option+1) == 0)
4251 break;
4252 if (LocaleCompare("average",option+1) == 0)
4253 break;
4254 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4255 }
4256 case 'b':
4257 {
4258 if (LocaleCompare("background",option+1) == 0)
4259 {
4260 if (*option == '+')
4261 break;
4262 i++;
4263 if (i == (long) argc)
4264 ThrowMogrifyException(OptionError,"MissingArgument",option);
4265 break;
4266 }
4267 if (LocaleCompare("bias",option+1) == 0)
4268 {
4269 if (*option == '+')
4270 break;
4271 i++;
4272 if (i == (long) (argc-1))
4273 ThrowMogrifyException(OptionError,"MissingArgument",option);
4274 if (IsGeometry(argv[i]) == MagickFalse)
4275 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4276 break;
4277 }
4278 if (LocaleCompare("black-point-compensation",option+1) == 0)
4279 break;
4280 if (LocaleCompare("black-threshold",option+1) == 0)
4281 {
4282 if (*option == '+')
4283 break;
4284 i++;
4285 if (i == (long) argc)
4286 ThrowMogrifyException(OptionError,"MissingArgument",option);
4287 if (IsGeometry(argv[i]) == MagickFalse)
4288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4289 break;
4290 }
4291 if (LocaleCompare("blue-primary",option+1) == 0)
4292 {
4293 if (*option == '+')
4294 break;
4295 i++;
4296 if (i == (long) argc)
4297 ThrowMogrifyException(OptionError,"MissingArgument",option);
4298 if (IsGeometry(argv[i]) == MagickFalse)
4299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4300 break;
4301 }
4302 if (LocaleCompare("blue-shift",option+1) == 0)
4303 {
4304 i++;
4305 if (i == (long) argc)
4306 ThrowMogrifyException(OptionError,"MissingArgument",option);
4307 if (IsGeometry(argv[i]) == MagickFalse)
4308 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4309 break;
4310 }
4311 if (LocaleCompare("blur",option+1) == 0)
4312 {
4313 i++;
4314 if (i == (long) argc)
4315 ThrowMogrifyException(OptionError,"MissingArgument",option);
4316 if (IsGeometry(argv[i]) == MagickFalse)
4317 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4318 break;
4319 }
4320 if (LocaleCompare("border",option+1) == 0)
4321 {
4322 if (*option == '+')
4323 break;
4324 i++;
4325 if (i == (long) argc)
4326 ThrowMogrifyException(OptionError,"MissingArgument",option);
4327 if (IsGeometry(argv[i]) == MagickFalse)
4328 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4329 break;
4330 }
4331 if (LocaleCompare("bordercolor",option+1) == 0)
4332 {
4333 if (*option == '+')
4334 break;
4335 i++;
4336 if (i == (long) argc)
4337 ThrowMogrifyException(OptionError,"MissingArgument",option);
4338 break;
4339 }
4340 if (LocaleCompare("box",option+1) == 0)
4341 {
4342 if (*option == '+')
4343 break;
4344 i++;
4345 if (i == (long) argc)
4346 ThrowMogrifyException(OptionError,"MissingArgument",option);
4347 break;
4348 }
cristya28d6b82010-01-11 20:03:47 +00004349 if (LocaleCompare("brightness-contrast",option+1) == 0)
4350 {
4351 i++;
4352 if (i == (long) argc)
4353 ThrowMogrifyException(OptionError,"MissingArgument",option);
4354 if (IsGeometry(argv[i]) == MagickFalse)
4355 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4356 break;
4357 }
cristy3ed852e2009-09-05 21:47:34 +00004358 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4359 }
4360 case 'c':
4361 {
4362 if (LocaleCompare("cache",option+1) == 0)
4363 {
4364 if (*option == '+')
4365 break;
4366 i++;
4367 if (i == (long) argc)
4368 ThrowMogrifyException(OptionError,"MissingArgument",option);
4369 if (IsGeometry(argv[i]) == MagickFalse)
4370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4371 break;
4372 }
4373 if (LocaleCompare("caption",option+1) == 0)
4374 {
4375 if (*option == '+')
4376 break;
4377 i++;
4378 if (i == (long) argc)
4379 ThrowMogrifyException(OptionError,"MissingArgument",option);
4380 break;
4381 }
4382 if (LocaleCompare("channel",option+1) == 0)
4383 {
4384 long
4385 channel;
4386
4387 if (*option == '+')
4388 break;
4389 i++;
4390 if (i == (long) (argc-1))
4391 ThrowMogrifyException(OptionError,"MissingArgument",option);
4392 channel=ParseChannelOption(argv[i]);
4393 if (channel < 0)
4394 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4395 argv[i]);
4396 break;
4397 }
4398 if (LocaleCompare("cdl",option+1) == 0)
4399 {
4400 if (*option == '+')
4401 break;
4402 i++;
4403 if (i == (long) (argc-1))
4404 ThrowMogrifyException(OptionError,"MissingArgument",option);
4405 break;
4406 }
4407 if (LocaleCompare("charcoal",option+1) == 0)
4408 {
4409 if (*option == '+')
4410 break;
4411 i++;
4412 if (i == (long) argc)
4413 ThrowMogrifyException(OptionError,"MissingArgument",option);
4414 if (IsGeometry(argv[i]) == MagickFalse)
4415 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4416 break;
4417 }
4418 if (LocaleCompare("chop",option+1) == 0)
4419 {
4420 if (*option == '+')
4421 break;
4422 i++;
4423 if (i == (long) argc)
4424 ThrowMogrifyException(OptionError,"MissingArgument",option);
4425 if (IsGeometry(argv[i]) == MagickFalse)
4426 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4427 break;
4428 }
cristy1eb45dd2009-09-25 16:38:06 +00004429 if (LocaleCompare("clamp",option+1) == 0)
4430 break;
4431 if (LocaleCompare("clip",option+1) == 0)
4432 break;
cristy3ed852e2009-09-05 21:47:34 +00004433 if (LocaleCompare("clip-mask",option+1) == 0)
4434 {
4435 if (*option == '+')
4436 break;
4437 i++;
4438 if (i == (long) argc)
4439 ThrowMogrifyException(OptionError,"MissingArgument",option);
4440 break;
4441 }
4442 if (LocaleCompare("clut",option+1) == 0)
4443 break;
4444 if (LocaleCompare("coalesce",option+1) == 0)
4445 break;
4446 if (LocaleCompare("colorize",option+1) == 0)
4447 {
4448 if (*option == '+')
4449 break;
4450 i++;
4451 if (i == (long) argc)
4452 ThrowMogrifyException(OptionError,"MissingArgument",option);
4453 if (IsGeometry(argv[i]) == MagickFalse)
4454 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4455 break;
4456 }
4457 if (LocaleCompare("colors",option+1) == 0)
4458 {
4459 if (*option == '+')
4460 break;
4461 i++;
4462 if (i == (long) argc)
4463 ThrowMogrifyException(OptionError,"MissingArgument",option);
4464 if (IsGeometry(argv[i]) == MagickFalse)
4465 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4466 break;
4467 }
4468 if (LocaleCompare("colorspace",option+1) == 0)
4469 {
4470 long
4471 colorspace;
4472
4473 if (*option == '+')
4474 break;
4475 i++;
4476 if (i == (long) argc)
4477 ThrowMogrifyException(OptionError,"MissingArgument",option);
4478 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
4479 argv[i]);
4480 if (colorspace < 0)
4481 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4482 argv[i]);
4483 break;
4484 }
4485 if (LocaleCompare("combine",option+1) == 0)
4486 break;
4487 if (LocaleCompare("comment",option+1) == 0)
4488 {
4489 if (*option == '+')
4490 break;
4491 i++;
4492 if (i == (long) argc)
4493 ThrowMogrifyException(OptionError,"MissingArgument",option);
4494 break;
4495 }
4496 if (LocaleCompare("composite",option+1) == 0)
4497 break;
4498 if (LocaleCompare("compress",option+1) == 0)
4499 {
4500 long
4501 compress;
4502
4503 if (*option == '+')
4504 break;
4505 i++;
4506 if (i == (long) argc)
4507 ThrowMogrifyException(OptionError,"MissingArgument",option);
4508 compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
4509 argv[i]);
4510 if (compress < 0)
4511 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4512 argv[i]);
4513 break;
4514 }
cristy22879752009-10-25 23:55:40 +00004515 if (LocaleCompare("concurrent",option+1) == 0)
4516 break;
cristy3ed852e2009-09-05 21:47:34 +00004517 if (LocaleCompare("contrast",option+1) == 0)
4518 break;
4519 if (LocaleCompare("contrast-stretch",option+1) == 0)
4520 {
4521 i++;
4522 if (i == (long) argc)
4523 ThrowMogrifyException(OptionError,"MissingArgument",option);
4524 if (IsGeometry(argv[i]) == MagickFalse)
4525 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4526 break;
4527 }
4528 if (LocaleCompare("convolve",option+1) == 0)
4529 {
anthony29188a82010-01-22 10:12:34 +00004530 char
4531 token[MaxTextExtent];
4532
cristy3ed852e2009-09-05 21:47:34 +00004533 if (*option == '+')
4534 break;
4535 i++;
4536 if (i == (long) argc)
4537 ThrowMogrifyException(OptionError,"MissingArgument",option);
anthony29188a82010-01-22 10:12:34 +00004538#if 1
cristydfbe6ca2010-03-12 14:08:17 +00004539 (void) token;
cristy3ed852e2009-09-05 21:47:34 +00004540 if (IsGeometry(argv[i]) == MagickFalse)
4541 ThrowMogrifyInvalidArgumentException(option,argv[i]);
anthony29188a82010-01-22 10:12:34 +00004542#else
4543 /* Allow the use of built-in kernels like 'gaussian'
4544 * These may not work for kernels with 'nan' values, like 'diamond'
4545 */
4546 GetMagickToken(argv[i],NULL,token);
4547 if ( isalpha((int)token[0]) )
4548 {
4549 long
4550 op;
4551
4552 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
4553 if (op < 0)
4554 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
4555 token);
4556 }
4557 /* geometry current returns invalid if 'nan' values are used */
4558 else if (IsGeometry(argv[i]) == MagickFalse)
4559 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4560#endif
cristy3ed852e2009-09-05 21:47:34 +00004561 break;
4562 }
4563 if (LocaleCompare("crop",option+1) == 0)
4564 {
4565 if (*option == '+')
4566 break;
4567 i++;
4568 if (i == (long) argc)
4569 ThrowMogrifyException(OptionError,"MissingArgument",option);
4570 if (IsGeometry(argv[i]) == MagickFalse)
4571 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4572 break;
4573 }
4574 if (LocaleCompare("cycle",option+1) == 0)
4575 {
4576 if (*option == '+')
4577 break;
4578 i++;
4579 if (i == (long) argc)
4580 ThrowMogrifyException(OptionError,"MissingArgument",option);
4581 if (IsGeometry(argv[i]) == MagickFalse)
4582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4583 break;
4584 }
4585 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4586 }
4587 case 'd':
4588 {
4589 if (LocaleCompare("decipher",option+1) == 0)
4590 {
4591 if (*option == '+')
4592 break;
4593 i++;
4594 if (i == (long) (argc-1))
4595 ThrowMogrifyException(OptionError,"MissingArgument",option);
4596 break;
4597 }
4598 if (LocaleCompare("deconstruct",option+1) == 0)
4599 break;
4600 if (LocaleCompare("debug",option+1) == 0)
4601 {
4602 long
4603 event;
4604
4605 if (*option == '+')
4606 break;
4607 i++;
4608 if (i == (long) argc)
4609 ThrowMogrifyException(OptionError,"MissingArgument",option);
4610 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
4611 if (event < 0)
4612 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4613 argv[i]);
4614 (void) SetLogEventMask(argv[i]);
4615 break;
4616 }
4617 if (LocaleCompare("define",option+1) == 0)
4618 {
4619 i++;
4620 if (i == (long) argc)
4621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 if (*option == '+')
4623 {
4624 const char
4625 *define;
4626
4627 define=GetImageOption(image_info,argv[i]);
4628 if (define == (const char *) NULL)
4629 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4630 break;
4631 }
4632 break;
4633 }
4634 if (LocaleCompare("delay",option+1) == 0)
4635 {
4636 if (*option == '+')
4637 break;
4638 i++;
4639 if (i == (long) argc)
4640 ThrowMogrifyException(OptionError,"MissingArgument",option);
4641 if (IsGeometry(argv[i]) == MagickFalse)
4642 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4643 break;
4644 }
4645 if (LocaleCompare("density",option+1) == 0)
4646 {
4647 if (*option == '+')
4648 break;
4649 i++;
4650 if (i == (long) argc)
4651 ThrowMogrifyException(OptionError,"MissingArgument",option);
4652 if (IsGeometry(argv[i]) == MagickFalse)
4653 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4654 break;
4655 }
4656 if (LocaleCompare("depth",option+1) == 0)
4657 {
4658 if (*option == '+')
4659 break;
4660 i++;
4661 if (i == (long) argc)
4662 ThrowMogrifyException(OptionError,"MissingArgument",option);
4663 if (IsGeometry(argv[i]) == MagickFalse)
4664 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4665 break;
4666 }
4667 if (LocaleCompare("deskew",option+1) == 0)
4668 {
4669 if (*option == '+')
4670 break;
4671 i++;
4672 if (i == (long) argc)
4673 ThrowMogrifyException(OptionError,"MissingArgument",option);
4674 if (IsGeometry(argv[i]) == MagickFalse)
4675 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676 break;
4677 }
4678 if (LocaleCompare("despeckle",option+1) == 0)
4679 break;
4680 if (LocaleCompare("dft",option+1) == 0)
4681 break;
4682 if (LocaleCompare("display",option+1) == 0)
4683 {
4684 if (*option == '+')
4685 break;
4686 i++;
4687 if (i == (long) argc)
4688 ThrowMogrifyException(OptionError,"MissingArgument",option);
4689 break;
4690 }
4691 if (LocaleCompare("dispose",option+1) == 0)
4692 {
4693 long
4694 dispose;
4695
4696 if (*option == '+')
4697 break;
4698 i++;
4699 if (i == (long) argc)
4700 ThrowMogrifyException(OptionError,"MissingArgument",option);
4701 dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
4702 if (dispose < 0)
4703 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4704 argv[i]);
4705 break;
4706 }
4707 if (LocaleCompare("distort",option+1) == 0)
4708 {
4709 long
4710 op;
4711
4712 i++;
4713 if (i == (long) argc)
4714 ThrowMogrifyException(OptionError,"MissingArgument",option);
4715 op=ParseMagickOption(MagickDistortOptions,MagickFalse,argv[i]);
4716 if (op < 0)
4717 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4718 argv[i]);
4719 i++;
4720 if (i == (long) (argc-1))
4721 ThrowMogrifyException(OptionError,"MissingArgument",option);
4722 break;
4723 }
4724 if (LocaleCompare("dither",option+1) == 0)
4725 {
4726 long
4727 method;
4728
4729 if (*option == '+')
4730 break;
4731 i++;
4732 if (i == (long) argc)
4733 ThrowMogrifyException(OptionError,"MissingArgument",option);
4734 method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
4735 if (method < 0)
4736 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4737 argv[i]);
4738 break;
4739 }
4740 if (LocaleCompare("draw",option+1) == 0)
4741 {
4742 if (*option == '+')
4743 break;
4744 i++;
4745 if (i == (long) argc)
4746 ThrowMogrifyException(OptionError,"MissingArgument",option);
4747 break;
4748 }
cristy22879752009-10-25 23:55:40 +00004749 if (LocaleCompare("duration",option+1) == 0)
4750 {
4751 if (*option == '+')
4752 break;
4753 i++;
4754 if (i == (long) (argc-1))
4755 ThrowMogrifyException(OptionError,"MissingArgument",option);
4756 if (IsGeometry(argv[i]) == MagickFalse)
4757 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4758 break;
4759 }
cristy3ed852e2009-09-05 21:47:34 +00004760 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4761 }
4762 case 'e':
4763 {
4764 if (LocaleCompare("edge",option+1) == 0)
4765 {
4766 if (*option == '+')
4767 break;
4768 i++;
4769 if (i == (long) argc)
4770 ThrowMogrifyException(OptionError,"MissingArgument",option);
4771 if (IsGeometry(argv[i]) == MagickFalse)
4772 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4773 break;
4774 }
4775 if (LocaleCompare("emboss",option+1) == 0)
4776 {
4777 if (*option == '+')
4778 break;
4779 i++;
4780 if (i == (long) argc)
4781 ThrowMogrifyException(OptionError,"MissingArgument",option);
4782 if (IsGeometry(argv[i]) == MagickFalse)
4783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4784 break;
4785 }
4786 if (LocaleCompare("encipher",option+1) == 0)
4787 {
4788 if (*option == '+')
4789 break;
4790 i++;
4791 if (i == (long) argc)
4792 ThrowMogrifyException(OptionError,"MissingArgument",option);
4793 break;
4794 }
4795 if (LocaleCompare("encoding",option+1) == 0)
4796 {
4797 if (*option == '+')
4798 break;
4799 i++;
4800 if (i == (long) argc)
4801 ThrowMogrifyException(OptionError,"MissingArgument",option);
4802 break;
4803 }
4804 if (LocaleCompare("endian",option+1) == 0)
4805 {
4806 long
4807 endian;
4808
4809 if (*option == '+')
4810 break;
4811 i++;
4812 if (i == (long) argc)
4813 ThrowMogrifyException(OptionError,"MissingArgument",option);
4814 endian=ParseMagickOption(MagickEndianOptions,MagickFalse,argv[i]);
4815 if (endian < 0)
4816 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4817 argv[i]);
4818 break;
4819 }
4820 if (LocaleCompare("enhance",option+1) == 0)
4821 break;
4822 if (LocaleCompare("equalize",option+1) == 0)
4823 break;
4824 if (LocaleCompare("evaluate",option+1) == 0)
4825 {
4826 long
4827 op;
4828
4829 if (*option == '+')
4830 break;
4831 i++;
4832 if (i == (long) argc)
4833 ThrowMogrifyException(OptionError,"MissingArgument",option);
4834 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4835 if (op < 0)
4836 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4837 argv[i]);
4838 i++;
4839 if (i == (long) (argc-1))
4840 ThrowMogrifyException(OptionError,"MissingArgument",option);
4841 if (IsGeometry(argv[i]) == MagickFalse)
4842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4843 break;
4844 }
cristyd18ae7c2010-03-07 17:39:52 +00004845 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4846 {
4847 long
4848 op;
4849
4850 if (*option == '+')
4851 break;
4852 i++;
4853 if (i == (long) argc)
4854 ThrowMogrifyException(OptionError,"MissingArgument",option);
4855 op=ParseMagickOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4856 if (op < 0)
4857 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4858 argv[i]);
4859 break;
4860 }
cristy3ed852e2009-09-05 21:47:34 +00004861 if (LocaleCompare("extent",option+1) == 0)
4862 {
4863 if (*option == '+')
4864 break;
4865 i++;
4866 if (i == (long) argc)
4867 ThrowMogrifyException(OptionError,"MissingArgument",option);
4868 if (IsGeometry(argv[i]) == MagickFalse)
4869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4870 break;
4871 }
4872 if (LocaleCompare("extract",option+1) == 0)
4873 {
4874 if (*option == '+')
4875 break;
4876 i++;
4877 if (i == (long) argc)
4878 ThrowMogrifyException(OptionError,"MissingArgument",option);
4879 if (IsGeometry(argv[i]) == MagickFalse)
4880 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4881 break;
4882 }
4883 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4884 }
4885 case 'f':
4886 {
4887 if (LocaleCompare("family",option+1) == 0)
4888 {
4889 if (*option == '+')
4890 break;
4891 i++;
4892 if (i == (long) (argc-1))
4893 ThrowMogrifyException(OptionError,"MissingArgument",option);
4894 break;
4895 }
4896 if (LocaleCompare("fill",option+1) == 0)
4897 {
4898 if (*option == '+')
4899 break;
4900 i++;
4901 if (i == (long) argc)
4902 ThrowMogrifyException(OptionError,"MissingArgument",option);
4903 break;
4904 }
4905 if (LocaleCompare("filter",option+1) == 0)
4906 {
4907 long
4908 filter;
4909
4910 if (*option == '+')
4911 break;
4912 i++;
4913 if (i == (long) argc)
4914 ThrowMogrifyException(OptionError,"MissingArgument",option);
4915 filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
4916 if (filter < 0)
4917 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4918 argv[i]);
4919 break;
4920 }
4921 if (LocaleCompare("flatten",option+1) == 0)
4922 break;
4923 if (LocaleCompare("flip",option+1) == 0)
4924 break;
4925 if (LocaleCompare("flop",option+1) == 0)
4926 break;
4927 if (LocaleCompare("floodfill",option+1) == 0)
4928 {
4929 if (*option == '+')
4930 break;
4931 i++;
4932 if (i == (long) argc)
4933 ThrowMogrifyException(OptionError,"MissingArgument",option);
4934 if (IsGeometry(argv[i]) == MagickFalse)
4935 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4936 i++;
4937 if (i == (long) argc)
4938 ThrowMogrifyException(OptionError,"MissingArgument",option);
4939 break;
4940 }
4941 if (LocaleCompare("font",option+1) == 0)
4942 {
4943 if (*option == '+')
4944 break;
4945 i++;
4946 if (i == (long) argc)
4947 ThrowMogrifyException(OptionError,"MissingArgument",option);
4948 break;
4949 }
4950 if (LocaleCompare("format",option+1) == 0)
4951 {
4952 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4953 (void) CloneString(&format,(char *) NULL);
4954 if (*option == '+')
4955 break;
4956 i++;
4957 if (i == (long) argc)
4958 ThrowMogrifyException(OptionError,"MissingArgument",option);
4959 (void) CloneString(&format,argv[i]);
4960 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4961 (void) ConcatenateMagickString(image_info->filename,":",
4962 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004963 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004964 if (*image_info->magick == '\0')
4965 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4966 format);
4967 break;
4968 }
4969 if (LocaleCompare("frame",option+1) == 0)
4970 {
4971 if (*option == '+')
4972 break;
4973 i++;
4974 if (i == (long) argc)
4975 ThrowMogrifyException(OptionError,"MissingArgument",option);
4976 if (IsGeometry(argv[i]) == MagickFalse)
4977 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4978 break;
4979 }
4980 if (LocaleCompare("function",option+1) == 0)
4981 {
4982 long
4983 op;
4984
4985 if (*option == '+')
4986 break;
4987 i++;
4988 if (i == (long) argc)
4989 ThrowMogrifyException(OptionError,"MissingArgument",option);
4990 op=ParseMagickOption(MagickFunctionOptions,MagickFalse,argv[i]);
4991 if (op < 0)
4992 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4993 i++;
4994 if (i == (long) (argc-1))
4995 ThrowMogrifyException(OptionError,"MissingArgument",option);
4996 break;
4997 }
4998 if (LocaleCompare("fuzz",option+1) == 0)
4999 {
5000 if (*option == '+')
5001 break;
5002 i++;
5003 if (i == (long) argc)
5004 ThrowMogrifyException(OptionError,"MissingArgument",option);
5005 if (IsGeometry(argv[i]) == MagickFalse)
5006 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5007 break;
5008 }
5009 if (LocaleCompare("fx",option+1) == 0)
5010 {
5011 if (*option == '+')
5012 break;
5013 i++;
5014 if (i == (long) (argc-1))
5015 ThrowMogrifyException(OptionError,"MissingArgument",option);
5016 break;
5017 }
5018 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5019 }
5020 case 'g':
5021 {
5022 if (LocaleCompare("gamma",option+1) == 0)
5023 {
5024 i++;
5025 if (i == (long) argc)
5026 ThrowMogrifyException(OptionError,"MissingArgument",option);
5027 if (IsGeometry(argv[i]) == MagickFalse)
5028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5029 break;
5030 }
5031 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5032 (LocaleCompare("gaussian",option+1) == 0))
5033 {
5034 i++;
5035 if (i == (long) argc)
5036 ThrowMogrifyException(OptionError,"MissingArgument",option);
5037 if (IsGeometry(argv[i]) == MagickFalse)
5038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5039 break;
5040 }
5041 if (LocaleCompare("geometry",option+1) == 0)
5042 {
5043 if (*option == '+')
5044 break;
5045 i++;
5046 if (i == (long) argc)
5047 ThrowMogrifyException(OptionError,"MissingArgument",option);
5048 if (IsGeometry(argv[i]) == MagickFalse)
5049 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5050 break;
5051 }
5052 if (LocaleCompare("gravity",option+1) == 0)
5053 {
5054 long
5055 gravity;
5056
5057 if (*option == '+')
5058 break;
5059 i++;
5060 if (i == (long) argc)
5061 ThrowMogrifyException(OptionError,"MissingArgument",option);
5062 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
5063 if (gravity < 0)
5064 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5065 argv[i]);
5066 break;
5067 }
5068 if (LocaleCompare("green-primary",option+1) == 0)
5069 {
5070 if (*option == '+')
5071 break;
5072 i++;
5073 if (i == (long) argc)
5074 ThrowMogrifyException(OptionError,"MissingArgument",option);
5075 if (IsGeometry(argv[i]) == MagickFalse)
5076 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5077 break;
5078 }
5079 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5080 }
5081 case 'h':
5082 {
5083 if (LocaleCompare("hald-clut",option+1) == 0)
5084 break;
5085 if ((LocaleCompare("help",option+1) == 0) ||
5086 (LocaleCompare("-help",option+1) == 0))
5087 return(MogrifyUsage());
5088 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5089 }
5090 case 'i':
5091 {
5092 if (LocaleCompare("identify",option+1) == 0)
5093 break;
5094 if (LocaleCompare("idft",option+1) == 0)
5095 break;
5096 if (LocaleCompare("implode",option+1) == 0)
5097 {
5098 if (*option == '+')
5099 break;
5100 i++;
5101 if (i == (long) argc)
5102 ThrowMogrifyException(OptionError,"MissingArgument",option);
5103 if (IsGeometry(argv[i]) == MagickFalse)
5104 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5105 break;
5106 }
5107 if (LocaleCompare("intent",option+1) == 0)
5108 {
5109 long
5110 intent;
5111
5112 if (*option == '+')
5113 break;
5114 i++;
5115 if (i == (long) (argc-1))
5116 ThrowMogrifyException(OptionError,"MissingArgument",option);
5117 intent=ParseMagickOption(MagickIntentOptions,MagickFalse,argv[i]);
5118 if (intent < 0)
5119 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5120 argv[i]);
5121 break;
5122 }
5123 if (LocaleCompare("interlace",option+1) == 0)
5124 {
5125 long
5126 interlace;
5127
5128 if (*option == '+')
5129 break;
5130 i++;
5131 if (i == (long) argc)
5132 ThrowMogrifyException(OptionError,"MissingArgument",option);
5133 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
5134 argv[i]);
5135 if (interlace < 0)
5136 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5137 argv[i]);
5138 break;
5139 }
cristyb32b90a2009-09-07 21:45:48 +00005140 if (LocaleCompare("interline-spacing",option+1) == 0)
5141 {
5142 if (*option == '+')
5143 break;
5144 i++;
5145 if (i == (long) (argc-1))
5146 ThrowMogrifyException(OptionError,"MissingArgument",option);
5147 if (IsGeometry(argv[i]) == MagickFalse)
5148 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5149 break;
5150 }
cristy3ed852e2009-09-05 21:47:34 +00005151 if (LocaleCompare("interpolate",option+1) == 0)
5152 {
5153 long
5154 interpolate;
5155
5156 if (*option == '+')
5157 break;
5158 i++;
5159 if (i == (long) argc)
5160 ThrowMogrifyException(OptionError,"MissingArgument",option);
5161 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
5162 argv[i]);
5163 if (interpolate < 0)
5164 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5165 argv[i]);
5166 break;
5167 }
5168 if (LocaleCompare("interword-spacing",option+1) == 0)
5169 {
5170 if (*option == '+')
5171 break;
5172 i++;
5173 if (i == (long) (argc-1))
5174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 if (IsGeometry(argv[i]) == MagickFalse)
5176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5177 break;
5178 }
5179 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5180 }
5181 case 'k':
5182 {
5183 if (LocaleCompare("kerning",option+1) == 0)
5184 {
5185 if (*option == '+')
5186 break;
5187 i++;
5188 if (i == (long) (argc-1))
5189 ThrowMogrifyException(OptionError,"MissingArgument",option);
5190 if (IsGeometry(argv[i]) == MagickFalse)
5191 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5192 break;
5193 }
5194 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5195 }
5196 case 'l':
5197 {
5198 if (LocaleCompare("label",option+1) == 0)
5199 {
5200 if (*option == '+')
5201 break;
5202 i++;
5203 if (i == (long) argc)
5204 ThrowMogrifyException(OptionError,"MissingArgument",option);
5205 break;
5206 }
5207 if (LocaleCompare("lat",option+1) == 0)
5208 {
5209 if (*option == '+')
5210 break;
5211 i++;
5212 if (i == (long) argc)
5213 ThrowMogrifyException(OptionError,"MissingArgument",option);
5214 if (IsGeometry(argv[i]) == MagickFalse)
5215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5216 }
5217 if (LocaleCompare("layers",option+1) == 0)
5218 {
5219 long
5220 type;
5221
5222 if (*option == '+')
5223 break;
5224 i++;
5225 if (i == (long) (argc-1))
5226 ThrowMogrifyException(OptionError,"MissingArgument",option);
5227 type=ParseMagickOption(MagickLayerOptions,MagickFalse,argv[i]);
5228 if (type < 0)
5229 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5230 argv[i]);
5231 break;
5232 }
5233 if (LocaleCompare("level",option+1) == 0)
5234 {
5235 i++;
5236 if (i == (long) argc)
5237 ThrowMogrifyException(OptionError,"MissingArgument",option);
5238 if (IsGeometry(argv[i]) == MagickFalse)
5239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5240 break;
5241 }
5242 if (LocaleCompare("level-colors",option+1) == 0)
5243 {
5244 i++;
5245 if (i == (long) argc)
5246 ThrowMogrifyException(OptionError,"MissingArgument",option);
5247 break;
5248 }
5249 if (LocaleCompare("linewidth",option+1) == 0)
5250 {
5251 if (*option == '+')
5252 break;
5253 i++;
5254 if (i == (long) argc)
5255 ThrowMogrifyException(OptionError,"MissingArgument",option);
5256 if (IsGeometry(argv[i]) == MagickFalse)
5257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5258 break;
5259 }
5260 if (LocaleCompare("limit",option+1) == 0)
5261 {
5262 char
5263 *p;
5264
5265 double
5266 value;
5267
5268 long
5269 resource;
5270
5271 if (*option == '+')
5272 break;
5273 i++;
5274 if (i == (long) argc)
5275 ThrowMogrifyException(OptionError,"MissingArgument",option);
5276 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
5277 argv[i]);
5278 if (resource < 0)
5279 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5280 argv[i]);
5281 i++;
5282 if (i == (long) argc)
5283 ThrowMogrifyException(OptionError,"MissingArgument",option);
5284 value=strtod(argv[i],&p);
5285 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5287 break;
5288 }
5289 if (LocaleCompare("liquid-rescale",option+1) == 0)
5290 {
5291 i++;
5292 if (i == (long) argc)
5293 ThrowMogrifyException(OptionError,"MissingArgument",option);
5294 if (IsGeometry(argv[i]) == MagickFalse)
5295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5296 break;
5297 }
5298 if (LocaleCompare("list",option+1) == 0)
5299 {
5300 long
5301 list;
5302
5303 if (*option == '+')
5304 break;
5305 i++;
5306 if (i == (long) argc)
5307 ThrowMogrifyException(OptionError,"MissingArgument",option);
5308 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
5309 if (list < 0)
5310 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5311 (void) MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5312 argv+j,exception);
5313 return(MagickTrue);
5314 }
5315 if (LocaleCompare("log",option+1) == 0)
5316 {
5317 if (*option == '+')
5318 break;
5319 i++;
5320 if ((i == (long) argc) ||
5321 (strchr(argv[i],'%') == (char *) NULL))
5322 ThrowMogrifyException(OptionError,"MissingArgument",option);
5323 break;
5324 }
5325 if (LocaleCompare("loop",option+1) == 0)
5326 {
5327 if (*option == '+')
5328 break;
5329 i++;
5330 if (i == (long) argc)
5331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 if (IsGeometry(argv[i]) == MagickFalse)
5333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5334 break;
5335 }
5336 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5337 }
5338 case 'm':
5339 {
5340 if (LocaleCompare("map",option+1) == 0)
5341 {
5342 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5343 if (*option == '+')
5344 break;
5345 i++;
5346 if (i == (long) argc)
5347 ThrowMogrifyException(OptionError,"MissingArgument",option);
5348 break;
5349 }
5350 if (LocaleCompare("mask",option+1) == 0)
5351 {
5352 if (*option == '+')
5353 break;
5354 i++;
5355 if (i == (long) argc)
5356 ThrowMogrifyException(OptionError,"MissingArgument",option);
5357 break;
5358 }
5359 if (LocaleCompare("matte",option+1) == 0)
5360 break;
5361 if (LocaleCompare("mattecolor",option+1) == 0)
5362 {
5363 if (*option == '+')
5364 break;
5365 i++;
5366 if (i == (long) argc)
5367 ThrowMogrifyException(OptionError,"MissingArgument",option);
5368 break;
5369 }
cristyf40785b2010-03-06 02:27:27 +00005370 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005371 break;
cristyf40785b2010-03-06 02:27:27 +00005372 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005373 break;
cristy3ed852e2009-09-05 21:47:34 +00005374 if (LocaleCompare("modulate",option+1) == 0)
5375 {
5376 if (*option == '+')
5377 break;
5378 i++;
5379 if (i == (long) argc)
5380 ThrowMogrifyException(OptionError,"MissingArgument",option);
5381 if (IsGeometry(argv[i]) == MagickFalse)
5382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5383 break;
5384 }
5385 if (LocaleCompare("median",option+1) == 0)
5386 {
5387 if (*option == '+')
5388 break;
5389 i++;
5390 if (i == (long) argc)
5391 ThrowMogrifyException(OptionError,"MissingArgument",option);
5392 if (IsGeometry(argv[i]) == MagickFalse)
5393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5394 break;
5395 }
5396 if (LocaleCompare("monitor",option+1) == 0)
5397 break;
5398 if (LocaleCompare("monochrome",option+1) == 0)
5399 break;
5400 if (LocaleCompare("morph",option+1) == 0)
5401 {
5402 if (*option == '+')
5403 break;
5404 i++;
5405 if (i == (long) (argc-1))
5406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 if (IsGeometry(argv[i]) == MagickFalse)
5408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5409 break;
5410 }
anthony29188a82010-01-22 10:12:34 +00005411 if (LocaleCompare("morphology",option+1) == 0)
5412 {
5413 long
5414 op;
5415
5416 char
5417 token[MaxTextExtent];
5418
5419 i++;
5420 if (i == (long) argc)
5421 ThrowMogrifyException(OptionError,"MissingArgument",option);
5422 GetMagickToken(argv[i],NULL,token);
5423 op=ParseMagickOption(MagickMorphologyOptions,MagickFalse,token);
5424 if (op < 0)
5425 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5426 token);
5427 i++;
5428 if (i == (long) (argc-1))
5429 ThrowMogrifyException(OptionError,"MissingArgument",option);
5430 GetMagickToken(argv[i],NULL,token);
5431 if ( isalpha((int)token[0]) )
5432 {
5433 op=ParseMagickOption(MagickKernelOptions,MagickFalse,token);
5434 if (op < 0)
5435 ThrowMogrifyException(OptionError,"UnrecognizedKernelType",
5436 token);
5437 }
5438#if 0
5439 /* DO NOT ENABLE, geometry can not handle user defined kernels
5440 * which include 'nan' values, though '-' are acceptable.
5441 */
5442 else if (IsGeometry(argv[i]) == MagickFalse)
5443 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5444#endif
5445 break;
5446 }
cristy3ed852e2009-09-05 21:47:34 +00005447 if (LocaleCompare("mosaic",option+1) == 0)
5448 break;
5449 if (LocaleCompare("motion-blur",option+1) == 0)
5450 {
5451 if (*option == '+')
5452 break;
5453 i++;
5454 if (i == (long) argc)
5455 ThrowMogrifyException(OptionError,"MissingArgument",option);
5456 if (IsGeometry(argv[i]) == MagickFalse)
5457 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5458 break;
5459 }
5460 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5461 }
5462 case 'n':
5463 {
5464 if (LocaleCompare("negate",option+1) == 0)
5465 break;
5466 if (LocaleCompare("noise",option+1) == 0)
5467 {
5468 i++;
5469 if (i == (long) argc)
5470 ThrowMogrifyException(OptionError,"MissingArgument",option);
5471 if (*option == '+')
5472 {
5473 long
5474 noise;
5475
5476 noise=ParseMagickOption(MagickNoiseOptions,MagickFalse,argv[i]);
5477 if (noise < 0)
5478 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5479 argv[i]);
5480 break;
5481 }
5482 if (IsGeometry(argv[i]) == MagickFalse)
5483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484 break;
5485 }
5486 if (LocaleCompare("noop",option+1) == 0)
5487 break;
5488 if (LocaleCompare("normalize",option+1) == 0)
5489 break;
5490 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5491 }
5492 case 'o':
5493 {
5494 if (LocaleCompare("opaque",option+1) == 0)
5495 {
cristy3ed852e2009-09-05 21:47:34 +00005496 i++;
5497 if (i == (long) argc)
5498 ThrowMogrifyException(OptionError,"MissingArgument",option);
5499 break;
5500 }
5501 if (LocaleCompare("ordered-dither",option+1) == 0)
5502 {
5503 if (*option == '+')
5504 break;
5505 i++;
5506 if (i == (long) argc)
5507 ThrowMogrifyException(OptionError,"MissingArgument",option);
5508 break;
5509 }
5510 if (LocaleCompare("orient",option+1) == 0)
5511 {
5512 long
5513 orientation;
5514
5515 orientation=UndefinedOrientation;
5516 if (*option == '+')
5517 break;
5518 i++;
5519 if (i == (long) (argc-1))
5520 ThrowMogrifyException(OptionError,"MissingArgument",option);
5521 orientation=ParseMagickOption(MagickOrientationOptions,MagickFalse,
5522 argv[i]);
5523 if (orientation < 0)
5524 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5525 argv[i]);
5526 break;
5527 }
5528 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5529 }
5530 case 'p':
5531 {
5532 if (LocaleCompare("page",option+1) == 0)
5533 {
5534 if (*option == '+')
5535 break;
5536 i++;
5537 if (i == (long) argc)
5538 ThrowMogrifyException(OptionError,"MissingArgument",option);
5539 break;
5540 }
5541 if (LocaleCompare("paint",option+1) == 0)
5542 {
5543 if (*option == '+')
5544 break;
5545 i++;
5546 if (i == (long) argc)
5547 ThrowMogrifyException(OptionError,"MissingArgument",option);
5548 if (IsGeometry(argv[i]) == MagickFalse)
5549 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550 break;
5551 }
5552 if (LocaleCompare("path",option+1) == 0)
5553 {
5554 (void) CloneString(&path,(char *) NULL);
5555 if (*option == '+')
5556 break;
5557 i++;
5558 if (i == (long) argc)
5559 ThrowMogrifyException(OptionError,"MissingArgument",option);
5560 (void) CloneString(&path,argv[i]);
5561 break;
5562 }
5563 if (LocaleCompare("pointsize",option+1) == 0)
5564 {
5565 if (*option == '+')
5566 break;
5567 i++;
5568 if (i == (long) argc)
5569 ThrowMogrifyException(OptionError,"MissingArgument",option);
5570 if (IsGeometry(argv[i]) == MagickFalse)
5571 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5572 break;
5573 }
5574 if (LocaleCompare("polaroid",option+1) == 0)
5575 {
5576 if (*option == '+')
5577 break;
5578 i++;
5579 if (i == (long) argc)
5580 ThrowMogrifyException(OptionError,"MissingArgument",option);
5581 if (IsGeometry(argv[i]) == MagickFalse)
5582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5583 break;
5584 }
5585 if (LocaleCompare("posterize",option+1) == 0)
5586 {
5587 if (*option == '+')
5588 break;
5589 i++;
5590 if (i == (long) argc)
5591 ThrowMogrifyException(OptionError,"MissingArgument",option);
5592 if (IsGeometry(argv[i]) == MagickFalse)
5593 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5594 break;
5595 }
cristye7f51092010-01-17 00:39:37 +00005596 if (LocaleCompare("precision",option+1) == 0)
5597 {
5598 if (*option == '+')
5599 break;
5600 i++;
5601 if (i == (long) argc)
5602 ThrowMogrifyException(OptionError,"MissingArgument",option);
5603 if (IsGeometry(argv[i]) == MagickFalse)
5604 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5605 break;
5606 }
cristy3ed852e2009-09-05 21:47:34 +00005607 if (LocaleCompare("print",option+1) == 0)
5608 {
5609 if (*option == '+')
5610 break;
5611 i++;
5612 if (i == (long) argc)
5613 ThrowMogrifyException(OptionError,"MissingArgument",option);
5614 break;
5615 }
5616 if (LocaleCompare("process",option+1) == 0)
5617 {
5618 if (*option == '+')
5619 break;
5620 i++;
5621 if (i == (long) (argc-1))
5622 ThrowMogrifyException(OptionError,"MissingArgument",option);
5623 break;
5624 }
5625 if (LocaleCompare("profile",option+1) == 0)
5626 {
5627 i++;
5628 if (i == (long) argc)
5629 ThrowMogrifyException(OptionError,"MissingArgument",option);
5630 break;
5631 }
5632 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5633 }
5634 case 'q':
5635 {
5636 if (LocaleCompare("quality",option+1) == 0)
5637 {
5638 if (*option == '+')
5639 break;
5640 i++;
5641 if (i == (long) argc)
5642 ThrowMogrifyException(OptionError,"MissingArgument",option);
5643 if (IsGeometry(argv[i]) == MagickFalse)
5644 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5645 break;
5646 }
5647 if (LocaleCompare("quantize",option+1) == 0)
5648 {
5649 long
5650 colorspace;
5651
5652 if (*option == '+')
5653 break;
5654 i++;
5655 if (i == (long) (argc-1))
5656 ThrowMogrifyException(OptionError,"MissingArgument",option);
5657 colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
5658 argv[i]);
5659 if (colorspace < 0)
5660 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5661 argv[i]);
5662 break;
5663 }
5664 if (LocaleCompare("quiet",option+1) == 0)
5665 break;
5666 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5667 }
5668 case 'r':
5669 {
5670 if (LocaleCompare("radial-blur",option+1) == 0)
5671 {
5672 i++;
5673 if (i == (long) argc)
5674 ThrowMogrifyException(OptionError,"MissingArgument",option);
5675 if (IsGeometry(argv[i]) == MagickFalse)
5676 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5677 break;
5678 }
5679 if (LocaleCompare("raise",option+1) == 0)
5680 {
5681 i++;
5682 if (i == (long) argc)
5683 ThrowMogrifyException(OptionError,"MissingArgument",option);
5684 if (IsGeometry(argv[i]) == MagickFalse)
5685 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5686 break;
5687 }
5688 if (LocaleCompare("random-threshold",option+1) == 0)
5689 {
5690 if (*option == '+')
5691 break;
5692 i++;
5693 if (i == (long) argc)
5694 ThrowMogrifyException(OptionError,"MissingArgument",option);
5695 if (IsGeometry(argv[i]) == MagickFalse)
5696 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5697 break;
5698 }
5699 if (LocaleCompare("red-primary",option+1) == 0)
5700 {
5701 if (*option == '+')
5702 break;
5703 i++;
5704 if (i == (long) argc)
5705 ThrowMogrifyException(OptionError,"MissingArgument",option);
5706 if (IsGeometry(argv[i]) == MagickFalse)
5707 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5708 }
5709 if (LocaleCompare("region",option+1) == 0)
5710 {
5711 if (*option == '+')
5712 break;
5713 i++;
5714 if (i == (long) argc)
5715 ThrowMogrifyException(OptionError,"MissingArgument",option);
5716 if (IsGeometry(argv[i]) == MagickFalse)
5717 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5718 break;
5719 }
5720 if (LocaleCompare("render",option+1) == 0)
5721 break;
5722 if (LocaleCompare("repage",option+1) == 0)
5723 {
5724 if (*option == '+')
5725 break;
5726 i++;
5727 if (i == (long) argc)
5728 ThrowMogrifyException(OptionError,"MissingArgument",option);
5729 if (IsGeometry(argv[i]) == MagickFalse)
5730 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5731 break;
5732 }
5733 if (LocaleCompare("resample",option+1) == 0)
5734 {
5735 if (*option == '+')
5736 break;
5737 i++;
5738 if (i == (long) argc)
5739 ThrowMogrifyException(OptionError,"MissingArgument",option);
5740 if (IsGeometry(argv[i]) == MagickFalse)
5741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5742 break;
5743 }
5744 if (LocaleCompare("resize",option+1) == 0)
5745 {
5746 if (*option == '+')
5747 break;
5748 i++;
5749 if (i == (long) argc)
5750 ThrowMogrifyException(OptionError,"MissingArgument",option);
5751 if (IsGeometry(argv[i]) == MagickFalse)
5752 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5753 break;
5754 }
5755 if (LocaleCompare("reverse",option+1) == 0)
5756 break;
5757 if (LocaleCompare("roll",option+1) == 0)
5758 {
5759 if (*option == '+')
5760 break;
5761 i++;
5762 if (i == (long) argc)
5763 ThrowMogrifyException(OptionError,"MissingArgument",option);
5764 if (IsGeometry(argv[i]) == MagickFalse)
5765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5766 break;
5767 }
5768 if (LocaleCompare("rotate",option+1) == 0)
5769 {
5770 i++;
5771 if (i == (long) argc)
5772 ThrowMogrifyException(OptionError,"MissingArgument",option);
5773 if (IsGeometry(argv[i]) == MagickFalse)
5774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5775 break;
5776 }
5777 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5778 }
5779 case 's':
5780 {
5781 if (LocaleCompare("sample",option+1) == 0)
5782 {
5783 if (*option == '+')
5784 break;
5785 i++;
5786 if (i == (long) argc)
5787 ThrowMogrifyException(OptionError,"MissingArgument",option);
5788 if (IsGeometry(argv[i]) == MagickFalse)
5789 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5790 break;
5791 }
5792 if (LocaleCompare("sampling-factor",option+1) == 0)
5793 {
5794 if (*option == '+')
5795 break;
5796 i++;
5797 if (i == (long) argc)
5798 ThrowMogrifyException(OptionError,"MissingArgument",option);
5799 if (IsGeometry(argv[i]) == MagickFalse)
5800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5801 break;
5802 }
5803 if (LocaleCompare("scale",option+1) == 0)
5804 {
5805 if (*option == '+')
5806 break;
5807 i++;
5808 if (i == (long) argc)
5809 ThrowMogrifyException(OptionError,"MissingArgument",option);
5810 if (IsGeometry(argv[i]) == MagickFalse)
5811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5812 break;
5813 }
5814 if (LocaleCompare("scene",option+1) == 0)
5815 {
5816 if (*option == '+')
5817 break;
5818 i++;
5819 if (i == (long) argc)
5820 ThrowMogrifyException(OptionError,"MissingArgument",option);
5821 if (IsGeometry(argv[i]) == MagickFalse)
5822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5823 break;
5824 }
5825 if (LocaleCompare("seed",option+1) == 0)
5826 {
5827 if (*option == '+')
5828 break;
5829 i++;
5830 if (i == (long) argc)
5831 ThrowMogrifyException(OptionError,"MissingArgument",option);
5832 if (IsGeometry(argv[i]) == MagickFalse)
5833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834 break;
5835 }
5836 if (LocaleCompare("segment",option+1) == 0)
5837 {
5838 if (*option == '+')
5839 break;
5840 i++;
5841 if (i == (long) argc)
5842 ThrowMogrifyException(OptionError,"MissingArgument",option);
5843 if (IsGeometry(argv[i]) == MagickFalse)
5844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5845 break;
5846 }
5847 if (LocaleCompare("selective-blur",option+1) == 0)
5848 {
5849 i++;
5850 if (i == (long) argc)
5851 ThrowMogrifyException(OptionError,"MissingArgument",option);
5852 if (IsGeometry(argv[i]) == MagickFalse)
5853 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5854 break;
5855 }
5856 if (LocaleCompare("separate",option+1) == 0)
5857 break;
5858 if (LocaleCompare("sepia-tone",option+1) == 0)
5859 {
5860 if (*option == '+')
5861 break;
5862 i++;
5863 if (i == (long) argc)
5864 ThrowMogrifyException(OptionError,"MissingArgument",option);
5865 if (IsGeometry(argv[i]) == MagickFalse)
5866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5867 break;
5868 }
5869 if (LocaleCompare("set",option+1) == 0)
5870 {
5871 i++;
5872 if (i == (long) argc)
5873 ThrowMogrifyException(OptionError,"MissingArgument",option);
5874 if (*option == '+')
5875 break;
5876 i++;
5877 if (i == (long) argc)
5878 ThrowMogrifyException(OptionError,"MissingArgument",option);
5879 break;
5880 }
5881 if (LocaleCompare("shade",option+1) == 0)
5882 {
5883 i++;
5884 if (i == (long) argc)
5885 ThrowMogrifyException(OptionError,"MissingArgument",option);
5886 if (IsGeometry(argv[i]) == MagickFalse)
5887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5888 break;
5889 }
5890 if (LocaleCompare("shadow",option+1) == 0)
5891 {
5892 if (*option == '+')
5893 break;
5894 i++;
5895 if (i == (long) argc)
5896 ThrowMogrifyException(OptionError,"MissingArgument",option);
5897 if (IsGeometry(argv[i]) == MagickFalse)
5898 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5899 break;
5900 }
5901 if (LocaleCompare("sharpen",option+1) == 0)
5902 {
5903 i++;
5904 if (i == (long) argc)
5905 ThrowMogrifyException(OptionError,"MissingArgument",option);
5906 if (IsGeometry(argv[i]) == MagickFalse)
5907 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5908 break;
5909 }
5910 if (LocaleCompare("shave",option+1) == 0)
5911 {
5912 if (*option == '+')
5913 break;
5914 i++;
5915 if (i == (long) argc)
5916 ThrowMogrifyException(OptionError,"MissingArgument",option);
5917 if (IsGeometry(argv[i]) == MagickFalse)
5918 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5919 break;
5920 }
5921 if (LocaleCompare("shear",option+1) == 0)
5922 {
5923 i++;
5924 if (i == (long) argc)
5925 ThrowMogrifyException(OptionError,"MissingArgument",option);
5926 if (IsGeometry(argv[i]) == MagickFalse)
5927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5928 break;
5929 }
5930 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5931 {
5932 i++;
5933 if (i == (long) (argc-1))
5934 ThrowMogrifyException(OptionError,"MissingArgument",option);
5935 if (IsGeometry(argv[i]) == MagickFalse)
5936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5937 break;
5938 }
5939 if (LocaleCompare("size",option+1) == 0)
5940 {
5941 if (*option == '+')
5942 break;
5943 i++;
5944 if (i == (long) argc)
5945 ThrowMogrifyException(OptionError,"MissingArgument",option);
5946 if (IsGeometry(argv[i]) == MagickFalse)
5947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5948 break;
5949 }
5950 if (LocaleCompare("sketch",option+1) == 0)
5951 {
5952 if (*option == '+')
5953 break;
5954 i++;
5955 if (i == (long) argc)
5956 ThrowMogrifyException(OptionError,"MissingArgument",option);
5957 if (IsGeometry(argv[i]) == MagickFalse)
5958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5959 break;
5960 }
5961 if (LocaleCompare("solarize",option+1) == 0)
5962 {
5963 if (*option == '+')
5964 break;
5965 i++;
5966 if (i == (long) argc)
5967 ThrowMogrifyException(OptionError,"MissingArgument",option);
5968 if (IsGeometry(argv[i]) == MagickFalse)
5969 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5970 break;
5971 }
5972 if (LocaleCompare("sparse-color",option+1) == 0)
5973 {
5974 long
5975 op;
5976
5977 i++;
5978 if (i == (long) argc)
5979 ThrowMogrifyException(OptionError,"MissingArgument",option);
5980 op=ParseMagickOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5981 if (op < 0)
5982 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5983 argv[i]);
5984 i++;
5985 if (i == (long) (argc-1))
5986 ThrowMogrifyException(OptionError,"MissingArgument",option);
5987 break;
5988 }
5989 if (LocaleCompare("spread",option+1) == 0)
5990 {
5991 if (*option == '+')
5992 break;
5993 i++;
5994 if (i == (long) argc)
5995 ThrowMogrifyException(OptionError,"MissingArgument",option);
5996 if (IsGeometry(argv[i]) == MagickFalse)
5997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5998 break;
5999 }
6000 if (LocaleCompare("stretch",option+1) == 0)
6001 {
6002 long
6003 stretch;
6004
6005 if (*option == '+')
6006 break;
6007 i++;
6008 if (i == (long) (argc-1))
6009 ThrowMogrifyException(OptionError,"MissingArgument",option);
6010 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,argv[i]);
6011 if (stretch < 0)
6012 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6013 argv[i]);
6014 break;
6015 }
6016 if (LocaleCompare("strip",option+1) == 0)
6017 break;
6018 if (LocaleCompare("stroke",option+1) == 0)
6019 {
6020 if (*option == '+')
6021 break;
6022 i++;
6023 if (i == (long) argc)
6024 ThrowMogrifyException(OptionError,"MissingArgument",option);
6025 break;
6026 }
6027 if (LocaleCompare("strokewidth",option+1) == 0)
6028 {
6029 if (*option == '+')
6030 break;
6031 i++;
6032 if (i == (long) argc)
6033 ThrowMogrifyException(OptionError,"MissingArgument",option);
6034 if (IsGeometry(argv[i]) == MagickFalse)
6035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036 break;
6037 }
6038 if (LocaleCompare("style",option+1) == 0)
6039 {
6040 long
6041 style;
6042
6043 if (*option == '+')
6044 break;
6045 i++;
6046 if (i == (long) (argc-1))
6047 ThrowMogrifyException(OptionError,"MissingArgument",option);
6048 style=ParseMagickOption(MagickStyleOptions,MagickFalse,argv[i]);
6049 if (style < 0)
6050 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6051 argv[i]);
6052 break;
6053 }
6054 if (LocaleCompare("swirl",option+1) == 0)
6055 {
6056 if (*option == '+')
6057 break;
6058 i++;
6059 if (i == (long) argc)
6060 ThrowMogrifyException(OptionError,"MissingArgument",option);
6061 if (IsGeometry(argv[i]) == MagickFalse)
6062 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6063 break;
6064 }
6065 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6066 }
6067 case 't':
6068 {
6069 if (LocaleCompare("taint",option+1) == 0)
6070 break;
6071 if (LocaleCompare("texture",option+1) == 0)
6072 {
6073 if (*option == '+')
6074 break;
6075 i++;
6076 if (i == (long) argc)
6077 ThrowMogrifyException(OptionError,"MissingArgument",option);
6078 break;
6079 }
6080 if (LocaleCompare("tile",option+1) == 0)
6081 {
6082 if (*option == '+')
6083 break;
6084 i++;
6085 if (i == (long) (argc-1))
6086 ThrowMogrifyException(OptionError,"MissingArgument",option);
6087 break;
6088 }
6089 if (LocaleCompare("tile-offset",option+1) == 0)
6090 {
6091 if (*option == '+')
6092 break;
6093 i++;
6094 if (i == (long) argc)
6095 ThrowMogrifyException(OptionError,"MissingArgument",option);
6096 if (IsGeometry(argv[i]) == MagickFalse)
6097 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6098 break;
6099 }
6100 if (LocaleCompare("tint",option+1) == 0)
6101 {
6102 if (*option == '+')
6103 break;
6104 i++;
6105 if (i == (long) (argc-1))
6106 ThrowMogrifyException(OptionError,"MissingArgument",option);
6107 if (IsGeometry(argv[i]) == MagickFalse)
6108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6109 break;
6110 }
6111 if (LocaleCompare("transform",option+1) == 0)
6112 break;
6113 if (LocaleCompare("transpose",option+1) == 0)
6114 break;
6115 if (LocaleCompare("transverse",option+1) == 0)
6116 break;
6117 if (LocaleCompare("threshold",option+1) == 0)
6118 {
6119 if (*option == '+')
6120 break;
6121 i++;
6122 if (i == (long) argc)
6123 ThrowMogrifyException(OptionError,"MissingArgument",option);
6124 if (IsGeometry(argv[i]) == MagickFalse)
6125 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6126 break;
6127 }
6128 if (LocaleCompare("thumbnail",option+1) == 0)
6129 {
6130 if (*option == '+')
6131 break;
6132 i++;
6133 if (i == (long) argc)
6134 ThrowMogrifyException(OptionError,"MissingArgument",option);
6135 if (IsGeometry(argv[i]) == MagickFalse)
6136 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6137 break;
6138 }
6139 if (LocaleCompare("transparent",option+1) == 0)
6140 {
6141 i++;
6142 if (i == (long) argc)
6143 ThrowMogrifyException(OptionError,"MissingArgument",option);
6144 break;
6145 }
6146 if (LocaleCompare("transparent-color",option+1) == 0)
6147 {
6148 if (*option == '+')
6149 break;
6150 i++;
6151 if (i == (long) (argc-1))
6152 ThrowMogrifyException(OptionError,"MissingArgument",option);
6153 break;
6154 }
6155 if (LocaleCompare("treedepth",option+1) == 0)
6156 {
6157 if (*option == '+')
6158 break;
6159 i++;
6160 if (i == (long) argc)
6161 ThrowMogrifyException(OptionError,"MissingArgument",option);
6162 if (IsGeometry(argv[i]) == MagickFalse)
6163 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6164 break;
6165 }
6166 if (LocaleCompare("trim",option+1) == 0)
6167 break;
6168 if (LocaleCompare("type",option+1) == 0)
6169 {
6170 long
6171 type;
6172
6173 if (*option == '+')
6174 break;
6175 i++;
6176 if (i == (long) argc)
6177 ThrowMogrifyException(OptionError,"MissingArgument",option);
6178 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
6179 if (type < 0)
6180 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6181 argv[i]);
6182 break;
6183 }
6184 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6185 }
6186 case 'u':
6187 {
6188 if (LocaleCompare("undercolor",option+1) == 0)
6189 {
6190 if (*option == '+')
6191 break;
6192 i++;
6193 if (i == (long) argc)
6194 ThrowMogrifyException(OptionError,"MissingArgument",option);
6195 break;
6196 }
6197 if (LocaleCompare("unique-colors",option+1) == 0)
6198 break;
6199 if (LocaleCompare("units",option+1) == 0)
6200 {
6201 long
6202 units;
6203
6204 if (*option == '+')
6205 break;
6206 i++;
6207 if (i == (long) argc)
6208 ThrowMogrifyException(OptionError,"MissingArgument",option);
6209 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
6210 argv[i]);
6211 if (units < 0)
6212 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6213 argv[i]);
6214 break;
6215 }
6216 if (LocaleCompare("unsharp",option+1) == 0)
6217 {
6218 i++;
6219 if (i == (long) argc)
6220 ThrowMogrifyException(OptionError,"MissingArgument",option);
6221 if (IsGeometry(argv[i]) == MagickFalse)
6222 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6223 break;
6224 }
6225 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6226 }
6227 case 'v':
6228 {
6229 if (LocaleCompare("verbose",option+1) == 0)
6230 {
6231 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6232 break;
6233 }
6234 if ((LocaleCompare("version",option+1) == 0) ||
6235 (LocaleCompare("-version",option+1) == 0))
6236 {
6237 (void) fprintf(stdout,"Version: %s\n",
6238 GetMagickVersion((unsigned long *) NULL));
cristy610b2e22009-10-22 14:59:43 +00006239 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
6240 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006241 break;
6242 }
6243 if (LocaleCompare("view",option+1) == 0)
6244 {
6245 if (*option == '+')
6246 break;
6247 i++;
6248 if (i == (long) argc)
6249 ThrowMogrifyException(OptionError,"MissingArgument",option);
6250 break;
6251 }
6252 if (LocaleCompare("vignette",option+1) == 0)
6253 {
6254 if (*option == '+')
6255 break;
6256 i++;
6257 if (i == (long) argc)
6258 ThrowMogrifyException(OptionError,"MissingArgument",option);
6259 if (IsGeometry(argv[i]) == MagickFalse)
6260 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6261 break;
6262 }
6263 if (LocaleCompare("virtual-pixel",option+1) == 0)
6264 {
6265 long
6266 method;
6267
6268 if (*option == '+')
6269 break;
6270 i++;
6271 if (i == (long) argc)
6272 ThrowMogrifyException(OptionError,"MissingArgument",option);
6273 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
6274 argv[i]);
6275 if (method < 0)
6276 ThrowMogrifyException(OptionError,
6277 "UnrecognizedVirtualPixelMethod",argv[i]);
6278 break;
6279 }
6280 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6281 }
6282 case 'w':
6283 {
6284 if (LocaleCompare("wave",option+1) == 0)
6285 {
6286 i++;
6287 if (i == (long) argc)
6288 ThrowMogrifyException(OptionError,"MissingArgument",option);
6289 if (IsGeometry(argv[i]) == MagickFalse)
6290 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6291 break;
6292 }
6293 if (LocaleCompare("weight",option+1) == 0)
6294 {
6295 if (*option == '+')
6296 break;
6297 i++;
6298 if (i == (long) (argc-1))
6299 ThrowMogrifyException(OptionError,"MissingArgument",option);
6300 break;
6301 }
6302 if (LocaleCompare("white-point",option+1) == 0)
6303 {
6304 if (*option == '+')
6305 break;
6306 i++;
6307 if (i == (long) argc)
6308 ThrowMogrifyException(OptionError,"MissingArgument",option);
6309 if (IsGeometry(argv[i]) == MagickFalse)
6310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6311 break;
6312 }
6313 if (LocaleCompare("white-threshold",option+1) == 0)
6314 {
6315 if (*option == '+')
6316 break;
6317 i++;
6318 if (i == (long) argc)
6319 ThrowMogrifyException(OptionError,"MissingArgument",option);
6320 if (IsGeometry(argv[i]) == MagickFalse)
6321 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6322 break;
6323 }
6324 if (LocaleCompare("write",option+1) == 0)
6325 {
6326 i++;
6327 if (i == (long) (argc-1))
6328 ThrowMogrifyException(OptionError,"MissingArgument",option);
6329 break;
6330 }
6331 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6332 }
6333 case '?':
6334 break;
6335 default:
6336 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6337 }
6338 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
6339 MagickFalse : MagickTrue;
6340 if (fire != MagickFalse)
6341 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6342 }
6343 if (k != 0)
6344 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6345 if (i != argc)
6346 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6347 DestroyMogrify();
6348 return(status != 0 ? MagickTrue : MagickFalse);
6349}
6350
6351/*
6352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6353% %
6354% %
6355% %
6356+ M o g r i f y I m a g e I n f o %
6357% %
6358% %
6359% %
6360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6361%
6362% MogrifyImageInfo() applies image processing settings to the image as
6363% prescribed by command line options.
6364%
6365% The format of the MogrifyImageInfo method is:
6366%
6367% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6368% const char **argv,ExceptionInfo *exception)
6369%
6370% A description of each parameter follows:
6371%
6372% o image_info: the image info..
6373%
6374% o argc: Specifies a pointer to an integer describing the number of
6375% elements in the argument vector.
6376%
6377% o argv: Specifies a pointer to a text array containing the command line
6378% arguments.
6379%
6380% o exception: return any errors or warnings in this structure.
6381%
6382*/
6383WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6384 const int argc,const char **argv,ExceptionInfo *exception)
6385{
6386 const char
6387 *option;
6388
6389 GeometryInfo
6390 geometry_info;
6391
6392 long
6393 count;
6394
6395 register long
6396 i;
6397
6398 /*
6399 Initialize method variables.
6400 */
6401 assert(image_info != (ImageInfo *) NULL);
6402 assert(image_info->signature == MagickSignature);
6403 if (image_info->debug != MagickFalse)
6404 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6405 image_info->filename);
6406 if (argc < 0)
6407 return(MagickTrue);
6408 /*
6409 Set the image settings.
6410 */
6411 for (i=0; i < (long) argc; i++)
6412 {
6413 option=argv[i];
6414 if (IsMagickOption(option) == MagickFalse)
6415 continue;
6416 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
6417 0L);
6418 if ((i+count) >= argc)
6419 break;
6420 switch (*(option+1))
6421 {
6422 case 'a':
6423 {
6424 if (LocaleCompare("adjoin",option+1) == 0)
6425 {
6426 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6427 break;
6428 }
6429 if (LocaleCompare("antialias",option+1) == 0)
6430 {
6431 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6432 break;
6433 }
6434 if (LocaleCompare("attenuate",option+1) == 0)
6435 {
6436 if (*option == '+')
6437 {
6438 (void) DeleteImageOption(image_info,option+1);
6439 break;
6440 }
6441 (void) SetImageOption(image_info,option+1,argv[i+1]);
6442 break;
6443 }
6444 if (LocaleCompare("authenticate",option+1) == 0)
6445 {
6446 if (*option == '+')
6447 (void) CloneString(&image_info->authenticate,(char *) NULL);
6448 else
6449 (void) CloneString(&image_info->authenticate,argv[i+1]);
6450 break;
6451 }
6452 break;
6453 }
6454 case 'b':
6455 {
6456 if (LocaleCompare("background",option+1) == 0)
6457 {
6458 if (*option == '+')
6459 {
6460 (void) DeleteImageOption(image_info,option+1);
6461 (void) QueryColorDatabase(BackgroundColor,
6462 &image_info->background_color,exception);
6463 break;
6464 }
6465 (void) SetImageOption(image_info,option+1,argv[i+1]);
6466 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6467 exception);
6468 break;
6469 }
6470 if (LocaleCompare("bias",option+1) == 0)
6471 {
6472 if (*option == '+')
6473 {
6474 (void) SetImageOption(image_info,option+1,"0.0");
6475 break;
6476 }
6477 (void) SetImageOption(image_info,option+1,argv[i+1]);
6478 break;
6479 }
6480 if (LocaleCompare("black-point-compensation",option+1) == 0)
6481 {
6482 if (*option == '+')
6483 {
6484 (void) SetImageOption(image_info,option+1,"false");
6485 break;
6486 }
6487 (void) SetImageOption(image_info,option+1,"true");
6488 break;
6489 }
6490 if (LocaleCompare("blue-primary",option+1) == 0)
6491 {
6492 if (*option == '+')
6493 {
6494 (void) SetImageOption(image_info,option+1,"0.0");
6495 break;
6496 }
6497 (void) SetImageOption(image_info,option+1,argv[i+1]);
6498 break;
6499 }
6500 if (LocaleCompare("bordercolor",option+1) == 0)
6501 {
6502 if (*option == '+')
6503 {
6504 (void) DeleteImageOption(image_info,option+1);
6505 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6506 exception);
6507 break;
6508 }
6509 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6510 exception);
6511 (void) SetImageOption(image_info,option+1,argv[i+1]);
6512 break;
6513 }
6514 if (LocaleCompare("box",option+1) == 0)
6515 {
6516 if (*option == '+')
6517 {
6518 (void) SetImageOption(image_info,"undercolor","none");
6519 break;
6520 }
6521 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6522 break;
6523 }
6524 break;
6525 }
6526 case 'c':
6527 {
6528 if (LocaleCompare("cache",option+1) == 0)
6529 {
6530 MagickSizeType
6531 limit;
6532
6533 limit=MagickResourceInfinity;
6534 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006535 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006536 (void) SetMagickResourceLimit(MemoryResource,limit);
6537 (void) SetMagickResourceLimit(MapResource,2*limit);
6538 break;
6539 }
6540 if (LocaleCompare("caption",option+1) == 0)
6541 {
6542 if (*option == '+')
6543 {
6544 (void) DeleteImageOption(image_info,option+1);
6545 break;
6546 }
6547 (void) SetImageOption(image_info,option+1,argv[i+1]);
6548 break;
6549 }
6550 if (LocaleCompare("channel",option+1) == 0)
6551 {
6552 if (*option == '+')
6553 {
6554 image_info->channel=DefaultChannels;
6555 break;
6556 }
6557 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6558 break;
6559 }
6560 if (LocaleCompare("colors",option+1) == 0)
6561 {
cristye27293e2009-12-18 02:53:20 +00006562 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006563 break;
6564 }
6565 if (LocaleCompare("colorspace",option+1) == 0)
6566 {
6567 if (*option == '+')
6568 {
6569 image_info->colorspace=UndefinedColorspace;
6570 (void) SetImageOption(image_info,option+1,"undefined");
6571 break;
6572 }
6573 image_info->colorspace=(ColorspaceType) ParseMagickOption(
6574 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6575 (void) SetImageOption(image_info,option+1,argv[i+1]);
6576 break;
6577 }
6578 if (LocaleCompare("compress",option+1) == 0)
6579 {
6580 if (*option == '+')
6581 {
6582 image_info->compression=UndefinedCompression;
6583 (void) SetImageOption(image_info,option+1,"undefined");
6584 break;
6585 }
6586 image_info->compression=(CompressionType) ParseMagickOption(
6587 MagickCompressOptions,MagickFalse,argv[i+1]);
6588 (void) SetImageOption(image_info,option+1,argv[i+1]);
6589 break;
6590 }
6591 if (LocaleCompare("comment",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 (void) DeleteImageOption(image_info,option+1);
6596 break;
6597 }
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
6601 if (LocaleCompare("compose",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 }
6611 if (LocaleCompare("compress",option+1) == 0)
6612 {
6613 if (*option == '+')
6614 {
6615 image_info->compression=UndefinedCompression;
6616 (void) SetImageOption(image_info,option+1,"undefined");
6617 break;
6618 }
6619 image_info->compression=(CompressionType) ParseMagickOption(
6620 MagickCompressOptions,MagickFalse,argv[i+1]);
6621 (void) SetImageOption(image_info,option+1,argv[i+1]);
6622 break;
6623 }
6624 break;
6625 }
6626 case 'd':
6627 {
6628 if (LocaleCompare("debug",option+1) == 0)
6629 {
6630 if (*option == '+')
6631 (void) SetLogEventMask("none");
6632 else
6633 (void) SetLogEventMask(argv[i+1]);
6634 image_info->debug=IsEventLogging();
6635 break;
6636 }
6637 if (LocaleCompare("define",option+1) == 0)
6638 {
6639 if (*option == '+')
6640 {
6641 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6642 (void) DeleteImageRegistry(argv[i+1]+9);
6643 else
6644 (void) DeleteImageOption(image_info,argv[i+1]);
6645 break;
6646 }
6647 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6648 {
6649 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6650 exception);
6651 break;
6652 }
6653 (void) DefineImageOption(image_info,argv[i+1]);
6654 break;
6655 }
6656 if (LocaleCompare("delay",option+1) == 0)
6657 {
6658 if (*option == '+')
6659 {
6660 (void) SetImageOption(image_info,option+1,"0");
6661 break;
6662 }
6663 (void) SetImageOption(image_info,option+1,argv[i+1]);
6664 break;
6665 }
6666 if (LocaleCompare("density",option+1) == 0)
6667 {
6668 /*
6669 Set image density.
6670 */
6671 if (*option == '+')
6672 {
6673 if (image_info->density != (char *) NULL)
6674 image_info->density=DestroyString(image_info->density);
6675 (void) SetImageOption(image_info,option+1,"72");
6676 break;
6677 }
6678 (void) CloneString(&image_info->density,argv[i+1]);
6679 (void) SetImageOption(image_info,option+1,argv[i+1]);
6680 break;
6681 }
6682 if (LocaleCompare("depth",option+1) == 0)
6683 {
6684 if (*option == '+')
6685 {
6686 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6687 break;
6688 }
cristye27293e2009-12-18 02:53:20 +00006689 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006690 break;
6691 }
6692 if (LocaleCompare("display",option+1) == 0)
6693 {
6694 if (*option == '+')
6695 {
6696 if (image_info->server_name != (char *) NULL)
6697 image_info->server_name=DestroyString(
6698 image_info->server_name);
6699 break;
6700 }
6701 (void) CloneString(&image_info->server_name,argv[i+1]);
6702 break;
6703 }
6704 if (LocaleCompare("dispose",option+1) == 0)
6705 {
6706 if (*option == '+')
6707 {
6708 (void) SetImageOption(image_info,option+1,"undefined");
6709 break;
6710 }
6711 (void) SetImageOption(image_info,option+1,argv[i+1]);
6712 break;
6713 }
6714 if (LocaleCompare("dither",option+1) == 0)
6715 {
6716 if (*option == '+')
6717 {
6718 image_info->dither=MagickFalse;
6719 (void) SetImageOption(image_info,option+1,"undefined");
6720 break;
6721 }
6722 (void) SetImageOption(image_info,option+1,argv[i+1]);
6723 image_info->dither=MagickTrue;
6724 break;
6725 }
6726 break;
6727 }
6728 case 'e':
6729 {
6730 if (LocaleCompare("encoding",option+1) == 0)
6731 {
6732 if (*option == '+')
6733 {
6734 (void) SetImageOption(image_info,option+1,"undefined");
6735 break;
6736 }
6737 (void) SetImageOption(image_info,option+1,argv[i+1]);
6738 break;
6739 }
6740 if (LocaleCompare("endian",option+1) == 0)
6741 {
6742 if (*option == '+')
6743 {
6744 image_info->endian=UndefinedEndian;
6745 (void) SetImageOption(image_info,option+1,"undefined");
6746 break;
6747 }
6748 image_info->endian=(EndianType) ParseMagickOption(
6749 MagickEndianOptions,MagickFalse,argv[i+1]);
6750 (void) SetImageOption(image_info,option+1,argv[i+1]);
6751 break;
6752 }
6753 if (LocaleCompare("extract",option+1) == 0)
6754 {
6755 /*
6756 Set image extract geometry.
6757 */
6758 if (*option == '+')
6759 {
6760 if (image_info->extract != (char *) NULL)
6761 image_info->extract=DestroyString(image_info->extract);
6762 break;
6763 }
6764 (void) CloneString(&image_info->extract,argv[i+1]);
6765 break;
6766 }
6767 break;
6768 }
6769 case 'f':
6770 {
6771 if (LocaleCompare("fill",option+1) == 0)
6772 {
6773 if (*option == '+')
6774 {
6775 (void) SetImageOption(image_info,option+1,"none");
6776 break;
6777 }
6778 (void) SetImageOption(image_info,option+1,argv[i+1]);
6779 break;
6780 }
6781 if (LocaleCompare("filter",option+1) == 0)
6782 {
6783 if (*option == '+')
6784 {
6785 (void) SetImageOption(image_info,option+1,"undefined");
6786 break;
6787 }
6788 (void) SetImageOption(image_info,option+1,argv[i+1]);
6789 break;
6790 }
6791 if (LocaleCompare("font",option+1) == 0)
6792 {
6793 if (*option == '+')
6794 {
6795 if (image_info->font != (char *) NULL)
6796 image_info->font=DestroyString(image_info->font);
6797 break;
6798 }
6799 (void) CloneString(&image_info->font,argv[i+1]);
6800 break;
6801 }
6802 if (LocaleCompare("format",option+1) == 0)
6803 {
6804 register const char
6805 *q;
6806
6807 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6808 if (strchr("gkrz@[#",*(q+1)) != (char *) NULL)
6809 image_info->ping=MagickFalse;
6810 (void) SetImageOption(image_info,option+1,argv[i+1]);
6811 break;
6812 }
6813 if (LocaleCompare("fuzz",option+1) == 0)
6814 {
6815 if (*option == '+')
6816 {
6817 image_info->fuzz=0.0;
6818 (void) SetImageOption(image_info,option+1,"0");
6819 break;
6820 }
cristyf2f27272009-12-17 14:48:46 +00006821 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006822 1.0);
6823 (void) SetImageOption(image_info,option+1,argv[i+1]);
6824 break;
6825 }
6826 break;
6827 }
6828 case 'g':
6829 {
6830 if (LocaleCompare("gravity",option+1) == 0)
6831 {
6832 if (*option == '+')
6833 {
6834 (void) SetImageOption(image_info,option+1,"undefined");
6835 break;
6836 }
6837 (void) SetImageOption(image_info,option+1,argv[i+1]);
6838 break;
6839 }
6840 if (LocaleCompare("green-primary",option+1) == 0)
6841 {
6842 if (*option == '+')
6843 {
6844 (void) SetImageOption(image_info,option+1,"0.0");
6845 break;
6846 }
6847 (void) SetImageOption(image_info,option+1,argv[i+1]);
6848 break;
6849 }
6850 break;
6851 }
6852 case 'i':
6853 {
6854 if (LocaleCompare("intent",option+1) == 0)
6855 {
6856 if (*option == '+')
6857 {
6858 (void) SetImageOption(image_info,option+1,"undefined");
6859 break;
6860 }
6861 (void) SetImageOption(image_info,option+1,argv[i+1]);
6862 break;
6863 }
6864 if (LocaleCompare("interlace",option+1) == 0)
6865 {
6866 if (*option == '+')
6867 {
6868 image_info->interlace=UndefinedInterlace;
6869 (void) SetImageOption(image_info,option+1,"undefined");
6870 break;
6871 }
6872 image_info->interlace=(InterlaceType) ParseMagickOption(
6873 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6874 (void) SetImageOption(image_info,option+1,argv[i+1]);
6875 break;
6876 }
cristyb32b90a2009-09-07 21:45:48 +00006877 if (LocaleCompare("interline-spacing",option+1) == 0)
6878 {
6879 if (*option == '+')
6880 {
6881 (void) SetImageOption(image_info,option+1,"undefined");
6882 break;
6883 }
6884 (void) SetImageOption(image_info,option+1,argv[i+1]);
6885 break;
6886 }
cristy3ed852e2009-09-05 21:47:34 +00006887 if (LocaleCompare("interpolate",option+1) == 0)
6888 {
6889 if (*option == '+')
6890 {
6891 (void) SetImageOption(image_info,option+1,"undefined");
6892 break;
6893 }
6894 (void) SetImageOption(image_info,option+1,argv[i+1]);
6895 break;
6896 }
6897 if (LocaleCompare("interword-spacing",option+1) == 0)
6898 {
6899 if (*option == '+')
6900 {
6901 (void) SetImageOption(image_info,option+1,"undefined");
6902 break;
6903 }
6904 (void) SetImageOption(image_info,option+1,argv[i+1]);
6905 break;
6906 }
6907 break;
6908 }
6909 case 'k':
6910 {
6911 if (LocaleCompare("kerning",option+1) == 0)
6912 {
6913 if (*option == '+')
6914 {
6915 (void) SetImageOption(image_info,option+1,"undefined");
6916 break;
6917 }
6918 (void) SetImageOption(image_info,option+1,argv[i+1]);
6919 break;
6920 }
6921 break;
6922 }
6923 case 'l':
6924 {
6925 if (LocaleCompare("label",option+1) == 0)
6926 {
6927 if (*option == '+')
6928 {
6929 (void) DeleteImageOption(image_info,option+1);
6930 break;
6931 }
6932 (void) SetImageOption(image_info,option+1,argv[i+1]);
6933 break;
6934 }
6935 if (LocaleCompare("limit",option+1) == 0)
6936 {
6937 MagickSizeType
6938 limit;
6939
6940 ResourceType
6941 type;
6942
6943 if (*option == '+')
6944 break;
6945 type=(ResourceType) ParseMagickOption(MagickResourceOptions,
6946 MagickFalse,argv[i+1]);
6947 limit=MagickResourceInfinity;
6948 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006949 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006950 (void) SetMagickResourceLimit(type,limit);
6951 break;
6952 }
6953 if (LocaleCompare("list",option+1) == 0)
6954 {
6955 long
6956 list;
6957
6958 /*
6959 Display configuration list.
6960 */
6961 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i+1]);
6962 switch (list)
6963 {
6964 case MagickCoderOptions:
6965 {
6966 (void) ListCoderInfo((FILE *) NULL,exception);
6967 break;
6968 }
6969 case MagickColorOptions:
6970 {
6971 (void) ListColorInfo((FILE *) NULL,exception);
6972 break;
6973 }
6974 case MagickConfigureOptions:
6975 {
6976 (void) ListConfigureInfo((FILE *) NULL,exception);
6977 break;
6978 }
6979 case MagickDelegateOptions:
6980 {
6981 (void) ListDelegateInfo((FILE *) NULL,exception);
6982 break;
6983 }
6984 case MagickFontOptions:
6985 {
6986 (void) ListTypeInfo((FILE *) NULL,exception);
6987 break;
6988 }
6989 case MagickFormatOptions:
6990 {
6991 (void) ListMagickInfo((FILE *) NULL,exception);
6992 break;
6993 }
6994 case MagickLocaleOptions:
6995 {
6996 (void) ListLocaleInfo((FILE *) NULL,exception);
6997 break;
6998 }
6999 case MagickLogOptions:
7000 {
7001 (void) ListLogInfo((FILE *) NULL,exception);
7002 break;
7003 }
7004 case MagickMagicOptions:
7005 {
7006 (void) ListMagicInfo((FILE *) NULL,exception);
7007 break;
7008 }
7009 case MagickMimeOptions:
7010 {
7011 (void) ListMimeInfo((FILE *) NULL,exception);
7012 break;
7013 }
7014 case MagickModuleOptions:
7015 {
7016 (void) ListModuleInfo((FILE *) NULL,exception);
7017 break;
7018 }
7019 case MagickPolicyOptions:
7020 {
7021 (void) ListPolicyInfo((FILE *) NULL,exception);
7022 break;
7023 }
7024 case MagickResourceOptions:
7025 {
7026 (void) ListMagickResourceInfo((FILE *) NULL,exception);
7027 break;
7028 }
7029 case MagickThresholdOptions:
7030 {
7031 (void) ListThresholdMaps((FILE *) NULL,exception);
7032 break;
7033 }
7034 default:
7035 {
7036 (void) ListMagickOptions((FILE *) NULL,(MagickOption) list,
7037 exception);
7038 break;
7039 }
7040 }
7041 }
7042 if (LocaleCompare("log",option+1) == 0)
7043 {
7044 if (*option == '+')
7045 break;
7046 (void) SetLogFormat(argv[i+1]);
7047 break;
7048 }
7049 if (LocaleCompare("loop",option+1) == 0)
7050 {
7051 if (*option == '+')
7052 {
7053 (void) SetImageOption(image_info,option+1,"0");
7054 break;
7055 }
7056 (void) SetImageOption(image_info,option+1,argv[i+1]);
7057 break;
7058 }
7059 break;
7060 }
7061 case 'm':
7062 {
7063 if (LocaleCompare("matte",option+1) == 0)
7064 {
7065 if (*option == '+')
7066 {
7067 (void) SetImageOption(image_info,option+1,"false");
7068 break;
7069 }
7070 (void) SetImageOption(image_info,option+1,"true");
7071 break;
7072 }
7073 if (LocaleCompare("mattecolor",option+1) == 0)
7074 {
7075 if (*option == '+')
7076 {
7077 (void) SetImageOption(image_info,option+1,argv[i+1]);
7078 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
7079 exception);
7080 break;
7081 }
7082 (void) SetImageOption(image_info,option+1,argv[i+1]);
7083 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7084 exception);
7085 break;
7086 }
7087 if (LocaleCompare("monitor",option+1) == 0)
7088 {
7089 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7090 (void *) NULL);
7091 break;
7092 }
7093 if (LocaleCompare("monochrome",option+1) == 0)
7094 {
7095 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7096 break;
7097 }
7098 break;
7099 }
7100 case 'o':
7101 {
7102 if (LocaleCompare("orient",option+1) == 0)
7103 {
7104 if (*option == '+')
7105 {
7106 image_info->orientation=UndefinedOrientation;
7107 (void) SetImageOption(image_info,option+1,"undefined");
7108 break;
7109 }
7110 image_info->orientation=(OrientationType) ParseMagickOption(
7111 MagickOrientationOptions,MagickFalse,argv[i+1]);
7112 (void) SetImageOption(image_info,option+1,"undefined");
7113 break;
7114 }
7115 }
7116 case 'p':
7117 {
7118 if (LocaleCompare("page",option+1) == 0)
7119 {
7120 char
7121 *canonical_page,
7122 page[MaxTextExtent];
7123
7124 const char
7125 *image_option;
7126
7127 MagickStatusType
7128 flags;
7129
7130 RectangleInfo
7131 geometry;
7132
7133 if (*option == '+')
7134 {
7135 (void) DeleteImageOption(image_info,option+1);
7136 (void) CloneString(&image_info->page,(char *) NULL);
7137 break;
7138 }
7139 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
7140 image_option=GetImageOption(image_info,"page");
7141 if (image_option != (const char *) NULL)
7142 flags=ParseAbsoluteGeometry(image_option,&geometry);
7143 canonical_page=GetPageGeometry(argv[i+1]);
7144 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7145 canonical_page=DestroyString(canonical_page);
7146 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu",
7147 geometry.width,geometry.height);
7148 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7149 (void) FormatMagickString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7150 geometry.width,geometry.height,geometry.x,geometry.y);
7151 (void) SetImageOption(image_info,option+1,page);
7152 (void) CloneString(&image_info->page,page);
7153 break;
7154 }
7155 if (LocaleCompare("pen",option+1) == 0)
7156 {
7157 if (*option == '+')
7158 {
7159 (void) SetImageOption(image_info,option+1,"none");
7160 break;
7161 }
7162 (void) SetImageOption(image_info,option+1,argv[i+1]);
7163 break;
7164 }
7165 if (LocaleCompare("ping",option+1) == 0)
7166 {
7167 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7168 break;
7169 }
7170 if (LocaleCompare("pointsize",option+1) == 0)
7171 {
7172 if (*option == '+')
7173 geometry_info.rho=0.0;
7174 else
7175 (void) ParseGeometry(argv[i+1],&geometry_info);
7176 image_info->pointsize=geometry_info.rho;
7177 break;
7178 }
cristye7f51092010-01-17 00:39:37 +00007179 if (LocaleCompare("precision",option+1) == 0)
7180 {
cristybf2766a2010-01-17 03:33:23 +00007181 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00007182 break;
7183 }
cristy3ed852e2009-09-05 21:47:34 +00007184 if (LocaleCompare("preview",option+1) == 0)
7185 {
7186 /*
7187 Preview image.
7188 */
7189 if (*option == '+')
7190 {
7191 image_info->preview_type=UndefinedPreview;
7192 break;
7193 }
7194 image_info->preview_type=(PreviewType) ParseMagickOption(
7195 MagickPreviewOptions,MagickFalse,argv[i+1]);
7196 break;
7197 }
7198 break;
7199 }
7200 case 'q':
7201 {
7202 if (LocaleCompare("quality",option+1) == 0)
7203 {
7204 /*
7205 Set image compression quality.
7206 */
7207 if (*option == '+')
7208 {
7209 image_info->quality=UndefinedCompressionQuality;
7210 (void) SetImageOption(image_info,option+1,"0");
7211 break;
7212 }
cristye27293e2009-12-18 02:53:20 +00007213 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007214 (void) SetImageOption(image_info,option+1,argv[i+1]);
7215 break;
7216 }
7217 if (LocaleCompare("quiet",option+1) == 0)
7218 {
7219 static WarningHandler
7220 warning_handler = (WarningHandler) NULL;
7221
7222 if (*option == '+')
7223 {
7224 /*
7225 Restore error or warning messages.
7226 */
7227 warning_handler=SetWarningHandler(warning_handler);
7228 break;
7229 }
7230 /*
7231 Suppress error or warning messages.
7232 */
7233 warning_handler=SetWarningHandler((WarningHandler) NULL);
7234 break;
7235 }
7236 break;
7237 }
7238 case 'r':
7239 {
7240 if (LocaleCompare("red-primary",option+1) == 0)
7241 {
7242 if (*option == '+')
7243 {
7244 (void) SetImageOption(image_info,option+1,"0.0");
7245 break;
7246 }
7247 (void) SetImageOption(image_info,option+1,argv[i+1]);
7248 break;
7249 }
7250 break;
7251 }
7252 case 's':
7253 {
7254 if (LocaleCompare("sampling-factor",option+1) == 0)
7255 {
7256 /*
7257 Set image sampling factor.
7258 */
7259 if (*option == '+')
7260 {
7261 if (image_info->sampling_factor != (char *) NULL)
7262 image_info->sampling_factor=DestroyString(
7263 image_info->sampling_factor);
7264 break;
7265 }
7266 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7267 break;
7268 }
7269 if (LocaleCompare("scene",option+1) == 0)
7270 {
7271 /*
7272 Set image scene.
7273 */
7274 if (*option == '+')
7275 {
7276 image_info->scene=0;
7277 (void) SetImageOption(image_info,option+1,"0");
7278 break;
7279 }
cristye27293e2009-12-18 02:53:20 +00007280 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007281 (void) SetImageOption(image_info,option+1,argv[i+1]);
7282 break;
7283 }
7284 if (LocaleCompare("seed",option+1) == 0)
7285 {
7286 unsigned long
7287 seed;
7288
7289 if (*option == '+')
7290 {
7291 seed=(unsigned long) time((time_t *) NULL);
7292 SeedPseudoRandomGenerator(seed);
7293 break;
7294 }
cristye27293e2009-12-18 02:53:20 +00007295 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007296 SeedPseudoRandomGenerator(seed);
7297 break;
7298 }
7299 if (LocaleCompare("size",option+1) == 0)
7300 {
7301 if (*option == '+')
7302 {
7303 if (image_info->size != (char *) NULL)
7304 image_info->size=DestroyString(image_info->size);
7305 break;
7306 }
7307 (void) CloneString(&image_info->size,argv[i+1]);
7308 break;
7309 }
7310 if (LocaleCompare("stroke",option+1) == 0)
7311 {
7312 if (*option == '+')
7313 {
7314 (void) SetImageOption(image_info,option+1,"none");
7315 break;
7316 }
7317 (void) SetImageOption(image_info,option+1,argv[i+1]);
7318 break;
7319 }
7320 if (LocaleCompare("strokewidth",option+1) == 0)
7321 {
7322 if (*option == '+')
7323 {
7324 (void) SetImageOption(image_info,option+1,"0");
7325 break;
7326 }
7327 (void) SetImageOption(image_info,option+1,argv[i+1]);
7328 break;
7329 }
7330 break;
7331 }
7332 case 't':
7333 {
7334 if (LocaleCompare("taint",option+1) == 0)
7335 {
7336 if (*option == '+')
7337 {
7338 (void) SetImageOption(image_info,option+1,"false");
7339 break;
7340 }
7341 (void) SetImageOption(image_info,option+1,"true");
7342 break;
7343 }
7344 if (LocaleCompare("texture",option+1) == 0)
7345 {
7346 if (*option == '+')
7347 {
7348 if (image_info->texture != (char *) NULL)
7349 image_info->texture=DestroyString(image_info->texture);
7350 break;
7351 }
7352 (void) CloneString(&image_info->texture,argv[i+1]);
7353 break;
7354 }
7355 if (LocaleCompare("tile-offset",option+1) == 0)
7356 {
7357 if (*option == '+')
7358 {
7359 (void) SetImageOption(image_info,option+1,"0");
7360 break;
7361 }
7362 (void) SetImageOption(image_info,option+1,argv[i+1]);
7363 break;
7364 }
7365 if (LocaleCompare("transparent-color",option+1) == 0)
7366 {
7367 if (*option == '+')
7368 {
7369 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7370 (void) SetImageOption(image_info,option+1,"none");
7371 break;
7372 }
7373 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7374 exception);
7375 (void) SetImageOption(image_info,option+1,argv[i+1]);
7376 break;
7377 }
7378 if (LocaleCompare("type",option+1) == 0)
7379 {
7380 if (*option == '+')
7381 {
7382 image_info->type=UndefinedType;
7383 (void) SetImageOption(image_info,option+1,"undefined");
7384 break;
7385 }
7386 image_info->type=(ImageType) ParseMagickOption(MagickTypeOptions,
7387 MagickFalse,argv[i+1]);
7388 (void) SetImageOption(image_info,option+1,argv[i+1]);
7389 break;
7390 }
7391 break;
7392 }
7393 case 'u':
7394 {
7395 if (LocaleCompare("undercolor",option+1) == 0)
7396 {
7397 if (*option == '+')
7398 {
7399 (void) DeleteImageOption(image_info,option+1);
7400 break;
7401 }
7402 (void) SetImageOption(image_info,option+1,argv[i+1]);
7403 break;
7404 }
7405 if (LocaleCompare("units",option+1) == 0)
7406 {
7407 if (*option == '+')
7408 {
7409 image_info->units=UndefinedResolution;
7410 (void) SetImageOption(image_info,option+1,"undefined");
7411 break;
7412 }
7413 image_info->units=(ResolutionType) ParseMagickOption(
7414 MagickResolutionOptions,MagickFalse,argv[i+1]);
7415 (void) SetImageOption(image_info,option+1,argv[i+1]);
7416 break;
7417 }
7418 break;
7419 }
7420 case 'v':
7421 {
7422 if (LocaleCompare("verbose",option+1) == 0)
7423 {
7424 if (*option == '+')
7425 {
7426 image_info->verbose=MagickFalse;
7427 break;
7428 }
7429 image_info->verbose=MagickTrue;
7430 image_info->ping=MagickFalse;
7431 break;
7432 }
7433 if (LocaleCompare("view",option+1) == 0)
7434 {
7435 if (*option == '+')
7436 {
7437 if (image_info->view != (char *) NULL)
7438 image_info->view=DestroyString(image_info->view);
7439 break;
7440 }
7441 (void) CloneString(&image_info->view,argv[i+1]);
7442 break;
7443 }
7444 if (LocaleCompare("virtual-pixel",option+1) == 0)
7445 {
7446 if (*option == '+')
7447 {
7448 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7449 (void) SetImageOption(image_info,option+1,"undefined");
7450 break;
7451 }
7452 image_info->virtual_pixel_method=(VirtualPixelMethod)
7453 ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
7454 argv[i+1]);
7455 (void) SetImageOption(image_info,option+1,argv[i+1]);
7456 break;
7457 }
7458 break;
7459 }
7460 case 'w':
7461 {
7462 if (LocaleCompare("white-point",option+1) == 0)
7463 {
7464 if (*option == '+')
7465 {
7466 (void) SetImageOption(image_info,option+1,"0.0");
7467 break;
7468 }
7469 (void) SetImageOption(image_info,option+1,argv[i+1]);
7470 break;
7471 }
7472 break;
7473 }
7474 default:
7475 break;
7476 }
7477 i+=count;
7478 }
7479 return(MagickTrue);
7480}
7481
7482/*
7483%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7484% %
7485% %
7486% %
7487+ M o g r i f y I m a g e L i s t %
7488% %
7489% %
7490% %
7491%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7492%
7493% MogrifyImageList() applies any command line options that might affect the
7494% entire image list (e.g. -append, -coalesce, etc.).
7495%
7496% The format of the MogrifyImage method is:
7497%
7498% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7499% const char **argv,Image **images,ExceptionInfo *exception)
7500%
7501% A description of each parameter follows:
7502%
7503% o image_info: the image info..
7504%
7505% o argc: Specifies a pointer to an integer describing the number of
7506% elements in the argument vector.
7507%
7508% o argv: Specifies a pointer to a text array containing the command line
7509% arguments.
7510%
7511% o images: the images.
7512%
7513% o exception: return any errors or warnings in this structure.
7514%
7515*/
7516WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7517 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7518{
7519 ChannelType
7520 channel;
7521
7522 const char
7523 *option;
7524
7525 long
7526 count,
7527 index;
7528
7529 MagickStatusType
7530 status;
7531
7532 QuantizeInfo
7533 *quantize_info;
7534
7535 register long
7536 i;
7537
7538 /*
7539 Apply options to the image list.
7540 */
7541 assert(image_info != (ImageInfo *) NULL);
7542 assert(image_info->signature == MagickSignature);
7543 assert(images != (Image **) NULL);
7544 assert((*images)->signature == MagickSignature);
7545 if ((*images)->debug != MagickFalse)
7546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7547 (*images)->filename);
7548 if ((argc <= 0) || (*argv == (char *) NULL))
7549 return(MagickTrue);
7550 quantize_info=AcquireQuantizeInfo(image_info);
7551 channel=image_info->channel;
7552 status=MagickTrue;
7553 for (i=0; i < (long) argc; i++)
7554 {
cristy74fe8f12009-10-03 19:09:01 +00007555 if (*images == (Image *) NULL)
7556 break;
cristy3ed852e2009-09-05 21:47:34 +00007557 option=argv[i];
7558 if (IsMagickOption(option) == MagickFalse)
7559 continue;
7560 count=MagickMax(ParseMagickOption(MagickCommandOptions,MagickFalse,option),
7561 0L);
7562 if ((i+count) >= argc)
7563 break;
7564 status=MogrifyImageInfo(image_info,count+1,argv+i,exception);
7565 switch (*(option+1))
7566 {
7567 case 'a':
7568 {
7569 if (LocaleCompare("affinity",option+1) == 0)
7570 {
7571 (void) SyncImagesSettings(image_info,*images);
7572 if (*option == '+')
7573 {
7574 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7575 InheritException(exception,&(*images)->exception);
7576 break;
7577 }
7578 i++;
7579 break;
7580 }
7581 if (LocaleCompare("append",option+1) == 0)
7582 {
7583 Image
7584 *append_image;
7585
7586 (void) SyncImagesSettings(image_info,*images);
7587 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7588 MagickFalse,exception);
7589 if (append_image == (Image *) NULL)
7590 {
7591 status=MagickFalse;
7592 break;
7593 }
7594 *images=DestroyImageList(*images);
7595 *images=append_image;
7596 break;
7597 }
7598 if (LocaleCompare("average",option+1) == 0)
7599 {
7600 Image
7601 *average_image;
7602
cristyd18ae7c2010-03-07 17:39:52 +00007603 /*
7604 Average an image sequence (deprecated).
7605 */
cristy3ed852e2009-09-05 21:47:34 +00007606 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007607 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7608 exception);
cristy3ed852e2009-09-05 21:47:34 +00007609 if (average_image == (Image *) NULL)
7610 {
7611 status=MagickFalse;
7612 break;
7613 }
7614 *images=DestroyImageList(*images);
7615 *images=average_image;
7616 break;
7617 }
7618 break;
7619 }
7620 case 'c':
7621 {
7622 if (LocaleCompare("channel",option+1) == 0)
7623 {
7624 if (*option == '+')
7625 {
7626 channel=DefaultChannels;
7627 break;
7628 }
7629 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7630 break;
7631 }
7632 if (LocaleCompare("clut",option+1) == 0)
7633 {
7634 Image
7635 *clut_image,
7636 *image;
7637
7638 (void) SyncImagesSettings(image_info,*images);
7639 image=RemoveFirstImageFromList(images);
7640 clut_image=RemoveFirstImageFromList(images);
7641 if (clut_image == (Image *) NULL)
7642 {
7643 status=MagickFalse;
7644 break;
7645 }
7646 (void) ClutImageChannel(image,channel,clut_image);
7647 clut_image=DestroyImage(clut_image);
7648 InheritException(exception,&image->exception);
7649 *images=DestroyImageList(*images);
7650 *images=image;
7651 break;
7652 }
7653 if (LocaleCompare("coalesce",option+1) == 0)
7654 {
7655 Image
7656 *coalesce_image;
7657
7658 (void) SyncImagesSettings(image_info,*images);
7659 coalesce_image=CoalesceImages(*images,exception);
7660 if (coalesce_image == (Image *) NULL)
7661 {
7662 status=MagickFalse;
7663 break;
7664 }
7665 *images=DestroyImageList(*images);
7666 *images=coalesce_image;
7667 break;
7668 }
7669 if (LocaleCompare("combine",option+1) == 0)
7670 {
7671 Image
7672 *combine_image;
7673
7674 (void) SyncImagesSettings(image_info,*images);
7675 combine_image=CombineImages(*images,channel,exception);
7676 if (combine_image == (Image *) NULL)
7677 {
7678 status=MagickFalse;
7679 break;
7680 }
7681 *images=DestroyImageList(*images);
7682 *images=combine_image;
7683 break;
7684 }
7685 if (LocaleCompare("composite",option+1) == 0)
7686 {
7687 Image
7688 *mask_image,
7689 *composite_image,
7690 *image;
7691
7692 RectangleInfo
7693 geometry;
7694
7695 (void) SyncImagesSettings(image_info,*images);
7696 image=RemoveFirstImageFromList(images);
7697 composite_image=RemoveFirstImageFromList(images);
7698 if (composite_image == (Image *) NULL)
7699 {
7700 status=MagickFalse;
7701 break;
7702 }
7703 (void) TransformImage(&composite_image,(char *) NULL,
7704 composite_image->geometry);
7705 SetGeometry(composite_image,&geometry);
7706 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7707 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7708 &geometry);
7709 mask_image=RemoveFirstImageFromList(images);
7710 if (mask_image != (Image *) NULL)
7711 {
7712 if ((image->compose == DisplaceCompositeOp) ||
7713 (image->compose == DistortCompositeOp))
7714 {
7715 /*
7716 Merge Y displacement into X displacement image.
7717 */
7718 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7719 mask_image,0,0);
7720 mask_image=DestroyImage(mask_image);
7721 }
7722 else
7723 {
7724 /*
7725 Set a blending mask for the composition.
7726 */
7727 image->mask=mask_image;
7728 (void) NegateImage(image->mask,MagickFalse);
7729 }
7730 }
7731 (void) CompositeImageChannel(image,channel,image->compose,
7732 composite_image,geometry.x,geometry.y);
7733 if (image->mask != (Image *) NULL)
7734 image->mask=DestroyImage(image->mask);
7735 composite_image=DestroyImage(composite_image);
7736 InheritException(exception,&image->exception);
7737 *images=DestroyImageList(*images);
7738 *images=image;
7739 break;
7740 }
7741 if (LocaleCompare("crop",option+1) == 0)
7742 {
7743 MagickStatusType
7744 flags;
7745
7746 RectangleInfo
7747 geometry;
7748
7749 (void) SyncImagesSettings(image_info,*images);
7750 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7751 if (((geometry.width == 0) && (geometry.height == 0)) ||
7752 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7753 break;
7754 (void) TransformImages(images,argv[i+1],(char *) NULL);
7755 InheritException(exception,&(*images)->exception);
7756 break;
7757 }
7758 break;
7759 }
7760 case 'd':
7761 {
7762 if (LocaleCompare("deconstruct",option+1) == 0)
7763 {
7764 Image
7765 *deconstruct_image;
7766
7767 (void) SyncImagesSettings(image_info,*images);
7768 deconstruct_image=DeconstructImages(*images,exception);
7769 if (deconstruct_image == (Image *) NULL)
7770 {
7771 status=MagickFalse;
7772 break;
7773 }
7774 *images=DestroyImageList(*images);
7775 *images=deconstruct_image;
7776 break;
7777 }
7778 if (LocaleCompare("delete",option+1) == 0)
7779 {
7780 if (*option == '+')
7781 DeleteImages(images,"-1",exception);
7782 else
7783 DeleteImages(images,argv[i+1],exception);
7784 break;
7785 }
7786 if (LocaleCompare("dither",option+1) == 0)
7787 {
7788 if (*option == '+')
7789 {
7790 quantize_info->dither=MagickFalse;
7791 break;
7792 }
7793 quantize_info->dither=MagickTrue;
7794 quantize_info->dither_method=(DitherMethod) ParseMagickOption(
7795 MagickDitherOptions,MagickFalse,argv[i+1]);
7796 break;
7797 }
7798 break;
7799 }
cristyd18ae7c2010-03-07 17:39:52 +00007800 case 'e':
7801 {
7802 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7803 {
7804 Image
7805 *evaluate_image;
7806
7807 MagickEvaluateOperator
7808 op;
7809
7810 (void) SyncImageSettings(image_info,*images);
7811 op=(MagickEvaluateOperator) ParseMagickOption(MagickEvaluateOptions,
7812 MagickFalse,argv[i+1]);
7813 evaluate_image=EvaluateImages(*images,op,exception);
7814 if (evaluate_image == (Image *) NULL)
7815 {
7816 status=MagickFalse;
7817 break;
7818 }
7819 *images=DestroyImageList(*images);
7820 *images=evaluate_image;
7821 break;
7822 }
7823 break;
7824 }
cristy3ed852e2009-09-05 21:47:34 +00007825 case 'f':
7826 {
cristyf0a247f2009-10-04 00:20:03 +00007827 if (LocaleCompare("fft",option+1) == 0)
7828 {
7829 Image
7830 *fourier_image;
7831
7832 /*
7833 Implements the discrete Fourier transform (DFT).
7834 */
7835 (void) SyncImageSettings(image_info,*images);
7836 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7837 MagickTrue : MagickFalse,exception);
7838 if (fourier_image == (Image *) NULL)
7839 break;
7840 *images=DestroyImage(*images);
7841 *images=fourier_image;
7842 break;
7843 }
cristy3ed852e2009-09-05 21:47:34 +00007844 if (LocaleCompare("flatten",option+1) == 0)
7845 {
7846 Image
7847 *flatten_image;
7848
7849 (void) SyncImagesSettings(image_info,*images);
7850 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7851 if (flatten_image == (Image *) NULL)
7852 break;
7853 *images=DestroyImageList(*images);
7854 *images=flatten_image;
7855 break;
7856 }
7857 if (LocaleCompare("fx",option+1) == 0)
7858 {
7859 Image
7860 *fx_image;
7861
7862 (void) SyncImagesSettings(image_info,*images);
7863 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7864 if (fx_image == (Image *) NULL)
7865 {
7866 status=MagickFalse;
7867 break;
7868 }
7869 *images=DestroyImageList(*images);
7870 *images=fx_image;
7871 break;
7872 }
7873 break;
7874 }
7875 case 'h':
7876 {
7877 if (LocaleCompare("hald-clut",option+1) == 0)
7878 {
7879 Image
7880 *hald_image,
7881 *image;
7882
7883 (void) SyncImagesSettings(image_info,*images);
7884 image=RemoveFirstImageFromList(images);
7885 hald_image=RemoveFirstImageFromList(images);
7886 if (hald_image == (Image *) NULL)
7887 {
7888 status=MagickFalse;
7889 break;
7890 }
7891 (void) HaldClutImageChannel(image,channel,hald_image);
7892 hald_image=DestroyImage(hald_image);
7893 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007894 if (*images != (Image *) NULL)
7895 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007896 *images=image;
7897 break;
7898 }
7899 break;
7900 }
7901 case 'i':
7902 {
7903 if (LocaleCompare("ift",option+1) == 0)
7904 {
7905 Image
cristy8587f882009-11-13 20:28:49 +00007906 *fourier_image,
7907 *magnitude_image,
7908 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007909
7910 /*
7911 Implements the inverse fourier discrete Fourier transform (DFT).
7912 */
7913 (void) SyncImagesSettings(image_info,*images);
cristy8587f882009-11-13 20:28:49 +00007914 magnitude_image=RemoveFirstImageFromList(images);
7915 phase_image=RemoveFirstImageFromList(images);
7916 if (phase_image == (Image *) NULL)
7917 {
7918 status=MagickFalse;
7919 break;
7920 }
7921 fourier_image=InverseFourierTransformImage(magnitude_image,
7922 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007923 if (fourier_image == (Image *) NULL)
7924 break;
cristy0aff6ea2009-11-14 01:40:53 +00007925 if (*images != (Image *) NULL)
7926 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007927 *images=fourier_image;
7928 break;
7929 }
7930 if (LocaleCompare("insert",option+1) == 0)
7931 {
7932 Image
7933 *p,
7934 *q;
7935
7936 index=0;
7937 if (*option != '+')
cristyf2f27272009-12-17 14:48:46 +00007938 index=StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007939 p=RemoveLastImageFromList(images);
7940 if (p == (Image *) NULL)
7941 {
7942 (void) ThrowMagickException(exception,GetMagickModule(),
7943 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7944 status=MagickFalse;
7945 break;
7946 }
7947 q=p;
7948 if (index == 0)
7949 PrependImageToList(images,q);
7950 else
7951 if (index == (long) GetImageListLength(*images))
7952 AppendImageToList(images,q);
7953 else
7954 {
7955 q=GetImageFromList(*images,index-1);
7956 if (q == (Image *) NULL)
7957 {
7958 (void) ThrowMagickException(exception,GetMagickModule(),
7959 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7960 status=MagickFalse;
7961 break;
7962 }
7963 InsertImageInList(&q,p);
7964 }
7965 *images=GetFirstImageInList(q);
7966 break;
7967 }
7968 break;
7969 }
7970 case 'l':
7971 {
7972 if (LocaleCompare("layers",option+1) == 0)
7973 {
7974 Image
7975 *layers;
7976
7977 ImageLayerMethod
7978 method;
7979
7980 (void) SyncImagesSettings(image_info,*images);
7981 layers=(Image *) NULL;
7982 method=(ImageLayerMethod) ParseMagickOption(MagickLayerOptions,
7983 MagickFalse,argv[i+1]);
7984 switch (method)
7985 {
7986 case CoalesceLayer:
7987 {
7988 layers=CoalesceImages(*images,exception);
7989 break;
7990 }
7991 case CompareAnyLayer:
7992 case CompareClearLayer:
7993 case CompareOverlayLayer:
7994 default:
7995 {
7996 layers=CompareImageLayers(*images,method,exception);
7997 break;
7998 }
7999 case MergeLayer:
8000 case FlattenLayer:
8001 case MosaicLayer:
8002 case TrimBoundsLayer:
8003 {
8004 layers=MergeImageLayers(*images,method,exception);
8005 break;
8006 }
8007 case DisposeLayer:
8008 {
8009 layers=DisposeImages(*images,exception);
8010 break;
8011 }
8012 case OptimizeImageLayer:
8013 {
8014 layers=OptimizeImageLayers(*images,exception);
8015 break;
8016 }
8017 case OptimizePlusLayer:
8018 {
8019 layers=OptimizePlusImageLayers(*images,exception);
8020 break;
8021 }
8022 case OptimizeTransLayer:
8023 {
8024 OptimizeImageTransparency(*images,exception);
8025 break;
8026 }
8027 case RemoveDupsLayer:
8028 {
8029 RemoveDuplicateLayers(images,exception);
8030 break;
8031 }
8032 case RemoveZeroLayer:
8033 {
8034 RemoveZeroDelayLayers(images,exception);
8035 break;
8036 }
8037 case OptimizeLayer:
8038 {
8039 /*
8040 General Purpose, GIF Animation Optimizer.
8041 */
8042 layers=CoalesceImages(*images,exception);
8043 if (layers == (Image *) NULL)
8044 {
8045 status=MagickFalse;
8046 break;
8047 }
8048 InheritException(exception,&layers->exception);
8049 *images=DestroyImageList(*images);
8050 *images=layers;
8051 layers=OptimizeImageLayers(*images,exception);
8052 if (layers == (Image *) NULL)
8053 {
8054 status=MagickFalse;
8055 break;
8056 }
8057 InheritException(exception,&layers->exception);
8058 *images=DestroyImageList(*images);
8059 *images=layers;
8060 layers=(Image *) NULL;
8061 OptimizeImageTransparency(*images,exception);
8062 InheritException(exception,&(*images)->exception);
8063 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8064 break;
8065 }
8066 case CompositeLayer:
8067 {
8068 CompositeOperator
8069 compose;
8070
8071 Image
8072 *source;
8073
8074 RectangleInfo
8075 geometry;
8076
8077 /*
8078 Split image sequence at the first 'NULL:' image.
8079 */
8080 source=(*images);
8081 while (source != (Image *) NULL)
8082 {
8083 source=GetNextImageInList(source);
8084 if ((source != (Image *) NULL) &&
8085 (LocaleCompare(source->magick,"NULL") == 0))
8086 break;
8087 }
8088 if (source != (Image *) NULL)
8089 {
8090 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8091 (GetNextImageInList(source) == (Image *) NULL))
8092 source=(Image *) NULL;
8093 else
8094 {
8095 /*
8096 Separate the two lists, junk the null: image.
8097 */
8098 source=SplitImageList(source->previous);
8099 DeleteImageFromList(&source);
8100 }
8101 }
8102 if (source == (Image *) NULL)
8103 {
8104 (void) ThrowMagickException(exception,GetMagickModule(),
8105 OptionError,"MissingNullSeparator","layers Composite");
8106 status=MagickFalse;
8107 break;
8108 }
8109 /*
8110 Adjust offset with gravity and virtual canvas.
8111 */
8112 SetGeometry(*images,&geometry);
8113 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8114 geometry.width=source->page.width != 0 ?
8115 source->page.width : source->columns;
8116 geometry.height=source->page.height != 0 ?
8117 source->page.height : source->rows;
8118 GravityAdjustGeometry((*images)->page.width != 0 ?
8119 (*images)->page.width : (*images)->columns,
8120 (*images)->page.height != 0 ? (*images)->page.height :
8121 (*images)->rows,(*images)->gravity,&geometry);
8122 compose=OverCompositeOp;
8123 option=GetImageOption(image_info,"compose");
8124 if (option != (const char *) NULL)
8125 compose=(CompositeOperator) ParseMagickOption(
8126 MagickComposeOptions,MagickFalse,option);
8127 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8128 exception);
8129 source=DestroyImageList(source);
8130 break;
8131 }
8132 }
8133 if (layers == (Image *) NULL)
8134 break;
8135 InheritException(exception,&layers->exception);
8136 *images=DestroyImageList(*images);
8137 *images=layers;
8138 break;
8139 }
8140 break;
8141 }
8142 case 'm':
8143 {
8144 if (LocaleCompare("map",option+1) == 0)
8145 {
8146 (void) SyncImagesSettings(image_info,*images);
8147 if (*option == '+')
8148 {
8149 (void) RemapImages(quantize_info,*images,(Image *) NULL);
8150 InheritException(exception,&(*images)->exception);
8151 break;
8152 }
8153 i++;
8154 break;
8155 }
cristyf40785b2010-03-06 02:27:27 +00008156 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008157 {
8158 Image
cristyf40785b2010-03-06 02:27:27 +00008159 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008160
cristyd18ae7c2010-03-07 17:39:52 +00008161 /*
8162 Maximum image sequence (deprecated).
8163 */
cristy1c274c92010-03-06 02:06:45 +00008164 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008165 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008166 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008167 {
8168 status=MagickFalse;
8169 break;
8170 }
8171 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008172 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00008173 break;
8174 }
cristyf40785b2010-03-06 02:27:27 +00008175 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00008176 {
8177 Image
cristyf40785b2010-03-06 02:27:27 +00008178 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008179
cristyd18ae7c2010-03-07 17:39:52 +00008180 /*
8181 Minimum image sequence (deprecated).
8182 */
cristy1c274c92010-03-06 02:06:45 +00008183 (void) SyncImagesSettings(image_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00008184 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00008185 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00008186 {
8187 status=MagickFalse;
8188 break;
8189 }
8190 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00008191 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00008192 break;
8193 }
cristy3ed852e2009-09-05 21:47:34 +00008194 if (LocaleCompare("morph",option+1) == 0)
8195 {
8196 Image
8197 *morph_image;
8198
8199 (void) SyncImagesSettings(image_info,*images);
cristye27293e2009-12-18 02:53:20 +00008200 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00008201 exception);
8202 if (morph_image == (Image *) NULL)
8203 {
8204 status=MagickFalse;
8205 break;
8206 }
8207 *images=DestroyImageList(*images);
8208 *images=morph_image;
8209 break;
8210 }
8211 if (LocaleCompare("mosaic",option+1) == 0)
8212 {
8213 Image
8214 *mosaic_image;
8215
8216 (void) SyncImagesSettings(image_info,*images);
8217 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8218 if (mosaic_image == (Image *) NULL)
8219 {
8220 status=MagickFalse;
8221 break;
8222 }
8223 *images=DestroyImageList(*images);
8224 *images=mosaic_image;
8225 break;
8226 }
8227 break;
8228 }
8229 case 'p':
8230 {
8231 if (LocaleCompare("print",option+1) == 0)
8232 {
8233 char
8234 *string;
8235
8236 (void) SyncImagesSettings(image_info,*images);
8237 string=InterpretImageProperties(image_info,*images,argv[i+1]);
8238 if (string == (char *) NULL)
8239 break;
8240 InheritException(exception,&(*images)->exception);
8241 (void) fprintf(stdout,"%s",string);
8242 string=DestroyString(string);
8243 }
8244 if (LocaleCompare("process",option+1) == 0)
8245 {
8246 char
8247 **arguments;
8248
8249 int
8250 j,
8251 number_arguments;
8252
8253 (void) SyncImagesSettings(image_info,*images);
8254 arguments=StringToArgv(argv[i+1],&number_arguments);
8255 if (arguments == (char **) NULL)
8256 break;
8257 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8258 {
8259 char
8260 breaker,
8261 quote,
8262 *token;
8263
8264 const char
8265 *arguments;
8266
8267 int
8268 next,
8269 status;
8270
8271 size_t
8272 length;
8273
8274 TokenInfo
8275 *token_info;
8276
8277 /*
8278 Support old style syntax, filter="-option arg".
8279 */
8280 length=strlen(argv[i+1]);
8281 token=(char *) NULL;
8282 if (~length >= MaxTextExtent)
8283 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8284 sizeof(*token));
8285 if (token == (char *) NULL)
8286 break;
8287 next=0;
8288 arguments=argv[i+1];
8289 token_info=AcquireTokenInfo();
8290 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8291 "\"",'\0',&breaker,&next,&quote);
8292 token_info=DestroyTokenInfo(token_info);
8293 if (status == 0)
8294 {
8295 const char
8296 *argv;
8297
8298 argv=(&(arguments[next]));
8299 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8300 exception);
8301 }
8302 token=DestroyString(token);
8303 break;
8304 }
8305 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8306 number_arguments-2,(const char **) arguments+2,exception);
8307 for (j=0; j < number_arguments; j++)
8308 arguments[j]=DestroyString(arguments[j]);
8309 arguments=(char **) RelinquishMagickMemory(arguments);
8310 break;
8311 }
8312 break;
8313 }
8314 case 'r':
8315 {
8316 if (LocaleCompare("reverse",option+1) == 0)
8317 {
8318 ReverseImageList(images);
8319 InheritException(exception,&(*images)->exception);
8320 break;
8321 }
8322 break;
8323 }
8324 case 's':
8325 {
8326 if (LocaleCompare("swap",option+1) == 0)
8327 {
8328 Image
8329 *p,
8330 *q,
8331 *swap;
8332
8333 long
8334 swap_index;
8335
8336 index=(-1);
8337 swap_index=(-2);
8338 if (*option != '+')
8339 {
8340 GeometryInfo
8341 geometry_info;
8342
8343 MagickStatusType
8344 flags;
8345
8346 swap_index=(-1);
8347 flags=ParseGeometry(argv[i+1],&geometry_info);
8348 index=(long) geometry_info.rho;
8349 if ((flags & SigmaValue) != 0)
8350 swap_index=(long) geometry_info.sigma;
8351 }
8352 p=GetImageFromList(*images,index);
8353 q=GetImageFromList(*images,swap_index);
8354 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8355 {
8356 (void) ThrowMagickException(exception,GetMagickModule(),
8357 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8358 status=MagickFalse;
8359 break;
8360 }
8361 if (p == q)
8362 break;
8363 swap=CloneImage(p,0,0,MagickTrue,exception);
8364 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8365 ReplaceImageInList(&q,swap);
8366 *images=GetFirstImageInList(q);
8367 break;
8368 }
8369 break;
8370 }
8371 case 'w':
8372 {
8373 if (LocaleCompare("write",option+1) == 0)
8374 {
8375 Image
8376 *write_images;
8377
8378 ImageInfo
8379 *write_info;
8380
8381 (void) SyncImagesSettings(image_info,*images);
8382 write_images=(*images);
8383 if (*option == '+')
8384 write_images=CloneImageList(*images,exception);
8385 write_info=CloneImageInfo(image_info);
8386 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8387 write_info=DestroyImageInfo(write_info);
8388 if (*option == '+')
8389 write_images=DestroyImageList(write_images);
8390 break;
8391 }
8392 break;
8393 }
8394 default:
8395 break;
8396 }
8397 i+=count;
8398 }
8399 quantize_info=DestroyQuantizeInfo(quantize_info);
8400 return(status != 0 ? MagickTrue : MagickFalse);
8401}
8402
8403/*
8404%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8405% %
8406% %
8407% %
8408+ M o g r i f y I m a g e s %
8409% %
8410% %
8411% %
8412%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8413%
8414% MogrifyImages() applies image processing options to a sequence of images as
8415% prescribed by command line options.
8416%
8417% The format of the MogrifyImage method is:
8418%
8419% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8420% const MagickBooleanType post,const int argc,const char **argv,
8421% Image **images,Exceptioninfo *exception)
8422%
8423% A description of each parameter follows:
8424%
8425% o image_info: the image info..
8426%
8427% o post: If true, post process image list operators otherwise pre-process.
8428%
8429% o argc: Specifies a pointer to an integer describing the number of
8430% elements in the argument vector.
8431%
8432% o argv: Specifies a pointer to a text array containing the command line
8433% arguments.
8434%
8435% o images: the images.
8436%
8437% o exception: return any errors or warnings in this structure.
8438%
8439*/
8440WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8441 const MagickBooleanType post,const int argc,const char **argv,
8442 Image **images,ExceptionInfo *exception)
8443{
8444#define MogrifyImageTag "Mogrify/Image"
8445
8446 Image
8447 *image,
8448 *mogrify_images;
8449
cristy0e9f9c12010-02-11 03:00:47 +00008450 MagickBooleanType
8451 proceed;
8452
8453 MagickSizeType
8454 number_images;
8455
cristy3ed852e2009-09-05 21:47:34 +00008456 MagickStatusType
8457 status;
8458
8459 register long
8460 i;
8461
cristy3ed852e2009-09-05 21:47:34 +00008462 /*
8463 Apply options to individual images in the list.
8464 */
8465 assert(image_info != (ImageInfo *) NULL);
8466 assert(image_info->signature == MagickSignature);
8467 if (images == (Image **) NULL)
8468 return(MogrifyImage(image_info,argc,argv,images,exception));
8469 assert((*images)->signature == MagickSignature);
8470 if ((*images)->debug != MagickFalse)
8471 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8472 (*images)->filename);
8473 if ((argc <= 0) || (*argv == (char *) NULL))
8474 return(MagickTrue);
8475 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8476 (void *) NULL);
8477 mogrify_images=NewImageList();
8478 number_images=GetImageListLength(*images);
8479 status=0;
8480 if (post == MagickFalse)
8481 status&=MogrifyImageList(image_info,argc,argv,images,exception);
8482 for (i=0; i < (long) number_images; i++)
8483 {
8484 image=RemoveFirstImageFromList(images);
8485 if (image == (Image *) NULL)
8486 continue;
8487 status&=MogrifyImage(image_info,argc,argv,&image,exception);
8488 AppendImageToList(&mogrify_images,image);
cristy0e9f9c12010-02-11 03:00:47 +00008489 proceed=SetImageProgress(image,MogrifyImageTag,(MagickOffsetType) i,
8490 number_images);
8491 if (proceed == MagickFalse)
8492 break;
cristy3ed852e2009-09-05 21:47:34 +00008493 }
8494 if (post != MagickFalse)
8495 status&=MogrifyImageList(image_info,argc,argv,&mogrify_images,exception);
8496 *images=mogrify_images;
8497 return(status != 0 ? MagickTrue : MagickFalse);
8498}