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