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