1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Definition and implementation of template functions for using
6 // Magick::Image with STL containers.
9 #ifndef Magick_STL_header
10 #define Magick_STL_header
12 #include "Magick++/Include.h"
19 #include "Magick++/CoderInfo.h"
20 #include "Magick++/Drawable.h"
21 #include "Magick++/Exception.h"
22 #include "Magick++/Montage.h"
27 // STL function object declarations/definitions
30 // Function objects provide the means to invoke an operation on one
31 // or more image objects in an STL-compatable container. The
32 // arguments to the function object constructor(s) are compatable
33 // with the arguments to the equivalent Image class method and
34 // provide the means to supply these options when the function
37 // For example, to read a GIF animation, set the color red to
38 // transparent for all frames, and write back out:
40 // list<image> images;
41 // readImages( &images, "animation.gif" );
42 // for_each( images.begin(), images.end(), transparentImage( "red" ) );
43 // writeImages( images.begin(), images.end(), "animation.gif" );
45 // Adaptive-blur image with specified blur factor
46 class MagickPPExport adaptiveBlurImage : public std::unary_function<Image&,void>
49 adaptiveBlurImage( const double radius_ = 1, const double sigma_ = 0.5 );
51 void operator()( Image &image_ ) const;
58 // Local adaptive threshold image
59 // http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
60 // Width x height define the size of the pixel neighborhood
61 // offset = constant to subtract from pixel neighborhood mean
62 class MagickPPExport adaptiveThresholdImage : public std::unary_function<Image&,void>
65 adaptiveThresholdImage( const size_t width_,
67 const ::ssize_t offset_ = 0 );
69 void operator()( Image &image_ ) const;
77 // Add noise to image with specified noise type
78 class MagickPPExport addNoiseImage : public std::unary_function<Image&,void>
81 addNoiseImage ( NoiseType noiseType_ );
83 void operator()( Image &image_ ) const;
89 // Transform image by specified affine (or free transform) matrix.
90 class MagickPPExport affineTransformImage : public std::unary_function<Image&,void>
93 affineTransformImage( const DrawableAffine &affine_ );
95 void operator()( Image &image_ ) const;
98 DrawableAffine _affine;
101 // Annotate image (draw text on image)
102 class MagickPPExport annotateImage : public std::unary_function<Image&,void>
105 // Annotate using specified text, and placement location
106 annotateImage ( const std::string &text_,
107 const Geometry &geometry_ );
109 // Annotate using specified text, bounding area, and placement
111 annotateImage ( const std::string &text_,
112 const Geometry &geometry_,
113 const GravityType gravity_ );
115 // Annotate with text using specified text, bounding area,
116 // placement gravity, and rotation.
117 annotateImage ( const std::string &text_,
118 const Geometry &geometry_,
119 const GravityType gravity_,
120 const double degrees_ );
122 // Annotate with text (bounding area is entire image) and
123 // placement gravity.
124 annotateImage ( const std::string &text_,
125 const GravityType gravity_ );
127 void operator()( Image &image_ ) const;
130 // Copy constructor and assignment are not supported
131 annotateImage(const annotateImage&);
132 annotateImage& operator=(const annotateImage&);
134 const std::string _text;
135 const Geometry _geometry;
136 const GravityType _gravity;
137 const double _degrees;
140 // Blur image with specified blur factor
141 class MagickPPExport blurImage : public std::unary_function<Image&,void>
144 blurImage( const double radius_ = 1, const double sigma_ = 0.5 );
146 void operator()( Image &image_ ) const;
153 // Border image (add border to image)
154 class MagickPPExport borderImage : public std::unary_function<Image&,void>
157 borderImage( const Geometry &geometry_ = borderGeometryDefault );
159 void operator()( Image &image_ ) const;
165 // Extract channel from image
166 class MagickPPExport channelImage : public std::unary_function<Image&,void>
169 channelImage( const ChannelType channel_ );
171 void operator()( Image &image_ ) const;
174 ChannelType _channel;
177 // Charcoal effect image (looks like charcoal sketch)
178 class MagickPPExport charcoalImage : public std::unary_function<Image&,void>
181 charcoalImage( const double radius_ = 1, const double sigma_ = 0.5 );
183 void operator()( Image &image_ ) const;
190 // Chop image (remove vertical or horizontal subregion of image)
191 class MagickPPExport chopImage : public std::unary_function<Image&,void>
194 chopImage( const Geometry &geometry_ );
196 void operator()( Image &image_ ) const;
202 // Accepts a lightweight Color Correction Collection (CCC) file which solely
203 // contains one or more color corrections and applies the correction to the
205 class MagickPPExport cdlImage : public std::unary_function<Image&,void>
208 cdlImage( const std::string &cdl_ );
210 void operator()( Image &image_ ) const;
216 // Colorize image using pen color at specified percent alpha
217 class MagickPPExport colorizeImage : public std::unary_function<Image&,void>
220 colorizeImage( const unsigned int alphaRed_,
221 const unsigned int alphaGreen_,
222 const unsigned int alphaBlue_,
223 const Color &penColor_ );
225 colorizeImage( const unsigned int alpha_,
226 const Color &penColor_ );
228 void operator()( Image &image_ ) const;
231 unsigned int _alphaRed;
232 unsigned int _alphaGreen;
233 unsigned int _alphaBlue;
237 // Apply a color matrix to the image channels. The user supplied
238 // matrix may be of order 1 to 5 (1x1 through 5x5).
239 class MagickPPExport colorMatrixImage : public std::unary_function<Image&,void>
242 colorMatrixImage( const size_t order_,
243 const double *color_matrix_ );
245 void operator()( Image &image_ ) const;
249 const double *_color_matrix;
252 // Convert the image colorspace representation
253 class MagickPPExport colorSpaceImage : public std::unary_function<Image&,void>
256 colorSpaceImage( ColorspaceType colorSpace_ );
258 void operator()( Image &image_ ) const;
261 ColorspaceType _colorSpace;
264 // Comment image (add comment string to image)
265 class MagickPPExport commentImage : public std::unary_function<Image&,void>
268 commentImage( const std::string &comment_ );
270 void operator()( Image &image_ ) const;
273 std::string _comment;
276 // Compose an image onto another at specified offset and using
277 // specified algorithm
278 class MagickPPExport compositeImage : public std::unary_function<Image&,void>
281 compositeImage( const Image &compositeImage_,
284 CompositeOperator compose_ = InCompositeOp );
286 compositeImage( const Image &compositeImage_,
287 const Geometry &offset_,
288 CompositeOperator compose_ = InCompositeOp );
290 void operator()( Image &image_ ) const;
293 Image _compositeImage;
296 CompositeOperator _compose;
299 // Contrast image (enhance intensity differences in image)
300 class MagickPPExport contrastImage : public std::unary_function<Image&,void>
303 contrastImage( const size_t sharpen_ );
305 void operator()( Image &image_ ) const;
311 // Crop image (subregion of original image)
312 class MagickPPExport cropImage : public std::unary_function<Image&,void>
315 cropImage( const Geometry &geometry_ );
317 void operator()( Image &image_ ) const;
323 // Cycle image colormap
324 class MagickPPExport cycleColormapImage : public std::unary_function<Image&,void>
327 cycleColormapImage( const ::ssize_t amount_ );
329 void operator()( Image &image_ ) const;
335 // Despeckle image (reduce speckle noise)
336 class MagickPPExport despeckleImage : public std::unary_function<Image&,void>
339 despeckleImage( void );
341 void operator()( Image &image_ ) const;
346 // Distort image. distorts an image using various distortion methods, by
347 // mapping color lookups of the source image to a new destination image
348 // usally of the same size as the source image, unless 'bestfit' is set to
350 class MagickPPExport distortImage : public std::unary_function<Image&,void>
353 distortImage( const Magick::DistortImageMethod method_,
354 const size_t number_arguments_,
355 const double *arguments_,
356 const bool bestfit_ );
358 distortImage( const Magick::DistortImageMethod method_,
359 const size_t number_arguments_,
360 const double *arguments_ );
362 void operator()( Image &image_ ) const;
365 DistortImageMethod _method;
366 size_t _number_arguments;
367 const double *_arguments;
372 class MagickPPExport drawImage : public std::unary_function<Image&,void>
375 // Draw on image using a single drawable
376 // Store in list to make implementation easier
377 drawImage( const Drawable &drawable_ );
379 // Draw on image using a drawable list
380 drawImage( const DrawableList &drawable_ );
382 void operator()( Image &image_ ) const;
385 DrawableList _drawableList;
388 // Edge image (hilight edges in image)
389 class MagickPPExport edgeImage : public std::unary_function<Image&,void>
392 edgeImage( const double radius_ = 0.0, const double sigma_ = 0.5 );
394 void operator()( Image &image_ ) const;
401 // Emboss image (hilight edges with 3D effect)
402 class MagickPPExport embossImage : public std::unary_function<Image&,void>
406 embossImage( const double radius_, const double sigma_ );
408 void operator()( Image &image_ ) const;
415 // Enhance image (minimize noise)
416 class MagickPPExport enhanceImage : public std::unary_function<Image&,void>
419 enhanceImage( void );
421 void operator()( Image &image_ ) const;
426 // Equalize image (histogram equalization)
427 class MagickPPExport equalizeImage : public std::unary_function<Image&,void>
430 equalizeImage( void );
432 void operator()( Image &image_ ) const;
437 // Color to use when filling drawn objects
438 class MagickPPExport fillColorImage : public std::unary_function<Image&,void>
441 fillColorImage( const Color &fillColor_ );
443 void operator()( Image &image_ ) const;
449 // Flip image (reflect each scanline in the vertical direction)
450 class MagickPPExport flipImage : public std::unary_function<Image&,void>
455 void operator()( Image &image_ ) const;
460 // Flood-fill image with color
461 class MagickPPExport floodFillColorImage : public std::unary_function<Image&,void>
464 // Flood-fill color across pixels starting at target-pixel and
465 // stopping at pixels matching specified border color.
466 // Uses current fuzz setting when determining color match.
467 floodFillColorImage( const ::ssize_t x_,
469 const Color &fillColor_ );
471 floodFillColorImage( const Geometry &point_,
472 const Color &fillColor_ );
474 // Flood-fill color across pixels starting at target-pixel and
475 // stopping at pixels matching specified border color.
476 // Uses current fuzz setting when determining color match.
477 floodFillColorImage( const ::ssize_t x_,
479 const Color &fillColor_,
480 const Color &borderColor_ );
482 floodFillColorImage( const Geometry &point_,
483 const Color &fillColor_,
484 const Color &borderColor_ );
486 void operator()( Image &image_ ) const;
495 // Flood-fill image with texture
496 class MagickPPExport floodFillTextureImage : public std::unary_function<Image&,void>
499 // Flood-fill texture across pixels that match the color of the
500 // target pixel and are neighbors of the target pixel.
501 // Uses current fuzz setting when determining color match.
502 floodFillTextureImage( const ::ssize_t x_,
504 const Image &texture_ );
506 floodFillTextureImage( const Geometry &point_,
507 const Image &texture_ );
509 // Flood-fill texture across pixels starting at target-pixel and
510 // stopping at pixels matching specified border color.
511 // Uses current fuzz setting when determining color match.
512 floodFillTextureImage( const ::ssize_t x_,
514 const Image &texture_,
515 const Color &borderColor_ );
517 floodFillTextureImage( const Geometry &point_,
518 const Image &texture_,
519 const Color &borderColor_ );
521 void operator()( Image &image_ ) const;
530 // Flop image (reflect each scanline in the horizontal direction)
531 class MagickPPExport flopImage : public std::unary_function<Image&,void>
536 void operator()( Image &image_ ) const;
542 class MagickPPExport frameImage : public std::unary_function<Image&,void>
545 frameImage( const Geometry &geometry_ = frameGeometryDefault );
547 frameImage( const size_t width_, const size_t height_,
548 const ::ssize_t innerBevel_ = 6, const ::ssize_t outerBevel_ = 6 );
550 void operator()( Image &image_ ) const;
555 ::ssize_t _outerBevel;
556 ::ssize_t _innerBevel;
559 // Gamma correct image
560 class MagickPPExport gammaImage : public std::unary_function<Image&,void>
563 gammaImage( const double gamma_ );
565 gammaImage ( const double gammaRed_,
566 const double gammaGreen_,
567 const double gammaBlue_ );
569 void operator()( Image &image_ ) const;
577 // Gaussian blur image
578 // The number of neighbor pixels to be included in the convolution
579 // mask is specified by 'width_'. The standard deviation of the
580 // gaussian bell curve is specified by 'sigma_'.
581 class MagickPPExport gaussianBlurImage : public std::unary_function<Image&,void>
584 gaussianBlurImage( const double width_, const double sigma_ );
586 void operator()( Image &image_ ) const;
593 // Apply a color lookup table (Hald CLUT) to the image.
594 class MagickPPExport haldClutImage : public std::unary_function<Image&,void>
597 haldClutImage( const Image &haldClutImage_ );
599 void operator()( Image &image_ ) const;
602 Image _haldClutImage;
605 // Implode image (special effect)
606 class MagickPPExport implodeImage : public std::unary_function<Image&,void>
609 implodeImage( const double factor_ = 50 );
611 void operator()( Image &image_ ) const;
617 // implements the inverse discrete Fourier transform (IFT) of the image
618 // either as a magnitude / phase or real / imaginary image pair.
619 class MagickPPExport inverseFourierTransformImage : public std::unary_function<Image&,void>
622 inverseFourierTransformImage( const Image &phaseImage_ );
624 void operator()( Image &image_ ) const;
630 // Set image validity. Valid images become empty (inValid) if
631 // argument is false.
632 class MagickPPExport isValidImage : public std::unary_function<Image&,void>
635 isValidImage( const bool isValid_ );
637 void operator()( Image &image_ ) const;
644 class MagickPPExport labelImage : public std::unary_function<Image&,void>
647 labelImage( const std::string &label_ );
649 void operator()( Image &image_ ) const;
657 class MagickPPExport levelImage : public std::unary_function<Image&,void>
660 levelImage( const double black_point,
661 const double white_point,
662 const double mid_point=1.0 );
664 void operator()( Image &image_ ) const;
672 // Magnify image by integral size
673 class MagickPPExport magnifyImage : public std::unary_function<Image&,void>
676 magnifyImage( void );
678 void operator()( Image &image_ ) const;
683 // Remap image colors with closest color from reference image
684 class MagickPPExport mapImage : public std::unary_function<Image&,void>
687 mapImage( const Image &mapImage_ ,
688 const bool dither_ = false );
690 void operator()( Image &image_ ) const;
697 // Floodfill designated area with a matte value
698 class MagickPPExport matteFloodfillImage : public std::unary_function<Image&,void>
701 matteFloodfillImage( const Color &target_ ,
702 const unsigned int matte_,
703 const ::ssize_t x_, const ::ssize_t y_,
704 const PaintMethod method_ );
706 void operator()( Image &image_ ) const;
716 // Filter image by replacing each pixel component with the median
717 // color in a circular neighborhood
718 class MagickPPExport medianConvolveImage : public std::unary_function<Image&,void>
721 medianConvolveImage( const double radius_ = 0.0 );
723 void operator()( Image &image_ ) const;
729 // Reduce image by integral size
730 class MagickPPExport minifyImage : public std::unary_function<Image&,void>
735 void operator()( Image &image_ ) const;
740 // Modulate percent hue, saturation, and brightness of an image
741 class MagickPPExport modulateImage : public std::unary_function<Image&,void>
744 modulateImage( const double brightness_,
745 const double saturation_,
748 void operator()( Image &image_ ) const;
756 // Negate colors in image. Set grayscale to only negate grayscale
758 class MagickPPExport negateImage : public std::unary_function<Image&,void>
761 negateImage( const bool grayscale_ = false );
763 void operator()( Image &image_ ) const;
769 // Normalize image (increase contrast by normalizing the pixel
770 // values to span the full range of color values)
771 class MagickPPExport normalizeImage : public std::unary_function<Image&,void>
774 normalizeImage( void );
776 void operator()( Image &image_ ) const;
781 // Oilpaint image (image looks like oil painting)
782 class MagickPPExport oilPaintImage : public std::unary_function<Image&,void>
785 oilPaintImage( const double radius_ = 3 );
787 void operator()( Image &image_ ) const;
793 // Set or attenuate the image alpha channel. If the image pixels
794 // are opaque then they are set to the specified alpha value,
795 // otherwise they are blended with the supplied alpha value. The
796 // value of alpha_ ranges from 0 (completely opaque) to
797 // QuantumRange. The defines OpaqueAlpha and TransparentAlpha are
798 // available to specify completely opaque or completely transparent,
800 class MagickPPExport alphaImage : public std::unary_function<Image&,void>
803 alphaImage( const unsigned int alpha_ );
805 void operator()( Image &image_ ) const;
811 // Change color of opaque pixel to specified pen color.
812 class MagickPPExport opaqueImage : public std::unary_function<Image&,void>
815 opaqueImage( const Color &opaqueColor_,
816 const Color &penColor_ );
818 void operator()( Image &image_ ) const;
825 // Quantize image (reduce number of colors)
826 class MagickPPExport quantizeImage : public std::unary_function<Image&,void>
829 quantizeImage( const bool measureError_ = false );
831 void operator()( Image &image_ ) const;
837 // Raise image (lighten or darken the edges of an image to give a
838 // 3-D raised or lowered effect)
839 class MagickPPExport raiseImage : public std::unary_function<Image&,void>
842 raiseImage( const Geometry &geometry_ = raiseGeometryDefault,
843 const bool raisedFlag_ = false );
845 void operator()( Image &image_ ) const;
852 // Reduce noise in image using a noise peak elimination filter
853 class MagickPPExport reduceNoiseImage : public std::unary_function<Image&,void>
856 reduceNoiseImage( void );
858 reduceNoiseImage (const size_t order_ );
860 void operator()( Image &image_ ) const;
866 // Resize image to specified size.
867 class MagickPPExport resizeImage : public std::unary_function<Image&,void>
870 resizeImage( const Geometry &geometry_ );
872 void operator()( Image &image_ ) const;
878 // Roll image (rolls image vertically and horizontally) by specified
879 // number of columnms and rows)
880 class MagickPPExport rollImage : public std::unary_function<Image&,void>
883 rollImage( const Geometry &roll_ );
885 rollImage( const ::ssize_t columns_, const ::ssize_t rows_ );
887 void operator()( Image &image_ ) const;
894 // Rotate image counter-clockwise by specified number of degrees.
895 class MagickPPExport rotateImage : public std::unary_function<Image&,void>
898 rotateImage( const double degrees_ );
900 void operator()( Image &image_ ) const;
906 // Resize image by using pixel sampling algorithm
907 class MagickPPExport sampleImage : public std::unary_function<Image&,void>
910 sampleImage( const Geometry &geometry_ );
912 void operator()( Image &image_ ) const;
918 // Resize image by using simple ratio algorithm
919 class MagickPPExport scaleImage : public std::unary_function<Image&,void>
922 scaleImage( const Geometry &geometry_ );
924 void operator()( Image &image_ ) const;
930 // Segment (coalesce similar image components) by analyzing the
931 // histograms of the color components and identifying units that are
932 // homogeneous with the fuzzy c-means technique.
933 // Also uses QuantizeColorSpace and Verbose image attributes
934 class MagickPPExport segmentImage : public std::unary_function<Image&,void>
937 segmentImage( const double clusterThreshold_ = 1.0,
938 const double smoothingThreshold_ = 1.5 );
940 void operator()( Image &image_ ) const;
943 double _clusterThreshold;
944 double _smoothingThreshold;
947 // Shade image using distant light source
948 class MagickPPExport shadeImage : public std::unary_function<Image&,void>
951 shadeImage( const double azimuth_ = 30,
952 const double elevation_ = 30,
953 const bool colorShading_ = false );
955 void operator()( Image &image_ ) const;
963 // Sharpen pixels in image
964 class MagickPPExport sharpenImage : public std::unary_function<Image&,void>
967 sharpenImage( const double radius_ = 1, const double sigma_ = 0.5 );
969 void operator()( Image &image_ ) const;
976 // Shave pixels from image edges.
977 class MagickPPExport shaveImage : public std::unary_function<Image&,void>
980 shaveImage( const Geometry &geometry_ );
982 void operator()( Image &image_ ) const;
989 // Shear image (create parallelogram by sliding image by X or Y axis)
990 class MagickPPExport shearImage : public std::unary_function<Image&,void>
993 shearImage( const double xShearAngle_,
994 const double yShearAngle_ );
996 void operator()( Image &image_ ) const;
1000 double _yShearAngle;
1003 // Solarize image (similar to effect seen when exposing a
1004 // photographic film to light during the development process)
1005 class MagickPPExport solarizeImage : public std::unary_function<Image&,void>
1008 solarizeImage( const double factor_ );
1010 void operator()( Image &image_ ) const;
1016 // Splice the background color into the image.
1017 class MagickPPExport spliceImage : public std::unary_function<Image&,void>
1020 spliceImage( const Geometry &geometry_ );
1022 void operator()( Image &image_ ) const;
1028 // Spread pixels randomly within image by specified ammount
1029 class MagickPPExport spreadImage : public std::unary_function<Image&,void>
1032 spreadImage( const size_t amount_ = 3 );
1034 void operator()( Image &image_ ) const;
1040 // Add a digital watermark to the image (based on second image)
1041 class MagickPPExport steganoImage : public std::unary_function<Image&,void>
1044 steganoImage( const Image &waterMark_ );
1046 void operator()( Image &image_ ) const;
1052 // Create an image which appears in stereo when viewed with red-blue glasses
1053 // (Red image on left, blue on right)
1054 class MagickPPExport stereoImage : public std::unary_function<Image&,void>
1057 stereoImage( const Image &rightImage_ );
1059 void operator()( Image &image_ ) const;
1065 // Color to use when drawing object outlines
1066 class MagickPPExport strokeColorImage : public std::unary_function<Image&,void>
1069 strokeColorImage( const Color &strokeColor_ );
1071 void operator()( Image &image_ ) const;
1077 // Swirl image (image pixels are rotated by degrees)
1078 class MagickPPExport swirlImage : public std::unary_function<Image&,void>
1081 swirlImage( const double degrees_ );
1083 void operator()( Image &image_ ) const;
1089 // Channel a texture on image background
1090 class MagickPPExport textureImage : public std::unary_function<Image&,void>
1093 textureImage( const Image &texture_ );
1095 void operator()( Image &image_ ) const;
1102 class MagickPPExport thresholdImage : public std::unary_function<Image&,void>
1105 thresholdImage( const double threshold_ );
1107 void operator()( Image &image_ ) const;
1113 // Transform image based on image and crop geometries
1114 class MagickPPExport transformImage : public std::unary_function<Image&,void>
1117 transformImage( const Geometry &imageGeometry_ );
1119 transformImage( const Geometry &imageGeometry_,
1120 const Geometry &cropGeometry_ );
1122 void operator()( Image &image_ ) const;
1125 Geometry _imageGeometry;
1126 Geometry _cropGeometry;
1129 // Set image color to transparent
1130 class MagickPPExport transparentImage : public std::unary_function<Image&,void>
1133 transparentImage( const Color& color_ );
1135 void operator()( Image &image_ ) const;
1141 // Trim edges that are the background color from the image
1142 class MagickPPExport trimImage : public std::unary_function<Image&,void>
1147 void operator()( Image &image_ ) const;
1152 // Map image pixels to a sine wave
1153 class MagickPPExport waveImage : public std::unary_function<Image&,void>
1156 waveImage( const double amplitude_ = 25.0,
1157 const double wavelength_ = 150.0 );
1159 void operator()( Image &image_ ) const;
1166 // Zoom image to specified size.
1167 class MagickPPExport zoomImage : public std::unary_function<Image&,void>
1170 zoomImage( const Geometry &geometry_ );
1172 void operator()( Image &image_ ) const;
1179 // Function object image attribute accessors
1182 // Anti-alias Postscript and TrueType fonts (default true)
1183 class MagickPPExport antiAliasImage : public std::unary_function<Image&,void>
1186 antiAliasImage( const bool flag_ );
1188 void operator()( Image &image_ ) const;
1194 // Join images into a single multi-image file
1195 class MagickPPExport adjoinImage : public std::unary_function<Image&,void>
1198 adjoinImage( const bool flag_ );
1200 void operator()( Image &image_ ) const;
1206 // Time in 1/100ths of a second which must expire before displaying
1207 // the next image in an animated sequence.
1208 class MagickPPExport animationDelayImage : public std::unary_function<Image&,void>
1211 animationDelayImage( const size_t delay_ );
1213 void operator()( Image &image_ ) const;
1219 // Number of iterations to loop an animation (e.g. Netscape loop
1221 class MagickPPExport animationIterationsImage : public std::unary_function<Image&,void>
1224 animationIterationsImage( const size_t iterations_ );
1226 void operator()( Image &image_ ) const;
1232 // Image background color
1233 class MagickPPExport backgroundColorImage : public std::unary_function<Image&,void>
1236 backgroundColorImage( const Color &color_ );
1238 void operator()( Image &image_ ) const;
1244 // Name of texture image to tile onto the image background
1245 class MagickPPExport backgroundTextureImage : public std::unary_function<Image&,void>
1248 backgroundTextureImage( const std::string &backgroundTexture_ );
1250 void operator()( Image &image_ ) const;
1253 std::string _backgroundTexture;
1256 // Image border color
1257 class MagickPPExport borderColorImage : public std::unary_function<Image&,void>
1260 borderColorImage( const Color &color_ );
1262 void operator()( Image &image_ ) const;
1268 // Text bounding-box base color (default none)
1269 class MagickPPExport boxColorImage : public std::unary_function<Image&,void>
1272 boxColorImage( const Color &boxColor_ );
1274 void operator()( Image &image_ ) const;
1280 // Chromaticity blue primary point (e.g. x=0.15, y=0.06)
1281 class MagickPPExport chromaBluePrimaryImage : public std::unary_function<Image&,void>
1284 chromaBluePrimaryImage( const double x_, const double y_ );
1286 void operator()( Image &image_ ) const;
1293 // Chromaticity green primary point (e.g. x=0.3, y=0.6)
1294 class MagickPPExport chromaGreenPrimaryImage : public std::unary_function<Image&,void>
1297 chromaGreenPrimaryImage( const double x_, const double y_ );
1299 void operator()( Image &image_ ) const;
1306 // Chromaticity red primary point (e.g. x=0.64, y=0.33)
1307 class MagickPPExport chromaRedPrimaryImage : public std::unary_function<Image&,void>
1310 chromaRedPrimaryImage( const double x_, const double y_ );
1312 void operator()( Image &image_ ) const;
1319 // Chromaticity white point (e.g. x=0.3127, y=0.329)
1320 class MagickPPExport chromaWhitePointImage : public std::unary_function<Image&,void>
1323 chromaWhitePointImage( const double x_, const double y_ );
1325 void operator()( Image &image_ ) const;
1332 // Colors within this distance are considered equal
1333 class MagickPPExport colorFuzzImage : public std::unary_function<Image&,void>
1336 colorFuzzImage( const double fuzz_ );
1338 void operator()( Image &image_ ) const;
1344 // Color at colormap position index_
1345 class MagickPPExport colorMapImage : public std::unary_function<Image&,void>
1348 colorMapImage( const size_t index_, const Color &color_ );
1350 void operator()( Image &image_ ) const;
1357 // Composition operator to be used when composition is implicitly used
1358 // (such as for image flattening).
1359 class MagickPPExport composeImage : public std::unary_function<Image&,void>
1362 composeImage( const CompositeOperator compose_ );
1364 void operator()( Image &image_ ) const;
1367 CompositeOperator _compose;
1371 class MagickPPExport compressTypeImage : public std::unary_function<Image&,void>
1374 compressTypeImage( const CompressionType compressType_ );
1376 void operator()( Image &image_ ) const;
1379 CompressionType _compressType;
1382 // Vertical and horizontal resolution in pixels of the image
1383 class MagickPPExport densityImage : public std::unary_function<Image&,void>
1386 densityImage( const Geometry &geomery_ );
1388 void operator()( Image &image_ ) const;
1394 // Image depth (bits allocated to red/green/blue components)
1395 class MagickPPExport depthImage : public std::unary_function<Image&,void>
1398 depthImage( const size_t depth_ );
1400 void operator()( Image &image_ ) const;
1406 // Endianness (LSBEndian like Intel or MSBEndian like SPARC) for image
1407 // formats which support endian-specific options.
1408 class MagickPPExport endianImage : public std::unary_function<Image&,void>
1411 endianImage( const EndianType endian_ );
1413 void operator()( Image &image_ ) const;
1420 class MagickPPExport fileNameImage : public std::unary_function<Image&,void>
1423 fileNameImage( const std::string &fileName_ );
1425 void operator()( Image &image_ ) const;
1428 std::string _fileName;
1431 // Filter to use when resizing image
1432 class MagickPPExport filterTypeImage : public std::unary_function<Image&,void>
1435 filterTypeImage( const FilterTypes filterType_ );
1437 void operator()( Image &image_ ) const;
1440 FilterTypes _filterType;
1443 // Text rendering font
1444 class MagickPPExport fontImage : public std::unary_function<Image&,void>
1447 fontImage( const std::string &font_ );
1449 void operator()( Image &image_ ) const;
1456 class MagickPPExport fontPointsizeImage : public std::unary_function<Image&,void>
1459 fontPointsizeImage( const size_t pointsize_ );
1461 void operator()( Image &image_ ) const;
1467 // GIF disposal method
1468 class MagickPPExport gifDisposeMethodImage : public std::unary_function<Image&,void>
1471 gifDisposeMethodImage( const size_t disposeMethod_ );
1473 void operator()( Image &image_ ) const;
1476 size_t _disposeMethod;
1479 // Type of interlacing to use
1480 class MagickPPExport interlaceTypeImage : public std::unary_function<Image&,void>
1483 interlaceTypeImage( const InterlaceType interlace_ );
1485 void operator()( Image &image_ ) const;
1488 InterlaceType _interlace;
1491 // Linewidth for drawing vector objects (default one)
1492 class MagickPPExport lineWidthImage : public std::unary_function<Image&,void>
1495 lineWidthImage( const double lineWidth_ );
1497 void operator()( Image &image_ ) const;
1503 // File type magick identifier (.e.g "GIF")
1504 class MagickPPExport magickImage : public std::unary_function<Image&,void>
1507 magickImage( const std::string &magick_ );
1509 void operator()( Image &image_ ) const;
1512 std::string _magick;
1515 // Image supports transparent color
1516 class MagickPPExport matteImage : public std::unary_function<Image&,void>
1519 matteImage( const bool matteFlag_ );
1521 void operator()( Image &image_ ) const;
1527 // Transparent color
1528 class MagickPPExport matteColorImage : public std::unary_function<Image&,void>
1531 matteColorImage( const Color &matteColor_ );
1533 void operator()( Image &image_ ) const;
1539 // Indicate that image is black and white
1540 class MagickPPExport monochromeImage : public std::unary_function<Image&,void>
1543 monochromeImage( const bool monochromeFlag_ );
1545 void operator()( Image &image_ ) const;
1548 bool _monochromeFlag;
1552 class MagickPPExport penColorImage : public std::unary_function<Image&,void>
1555 penColorImage( const Color &penColor_ );
1557 void operator()( Image &image_ ) const;
1563 // Pen texture image.
1564 class MagickPPExport penTextureImage : public std::unary_function<Image&,void>
1567 penTextureImage( const Image &penTexture_ );
1569 void operator()( Image &image_ ) const;
1575 // Set pixel color at location x & y.
1576 class MagickPPExport pixelColorImage : public std::unary_function<Image&,void>
1579 pixelColorImage( const ::ssize_t x_,
1581 const Color &color_);
1583 void operator()( Image &image_ ) const;
1591 // Postscript page size.
1592 class MagickPPExport pageImage : public std::unary_function<Image&,void>
1595 pageImage( const Geometry &pageSize_ );
1597 void operator()( Image &image_ ) const;
1603 // JPEG/MIFF/PNG compression level (default 75).
1604 class MagickPPExport qualityImage : public std::unary_function<Image&,void>
1607 qualityImage( const size_t quality_ );
1609 void operator()( Image &image_ ) const;
1615 // Maximum number of colors to quantize to
1616 class MagickPPExport quantizeColorsImage : public std::unary_function<Image&,void>
1619 quantizeColorsImage( const size_t colors_ );
1621 void operator()( Image &image_ ) const;
1627 // Colorspace to quantize in.
1628 class MagickPPExport quantizeColorSpaceImage : public std::unary_function<Image&,void>
1631 quantizeColorSpaceImage( const ColorspaceType colorSpace_ );
1633 void operator()( Image &image_ ) const;
1636 ColorspaceType _colorSpace;
1639 // Dither image during quantization (default true).
1640 class MagickPPExport quantizeDitherImage : public std::unary_function<Image&,void>
1643 quantizeDitherImage( const bool ditherFlag_ );
1645 void operator()( Image &image_ ) const;
1651 // Quantization tree-depth
1652 class MagickPPExport quantizeTreeDepthImage : public std::unary_function<Image&,void>
1655 quantizeTreeDepthImage( const size_t treeDepth_ );
1657 void operator()( Image &image_ ) const;
1663 // The type of rendering intent
1664 class MagickPPExport renderingIntentImage : public std::unary_function<Image&,void>
1667 renderingIntentImage( const RenderingIntent renderingIntent_ );
1669 void operator()( Image &image_ ) const;
1672 RenderingIntent _renderingIntent;
1675 // Units of image resolution
1676 class MagickPPExport resolutionUnitsImage : public std::unary_function<Image&,void>
1679 resolutionUnitsImage( const ResolutionType resolutionUnits_ );
1681 void operator()( Image &image_ ) const;
1684 ResolutionType _resolutionUnits;
1687 // Image scene number
1688 class MagickPPExport sceneImage : public std::unary_function<Image&,void>
1691 sceneImage( const size_t scene_ );
1693 void operator()( Image &image_ ) const;
1699 // adjust the image contrast with a non-linear sigmoidal contrast algorithm
1700 class MagickPPExport sigmoidalContrastImage : public std::unary_function<Image&,void>
1703 sigmoidalContrastImage( const size_t sharpen_,
1704 const double contrast,
1705 const double midpoint = QuantumRange / 2.0 );
1707 void operator()( Image &image_ ) const;
1715 // Width and height of a raw image
1716 class MagickPPExport sizeImage : public std::unary_function<Image&,void>
1719 sizeImage( const Geometry &geometry_ );
1721 void operator()( Image &image_ ) const;
1727 // stripImage strips an image of all profiles and comments.
1728 class MagickPPExport stripImage : public std::unary_function<Image&,void>
1733 void operator()( Image &image_ ) const;
1738 // Subimage of an image sequence
1739 class MagickPPExport subImageImage : public std::unary_function<Image&,void>
1742 subImageImage( const size_t subImage_ );
1744 void operator()( Image &image_ ) const;
1750 // Number of images relative to the base image
1751 class MagickPPExport subRangeImage : public std::unary_function<Image&,void>
1754 subRangeImage( const size_t subRange_ );
1756 void operator()( Image &image_ ) const;
1762 // Image storage type
1763 class MagickPPExport typeImage : public std::unary_function<Image&,void>
1766 typeImage( const ImageType type_ );
1768 void operator()( Image &image_ ) const;
1771 Magick::ImageType _type;
1775 // Print detailed information about the image
1776 class MagickPPExport verboseImage : public std::unary_function<Image&,void>
1779 verboseImage( const bool verbose_ );
1781 void operator()( Image &image_ ) const;
1787 // FlashPix viewing parameters
1788 class MagickPPExport viewImage : public std::unary_function<Image&,void>
1791 viewImage( const std::string &view_ );
1793 void operator()( Image &image_ ) const;
1799 // X11 display to display to, obtain fonts from, or to capture
1801 class MagickPPExport x11DisplayImage : public std::unary_function<Image&,void>
1804 x11DisplayImage( const std::string &display_ );
1806 void operator()( Image &image_ ) const;
1809 std::string _display;
1812 //////////////////////////////////////////////////////////
1814 // Implementation template definitions. Not for end-use.
1816 //////////////////////////////////////////////////////////
1818 // Link images together into an image list based on the ordering of
1819 // the container implied by the iterator. This step is done in
1820 // preparation for use with ImageMagick functions which operate on
1822 // Images are selected by range, first_ to last_ so that a subset of
1823 // the container may be selected. Specify first_ via the
1824 // container's begin() method and last_ via the container's end()
1825 // method in order to specify the entire container.
1826 template <class InputIterator>
1827 void linkImages( InputIterator first_,
1828 InputIterator last_ ) {
1830 MagickCore::Image* previous = 0;
1831 ::ssize_t scene = 0;
1832 for ( InputIterator iter = first_; iter != last_; ++iter )
1834 // Unless we reduce the reference count to one, the same image
1835 // structure may occur more than once in the container, causing
1836 // the linked list to fail.
1837 iter->modifyImage();
1839 MagickCore::Image* current = iter->image();
1841 current->previous = previous;
1845 previous->next = current;
1847 current->scene=scene;
1854 // Remove links added by linkImages. This should be called after the
1855 // ImageMagick function call has completed to reset the image list
1856 // back to its pristine un-linked state.
1857 template <class InputIterator>
1858 void unlinkImages( InputIterator first_,
1859 InputIterator last_ ) {
1860 for( InputIterator iter = first_; iter != last_; ++iter )
1862 MagickCore::Image* image = iter->image();
1863 image->previous = 0;
1868 // Insert images in image list into existing container (appending to container)
1869 // The images should not be deleted since only the image ownership is passed.
1870 // The options are copied into the object.
1871 template <class Container>
1872 void insertImages( Container *sequence_,
1873 MagickCore::Image* images_ ) {
1874 MagickCore::Image *image = images_;
1879 MagickCore::Image* next_image = image->next;
1882 if (next_image != 0)
1883 next_image->previous=0;
1885 sequence_->push_back( Magick::Image( image ) );
1894 ///////////////////////////////////////////////////////////////////
1896 // Template definitions for documented API
1898 ///////////////////////////////////////////////////////////////////
1900 template <class InputIterator>
1901 void animateImages( InputIterator first_,
1902 InputIterator last_ ) {
1903 MagickCore::ExceptionInfo exceptionInfo;
1904 MagickCore::GetExceptionInfo( &exceptionInfo );
1905 linkImages( first_, last_ );
1906 MagickCore::AnimateImages( first_->imageInfo(), first_->image() );
1907 MagickCore::GetImageException( first_->image(), &exceptionInfo );
1908 unlinkImages( first_, last_ );
1909 throwException( exceptionInfo );
1910 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
1913 // Append images from list into single image in either horizontal or
1914 // vertical direction.
1915 template <class InputIterator>
1916 void appendImages( Image *appendedImage_,
1917 InputIterator first_,
1918 InputIterator last_,
1919 bool stack_ = false) {
1920 MagickCore::ExceptionInfo exceptionInfo;
1921 MagickCore::GetExceptionInfo( &exceptionInfo );
1922 linkImages( first_, last_ );
1923 MagickCore::Image* image = MagickCore::AppendImages( first_->image(),
1924 (MagickBooleanType) stack_,
1926 unlinkImages( first_, last_ );
1927 appendedImage_->replaceImage( image );
1928 throwException( exceptionInfo );
1929 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
1932 // Average a set of images.
1933 // All the input images must be the same size in pixels.
1934 template <class InputIterator>
1935 void averageImages( Image *averagedImage_,
1936 InputIterator first_,
1937 InputIterator last_ ) {
1938 MagickCore::ExceptionInfo exceptionInfo;
1939 MagickCore::GetExceptionInfo( &exceptionInfo );
1940 linkImages( first_, last_ );
1941 MagickCore::Image* image = MagickCore::EvaluateImages( first_->image(),
1942 MagickCore::MeanEvaluateOperator, &exceptionInfo );
1943 unlinkImages( first_, last_ );
1944 averagedImage_->replaceImage( image );
1945 throwException( exceptionInfo );
1946 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
1949 // Merge a sequence of images.
1950 // This is useful for GIF animation sequences that have page
1951 // offsets and disposal methods. A container to contain
1952 // the updated image sequence is passed via the coalescedImages_
1954 template <class InputIterator, class Container >
1955 void coalesceImages( Container *coalescedImages_,
1956 InputIterator first_,
1957 InputIterator last_ ) {
1958 MagickCore::ExceptionInfo exceptionInfo;
1959 MagickCore::GetExceptionInfo( &exceptionInfo );
1962 linkImages( first_, last_ );
1963 MagickCore::Image* images = MagickCore::CoalesceImages( first_->image(),
1965 // Unlink image list
1966 unlinkImages( first_, last_ );
1968 // Ensure container is empty
1969 coalescedImages_->clear();
1971 // Move images to container
1972 insertImages( coalescedImages_, images );
1975 throwException( exceptionInfo );
1976 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
1979 // Return format coders matching specified conditions.
1981 // The default (if no match terms are supplied) is to return all
1982 // available format coders.
1984 // For example, to return all readable formats:
1985 // list<CoderInfo> coderList;
1986 // coderInfoList( &coderList, CoderInfo::TrueMatch, CoderInfo::AnyMatch, CoderInfo::AnyMatch)
1988 template <class Container >
1989 void coderInfoList( Container *container_,
1990 CoderInfo::MatchType isReadable_ = CoderInfo::AnyMatch,
1991 CoderInfo::MatchType isWritable_ = CoderInfo::AnyMatch,
1992 CoderInfo::MatchType isMultiFrame_ = CoderInfo::AnyMatch
1994 // Obtain first entry in MagickInfo list
1995 size_t number_formats;
1996 MagickCore::ExceptionInfo exceptionInfo;
1997 MagickCore::GetExceptionInfo( &exceptionInfo );
1999 MagickCore::GetMagickList( "*", &number_formats, &exceptionInfo );
2002 throwException( exceptionInfo );
2003 throwExceptionExplicit(MagickCore::MissingDelegateError,
2004 "Coder array not returned!", 0 );
2007 // Clear out container
2008 container_->clear();
2010 for ( ::ssize_t i=0; i < (::ssize_t) number_formats; i++)
2012 const MagickCore::MagickInfo *magick_info =
2013 MagickCore::GetMagickInfo( coder_list[i], &exceptionInfo );
2014 coder_list[i]=(char *)
2015 MagickCore::RelinquishMagickMemory( coder_list[i] );
2017 // Skip stealth coders
2018 if ( magick_info->stealth )
2022 CoderInfo coderInfo( magick_info->name );
2025 if ( isReadable_ != CoderInfo::AnyMatch &&
2026 (( coderInfo.isReadable() && isReadable_ != CoderInfo::TrueMatch ) ||
2027 ( !coderInfo.isReadable() && isReadable_ != CoderInfo::FalseMatch )) )
2031 if ( isWritable_ != CoderInfo::AnyMatch &&
2032 (( coderInfo.isWritable() && isWritable_ != CoderInfo::TrueMatch ) ||
2033 ( !coderInfo.isWritable() && isWritable_ != CoderInfo::FalseMatch )) )
2036 // Test isMultiFrame_
2037 if ( isMultiFrame_ != CoderInfo::AnyMatch &&
2038 (( coderInfo.isMultiFrame() && isMultiFrame_ != CoderInfo::TrueMatch ) ||
2039 ( !coderInfo.isMultiFrame() && isMultiFrame_ != CoderInfo::FalseMatch )) )
2042 // Append matches to container
2043 container_->push_back( coderInfo );
2045 // Intentionally ignore missing module errors
2046 catch ( Magick::ErrorModule )
2051 coder_list=(char **) MagickCore::RelinquishMagickMemory( coder_list );
2052 throwException( exceptionInfo );
2053 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2057 // Fill container with color histogram.
2058 // Entries are of type "std::pair<Color,size_t>". Use the pair
2059 // "first" member to access the Color and the "second" member to access
2060 // the number of times the color occurs in the image.
2066 // Image image("image.miff");
2067 // map<Color,size_t> histogram;
2068 // colorHistogram( &histogram, image );
2069 // std::map<Color,size_t>::const_iterator p=histogram.begin();
2070 // while (p != histogram.end())
2072 // cout << setw(10) << (int)p->second << ": ("
2073 // << setw(quantum_width) << (int)p->first.redQuantum() << ","
2074 // << setw(quantum_width) << (int)p->first.greenQuantum() << ","
2075 // << setw(quantum_width) << (int)p->first.blueQuantum() << ")"
2082 // Image image("image.miff");
2083 // std::vector<std::pair<Color,size_t> > histogram;
2084 // colorHistogram( &histogram, image );
2085 // std::vector<std::pair<Color,size_t> >::const_iterator p=histogram.begin();
2086 // while (p != histogram.end())
2088 // cout << setw(10) << (int)p->second << ": ("
2089 // << setw(quantum_width) << (int)p->first.redQuantum() << ","
2090 // << setw(quantum_width) << (int)p->first.greenQuantum() << ","
2091 // << setw(quantum_width) << (int)p->first.blueQuantum() << ")"
2096 template <class Container >
2097 void colorHistogram( Container *histogram_, const Image image)
2099 MagickCore::ExceptionInfo exceptionInfo;
2100 MagickCore::GetExceptionInfo( &exceptionInfo );
2102 // Obtain histogram array
2104 MagickCore::PixelInfo *histogram_array =
2105 MagickCore::GetImageHistogram( image.constImage(), &colors, &exceptionInfo );
2106 throwException( exceptionInfo );
2107 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2109 // Clear out container
2110 histogram_->clear();
2112 // Transfer histogram array to container
2113 for ( size_t i=0; i < colors; i++)
2115 histogram_->insert(histogram_->end(),std::pair<const Color,size_t>
2116 ( Color(histogram_array[i].red,
2117 histogram_array[i].green,
2118 histogram_array[i].blue),
2119 (size_t) histogram_array[i].count) );
2122 // Deallocate histogram array
2123 histogram_array=(MagickCore::PixelInfo *)
2124 MagickCore::RelinquishMagickMemory(histogram_array);
2127 // Break down an image sequence into constituent parts. This is
2128 // useful for creating GIF or MNG animation sequences.
2129 template <class InputIterator, class Container >
2130 void deconstructImages( Container *deconstructedImages_,
2131 InputIterator first_,
2132 InputIterator last_ ) {
2133 MagickCore::ExceptionInfo exceptionInfo;
2134 MagickCore::GetExceptionInfo( &exceptionInfo );
2137 linkImages( first_, last_ );
2138 MagickCore::Image* images = DeconstructImages( first_->image(),
2140 // Unlink image list
2141 unlinkImages( first_, last_ );
2143 // Ensure container is empty
2144 deconstructedImages_->clear();
2146 // Move images to container
2147 insertImages( deconstructedImages_, images );
2150 throwException( exceptionInfo );
2151 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2155 // Display an image sequence
2157 template <class InputIterator>
2158 void displayImages( InputIterator first_,
2159 InputIterator last_ ) {
2160 MagickCore::ExceptionInfo exceptionInfo;
2161 MagickCore::GetExceptionInfo( &exceptionInfo );
2162 linkImages( first_, last_ );
2163 MagickCore::DisplayImages( first_->imageInfo(), first_->image() );
2164 MagickCore::GetImageException( first_->image(), &exceptionInfo );
2165 unlinkImages( first_, last_ );
2166 throwException( exceptionInfo );
2167 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2170 // Merge a sequence of image frames which represent image layers.
2171 // This is useful for combining Photoshop layers into a single image.
2172 template <class InputIterator>
2173 void flattenImages( Image *flattendImage_,
2174 InputIterator first_,
2175 InputIterator last_ ) {
2176 MagickCore::ExceptionInfo exceptionInfo;
2177 MagickCore::GetExceptionInfo( &exceptionInfo );
2178 linkImages( first_, last_ );
2179 MagickCore::Image* image = MagickCore::MergeImageLayers( first_->image(),
2180 FlattenLayer,&exceptionInfo );
2181 unlinkImages( first_, last_ );
2182 flattendImage_->replaceImage( image );
2183 throwException( exceptionInfo );
2184 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2187 // Implements the discrete Fourier transform (DFT) of the image either as a
2188 // magnitude / phase or real / imaginary image pair.
2189 template <class Container >
2190 void forwardFourierTransformImage( Container *fourierImages_,
2191 const Image &image_ ) {
2192 MagickCore::ExceptionInfo exceptionInfo;
2193 MagickCore::GetExceptionInfo( &exceptionInfo );
2196 MagickCore::Image* images = ForwardFourierTransformImage(
2197 image_.constImage(), MagickTrue, &exceptionInfo);
2199 // Ensure container is empty
2200 fourierImages_->clear();
2202 // Move images to container
2203 insertImages( fourierImages_, images );
2206 throwException( exceptionInfo );
2207 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2209 template <class Container >
2210 void forwardFourierTransformImage( Container *fourierImages_,
2211 const Image &image_, const bool magnitude_ ) {
2212 MagickCore::ExceptionInfo exceptionInfo;
2213 MagickCore::GetExceptionInfo( &exceptionInfo );
2216 MagickCore::Image* images = ForwardFourierTransformImage(
2217 image_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
2220 // Ensure container is empty
2221 fourierImages_->clear();
2223 // Move images to container
2224 insertImages( fourierImages_, images );
2227 throwException( exceptionInfo );
2228 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2231 // Replace the colors of a sequence of images with the closest color
2232 // from a reference image.
2233 // Set dither_ to true to enable dithering. Set measureError_ to
2234 // true in order to evaluate quantization error.
2235 template <class InputIterator>
2236 void mapImages( InputIterator first_,
2237 InputIterator last_,
2238 const Image& mapImage_,
2239 bool dither_ = false,
2240 bool measureError_ = false ) {
2242 MagickCore::ExceptionInfo exceptionInfo;
2243 MagickCore::GetExceptionInfo( &exceptionInfo );
2244 MagickCore::QuantizeInfo quantizeInfo;
2245 MagickCore::GetQuantizeInfo( &quantizeInfo );
2246 quantizeInfo.dither = dither_ ? MagickCore::MagickTrue : MagickCore::MagickFalse;
2247 linkImages( first_, last_ );
2248 MagickCore::RemapImages( &quantizeInfo, first_->image(),
2249 mapImage_.constImage());
2250 MagickCore::GetImageException( first_->image(), &exceptionInfo );
2251 if ( exceptionInfo.severity != MagickCore::UndefinedException )
2253 unlinkImages( first_, last_ );
2254 throwException( exceptionInfo );
2257 MagickCore::Image* image = first_->image();
2260 // Calculate quantization error
2261 if ( measureError_ )
2263 MagickCore::ExceptionInfo exceptionInfo;
2264 MagickCore::GetExceptionInfo( &exceptionInfo );
2265 MagickCore::GetImageQuantizeError( image, &exceptionInfo );
2266 if ( exceptionInfo.severity > MagickCore::UndefinedException )
2268 unlinkImages( first_, last_ );
2269 throwException( exceptionInfo );
2271 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2274 // Udate DirectClass representation of pixels
2275 MagickCore::SyncImage( image );
2276 if ( image->exception.severity > MagickCore::UndefinedException )
2278 unlinkImages( first_, last_ );
2279 throwException( exceptionInfo );
2286 unlinkImages( first_, last_ );
2287 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2290 // Create a composite image by combining several separate images.
2291 template <class Container, class InputIterator>
2292 void montageImages( Container *montageImages_,
2293 InputIterator first_,
2294 InputIterator last_,
2295 const Montage &montageOpts_ ) {
2297 MagickCore::MontageInfo* montageInfo =
2298 static_cast<MagickCore::MontageInfo*>(MagickCore::AcquireMagickMemory(sizeof(MagickCore::MontageInfo)));
2300 // Update montage options with those set in montageOpts_
2301 montageOpts_.updateMontageInfo( *montageInfo );
2303 // Update options which must transfer to image options
2304 if ( montageOpts_.label().length() != 0 )
2305 first_->label( montageOpts_.label() );
2307 // Create linked image list
2308 linkImages( first_, last_ );
2310 // Reset output container to pristine state
2311 montageImages_->clear();
2314 MagickCore::ExceptionInfo exceptionInfo;
2315 MagickCore::GetExceptionInfo( &exceptionInfo );
2316 MagickCore::Image *images = MagickCore::MontageImages( first_->image(),
2321 insertImages( montageImages_, images );
2324 // Clean up any allocated data in montageInfo
2325 MagickCore::DestroyMontageInfo( montageInfo );
2327 // Unlink linked image list
2328 unlinkImages( first_, last_ );
2330 // Report any montage error
2331 throwException( exceptionInfo );
2333 // Apply transparency to montage images
2334 if ( montageImages_->size() > 0 && montageOpts_.transparentColor().isValid() )
2336 for_each( first_, last_, transparentImage( montageOpts_.transparentColor() ) );
2339 // Report any transparentImage() error
2340 MagickCore::GetImageException( first_->image(), &exceptionInfo );
2341 throwException( exceptionInfo );
2342 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2345 // Morph a set of images
2346 template <class InputIterator, class Container >
2347 void morphImages( Container *morphedImages_,
2348 InputIterator first_,
2349 InputIterator last_,
2351 MagickCore::ExceptionInfo exceptionInfo;
2352 MagickCore::GetExceptionInfo( &exceptionInfo );
2355 linkImages( first_, last_ );
2356 MagickCore::Image* images = MagickCore::MorphImages( first_->image(), frames_,
2358 // Unlink image list
2359 unlinkImages( first_, last_ );
2361 // Ensure container is empty
2362 morphedImages_->clear();
2364 // Move images to container
2365 insertImages( morphedImages_, images );
2368 throwException( exceptionInfo );
2369 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2372 // Inlay a number of images to form a single coherent picture.
2373 template <class InputIterator>
2374 void mosaicImages( Image *mosaicImage_,
2375 InputIterator first_,
2376 InputIterator last_ ) {
2377 MagickCore::ExceptionInfo exceptionInfo;
2378 MagickCore::GetExceptionInfo( &exceptionInfo );
2379 linkImages( first_, last_ );
2380 MagickCore::Image* image = MagickCore::MergeImageLayers( first_->image(),
2381 MosaicLayer,&exceptionInfo );
2382 unlinkImages( first_, last_ );
2383 mosaicImage_->replaceImage( image );
2384 throwException( exceptionInfo );
2385 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2388 // Quantize colors in images using current quantization settings
2389 // Set measureError_ to true in order to measure quantization error
2390 template <class InputIterator>
2391 void quantizeImages( InputIterator first_,
2392 InputIterator last_,
2393 bool measureError_ = false ) {
2394 MagickCore::ExceptionInfo exceptionInfo;
2395 MagickCore::GetExceptionInfo( &exceptionInfo );
2397 linkImages( first_, last_ );
2399 MagickCore::QuantizeImages( first_->quantizeInfo(),
2401 MagickCore::GetImageException( first_->image(), &exceptionInfo );
2402 if ( exceptionInfo.severity > MagickCore::UndefinedException )
2404 unlinkImages( first_, last_ );
2405 throwException( exceptionInfo );
2408 MagickCore::Image* image = first_->image();
2411 // Calculate quantization error
2412 if ( measureError_ )
2413 MagickCore::GetImageQuantizeError( image, &exceptionInfo );
2415 // Update DirectClass representation of pixels
2416 MagickCore::SyncImage( image );
2422 unlinkImages( first_, last_ );
2423 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2426 // Read images into existing container (appending to container)
2427 // FIXME: need a way to specify options like size, depth, and density.
2428 template <class Container>
2429 void readImages( Container *sequence_,
2430 const std::string &imageSpec_ ) {
2431 MagickCore::ImageInfo *imageInfo = MagickCore::CloneImageInfo(0);
2432 imageSpec_.copy( imageInfo->filename, MaxTextExtent-1 );
2433 imageInfo->filename[ imageSpec_.length() ] = 0;
2434 MagickCore::ExceptionInfo exceptionInfo;
2435 MagickCore::GetExceptionInfo( &exceptionInfo );
2436 MagickCore::Image* images = MagickCore::ReadImage( imageInfo, &exceptionInfo );
2437 MagickCore::DestroyImageInfo(imageInfo);
2438 insertImages( sequence_, images);
2439 throwException( exceptionInfo );
2440 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2442 template <class Container>
2443 void readImages( Container *sequence_,
2444 const Blob &blob_ ) {
2445 MagickCore::ImageInfo *imageInfo = MagickCore::CloneImageInfo(0);
2446 MagickCore::ExceptionInfo exceptionInfo;
2447 MagickCore::GetExceptionInfo( &exceptionInfo );
2448 MagickCore::Image *images = MagickCore::BlobToImage( imageInfo,
2450 blob_.length(), &exceptionInfo );
2451 MagickCore::DestroyImageInfo(imageInfo);
2452 insertImages( sequence_, images );
2453 throwException( exceptionInfo );
2454 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2458 template <class InputIterator>
2459 void writeImages( InputIterator first_,
2460 InputIterator last_,
2461 const std::string &imageSpec_,
2462 bool adjoin_ = true ) {
2464 first_->adjoin( adjoin_ );
2466 MagickCore::ExceptionInfo exceptionInfo;
2467 MagickCore::GetExceptionInfo( &exceptionInfo );
2469 linkImages( first_, last_ );
2470 ::ssize_t errorStat = MagickCore::WriteImages( first_->constImageInfo(),
2474 unlinkImages( first_, last_ );
2476 if ( errorStat != false )
2478 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2482 throwException( exceptionInfo );
2483 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2485 // Write images to BLOB
2486 template <class InputIterator>
2487 void writeImages( InputIterator first_,
2488 InputIterator last_,
2490 bool adjoin_ = true) {
2492 first_->adjoin( adjoin_ );
2494 linkImages( first_, last_ );
2496 MagickCore::ExceptionInfo exceptionInfo;
2497 MagickCore::GetExceptionInfo( &exceptionInfo );
2498 size_t length = 2048; // Efficient size for small images
2499 void* data = MagickCore::ImagesToBlob( first_->imageInfo(),
2503 blob_->updateNoCopy( data, length, Magick::Blob::MallocAllocator );
2505 unlinkImages( first_, last_ );
2507 throwException( exceptionInfo );
2508 (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
2511 } // namespace Magick
2513 #endif // Magick_STL_header