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