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