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