2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % CCCC OOO M M PPPP OOO SSSSS IIIII TTTTT EEEEE %
7 % C O O MM MM P P O O SS I T E %
8 % C O O M M M PPPP O O SSS I T EEE %
9 % C O O M M P O O SS I T E %
10 % CCCC OOO M M P OOO SSSSS IIIII T EEEEE %
13 % MagickWand Image Composite Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 % Use the composite program to overlap one image over another.
43 #include "MagickWand/studio.h"
44 #include "MagickWand/MagickWand.h"
45 #include "MagickWand/mogrify-private.h"
46 #include "MagickCore/string-private.h"
51 typedef struct _CompositeOptions
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % C o m p o s i t e I m a g e C o m m a n d %
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 % CompositeImageCommand() reads one or more images and an optional mask and
89 % composites them into a new image.
91 % The format of the CompositeImageCommand method is:
93 % MagickBooleanType CompositeImageCommand(ImageInfo *image_info,int argc,
94 % char **argv,char **metadata,ExceptionInfo *exception)
96 % A description of each parameter follows:
98 % o image_info: the image info.
100 % o argc: the number of elements in the argument vector.
102 % o argv: A text array containing the command line arguments.
104 % o metadata: any metadata is returned here.
106 % o exception: return any errors or warnings in this structure.
110 static MagickBooleanType CompositeImageList(ImageInfo *image_info,Image **image,
111 Image *composite_image,CompositeOptions *composite_options,
112 ExceptionInfo *exception)
117 assert(image_info != (ImageInfo *) NULL);
118 assert(image_info->signature == MagickSignature);
119 assert(image != (Image **) NULL);
120 assert((*image)->signature == MagickSignature);
121 if ((*image)->debug != MagickFalse)
122 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
123 assert(exception != (ExceptionInfo *) NULL);
125 if (composite_image != (Image *) NULL)
127 assert(composite_image->signature == MagickSignature);
128 switch( composite_options->compose )
130 case BlendCompositeOp:
131 case BlurCompositeOp:
132 case DisplaceCompositeOp:
133 case DistortCompositeOp:
134 case DissolveCompositeOp:
135 case ModulateCompositeOp:
136 case ThresholdCompositeOp:
137 (void) SetImageArtifact(composite_image,"compose:args",
138 composite_options->compose_args);
146 if (composite_options->stegano != 0)
151 (*image)->offset=composite_options->stegano-1;
152 stegano_image=SteganoImage(*image,composite_image,exception);
153 if (stegano_image != (Image *) NULL)
155 *image=DestroyImageList(*image);
156 *image=stegano_image;
160 if (composite_options->stereo != MagickFalse)
165 stereo_image=StereoAnaglyphImage(*image,composite_image,
166 composite_options->offset.x,composite_options->offset.y,
168 if (stereo_image != (Image *) NULL)
170 *image=DestroyImageList(*image);
175 if (composite_options->tile != MagickFalse)
185 Tile the composite image.
187 (void) SetImageArtifact(composite_image,"compose:outside-overlay",
189 columns=composite_image->columns;
190 for (y=0; y < (ssize_t) (*image)->rows; y+=(ssize_t) composite_image->rows)
191 for (x=0; x < (ssize_t) (*image)->columns; x+=(ssize_t) columns)
192 status&=CompositeImageChannel(*image,
193 composite_options->channel,composite_options->compose,
194 composite_image,x,y);
195 GetImageException(*image,exception);
203 Work out gravity Adjustment of Offset
205 SetGeometry(*image,&geometry);
206 (void) ParseAbsoluteGeometry(composite_options->geometry,
208 geometry.width=composite_image->columns;
209 geometry.height=composite_image->rows;
210 GravityAdjustGeometry((*image)->columns,(*image)->rows,
211 composite_options->gravity, &geometry);
212 (*image)->gravity=(GravityType) composite_options->gravity;
214 Digitally composite image.
216 status&=CompositeImageChannel(*image,composite_options->channel,
217 composite_options->compose,composite_image,geometry.x,
219 GetImageException(*image,exception);
222 return(status != 0 ? MagickTrue : MagickFalse);
225 static MagickBooleanType CompositeUsage(void)
233 "-debug events display copious debugging information",
234 "-help print program options",
235 "-list type print a list of supported option arguments",
236 "-log format format of debugging information",
237 "-version print version information",
242 "-blend geometry blend images",
243 "-border geometry surround image with a border of color",
244 "-bordercolor color border color",
245 "-colors value preferred number of colors in the image",
246 "-decipher filename convert cipher pixels to plain pixels",
247 "-displace geometry shift lookup according to a relative displacement map",
248 "-dissolve value dissolve the two images a given percent",
249 "-distort geometry shift lookup according to a absolute distortion map",
250 "-encipher filename convert plain pixels to cipher pixels",
251 "-extract geometry extract area from image",
252 "-geometry geometry location of the composite image",
253 "-identify identify the format and characteristics of the image",
254 "-monochrome transform image to black and white",
255 "-negate replace every pixel with its complementary color ",
256 "-profile filename add ICM or IPTC information profile to image",
257 "-quantize colorspace reduce colors in this colorspace",
258 "-repage geometry size and location of an image canvas (operator)",
259 "-rotate degrees apply Paeth rotation to the image",
260 "-resize geometry resize the image",
261 "-sharpen geometry sharpen the image",
262 "-shave geometry shave pixels from the image edges",
263 "-stegano offset hide watermark within an image",
264 "-stereo geometry combine two image to create a stereo anaglyph",
265 "-strip strip image of all profiles and comments",
266 "-thumbnail geometry create a thumbnail of the image",
267 "-transform affine transform image",
268 "-type type image type",
269 "-unsharp geometry sharpen the image",
270 "-watermark geometry percent brightness and saturation of a watermark",
271 "-write filename write images to this file",
276 "-affine matrix affine transform matrix",
277 "-alpha option on, activate, off, deactivate, set, opaque, copy",
278 " transparent, extract, background, or shape",
279 "-authenticate password",
280 " decipher image with this password",
281 "-blue-primary point chromaticity blue primary point",
282 "-channel type apply option to select image channels",
283 "-colorspace type alternate image colorspace",
284 "-comment string annotate image with comment",
285 "-compose operator composite operator",
286 "-compress type type of pixel compression when writing the image",
287 "-define format:option",
288 " define one or more image format options",
289 "-depth value image depth",
290 "-density geometry horizontal and vertical density of the image",
291 "-display server get image or font from this X server",
292 "-dispose method layer disposal method",
293 "-dither method apply error diffusion to image",
294 "-encoding type text encoding type",
295 "-endian type endianness (MSB or LSB) of the image",
296 "-filter type use this filter when resizing an image",
297 "-font name render text with this font",
298 "-format \"string\" output formatted image characteristics",
299 "-gravity type which direction to gravitate towards",
300 "-green-primary point chromaticity green primary point",
301 "-interlace type type of image interlacing scheme",
302 "-interpolate method pixel color interpolation method",
303 "-label string assign a label to an image",
304 "-limit type value pixel cache resource limit",
305 "-monitor monitor progress",
306 "-page geometry size and location of an image canvas (setting)",
307 "-pointsize value font point size",
308 "-quality value JPEG/MIFF/PNG compression level",
309 "-quiet suppress all warning messages",
310 "-red-primary point chromaticity red primary point",
311 "-regard-warnings pay attention to warning messages",
312 "-respect-parentheses settings remain in effect until parenthesis boundary",
313 "-sampling-factor geometry",
314 " horizontal and vertical sampling factor",
315 "-scene value image scene number",
316 "-seed value seed a new sequence of pseudo-random numbers",
317 "-size geometry width and height of image",
318 "-synchronize synchronize image to storage device",
319 "-taint declare the image as modified",
320 "-transparent-color color",
321 " transparent color",
322 "-treedepth value color tree depth",
323 "-tile repeat composite operation across and down image",
324 "-units type the units of image resolution",
325 "-verbose print detailed information about the image",
326 "-virtual-pixel method",
327 " virtual pixel access method",
328 "-white-point point chromaticity white point",
333 "-swap indexes swap two images in the image sequence",
338 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
339 (void) printf("Copyright: %s\n",GetMagickCopyright());
340 (void) printf("Features: %s\n\n",GetMagickFeatures());
341 (void) printf("Usage: %s [options ...] image [options ...] composite\n"
342 " [ [options ...] mask ] [options ...] composite\n",
344 (void) printf("\nImage Settings:\n");
345 for (p=settings; *p != (char *) NULL; p++)
346 (void) printf(" %s\n",*p);
347 (void) printf("\nImage Operators:\n");
348 for (p=operators; *p != (char *) NULL; p++)
349 (void) printf(" %s\n",*p);
350 (void) printf("\nImage Stack Operators:\n");
351 for (p=stack_operators; *p != (char *) NULL; p++)
352 (void) printf(" %s\n",*p);
353 (void) printf("\nMiscellaneous Options:\n");
354 for (p=miscellaneous; *p != (char *) NULL; p++)
355 (void) printf(" %s\n",*p);
357 "\nBy default, the image format of `file' is determined by its magic\n");
359 "number. To specify a particular image format, precede the filename\n");
361 "with an image format name and a colon (i.e. ps:image) or specify the\n");
363 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
364 (void) printf("'-' for standard input or output.\n");
368 static void GetCompositeOptions(CompositeOptions *composite_options)
370 (void) ResetMagickMemory(composite_options,0,sizeof(*composite_options));
371 composite_options->channel=DefaultChannels;
372 composite_options->compose=OverCompositeOp;
375 static void RelinquishCompositeOptions(CompositeOptions *composite_options)
377 if (composite_options->compose_args != (char *) NULL)
378 composite_options->compose_args=(char *)
379 RelinquishMagickMemory(composite_options->compose_args);
382 WandExport MagickBooleanType CompositeImageCommand(ImageInfo *image_info,
383 int argc,char **argv,char **metadata,ExceptionInfo *exception)
385 #define NotInitialized (unsigned int) (~0)
386 #define DestroyComposite() \
388 RelinquishCompositeOptions(&composite_options); \
389 DestroyImageStack(); \
390 for (i=0; i < (ssize_t) argc; i++) \
391 argv[i]=DestroyString(argv[i]); \
392 argv=(char **) RelinquishMagickMemory(argv); \
394 #define ThrowCompositeException(asperity,tag,option) \
396 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
397 option == (char *) NULL ? GetExceptionMessage(errno) : option); \
398 DestroyComposite(); \
399 return(MagickFalse); \
401 #define ThrowCompositeInvalidArgumentException(option,argument) \
403 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
404 "InvalidArgument","`%s': %s",option,argument); \
405 DestroyComposite(); \
406 return(MagickFalse); \
426 image_stack[MaxImageStackDepth+1];
446 assert(image_info != (ImageInfo *) NULL);
447 assert(image_info->signature == MagickSignature);
448 if (image_info->debug != MagickFalse)
449 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
450 assert(exception != (ExceptionInfo *) NULL);
454 if ((LocaleCompare("version",option+1) == 0) ||
455 (LocaleCompare("-version",option+1) == 0))
457 (void) FormatLocaleFile(stdout,"Version: %s\n",
458 GetMagickVersion((size_t *) NULL));
459 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
460 GetMagickCopyright());
461 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
462 GetMagickFeatures());
467 return(CompositeUsage());
468 GetCompositeOptions(&composite_options);
469 filename=(char *) NULL;
474 option=(char *) NULL;
476 respect_parenthesis=MagickFalse;
479 Check command syntax.
481 composite_image=NewImageList();
482 image=NewImageList();
483 mask_image=NewImageList();
484 ReadCommandlLine(argc,&argv);
485 status=ExpandFilenames(&argc,&argv);
486 if (status == MagickFalse)
487 ThrowCompositeException(ResourceLimitError,"MemoryAllocationFailed",
488 GetExceptionMessage(errno));
489 for (i=1; i < (ssize_t) (argc-1); i++)
492 if (LocaleCompare(option,"(") == 0)
494 FireImageStack(MagickFalse,MagickTrue,pend);
495 if (k == MaxImageStackDepth)
496 ThrowCompositeException(OptionError,"ParenthesisNestedTooDeeply",
501 if (LocaleCompare(option,")") == 0)
503 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
505 ThrowCompositeException(OptionError,"UnableToParseExpression",option);
509 if (IsCommandOption(option) == MagickFalse)
517 FireImageStack(MagickFalse,MagickFalse,pend);
519 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
521 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
522 images=ReadImages(image_info,exception);
523 status&=(images != (Image *) NULL) &&
524 (exception->severity < ErrorException);
525 if (images == (Image *) NULL)
527 AppendImageStack(images);
530 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
535 if (LocaleCompare("affine",option+1) == 0)
540 if (i == (ssize_t) argc)
541 ThrowCompositeException(OptionError,"MissingArgument",option);
542 if (IsGeometry(argv[i]) == MagickFalse)
543 ThrowCompositeInvalidArgumentException(option,argv[i]);
546 if (LocaleCompare("alpha",option+1) == 0)
554 if (i == (ssize_t) argc)
555 ThrowCompositeException(OptionError,"MissingArgument",option);
556 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
558 ThrowCompositeException(OptionError,
559 "UnrecognizedAlphaChannelType",argv[i]);
562 if (LocaleCompare("authenticate",option+1) == 0)
567 if (i == (ssize_t) argc)
568 ThrowCompositeException(OptionError,"MissingArgument",option);
571 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
575 if (LocaleCompare("background",option+1) == 0)
580 if (i == (ssize_t) argc)
581 ThrowCompositeException(OptionError,"MissingArgument",option);
584 if (LocaleCompare("blend",option+1) == 0)
586 (void) CloneString(&composite_options.compose_args,(char *) NULL);
590 if (i == (ssize_t) argc)
591 ThrowCompositeException(OptionError,"MissingArgument",option);
592 if (IsGeometry(argv[i]) == MagickFalse)
593 ThrowCompositeInvalidArgumentException(option,argv[i]);
594 (void) CloneString(&composite_options.compose_args,argv[i]);
595 composite_options.compose=BlendCompositeOp;
598 if (LocaleCompare("blur",option+1) == 0)
600 (void) CloneString(&composite_options.compose_args,(char *) NULL);
604 if (i == (ssize_t) argc)
605 ThrowCompositeException(OptionError,"MissingArgument",option);
606 if (IsGeometry(argv[i]) == MagickFalse)
607 ThrowCompositeInvalidArgumentException(option,argv[i]);
608 (void) CloneString(&composite_options.compose_args,argv[i]);
609 composite_options.compose=BlurCompositeOp;
612 if (LocaleCompare("blue-primary",option+1) == 0)
617 if (i == (ssize_t) argc)
618 ThrowCompositeException(OptionError,"MissingArgument",option);
619 if (IsGeometry(argv[i]) == MagickFalse)
620 ThrowCompositeInvalidArgumentException(option,argv[i]);
623 if (LocaleCompare("border",option+1) == 0)
628 if (i == (ssize_t) (argc-1))
629 ThrowCompositeException(OptionError,"MissingArgument",option);
630 if (IsGeometry(argv[i]) == MagickFalse)
631 ThrowCompositeInvalidArgumentException(option,argv[i]);
634 if (LocaleCompare("bordercolor",option+1) == 0)
639 if (i == (ssize_t) (argc-1))
640 ThrowCompositeException(OptionError,"MissingArgument",option);
643 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
647 if (LocaleCompare("cache",option+1) == 0)
652 if (i == (ssize_t) argc)
653 ThrowCompositeException(OptionError,"MissingArgument",option);
654 if (IsGeometry(argv[i]) == MagickFalse)
655 ThrowCompositeInvalidArgumentException(option,argv[i]);
658 if (LocaleCompare("channel",option+1) == 0)
665 composite_options.channel=DefaultChannels;
669 if (i == (ssize_t) (argc-1))
670 ThrowCompositeException(OptionError,"MissingArgument",option);
671 channel=ParseChannelOption(argv[i]);
673 ThrowCompositeException(OptionError,"UnrecognizedChannelType",
675 composite_options.channel=(ChannelType) channel;
678 if (LocaleCompare("colors",option+1) == 0)
683 if (i == (ssize_t) argc)
684 ThrowCompositeException(OptionError,"MissingArgument",option);
685 if (IsGeometry(argv[i]) == MagickFalse)
686 ThrowCompositeInvalidArgumentException(option,argv[i]);
689 if (LocaleCompare("colorspace",option+1) == 0)
697 if (i == (ssize_t) argc)
698 ThrowCompositeException(OptionError,"MissingArgument",option);
699 colorspace=ParseCommandOption(MagickColorspaceOptions,
700 MagickFalse,argv[i]);
702 ThrowCompositeException(OptionError,"UnrecognizedColorspace",
706 if (LocaleCompare("comment",option+1) == 0)
711 if (i == (ssize_t) argc)
712 ThrowCompositeException(OptionError,"MissingArgument",option);
715 if (LocaleCompare("compose",option+1) == 0)
720 composite_options.compose=UndefinedCompositeOp;
724 if (i == (ssize_t) argc)
725 ThrowCompositeException(OptionError,"MissingArgument",option);
726 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
729 ThrowCompositeException(OptionError,"UnrecognizedComposeOperator",
731 composite_options.compose=(CompositeOperator) compose;
734 if (LocaleCompare("compress",option+1) == 0)
742 if (i == (ssize_t) argc)
743 ThrowCompositeException(OptionError,"MissingArgument",option);
744 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
747 ThrowCompositeException(OptionError,
748 "UnrecognizedImageCompression",argv[i]);
751 if (LocaleCompare("concurrent",option+1) == 0)
753 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
757 if (LocaleCompare("debug",option+1) == 0)
765 if (i == (ssize_t) argc)
766 ThrowCompositeException(OptionError,"MissingArgument",option);
767 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
769 ThrowCompositeException(OptionError,"UnrecognizedEventType",
771 (void) SetLogEventMask(argv[i]);
774 if (LocaleCompare("decipher",option+1) == 0)
779 if (i == (ssize_t) (argc-1))
780 ThrowCompositeException(OptionError,"MissingArgument",option);
783 if (LocaleCompare("define",option+1) == 0)
786 if (i == (ssize_t) argc)
787 ThrowCompositeException(OptionError,"MissingArgument",option);
793 define=GetImageOption(image_info,argv[i]);
794 if (define == (const char *) NULL)
795 ThrowCompositeException(OptionError,"NoSuchOption",argv[i]);
800 if (LocaleCompare("density",option+1) == 0)
805 if (i == (ssize_t) argc)
806 ThrowCompositeException(OptionError,"MissingArgument",option);
807 if (IsGeometry(argv[i]) == MagickFalse)
808 ThrowCompositeInvalidArgumentException(option,argv[i]);
811 if (LocaleCompare("depth",option+1) == 0)
816 if (i == (ssize_t) argc)
817 ThrowCompositeException(OptionError,"MissingArgument",option);
818 if (IsGeometry(argv[i]) == MagickFalse)
819 ThrowCompositeInvalidArgumentException(option,argv[i]);
822 if (LocaleCompare("displace",option+1) == 0)
824 (void) CloneString(&composite_options.compose_args,(char *) NULL);
828 if (i == (ssize_t) argc)
829 ThrowCompositeException(OptionError,"MissingArgument",option);
830 if (IsGeometry(argv[i]) == MagickFalse)
831 ThrowCompositeInvalidArgumentException(option,argv[i]);
832 (void) CloneString(&composite_options.compose_args,argv[i]);
833 composite_options.compose=DisplaceCompositeOp;
836 if (LocaleCompare("display",option+1) == 0)
841 if (i == (ssize_t) argc)
842 ThrowCompositeException(OptionError,"MissingArgument",option);
845 if (LocaleCompare("dispose",option+1) == 0)
853 if (i == (ssize_t) argc)
854 ThrowCompositeException(OptionError,"MissingArgument",option);
855 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
857 ThrowCompositeException(OptionError,"UnrecognizedDisposeMethod",
861 if (LocaleCompare("dissolve",option+1) == 0)
863 (void) CloneString(&composite_options.compose_args,(char *) NULL);
867 if (i == (ssize_t) argc)
868 ThrowCompositeException(OptionError,"MissingArgument",option);
869 if (IsGeometry(argv[i]) == MagickFalse)
870 ThrowCompositeInvalidArgumentException(option,argv[i]);
871 (void) CloneString(&composite_options.compose_args,argv[i]);
872 composite_options.compose=DissolveCompositeOp;
875 if (LocaleCompare("distort",option+1) == 0)
877 (void) CloneString(&composite_options.compose_args,(char *) NULL);
881 if (i == (ssize_t) argc)
882 ThrowCompositeException(OptionError,"MissingArgument",option);
883 if (IsGeometry(argv[i]) == MagickFalse)
884 ThrowCompositeInvalidArgumentException(option,argv[i]);
885 (void) CloneString(&composite_options.compose_args,argv[i]);
886 composite_options.compose=DistortCompositeOp;
889 if (LocaleCompare("dither",option+1) == 0)
897 if (i == (ssize_t) argc)
898 ThrowCompositeException(OptionError,"MissingArgument",option);
899 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
901 ThrowCompositeException(OptionError,"UnrecognizedDitherMethod",
905 if (LocaleCompare("duration",option+1) == 0)
910 if (i == (ssize_t) (argc-1))
911 ThrowCompositeException(OptionError,"MissingArgument",option);
912 if (IsGeometry(argv[i]) == MagickFalse)
913 ThrowCompositeInvalidArgumentException(option,argv[i]);
916 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
920 if (LocaleCompare("encipher",option+1) == 0)
925 if (i == (ssize_t) (argc-1))
926 ThrowCompositeException(OptionError,"MissingArgument",option);
929 if (LocaleCompare("encoding",option+1) == 0)
934 if (i == (ssize_t) argc)
935 ThrowCompositeException(OptionError,"MissingArgument",option);
938 if (LocaleCompare("endian",option+1) == 0)
946 if (i == (ssize_t) argc)
947 ThrowCompositeException(OptionError,"MissingArgument",option);
948 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
951 ThrowCompositeException(OptionError,"UnrecognizedEndianType",
955 if (LocaleCompare("extract",option+1) == 0)
960 if (i == (ssize_t) argc)
961 ThrowCompositeException(OptionError,"MissingArgument",option);
962 if (IsGeometry(argv[i]) == MagickFalse)
963 ThrowCompositeInvalidArgumentException(option,argv[i]);
966 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
970 if (LocaleCompare("filter",option+1) == 0)
978 if (i == (ssize_t) argc)
979 ThrowCompositeException(OptionError,"MissingArgument",option);
980 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
982 ThrowCompositeException(OptionError,"UnrecognizedImageFilter",
986 if (LocaleCompare("font",option+1) == 0)
991 if (i == (ssize_t) argc)
992 ThrowCompositeException(OptionError,"MissingArgument",option);
995 if (LocaleCompare("format",option+1) == 0)
1000 if (i == (ssize_t) argc)
1001 ThrowCompositeException(OptionError,"MissingArgument",option);
1005 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1009 if (LocaleCompare("geometry",option+1) == 0)
1011 (void) CloneString(&composite_options.geometry,(char *) NULL);
1015 if (i == (ssize_t) argc)
1016 ThrowCompositeException(OptionError,"MissingArgument",option);
1017 if (IsGeometry(argv[i]) == MagickFalse)
1018 ThrowCompositeInvalidArgumentException(option,argv[i]);
1019 (void) CloneString(&composite_options.geometry,argv[i]);
1022 if (LocaleCompare("gravity",option+1) == 0)
1027 composite_options.gravity=UndefinedGravity;
1031 if (i == (ssize_t) argc)
1032 ThrowCompositeException(OptionError,"MissingArgument",option);
1033 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
1036 ThrowCompositeException(OptionError,"UnrecognizedGravityType",
1038 composite_options.gravity=(GravityType) gravity;
1041 if (LocaleCompare("green-primary",option+1) == 0)
1046 if (i == (ssize_t) argc)
1047 ThrowCompositeException(OptionError,"MissingArgument",option);
1048 if (IsGeometry(argv[i]) == MagickFalse)
1049 ThrowCompositeInvalidArgumentException(option,argv[i]);
1052 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1056 if ((LocaleCompare("help",option+1) == 0) ||
1057 (LocaleCompare("-help",option+1) == 0))
1058 return(CompositeUsage());
1059 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1063 if (LocaleCompare("identify",option+1) == 0)
1065 if (LocaleCompare("interlace",option+1) == 0)
1073 if (i == (ssize_t) argc)
1074 ThrowCompositeException(OptionError,"MissingArgument",option);
1075 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
1078 ThrowCompositeException(OptionError,
1079 "UnrecognizedInterlaceType",argv[i]);
1082 if (LocaleCompare("interpolate",option+1) == 0)
1090 if (i == (ssize_t) argc)
1091 ThrowCompositeException(OptionError,"MissingArgument",option);
1092 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
1094 if (interpolate < 0)
1095 ThrowCompositeException(OptionError,
1096 "UnrecognizedInterpolateMethod",argv[i]);
1099 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1103 if (LocaleCompare("label",option+1) == 0)
1108 if (i == (ssize_t) argc)
1109 ThrowCompositeException(OptionError,"MissingArgument",option);
1112 if (LocaleCompare("limit",option+1) == 0)
1126 if (i == (ssize_t) argc)
1127 ThrowCompositeException(OptionError,"MissingArgument",option);
1128 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
1131 ThrowCompositeException(OptionError,"UnrecognizedResourceType",
1134 if (i == (ssize_t) argc)
1135 ThrowCompositeException(OptionError,"MissingArgument",option);
1136 value=InterpretLocaleValue(argv[i],&p);
1138 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
1139 ThrowCompositeInvalidArgumentException(option,argv[i]);
1142 if (LocaleCompare("list",option+1) == 0)
1150 if (i == (ssize_t) argc)
1151 ThrowCompositeException(OptionError,"MissingArgument",option);
1152 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
1154 ThrowCompositeException(OptionError,"UnrecognizedListType",
1156 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
1159 return(status != 0 ? MagickFalse : MagickTrue);
1161 if (LocaleCompare("log",option+1) == 0)
1166 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
1167 ThrowCompositeException(OptionError,"MissingArgument",option);
1170 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1174 if (LocaleCompare("matte",option+1) == 0)
1176 if (LocaleCompare("monitor",option+1) == 0)
1178 if (LocaleCompare("monochrome",option+1) == 0)
1180 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1184 if (LocaleCompare("negate",option+1) == 0)
1186 if (LocaleCompare("noop",option+1) == 0)
1188 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1192 if (LocaleCompare("page",option+1) == 0)
1197 if (i == (ssize_t) argc)
1198 ThrowCompositeException(OptionError,"MissingArgument",option);
1201 if (LocaleCompare("pointsize",option+1) == 0)
1206 if (i == (ssize_t) (argc-1))
1207 ThrowCompositeException(OptionError,"MissingArgument",option);
1208 if (IsGeometry(argv[i]) == MagickFalse)
1209 ThrowCompositeInvalidArgumentException(option,argv[i]);
1212 if (LocaleCompare("process",option+1) == 0)
1217 if (i == (ssize_t) argc)
1218 ThrowCompositeException(OptionError,"MissingArgument",option);
1221 if (LocaleCompare("profile",option+1) == 0)
1224 if (i == (ssize_t) argc)
1225 ThrowCompositeException(OptionError,"MissingArgument",option);
1228 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1232 if (LocaleCompare("quality",option+1) == 0)
1237 if (i == (ssize_t) argc)
1238 ThrowCompositeException(OptionError,"MissingArgument",option);
1239 if (IsGeometry(argv[i]) == MagickFalse)
1240 ThrowCompositeInvalidArgumentException(option,argv[i]);
1243 if (LocaleCompare("quantize",option+1) == 0)
1251 if (i == (ssize_t) (argc-1))
1252 ThrowCompositeException(OptionError,"MissingArgument",option);
1253 colorspace=ParseCommandOption(MagickColorspaceOptions,
1254 MagickFalse,argv[i]);
1256 ThrowCompositeException(OptionError,"UnrecognizedColorspace",
1260 if (LocaleCompare("quiet",option+1) == 0)
1262 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1266 if (LocaleCompare("red-primary",option+1) == 0)
1271 if (i == (ssize_t) argc)
1272 ThrowCompositeException(OptionError,"MissingArgument",option);
1273 if (IsGeometry(argv[i]) == MagickFalse)
1274 ThrowCompositeInvalidArgumentException(option,argv[i]);
1277 if (LocaleCompare("regard-warnings",option+1) == 0)
1279 if (LocaleCompare("render",option+1) == 0)
1281 if (LocaleCompare("repage",option+1) == 0)
1286 if (i == (ssize_t) argc)
1287 ThrowCompositeException(OptionError,"MissingArgument",option);
1288 if (IsGeometry(argv[i]) == MagickFalse)
1289 ThrowCompositeInvalidArgumentException(option,argv[i]);
1292 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1294 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1297 if (LocaleCompare("resize",option+1) == 0)
1302 if (i == (ssize_t) argc)
1303 ThrowCompositeException(OptionError,"MissingArgument",option);
1304 if (IsGeometry(argv[i]) == MagickFalse)
1305 ThrowCompositeInvalidArgumentException(option,argv[i]);
1308 if (LocaleCompare("rotate",option+1) == 0)
1311 if (i == (ssize_t) argc)
1312 ThrowCompositeException(OptionError,"MissingArgument",option);
1313 if (IsGeometry(argv[i]) == MagickFalse)
1314 ThrowCompositeInvalidArgumentException(option,argv[i]);
1317 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1321 if (LocaleCompare("sampling-factor",option+1) == 0)
1326 if (i == (ssize_t) argc)
1327 ThrowCompositeException(OptionError,"MissingArgument",option);
1328 if (IsGeometry(argv[i]) == MagickFalse)
1329 ThrowCompositeInvalidArgumentException(option,argv[i]);
1332 if (LocaleCompare("scene",option+1) == 0)
1337 if (i == (ssize_t) argc)
1338 ThrowCompositeException(OptionError,"MissingArgument",option);
1339 if (IsGeometry(argv[i]) == MagickFalse)
1340 ThrowCompositeInvalidArgumentException(option,argv[i]);
1343 if (LocaleCompare("seed",option+1) == 0)
1348 if (i == (ssize_t) (argc-1))
1349 ThrowCompositeException(OptionError,"MissingArgument",option);
1350 if (IsGeometry(argv[i]) == MagickFalse)
1351 ThrowCompositeInvalidArgumentException(option,argv[i]);
1354 if (LocaleCompare("sharpen",option+1) == 0)
1357 if (i == (ssize_t) argc)
1358 ThrowCompositeException(OptionError,"MissingArgument",option);
1359 if (IsGeometry(argv[i]) == MagickFalse)
1360 ThrowCompositeInvalidArgumentException(option,argv[i]);
1363 if (LocaleCompare("shave",option+1) == 0)
1368 if (i == (ssize_t) (argc-1))
1369 ThrowCompositeException(OptionError,"MissingArgument",option);
1370 if (IsGeometry(argv[i]) == MagickFalse)
1371 ThrowCompositeInvalidArgumentException(option,argv[i]);
1374 if (LocaleCompare("size",option+1) == 0)
1379 if (i == (ssize_t) argc)
1380 ThrowCompositeException(OptionError,"MissingArgument",option);
1381 if (IsGeometry(argv[i]) == MagickFalse)
1382 ThrowCompositeInvalidArgumentException(option,argv[i]);
1385 if (LocaleCompare("stegano",option+1) == 0)
1387 composite_options.stegano=0;
1391 if (i == (ssize_t) argc)
1392 ThrowCompositeException(OptionError,"MissingArgument",option);
1393 if (IsGeometry(argv[i]) == MagickFalse)
1394 ThrowCompositeInvalidArgumentException(option,argv[i]);
1395 composite_options.stegano=(ssize_t) StringToLong(argv[i])+1;
1398 if (LocaleCompare("stereo",option+1) == 0)
1403 composite_options.stereo=MagickFalse;
1407 if (i == (ssize_t) argc)
1408 ThrowCompositeException(OptionError,"MissingArgument",option);
1409 if (IsGeometry(argv[i]) == MagickFalse)
1410 ThrowCompositeInvalidArgumentException(option,argv[i]);
1411 flags=ParseAbsoluteGeometry(argv[i],&composite_options.offset);
1412 if ((flags & YValue) == 0)
1413 composite_options.offset.y=composite_options.offset.x;
1414 composite_options.stereo=MagickTrue;
1417 if (LocaleCompare("strip",option+1) == 0)
1419 if (LocaleCompare("support",option+1) == 0)
1421 i++; /* deprecated */
1424 if (LocaleCompare("swap",option+1) == 0)
1429 if (i == (ssize_t) (argc-1))
1430 ThrowCompositeException(OptionError,"MissingArgument",option);
1431 if (IsGeometry(argv[i]) == MagickFalse)
1432 ThrowCompositeInvalidArgumentException(option,argv[i]);
1435 if (LocaleCompare("synchronize",option+1) == 0)
1437 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1441 if (LocaleCompare("taint",option+1) == 0)
1443 if (LocaleCompare("thumbnail",option+1) == 0)
1448 if (i == (ssize_t) argc)
1449 ThrowCompositeException(OptionError,"MissingArgument",option);
1450 if (IsGeometry(argv[i]) == MagickFalse)
1451 ThrowCompositeInvalidArgumentException(option,argv[i]);
1454 if (LocaleCompare("tile",option+1) == 0)
1456 composite_options.tile=(*option == '-') ? MagickTrue : MagickFalse;
1457 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
1460 if (LocaleCompare("transform",option+1) == 0)
1462 if (LocaleCompare("transparent-color",option+1) == 0)
1467 if (i == (ssize_t) (argc-1))
1468 ThrowCompositeException(OptionError,"MissingArgument",option);
1471 if (LocaleCompare("treedepth",option+1) == 0)
1476 if (i == (ssize_t) argc)
1477 ThrowCompositeException(OptionError,"MissingArgument",option);
1478 if (IsGeometry(argv[i]) == MagickFalse)
1479 ThrowCompositeInvalidArgumentException(option,argv[i]);
1482 if (LocaleCompare("type",option+1) == 0)
1490 if (i == (ssize_t) argc)
1491 ThrowCompositeException(OptionError,"MissingArgument",option);
1492 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
1494 ThrowCompositeException(OptionError,"UnrecognizedImageType",
1498 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1502 if (LocaleCompare("units",option+1) == 0)
1510 if (i == (ssize_t) argc)
1511 ThrowCompositeException(OptionError,"MissingArgument",option);
1512 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
1515 ThrowCompositeException(OptionError,"UnrecognizedUnitsType",
1519 if (LocaleCompare("unsharp",option+1) == 0)
1521 (void) CloneString(&composite_options.compose_args,(char *) NULL);
1525 if (i == (ssize_t) argc)
1526 ThrowCompositeException(OptionError,"MissingArgument",option);
1527 if (IsGeometry(argv[i]) == MagickFalse)
1528 ThrowCompositeInvalidArgumentException(option,argv[i]);
1529 (void) CloneString(&composite_options.compose_args,argv[i]);
1530 composite_options.compose=ThresholdCompositeOp;
1533 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1537 if (LocaleCompare("verbose",option+1) == 0)
1539 if ((LocaleCompare("version",option+1) == 0) ||
1540 (LocaleCompare("-version",option+1) == 0))
1542 (void) FormatLocaleFile(stdout,"Version: %s\n",
1543 GetMagickVersion((size_t *) NULL));
1544 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
1545 GetMagickCopyright());
1546 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1547 GetMagickFeatures());
1550 if (LocaleCompare("virtual-pixel",option+1) == 0)
1558 if (i == (ssize_t) argc)
1559 ThrowCompositeException(OptionError,"MissingArgument",option);
1560 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
1563 ThrowCompositeException(OptionError,
1564 "UnrecognizedVirtualPixelMethod",argv[i]);
1567 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1571 if (LocaleCompare("watermark",option+1) == 0)
1573 (void) CloneString(&composite_options.compose_args,(char *) NULL);
1577 if (i == (ssize_t) argc)
1578 ThrowCompositeException(OptionError,"MissingArgument",option);
1579 if (IsGeometry(argv[i]) == MagickFalse)
1580 ThrowCompositeInvalidArgumentException(option,argv[i]);
1581 (void) CloneString(&composite_options.compose_args,argv[i]);
1582 composite_options.compose=ModulateCompositeOp;
1585 if (LocaleCompare("white-point",option+1) == 0)
1590 if (i == (ssize_t) argc)
1591 ThrowCompositeException(OptionError,"MissingArgument",option);
1592 if (IsGeometry(argv[i]) == MagickFalse)
1593 ThrowCompositeInvalidArgumentException(option,argv[i]);
1596 if (LocaleCompare("write",option+1) == 0)
1599 if (i == (ssize_t) argc)
1600 ThrowCompositeException(OptionError,"MissingArgument",option);
1603 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1608 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1610 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1611 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
1612 if (fire != MagickFalse)
1613 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1616 ThrowCompositeException(OptionError,"UnbalancedParenthesis",argv[i]);
1617 if (i-- != (ssize_t) (argc-1))
1618 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[i]);
1619 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1620 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1621 FinalizeImageSettings(image_info,image,MagickTrue);
1622 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1623 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1627 RemoveImageStack(composite_image);
1628 RemoveImageStack(images);
1629 (void) TransformImage(&composite_image,(char *) NULL,
1630 composite_image->geometry);
1631 RemoveImageStack(mask_image);
1632 if (mask_image != (Image *) NULL)
1634 if ((composite_options.compose == DisplaceCompositeOp) ||
1635 (composite_options.compose == DistortCompositeOp))
1638 Merge Y displacement into X displacement image.
1640 (void) CompositeImage(composite_image,CopyGreenCompositeOp,mask_image,
1642 mask_image=DestroyImage(mask_image);
1647 Set a blending mask for the composition.
1649 images->mask=mask_image;
1650 (void) NegateImage(images->mask,MagickFalse);
1653 status&=CompositeImageList(image_info,&images,composite_image,
1654 &composite_options,exception);
1655 composite_image=DestroyImage(composite_image);
1657 Write composite images.
1659 status&=WriteImages(image_info,images,argv[argc-1],exception);
1660 if (metadata != (char **) NULL)
1665 text=InterpretImageProperties(image_info,images,format);
1666 if (text == (char *) NULL)
1667 ThrowCompositeException(ResourceLimitError,"MemoryAllocationFailed",
1668 GetExceptionMessage(errno));
1669 (void) ConcatenateString(&(*metadata),text);
1670 (void) ConcatenateString(&(*metadata),"\n");
1671 text=DestroyString(text);
1673 images=DestroyImage(images);
1674 RelinquishCompositeOptions(&composite_options);
1676 return(status != 0 ? MagickTrue : MagickFalse);