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