Magick++  6.9.3
STL.h
Go to the documentation of this file.
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4 // Copyright Dirk Lemstra 2013-2014
5 //
6 // Definition and implementation of template functions for using
7 // Magick::Image with STL containers.
8 //
9 
10 #ifndef Magick_STL_header
11 #define Magick_STL_header
12 
13 #include "Magick++/Include.h"
14 #include <algorithm>
15 #include <functional>
16 #include <iterator>
17 #include <map>
18 #include <utility>
19 
20 #include "Magick++/CoderInfo.h"
21 #include "Magick++/Drawable.h"
22 #include "Magick++/Exception.h"
23 #include "Magick++/Montage.h"
24 
25 namespace Magick
26 {
27  //
28  // STL function object declarations/definitions
29  //
30 
31  // Function objects provide the means to invoke an operation on one
32  // or more image objects in an STL-compatable container. The
33  // arguments to the function object constructor(s) are compatable
34  // with the arguments to the equivalent Image class method and
35  // provide the means to supply these options when the function
36  // object is invoked.
37 
38  // For example, to read a GIF animation, set the color red to
39  // transparent for all frames, and write back out:
40  //
41  // list<image> images;
42  // readImages( &images, "animation.gif" );
43  // for_each( images.begin(), images.end(), transparentImage( "red" ) );
44  // writeImages( images.begin(), images.end(), "animation.gif" );
45 
46  // Adaptive-blur image with specified blur factor
47  class MagickPPExport adaptiveBlurImage : public std::unary_function<Image&,void>
48  {
49  public:
50  adaptiveBlurImage( const double radius_ = 1, const double sigma_ = 0.5 );
51 
52  void operator()( Image &image_ ) const;
53 
54  private:
55  double _radius;
56  double _sigma;
57  };
58 
59  // Local adaptive threshold image
60  // http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
61  // Width x height define the size of the pixel neighborhood
62  // offset = constant to subtract from pixel neighborhood mean
63  class MagickPPExport adaptiveThresholdImage : public std::unary_function<Image&,void>
64  {
65  public:
66  adaptiveThresholdImage( const size_t width_,
67  const size_t height_,
68  const ::ssize_t offset_ = 0 );
69 
70  void operator()( Image &image_ ) const;
71 
72  private:
73  size_t _width;
74  size_t _height;
75  ::ssize_t _offset;
76  };
77 
78  // Add noise to image with specified noise type
79  class MagickPPExport addNoiseImage : public std::unary_function<Image&,void>
80  {
81  public:
82  addNoiseImage ( NoiseType noiseType_ );
83 
84  void operator()( Image &image_ ) const;
85 
86  private:
87  NoiseType _noiseType;
88  };
89 
90  // Transform image by specified affine (or free transform) matrix.
91  class MagickPPExport affineTransformImage : public std::unary_function<Image&,void>
92  {
93  public:
94  affineTransformImage( const DrawableAffine &affine_ );
95 
96  void operator()( Image &image_ ) const;
97 
98  private:
99  DrawableAffine _affine;
100  };
101 
102  // Annotate image (draw text on image)
103  class MagickPPExport annotateImage : public std::unary_function<Image&,void>
104  {
105  public:
106  // Annotate using specified text, and placement location
107  annotateImage ( const std::string &text_,
108  const Geometry &geometry_ );
109 
110  // Annotate using specified text, bounding area, and placement
111  // gravity
112  annotateImage ( const std::string &text_,
113  const Geometry &geometry_,
114  const GravityType gravity_ );
115 
116  // Annotate with text using specified text, bounding area,
117  // placement gravity, and rotation.
118  annotateImage ( const std::string &text_,
119  const Geometry &geometry_,
120  const GravityType gravity_,
121  const double degrees_ );
122 
123  // Annotate with text (bounding area is entire image) and
124  // placement gravity.
125  annotateImage ( const std::string &text_,
126  const GravityType gravity_ );
127 
128  void operator()( Image &image_ ) const;
129 
130  private:
131  // Copy constructor and assignment are not supported
133  annotateImage& operator=(const annotateImage&);
134 
135  const std::string _text;
136  const Geometry _geometry;
137  const GravityType _gravity;
138  const double _degrees;
139  };
140 
141  // Blur image with specified blur factor
142  class MagickPPExport blurImage : public std::unary_function<Image&,void>
143  {
144  public:
145  blurImage( const double radius_ = 1, const double sigma_ = 0.5 );
146 
147  void operator()( Image &image_ ) const;
148 
149  private:
150  double _radius;
151  double _sigma;
152  };
153 
154  // Border image (add border to image)
155  class MagickPPExport borderImage : public std::unary_function<Image&,void>
156  {
157  public:
158  borderImage( const Geometry &geometry_ = borderGeometryDefault );
159 
160  void operator()( Image &image_ ) const;
161 
162  private:
163  Geometry _geometry;
164  };
165 
166  // Extract channel from image
167  class MagickPPExport channelImage : public std::unary_function<Image&,void>
168  {
169  public:
170  channelImage( const ChannelType channel_ );
171 
172  void operator()( Image &image_ ) const;
173 
174  private:
175  ChannelType _channel;
176  };
177 
178  // Charcoal effect image (looks like charcoal sketch)
179  class MagickPPExport charcoalImage : public std::unary_function<Image&,void>
180  {
181  public:
182  charcoalImage( const double radius_ = 1, const double sigma_ = 0.5 );
183 
184  void operator()( Image &image_ ) const;
185 
186  private:
187  double _radius;
188  double _sigma;
189  };
190 
191  // Chop image (remove vertical or horizontal subregion of image)
192  class MagickPPExport chopImage : public std::unary_function<Image&,void>
193  {
194  public:
195  chopImage( const Geometry &geometry_ );
196 
197  void operator()( Image &image_ ) const;
198 
199  private:
200  Geometry _geometry;
201  };
202 
203  // Accepts a lightweight Color Correction Collection (CCC) file which solely
204  // contains one or more color corrections and applies the correction to the
205  // image.
206  class MagickPPExport cdlImage : public std::unary_function<Image&,void>
207  {
208  public:
209  cdlImage( const std::string &cdl_ );
210 
211  void operator()( Image &image_ ) const;
212 
213  private:
214  std::string _cdl;
215  };
216 
217  // Colorize image using pen color at specified percent opacity
218  class MagickPPExport colorizeImage : public std::unary_function<Image&,void>
219  {
220  public:
221  colorizeImage( const unsigned int opacityRed_,
222  const unsigned int opacityGreen_,
223  const unsigned int opacityBlue_,
224  const Color &penColor_ );
225 
226  colorizeImage( const unsigned int opacity_,
227  const Color &penColor_ );
228 
229  void operator()( Image &image_ ) const;
230 
231  private:
232  unsigned int _opacityRed;
233  unsigned int _opacityGreen;
234  unsigned int _opacityBlue;
235  Color _penColor;
236  };
237 
238  // Apply a color matrix to the image channels. The user supplied
239  // matrix may be of order 1 to 5 (1x1 through 5x5).
240  class MagickPPExport colorMatrixImage : public std::unary_function<Image&,void>
241  {
242  public:
243  colorMatrixImage( const size_t order_,
244  const double *color_matrix_ );
245 
246  void operator()( Image &image_ ) const;
247 
248  private:
249  size_t _order;
250  const double *_color_matrix;
251  };
252 
253  // Convert the image colorspace representation
254  class MagickPPExport colorSpaceImage : public std::unary_function<Image&,void>
255  {
256  public:
257  colorSpaceImage( ColorspaceType colorSpace_ );
258 
259  void operator()( Image &image_ ) const;
260 
261  private:
262  ColorspaceType _colorSpace;
263  };
264 
265  // Comment image (add comment string to image)
266  class MagickPPExport commentImage : public std::unary_function<Image&,void>
267  {
268  public:
269  commentImage( const std::string &comment_ );
270 
271  void operator()( Image &image_ ) const;
272 
273  private:
274  std::string _comment;
275  };
276 
277  // Compose an image onto another at specified offset and using
278  // specified algorithm
279  class MagickPPExport compositeImage : public std::unary_function<Image&,void>
280  {
281  public:
282  compositeImage( const Image &compositeImage_,
283  ::ssize_t xOffset_,
284  ::ssize_t yOffset_,
285  CompositeOperator compose_ = InCompositeOp );
286 
287  compositeImage( const Image &compositeImage_,
288  const Geometry &offset_,
289  CompositeOperator compose_ = InCompositeOp );
290 
291  void operator()( Image &image_ ) const;
292 
293  private:
294  Image _compositeImage;
295  ::ssize_t _xOffset;
296  ::ssize_t _yOffset;
297  CompositeOperator _compose;
298  };
299 
300  // Contrast image (enhance intensity differences in image)
301  class MagickPPExport contrastImage : public std::unary_function<Image&,void>
302  {
303  public:
304  contrastImage( const size_t sharpen_ );
305 
306  void operator()( Image &image_ ) const;
307 
308  private:
309  size_t _sharpen;
310  };
311 
312  // Crop image (subregion of original image)
313  class MagickPPExport cropImage : public std::unary_function<Image&,void>
314  {
315  public:
316  cropImage( const Geometry &geometry_ );
317 
318  void operator()( Image &image_ ) const;
319 
320  private:
321  Geometry _geometry;
322  };
323 
324  // Cycle image colormap
325  class MagickPPExport cycleColormapImage : public std::unary_function<Image&,void>
326  {
327  public:
328  cycleColormapImage( const ::ssize_t amount_ );
329 
330  void operator()( Image &image_ ) const;
331 
332  private:
333  ::ssize_t _amount;
334  };
335 
336  // Despeckle image (reduce speckle noise)
337  class MagickPPExport despeckleImage : public std::unary_function<Image&,void>
338  {
339  public:
340  despeckleImage( void );
341 
342  void operator()( Image &image_ ) const;
343 
344  private:
345  };
346 
347  // Distort image. distorts an image using various distortion methods, by
348  // mapping color lookups of the source image to a new destination image
349  // usally of the same size as the source image, unless 'bestfit' is set to
350  // true.
351  class MagickPPExport distortImage : public std::unary_function<Image&,void>
352  {
353  public:
354  distortImage( const Magick::DistortImageMethod method_,
355  const size_t number_arguments_,
356  const double *arguments_,
357  const bool bestfit_ );
358 
359  distortImage( const Magick::DistortImageMethod method_,
360  const size_t number_arguments_,
361  const double *arguments_ );
362 
363  void operator()( Image &image_ ) const;
364 
365  private:
366  DistortImageMethod _method;
367  size_t _number_arguments;
368  const double *_arguments;
369  bool _bestfit;
370  };
371 
372  // Draw on image
373  class MagickPPExport drawImage : public std::unary_function<Image&,void>
374  {
375  public:
376  // Draw on image using a single drawable
377  // Store in list to make implementation easier
378  drawImage( const Drawable &drawable_ );
379 
380  // Draw on image using a drawable list
381  drawImage( const DrawableList &drawable_ );
382 
383  void operator()( Image &image_ ) const;
384 
385  private:
386  DrawableList _drawableList;
387  };
388 
389  // Edge image (hilight edges in image)
390  class MagickPPExport edgeImage : public std::unary_function<Image&,void>
391  {
392  public:
393  edgeImage( const double radius_ = 0.0 );
394 
395  void operator()( Image &image_ ) const;
396 
397  private:
398  double _radius;
399  };
400 
401  // Emboss image (hilight edges with 3D effect)
402  class MagickPPExport embossImage : public std::unary_function<Image&,void>
403  {
404  public:
405  embossImage( void );
406  embossImage( const double radius_, const double sigma_ );
407 
408  void operator()( Image &image_ ) const;
409 
410  private:
411  double _radius;
412  double _sigma;
413  };
414 
415  // Enhance image (minimize noise)
416  class MagickPPExport enhanceImage : public std::unary_function<Image&,void>
417  {
418  public:
419  enhanceImage( void );
420 
421  void operator()( Image &image_ ) const;
422 
423  private:
424  };
425 
426  // Equalize image (histogram equalization)
427  class MagickPPExport equalizeImage : public std::unary_function<Image&,void>
428  {
429  public:
430  equalizeImage( void );
431 
432  void operator()( Image &image_ ) const;
433 
434  private:
435  };
436 
437  // Color to use when filling drawn objects
438  class MagickPPExport fillColorImage : public std::unary_function<Image&,void>
439  {
440  public:
441  fillColorImage( const Color &fillColor_ );
442 
443  void operator()( Image &image_ ) const;
444 
445  private:
446  Color _fillColor;
447  };
448 
449  // Flip image (reflect each scanline in the vertical direction)
450  class MagickPPExport flipImage : public std::unary_function<Image&,void>
451  {
452  public:
453  flipImage( void );
454 
455  void operator()( Image &image_ ) const;
456 
457  private:
458  };
459 
460  // Flood-fill image with color
461  class MagickPPExport floodFillColorImage : public std::unary_function<Image&,void>
462  {
463  public:
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_,
468  const ::ssize_t y_,
469  const Color &fillColor_ );
470 
471  floodFillColorImage( const Geometry &point_,
472  const Color &fillColor_ );
473 
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_,
478  const ::ssize_t y_,
479  const Color &fillColor_,
480  const Color &borderColor_ );
481 
482  floodFillColorImage( const Geometry &point_,
483  const Color &fillColor_,
484  const Color &borderColor_ );
485 
486  void operator()( Image &image_ ) const;
487 
488  private:
489  ::ssize_t _x;
490  ::ssize_t _y;
491  Color _fillColor;
492  Color _borderColor;
493  };
494 
495  // Flood-fill image with texture
496  class MagickPPExport floodFillTextureImage : public std::unary_function<Image&,void>
497  {
498  public:
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_,
503  const ::ssize_t y_,
504  const Image &texture_ );
505 
506  floodFillTextureImage( const Geometry &point_,
507  const Image &texture_ );
508 
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_,
513  const ::ssize_t y_,
514  const Image &texture_,
515  const Color &borderColor_ );
516 
517  floodFillTextureImage( const Geometry &point_,
518  const Image &texture_,
519  const Color &borderColor_ );
520 
521  void operator()( Image &image_ ) const;
522 
523  private:
524  ::ssize_t _x;
525  ::ssize_t _y;
526  Image _texture;
527  Color _borderColor;
528  };
529 
530  // Flop image (reflect each scanline in the horizontal direction)
531  class MagickPPExport flopImage : public std::unary_function<Image&,void>
532  {
533  public:
534  flopImage( void );
535 
536  void operator()( Image &image_ ) const;
537 
538  private:
539  };
540 
541  // Frame image
542  class MagickPPExport frameImage : public std::unary_function<Image&,void>
543  {
544  public:
545  frameImage( const Geometry &geometry_ = frameGeometryDefault );
546 
547  frameImage( const size_t width_, const size_t height_,
548  const ::ssize_t innerBevel_ = 6, const ::ssize_t outerBevel_ = 6 );
549 
550  void operator()( Image &image_ ) const;
551 
552  private:
553  size_t _width;
554  size_t _height;
555  ::ssize_t _outerBevel;
556  ::ssize_t _innerBevel;
557  };
558 
559  // Gamma correct image
560  class MagickPPExport gammaImage : public std::unary_function<Image&,void>
561  {
562  public:
563  gammaImage( const double gamma_ );
564 
565  gammaImage ( const double gammaRed_,
566  const double gammaGreen_,
567  const double gammaBlue_ );
568 
569  void operator()( Image &image_ ) const;
570 
571  private:
572  double _gammaRed;
573  double _gammaGreen;
574  double _gammaBlue;
575  };
576 
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>
582  {
583  public:
584  gaussianBlurImage( const double width_, const double sigma_ );
585 
586  void operator()( Image &image_ ) const;
587 
588  private:
589  double _width;
590  double _sigma;
591  };
592 
593  // Apply a color lookup table (Hald CLUT) to the image.
594  class MagickPPExport haldClutImage : public std::unary_function<Image&,void>
595  {
596  public:
597  haldClutImage( const Image &haldClutImage_ );
598 
599  void operator()( Image &image_ ) const;
600 
601  private:
602  Image _haldClutImage;
603  };
604 
605  // Implode image (special effect)
606  class MagickPPExport implodeImage : public std::unary_function<Image&,void>
607  {
608  public:
609  implodeImage( const double factor_ = 50 );
610 
611  void operator()( Image &image_ ) const;
612 
613  private:
614  double _factor;
615  };
616 
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>
620  {
621  public:
622  inverseFourierTransformImage( const Image &phaseImage_ );
623 
624  void operator()( Image &image_ ) const;
625 
626  private:
627  Image _phaseImage;
628  };
629 
630  // Set image validity. Valid images become empty (inValid) if
631  // argument is false.
632  class MagickPPExport isValidImage : public std::unary_function<Image&,void>
633  {
634  public:
635  isValidImage( const bool isValid_ );
636 
637  void operator()( Image &image_ ) const;
638 
639  private:
640  bool _isValid;
641  };
642 
643  // Label image
644  class MagickPPExport labelImage : public std::unary_function<Image&,void>
645  {
646  public:
647  labelImage( const std::string &label_ );
648 
649  void operator()( Image &image_ ) const;
650 
651  private:
652  std::string _label;
653  };
654 
655 
656  // Level image
657  class MagickPPExport levelImage : public std::unary_function<Image&,void>
658  {
659  public:
660  levelImage( const double black_point,
661  const double white_point,
662  const double mid_point=1.0 );
663 
664  void operator()( Image &image_ ) const;
665 
666  private:
667  double _black_point;
668  double _white_point;
669  double _mid_point;
670  };
671 
672  // Level image channel
673  class MagickPPExport levelChannelImage : public std::unary_function<Image&,void>
674  {
675  public:
676  levelChannelImage( const Magick::ChannelType channel,
677  const double black_point,
678  const double white_point,
679  const double mid_point=1.0 );
680 
681  void operator()( Image &image_ ) const;
682 
683  private:
684  Magick::ChannelType _channel;
685  double _black_point;
686  double _white_point;
687  double _mid_point;
688  };
689 
690  // Magnify image by integral size
691  class MagickPPExport magnifyImage : public std::unary_function<Image&,void>
692  {
693  public:
694  magnifyImage( void );
695 
696  void operator()( Image &image_ ) const;
697 
698  private:
699  };
700 
701  // Remap image colors with closest color from reference image
702  class MagickPPExport mapImage : public std::unary_function<Image&,void>
703  {
704  public:
705  mapImage( const Image &mapImage_ ,
706  const bool dither_ = false );
707 
708  void operator()( Image &image_ ) const;
709 
710  private:
711  Image _mapImage;
712  bool _dither;
713  };
714 
715  // Floodfill designated area with a matte value
716  class MagickPPExport matteFloodfillImage : public std::unary_function<Image&,void>
717  {
718  public:
719  matteFloodfillImage( const Color &target_ ,
720  const unsigned int matte_,
721  const ::ssize_t x_, const ::ssize_t y_,
722  const PaintMethod method_ );
723 
724  void operator()( Image &image_ ) const;
725 
726  private:
727  Color _target;
728  unsigned int _matte;
729  ::ssize_t _x;
730  ::ssize_t _y;
731  PaintMethod _method;
732  };
733 
734  // Filter image by replacing each pixel component with the median
735  // color in a circular neighborhood
736  class MagickPPExport medianFilterImage : public std::unary_function<Image&,void>
737  {
738  public:
739  medianFilterImage( const double radius_ = 0.0 );
740 
741  void operator()( Image &image_ ) const;
742 
743  private:
744  double _radius;
745  };
746 
747  // Merge image layers
749  std::unary_function<Image&,void>
750  {
751  public:
752  mergeLayersImage ( ImageLayerMethod layerMethod_ );
753 
754  void operator()( Image &image_ ) const;
755 
756  private:
757  ImageLayerMethod _layerMethod;
758  };
759 
760  // Reduce image by integral size
761  class MagickPPExport minifyImage : public std::unary_function<Image&,void>
762  {
763  public:
764  minifyImage( void );
765 
766  void operator()( Image &image_ ) const;
767 
768  private:
769  };
770 
771  // Modulate percent hue, saturation, and brightness of an image
772  class MagickPPExport modulateImage : public std::unary_function<Image&,void>
773  {
774  public:
775  modulateImage( const double brightness_,
776  const double saturation_,
777  const double hue_ );
778 
779  void operator()( Image &image_ ) const;
780 
781  private:
782  double _brightness;
783  double _saturation;
784  double _hue;
785  };
786 
787  // Negate colors in image. Set grayscale to only negate grayscale
788  // values in image.
789  class MagickPPExport negateImage : public std::unary_function<Image&,void>
790  {
791  public:
792  negateImage( const bool grayscale_ = false );
793 
794  void operator()( Image &image_ ) const;
795 
796  private:
797  bool _grayscale;
798  };
799 
800  // Normalize image (increase contrast by normalizing the pixel
801  // values to span the full range of color values)
802  class MagickPPExport normalizeImage : public std::unary_function<Image&,void>
803  {
804  public:
805  normalizeImage( void );
806 
807  void operator()( Image &image_ ) const;
808 
809  private:
810  };
811 
812  // Oilpaint image (image looks like oil painting)
813  class MagickPPExport oilPaintImage : public std::unary_function<Image&,void>
814  {
815  public:
816  oilPaintImage( const double radius_ = 3 );
817 
818  void operator()( Image &image_ ) const;
819 
820  private:
821  double _radius;
822  };
823 
824  // Set or attenuate the image opacity channel. If the image pixels
825  // are opaque then they are set to the specified opacity value,
826  // otherwise they are blended with the supplied opacity value. The
827  // value of opacity_ ranges from 0 (completely opaque) to
828  // QuantumRange. The defines OpaqueOpacity and TransparentOpacity are
829  // available to specify completely opaque or completely transparent,
830  // respectively.
831  class MagickPPExport opacityImage : public std::unary_function<Image&,void>
832  {
833  public:
834  opacityImage( const unsigned int opacity_ );
835 
836  void operator()( Image &image_ ) const;
837 
838  private:
839  unsigned int _opacity;
840  };
841 
842  // Change color of opaque pixel to specified pen color.
843  class MagickPPExport opaqueImage : public std::unary_function<Image&,void>
844  {
845  public:
846  opaqueImage( const Color &opaqueColor_,
847  const Color &penColor_ );
848 
849  void operator()( Image &image_ ) const;
850 
851  private:
852  Color _opaqueColor;
853  Color _penColor;
854  };
855 
856  // Quantize image (reduce number of colors)
857  class MagickPPExport quantizeImage : public std::unary_function<Image&,void>
858  {
859  public:
860  quantizeImage( const bool measureError_ = false );
861 
862  void operator()( Image &image_ ) const;
863 
864  private:
865  bool _measureError;
866  };
867 
868  // Raise image (lighten or darken the edges of an image to give a
869  // 3-D raised or lowered effect)
870  class MagickPPExport raiseImage : public std::unary_function<Image&,void>
871  {
872  public:
873  raiseImage( const Geometry &geometry_ = raiseGeometryDefault,
874  const bool raisedFlag_ = false );
875 
876  void operator()( Image &image_ ) const;
877 
878  private:
879  Geometry _geometry;
880  bool _raisedFlag;
881  };
882 
884  {
885  public:
886 
887  // Default constructor
888  ReadOptions(void);
889 
890  // Copy constructor
891  ReadOptions(const ReadOptions& options_);
892 
893  // Destructor
894  ~ReadOptions();
895 
896  // Vertical and horizontal resolution in pixels of the image
897  void density(const Geometry &geomery_);
898  Geometry density(void) const;
899 
900  // Image depth (8 or 16)
901  void depth(size_t depth_);
902  size_t depth(void) const;
903 
904  // Suppress all warning messages. Error messages are still reported.
905  void quiet(const bool quiet_);
906  bool quiet(void) const;
907 
908  // Image size (required for raw formats)
909  void size(const Geometry &geometry_);
910  Geometry size(void) const;
911 
912  //
913  // Internal implementation methods. Please do not use.
914  //
915 
916  MagickCore::ImageInfo *imageInfo(void);
917 
918  private:
919 
920  // Assignment not supported
921  ReadOptions& operator=(const ReadOptions&);
922 
923  MagickCore::ImageInfo *_imageInfo;
924  bool _quiet;
925  };
926 
927  // Reduce noise in image using a noise peak elimination filter
928  class MagickPPExport reduceNoiseImage : public std::unary_function<Image&,void>
929  {
930  public:
931  reduceNoiseImage( void );
932 
933  reduceNoiseImage (const size_t order_ );
934 
935  void operator()( Image &image_ ) const;
936 
937  private:
938  size_t _order;
939  };
940 
941  // Resize image to specified size.
942  class MagickPPExport resizeImage : public std::unary_function<Image&,void>
943  {
944  public:
945  resizeImage( const Geometry &geometry_ );
946 
947  void operator()( Image &image_ ) const;
948 
949  private:
950  Geometry _geometry;
951  };
952 
953  // Roll image (rolls image vertically and horizontally) by specified
954  // number of columnms and rows)
955  class MagickPPExport rollImage : public std::unary_function<Image&,void>
956  {
957  public:
958  rollImage( const Geometry &roll_ );
959 
960  rollImage( const ::ssize_t columns_, const ::ssize_t rows_ );
961 
962  void operator()( Image &image_ ) const;
963 
964  private:
965  size_t _columns;
966  size_t _rows;
967  };
968 
969  // Rotate image counter-clockwise by specified number of degrees.
970  class MagickPPExport rotateImage : public std::unary_function<Image&,void>
971  {
972  public:
973  rotateImage( const double degrees_ );
974 
975  void operator()( Image &image_ ) const;
976 
977  private:
978  double _degrees;
979  };
980 
981  // Resize image by using pixel sampling algorithm
982  class MagickPPExport sampleImage : public std::unary_function<Image&,void>
983  {
984  public:
985  sampleImage( const Geometry &geometry_ );
986 
987  void operator()( Image &image_ ) const;
988 
989  private:
990  Geometry _geometry;
991  };
992 
993  // Resize image by using simple ratio algorithm
994  class MagickPPExport scaleImage : public std::unary_function<Image&,void>
995  {
996  public:
997  scaleImage( const Geometry &geometry_ );
998 
999  void operator()( Image &image_ ) const;
1000 
1001  private:
1002  Geometry _geometry;
1003  };
1004 
1005  // Segment (coalesce similar image components) by analyzing the
1006  // histograms of the color components and identifying units that are
1007  // homogeneous with the fuzzy c-means technique.
1008  // Also uses QuantizeColorSpace and Verbose image attributes
1009  class MagickPPExport segmentImage : public std::unary_function<Image&,void>
1010  {
1011  public:
1012  segmentImage( const double clusterThreshold_ = 1.0,
1013  const double smoothingThreshold_ = 1.5 );
1014 
1015  void operator()( Image &image_ ) const;
1016 
1017  private:
1018  double _clusterThreshold;
1019  double _smoothingThreshold;
1020  };
1021 
1022  // Shade image using distant light source
1023  class MagickPPExport shadeImage : public std::unary_function<Image&,void>
1024  {
1025  public:
1026  shadeImage( const double azimuth_ = 30,
1027  const double elevation_ = 30,
1028  const bool colorShading_ = false );
1029 
1030  void operator()( Image &image_ ) const;
1031 
1032  private:
1033  double _azimuth;
1034  double _elevation;
1035  bool _colorShading;
1036  };
1037 
1038  // Shadow effect image (simulate an image shadow)
1039  class MagickPPExport shadowImage : public std::unary_function<Image&,void>
1040  {
1041  public:
1042  shadowImage( const double percent_opacity_ = 80, const double sigma_ = 0.5,
1043  const ssize_t x_ = 5, const ssize_t y_ = 5 );
1044 
1045  void operator()( Image &image_ ) const;
1046 
1047  private:
1048  double _percent_opacity;
1049  double _sigma;
1050  ssize_t _x;
1051  ssize_t _y;
1052  };
1053 
1054  // Sharpen pixels in image
1055  class MagickPPExport sharpenImage : public std::unary_function<Image&,void>
1056  {
1057  public:
1058  sharpenImage( const double radius_ = 1, const double sigma_ = 0.5 );
1059 
1060  void operator()( Image &image_ ) const;
1061 
1062  private:
1063  double _radius;
1064  double _sigma;
1065  };
1066 
1067  // Shave pixels from image edges.
1068  class MagickPPExport shaveImage : public std::unary_function<Image&,void>
1069  {
1070  public:
1071  shaveImage( const Geometry &geometry_ );
1072 
1073  void operator()( Image &image_ ) const;
1074 
1075  private:
1076  Geometry _geometry;
1077  };
1078 
1079 
1080  // Shear image (create parallelogram by sliding image by X or Y axis)
1081  class MagickPPExport shearImage : public std::unary_function<Image&,void>
1082  {
1083  public:
1084  shearImage( const double xShearAngle_,
1085  const double yShearAngle_ );
1086 
1087  void operator()( Image &image_ ) const;
1088 
1089  private:
1090  double _xShearAngle;
1091  double _yShearAngle;
1092  };
1093 
1094  // Solarize image (similar to effect seen when exposing a
1095  // photographic film to light during the development process)
1096  class MagickPPExport solarizeImage : public std::unary_function<Image&,void>
1097  {
1098  public:
1099  solarizeImage( const double factor_ );
1100 
1101  void operator()( Image &image_ ) const;
1102 
1103  private:
1104  double _factor;
1105  };
1106 
1107  // Splice the background color into the image.
1108  class MagickPPExport spliceImage : public std::unary_function<Image&,void>
1109  {
1110  public:
1111  spliceImage( const Geometry &geometry_ );
1112 
1113  void operator()( Image &image_ ) const;
1114 
1115  private:
1116  Geometry _geometry;
1117  };
1118 
1119  // Spread pixels randomly within image by specified ammount
1120  class MagickPPExport spreadImage : public std::unary_function<Image&,void>
1121  {
1122  public:
1123  spreadImage( const size_t amount_ = 3 );
1124 
1125  void operator()( Image &image_ ) const;
1126 
1127  private:
1128  size_t _amount;
1129  };
1130 
1131  // Add a digital watermark to the image (based on second image)
1132  class MagickPPExport steganoImage : public std::unary_function<Image&,void>
1133  {
1134  public:
1135  steganoImage( const Image &waterMark_ );
1136 
1137  void operator()( Image &image_ ) const;
1138 
1139  private:
1140  Image _waterMark;
1141  };
1142 
1143  // Create an image which appears in stereo when viewed with red-blue glasses
1144  // (Red image on left, blue on right)
1145  class MagickPPExport stereoImage : public std::unary_function<Image&,void>
1146  {
1147  public:
1148  stereoImage( const Image &rightImage_ );
1149 
1150  void operator()( Image &image_ ) const;
1151 
1152  private:
1153  Image _rightImage;
1154  };
1155 
1156  // Color to use when drawing object outlines
1157  class MagickPPExport strokeColorImage : public std::unary_function<Image&,void>
1158  {
1159  public:
1160  strokeColorImage( const Color &strokeColor_ );
1161 
1162  void operator()( Image &image_ ) const;
1163 
1164  private:
1165  Color _strokeColor;
1166  };
1167 
1168  // Swirl image (image pixels are rotated by degrees)
1169  class MagickPPExport swirlImage : public std::unary_function<Image&,void>
1170  {
1171  public:
1172  swirlImage( const double degrees_ );
1173 
1174  void operator()( Image &image_ ) const;
1175 
1176  private:
1177  double _degrees;
1178  };
1179 
1180  // Channel a texture on image background
1181  class MagickPPExport textureImage : public std::unary_function<Image&,void>
1182  {
1183  public:
1184  textureImage( const Image &texture_ );
1185 
1186  void operator()( Image &image_ ) const;
1187 
1188  private:
1189  Image _texture;
1190  };
1191 
1192  // Threshold image
1193  class MagickPPExport thresholdImage : public std::unary_function<Image&,void>
1194  {
1195  public:
1196  thresholdImage( const double threshold_ );
1197 
1198  void operator()( Image &image_ ) const;
1199 
1200  private:
1201  double _threshold;
1202  };
1203 
1204  // Transform image based on image and crop geometries
1205  class MagickPPExport transformImage : public std::unary_function<Image&,void>
1206  {
1207  public:
1208  transformImage( const Geometry &imageGeometry_ );
1209 
1210  transformImage( const Geometry &imageGeometry_,
1211  const Geometry &cropGeometry_ );
1212 
1213  void operator()( Image &image_ ) const;
1214 
1215  private:
1216  Geometry _imageGeometry;
1217  Geometry _cropGeometry;
1218  };
1219 
1220  // Set image color to transparent
1221  class MagickPPExport transparentImage : public std::unary_function<Image&,void>
1222  {
1223  public:
1224  transparentImage( const Color& color_ );
1225 
1226  void operator()( Image &image_ ) const;
1227 
1228  private:
1229  Color _color;
1230  };
1231 
1232  // Trim edges that are the background color from the image
1233  class MagickPPExport trimImage : public std::unary_function<Image&,void>
1234  {
1235  public:
1236  trimImage( void );
1237 
1238  void operator()( Image &image_ ) const;
1239 
1240  private:
1241  };
1242 
1243  // Map image pixels to a sine wave
1244  class MagickPPExport waveImage : public std::unary_function<Image&,void>
1245  {
1246  public:
1247  waveImage( const double amplitude_ = 25.0,
1248  const double wavelength_ = 150.0 );
1249 
1250  void operator()( Image &image_ ) const;
1251 
1252  private:
1253  double _amplitude;
1254  double _wavelength;
1255  };
1256 
1257  // Zoom image to specified size.
1258  class MagickPPExport zoomImage : public std::unary_function<Image&,void>
1259  {
1260  public:
1261  zoomImage( const Geometry &geometry_ );
1262 
1263  void operator()( Image &image_ ) const;
1264 
1265  private:
1266  Geometry _geometry;
1267  };
1268 
1269  //
1270  // Function object image attribute accessors
1271  //
1272 
1273  // Anti-alias Postscript and TrueType fonts (default true)
1274  class MagickPPExport antiAliasImage : public std::unary_function<Image&,void>
1275  {
1276  public:
1277  antiAliasImage( const bool flag_ );
1278 
1279  void operator()( Image &image_ ) const;
1280 
1281  private:
1282  bool _flag;
1283  };
1284 
1285  // Join images into a single multi-image file
1286  class MagickPPExport adjoinImage : public std::unary_function<Image&,void>
1287  {
1288  public:
1289  adjoinImage( const bool flag_ );
1290 
1291  void operator()( Image &image_ ) const;
1292 
1293  private:
1294  bool _flag;
1295  };
1296 
1297  // Time in 1/100ths of a second which must expire before displaying
1298  // the next image in an animated sequence.
1299  class MagickPPExport animationDelayImage : public std::unary_function<Image&,void>
1300  {
1301  public:
1302  animationDelayImage( const size_t delay_ );
1303 
1304  void operator()( Image &image_ ) const;
1305 
1306  private:
1307  size_t _delay;
1308  };
1309 
1310  // Number of iterations to loop an animation (e.g. Netscape loop
1311  // extension) for.
1312  class MagickPPExport animationIterationsImage : public std::unary_function<Image&,void>
1313  {
1314  public:
1315  animationIterationsImage( const size_t iterations_ );
1316 
1317  void operator()( Image &image_ ) const;
1318 
1319  private:
1320  size_t _iterations;
1321  };
1322 
1323  // Image background color
1324  class MagickPPExport backgroundColorImage : public std::unary_function<Image&,void>
1325  {
1326  public:
1327  backgroundColorImage( const Color &color_ );
1328 
1329  void operator()( Image &image_ ) const;
1330 
1331  private:
1332  Color _color;
1333  };
1334 
1335  // Name of texture image to tile onto the image background
1336  class MagickPPExport backgroundTextureImage : public std::unary_function<Image&,void>
1337  {
1338  public:
1339  backgroundTextureImage( const std::string &backgroundTexture_ );
1340 
1341  void operator()( Image &image_ ) const;
1342 
1343  private:
1344  std::string _backgroundTexture;
1345  };
1346 
1347  // Image border color
1348  class MagickPPExport borderColorImage : public std::unary_function<Image&,void>
1349  {
1350  public:
1351  borderColorImage( const Color &color_ );
1352 
1353  void operator()( Image &image_ ) const;
1354 
1355  private:
1356  Color _color;
1357  };
1358 
1359  // Text bounding-box base color (default none)
1360  class MagickPPExport boxColorImage : public std::unary_function<Image&,void>
1361  {
1362  public:
1363  boxColorImage( const Color &boxColor_ );
1364 
1365  void operator()( Image &image_ ) const;
1366 
1367  private:
1368  Color _boxColor;
1369  };
1370 
1371  // Chromaticity blue primary point (e.g. x=0.15, y=0.06)
1372  class MagickPPExport chromaBluePrimaryImage : public std::unary_function<Image&,void>
1373  {
1374  public:
1375  chromaBluePrimaryImage( const double x_, const double y_ );
1376 
1377  void operator()( Image &image_ ) const;
1378 
1379  private:
1380  double _x;
1381  double _y;
1382  };
1383 
1384  // Chromaticity green primary point (e.g. x=0.3, y=0.6)
1385  class MagickPPExport chromaGreenPrimaryImage : public std::unary_function<Image&,void>
1386  {
1387  public:
1388  chromaGreenPrimaryImage( const double x_, const double y_ );
1389 
1390  void operator()( Image &image_ ) const;
1391 
1392  private:
1393  double _x;
1394  double _y;
1395  };
1396 
1397  // Chromaticity red primary point (e.g. x=0.64, y=0.33)
1398  class MagickPPExport chromaRedPrimaryImage : public std::unary_function<Image&,void>
1399  {
1400  public:
1401  chromaRedPrimaryImage( const double x_, const double y_ );
1402 
1403  void operator()( Image &image_ ) const;
1404 
1405  private:
1406  double _x;
1407  double _y;
1408  };
1409 
1410  // Chromaticity white point (e.g. x=0.3127, y=0.329)
1411  class MagickPPExport chromaWhitePointImage : public std::unary_function<Image&,void>
1412  {
1413  public:
1414  chromaWhitePointImage( const double x_, const double y_ );
1415 
1416  void operator()( Image &image_ ) const;
1417 
1418  private:
1419  double _x;
1420  double _y;
1421  };
1422 
1423  // Colors within this distance are considered equal
1424  class MagickPPExport colorFuzzImage : public std::unary_function<Image&,void>
1425  {
1426  public:
1427  colorFuzzImage( const double fuzz_ );
1428 
1429  void operator()( Image &image_ ) const;
1430 
1431  private:
1432  double _fuzz;
1433  };
1434 
1435  // Color at colormap position index_
1436  class MagickPPExport colorMapImage : public std::unary_function<Image&,void>
1437  {
1438  public:
1439  colorMapImage( const size_t index_, const Color &color_ );
1440 
1441  void operator()( Image &image_ ) const;
1442 
1443  private:
1444  size_t _index;
1445  Color _color;
1446  };
1447 
1448  // Composition operator to be used when composition is implicitly used
1449  // (such as for image flattening).
1450  class MagickPPExport composeImage : public std::unary_function<Image&,void>
1451  {
1452  public:
1453  composeImage( const CompositeOperator compose_ );
1454 
1455  void operator()( Image &image_ ) const;
1456 
1457  private:
1458  CompositeOperator _compose;
1459  };
1460 
1461  // Compression type
1462  class MagickPPExport compressTypeImage : public std::unary_function<Image&,void>
1463  {
1464  public:
1465  compressTypeImage( const CompressionType compressType_ );
1466 
1467  void operator()( Image &image_ ) const;
1468 
1469  private:
1470  CompressionType _compressType;
1471  };
1472 
1473  // Vertical and horizontal resolution in pixels of the image
1474  class MagickPPExport densityImage : public std::unary_function<Image&,void>
1475  {
1476  public:
1477  densityImage( const Geometry &geomery_ );
1478 
1479  void operator()( Image &image_ ) const;
1480 
1481  private:
1482  Geometry _geomery;
1483  };
1484 
1485  // Image depth (bits allocated to red/green/blue components)
1486  class MagickPPExport depthImage : public std::unary_function<Image&,void>
1487  {
1488  public:
1489  depthImage( const size_t depth_ );
1490 
1491  void operator()( Image &image_ ) const;
1492 
1493  private:
1494  size_t _depth;
1495  };
1496 
1497  // Endianness (LSBEndian like Intel or MSBEndian like SPARC) for image
1498  // formats which support endian-specific options.
1499  class MagickPPExport endianImage : public std::unary_function<Image&,void>
1500  {
1501  public:
1502  endianImage( const EndianType endian_ );
1503 
1504  void operator()( Image &image_ ) const;
1505 
1506  private:
1507  EndianType _endian;
1508  };
1509 
1510  // Image file name
1511  class MagickPPExport fileNameImage : public std::unary_function<Image&,void>
1512  {
1513  public:
1514  fileNameImage( const std::string &fileName_ );
1515 
1516  void operator()( Image &image_ ) const;
1517 
1518  private:
1519  std::string _fileName;
1520  };
1521 
1522  // Filter to use when resizing image
1523  class MagickPPExport filterTypeImage : public std::unary_function<Image&,void>
1524  {
1525  public:
1526  filterTypeImage( const FilterTypes filterType_ );
1527 
1528  void operator()( Image &image_ ) const;
1529 
1530  private:
1531  FilterTypes _filterType;
1532  };
1533 
1534  // Text rendering font
1535  class MagickPPExport fontImage : public std::unary_function<Image&,void>
1536  {
1537  public:
1538  fontImage( const std::string &font_ );
1539 
1540  void operator()( Image &image_ ) const;
1541 
1542  private:
1543  std::string _font;
1544  };
1545 
1546  // Font point size
1547  class MagickPPExport fontPointsizeImage : public std::unary_function<Image&,void>
1548  {
1549  public:
1550  fontPointsizeImage( const size_t pointsize_ );
1551 
1552  void operator()( Image &image_ ) const;
1553 
1554  private:
1555  size_t _pointsize;
1556  };
1557 
1558  // GIF disposal method
1559  class MagickPPExport gifDisposeMethodImage : public std::unary_function<Image&,void>
1560  {
1561  public:
1562  gifDisposeMethodImage( const size_t disposeMethod_ );
1563 
1564  void operator()( Image &image_ ) const;
1565 
1566  private:
1567  size_t _disposeMethod;
1568  };
1569 
1570  // Type of interlacing to use
1571  class MagickPPExport interlaceTypeImage : public std::unary_function<Image&,void>
1572  {
1573  public:
1574  interlaceTypeImage( const InterlaceType interlace_ );
1575 
1576  void operator()( Image &image_ ) const;
1577 
1578  private:
1579  InterlaceType _interlace;
1580  };
1581 
1582  // Linewidth for drawing vector objects (default one)
1583  class MagickPPExport lineWidthImage : public std::unary_function<Image&,void>
1584  {
1585  public:
1586  lineWidthImage( const double lineWidth_ );
1587 
1588  void operator()( Image &image_ ) const;
1589 
1590  private:
1591  double _lineWidth;
1592  };
1593 
1594  // File type magick identifier (.e.g "GIF")
1595  class MagickPPExport magickImage : public std::unary_function<Image&,void>
1596  {
1597  public:
1598  magickImage( const std::string &magick_ );
1599 
1600  void operator()( Image &image_ ) const;
1601 
1602  private:
1603  std::string _magick;
1604  };
1605 
1606  // Image supports transparent color
1607  class MagickPPExport matteImage : public std::unary_function<Image&,void>
1608  {
1609  public:
1610  matteImage( const bool matteFlag_ );
1611 
1612  void operator()( Image &image_ ) const;
1613 
1614  private:
1615  bool _matteFlag;
1616  };
1617 
1618  // Transparent color
1619  class MagickPPExport matteColorImage : public std::unary_function<Image&,void>
1620  {
1621  public:
1622  matteColorImage( const Color &matteColor_ );
1623 
1624  void operator()( Image &image_ ) const;
1625 
1626  private:
1627  Color _matteColor;
1628  };
1629 
1630  // Indicate that image is black and white
1631  class MagickPPExport monochromeImage : public std::unary_function<Image&,void>
1632  {
1633  public:
1634  monochromeImage( const bool monochromeFlag_ );
1635 
1636  void operator()( Image &image_ ) const;
1637 
1638  private:
1639  bool _monochromeFlag;
1640  };
1641 
1642  // Pen color
1643  class MagickPPExport penColorImage : public std::unary_function<Image&,void>
1644  {
1645  public:
1646  penColorImage( const Color &penColor_ );
1647 
1648  void operator()( Image &image_ ) const;
1649 
1650  private:
1651  Color _penColor;
1652  };
1653 
1654  // Pen texture image.
1655  class MagickPPExport penTextureImage : public std::unary_function<Image&,void>
1656  {
1657  public:
1658  penTextureImage( const Image &penTexture_ );
1659 
1660  void operator()( Image &image_ ) const;
1661 
1662  private:
1663  Image _penTexture;
1664  };
1665 
1666  // Set pixel color at location x & y.
1667  class MagickPPExport pixelColorImage : public std::unary_function<Image&,void>
1668  {
1669  public:
1670  pixelColorImage( const ::ssize_t x_,
1671  const ::ssize_t y_,
1672  const Color &color_);
1673 
1674  void operator()( Image &image_ ) const;
1675 
1676  private:
1677  ::ssize_t _x;
1678  ::ssize_t _y;
1679  Color _color;
1680  };
1681 
1682  // Postscript page size.
1683  class MagickPPExport pageImage : public std::unary_function<Image&,void>
1684  {
1685  public:
1686  pageImage( const Geometry &pageSize_ );
1687 
1688  void operator()( Image &image_ ) const;
1689 
1690  private:
1691  Geometry _pageSize;
1692  };
1693 
1694  // JPEG/MIFF/PNG compression level (default 75).
1695  class MagickPPExport qualityImage : public std::unary_function<Image&,void>
1696  {
1697  public:
1698  qualityImage( const size_t quality_ );
1699 
1700  void operator()( Image &image_ ) const;
1701 
1702  private:
1703  size_t _quality;
1704  };
1705 
1706  // Maximum number of colors to quantize to
1707  class MagickPPExport quantizeColorsImage : public std::unary_function<Image&,void>
1708  {
1709  public:
1710  quantizeColorsImage( const size_t colors_ );
1711 
1712  void operator()( Image &image_ ) const;
1713 
1714  private:
1715  size_t _colors;
1716  };
1717 
1718  // Colorspace to quantize in.
1719  class MagickPPExport quantizeColorSpaceImage : public std::unary_function<Image&,void>
1720  {
1721  public:
1722  quantizeColorSpaceImage( const ColorspaceType colorSpace_ );
1723 
1724  void operator()( Image &image_ ) const;
1725 
1726  private:
1727  ColorspaceType _colorSpace;
1728  };
1729 
1730  // Dither image during quantization (default true).
1731  class MagickPPExport quantizeDitherImage : public std::unary_function<Image&,void>
1732  {
1733  public:
1734  quantizeDitherImage( const bool ditherFlag_ );
1735 
1736  void operator()( Image &image_ ) const;
1737 
1738  private:
1739  bool _ditherFlag;
1740  };
1741 
1742  // Quantization tree-depth
1743  class MagickPPExport quantizeTreeDepthImage : public std::unary_function<Image&,void>
1744  {
1745  public:
1746  quantizeTreeDepthImage( const size_t treeDepth_ );
1747 
1748  void operator()( Image &image_ ) const;
1749 
1750  private:
1751  size_t _treeDepth;
1752  };
1753 
1754  // The type of rendering intent
1755  class MagickPPExport renderingIntentImage : public std::unary_function<Image&,void>
1756  {
1757  public:
1758  renderingIntentImage( const RenderingIntent renderingIntent_ );
1759 
1760  void operator()( Image &image_ ) const;
1761 
1762  private:
1763  RenderingIntent _renderingIntent;
1764  };
1765 
1766  // Units of image resolution
1767  class MagickPPExport resolutionUnitsImage : public std::unary_function<Image&,void>
1768  {
1769  public:
1770  resolutionUnitsImage( const ResolutionType resolutionUnits_ );
1771 
1772  void operator()( Image &image_ ) const;
1773 
1774  private:
1775  ResolutionType _resolutionUnits;
1776  };
1777 
1778  // Image scene number
1779  class MagickPPExport sceneImage : public std::unary_function<Image&,void>
1780  {
1781  public:
1782  sceneImage( const size_t scene_ );
1783 
1784  void operator()( Image &image_ ) const;
1785 
1786  private:
1787  size_t _scene;
1788  };
1789 
1790  // adjust the image contrast with a non-linear sigmoidal contrast algorithm
1791  class MagickPPExport sigmoidalContrastImage : public std::unary_function<Image&,void>
1792  {
1793  public:
1794  sigmoidalContrastImage( const size_t sharpen_,
1795  const double contrast,
1796  const double midpoint = QuantumRange / 2.0 );
1797 
1798  void operator()( Image &image_ ) const;
1799 
1800  private:
1801  size_t _sharpen;
1802  double contrast;
1803  double midpoint;
1804  };
1805 
1806  // Width and height of a raw image
1807  class MagickPPExport sizeImage : public std::unary_function<Image&,void>
1808  {
1809  public:
1810  sizeImage( const Geometry &geometry_ );
1811 
1812  void operator()( Image &image_ ) const;
1813 
1814  private:
1815  Geometry _geometry;
1816  };
1817 
1818  // stripImage strips an image of all profiles and comments.
1819  class MagickPPExport stripImage : public std::unary_function<Image&,void>
1820  {
1821  public:
1822  stripImage( void );
1823 
1824  void operator()( Image &image_ ) const;
1825 
1826  private:
1827  };
1828 
1829  // Subimage of an image sequence
1830  class MagickPPExport subImageImage : public std::unary_function<Image&,void>
1831  {
1832  public:
1833  subImageImage( const size_t subImage_ );
1834 
1835  void operator()( Image &image_ ) const;
1836 
1837  private:
1838  size_t _subImage;
1839  };
1840 
1841  // Number of images relative to the base image
1842  class MagickPPExport subRangeImage : public std::unary_function<Image&,void>
1843  {
1844  public:
1845  subRangeImage( const size_t subRange_ );
1846 
1847  void operator()( Image &image_ ) const;
1848 
1849  private:
1850  size_t _subRange;
1851  };
1852 
1853  // Tile name
1854  class MagickPPExport tileNameImage : public std::unary_function<Image&,void>
1855  {
1856  public:
1857  tileNameImage( const std::string &tileName_ );
1858 
1859  void operator()( Image &image_ ) const;
1860 
1861  private:
1862  std::string _tileName;
1863  };
1864 
1865  // Image storage type
1866  class MagickPPExport typeImage : public std::unary_function<Image&,void>
1867  {
1868  public:
1869  typeImage( const ImageType type_ );
1870 
1871  void operator()( Image &image_ ) const;
1872 
1873  private:
1874  Magick::ImageType _type;
1875  };
1876 
1877 
1878  // Print detailed information about the image
1879  class MagickPPExport verboseImage : public std::unary_function<Image&,void>
1880  {
1881  public:
1882  verboseImage( const bool verbose_ );
1883 
1884  void operator()( Image &image_ ) const;
1885 
1886  private:
1887  bool _verbose;
1888  };
1889 
1890  // FlashPix viewing parameters
1891  class MagickPPExport viewImage : public std::unary_function<Image&,void>
1892  {
1893  public:
1894  viewImage( const std::string &view_ );
1895 
1896  void operator()( Image &image_ ) const;
1897 
1898  private:
1899  std::string _view;
1900  };
1901 
1902  // X11 display to display to, obtain fonts from, or to capture
1903  // image from
1904  class MagickPPExport x11DisplayImage : public std::unary_function<Image&,void>
1905  {
1906  public:
1907  x11DisplayImage( const std::string &display_ );
1908 
1909  void operator()( Image &image_ ) const;
1910 
1911  private:
1912  std::string _display;
1913  };
1914 
1916  //
1917  // Implementation template definitions. Not for end-use.
1918  //
1920 
1921  // Link images together into an image list based on the ordering of
1922  // the container implied by the iterator. This step is done in
1923  // preparation for use with ImageMagick functions which operate on
1924  // lists of images.
1925  // Images are selected by range, first_ to last_ so that a subset of
1926  // the container may be selected. Specify first_ via the
1927  // container's begin() method and last_ via the container's end()
1928  // method in order to specify the entire container.
1929  template <class InputIterator>
1930  void linkImages( InputIterator first_,
1931  InputIterator last_ ) {
1932 
1933  MagickCore::Image* previous = 0;
1934  ::ssize_t scene = 0;
1935  for ( InputIterator iter = first_; iter != last_; ++iter )
1936  {
1937  // Unless we reduce the reference count to one, the same image
1938  // structure may occur more than once in the container, causing
1939  // the linked list to fail.
1940  iter->modifyImage();
1941 
1942  MagickCore::Image* current = iter->image();
1943 
1944  current->previous = previous;
1945  current->next = 0;
1946  current->scene = scene++;
1947 
1948  if ( previous != 0)
1949  previous->next = current;
1950 
1951  previous = current;
1952  }
1953  }
1954 
1955  // Remove links added by linkImages. This should be called after the
1956  // ImageMagick function call has completed to reset the image list
1957  // back to its pristine un-linked state.
1958  template <class InputIterator>
1959  void unlinkImages( InputIterator first_,
1960  InputIterator last_ ) {
1961  for( InputIterator iter = first_; iter != last_; ++iter )
1962  {
1963  MagickCore::Image* image = iter->image();
1964  image->previous = 0;
1965  image->next = 0;
1966  }
1967  }
1968 
1969  // Insert images in image list into existing container (appending to container)
1970  // The images should not be deleted since only the image ownership is passed.
1971  // The options are copied into the object.
1972  template <class Container>
1973  void insertImages( Container *sequence_,
1974  MagickCore::Image* images_ ) {
1975  MagickCore::Image *image = images_;
1976  if ( image )
1977  {
1978  do
1979  {
1980  MagickCore::Image* next_image = image->next;
1981  image->next = 0;
1982 
1983  if (next_image != 0)
1984  next_image->previous=0;
1985 
1986  sequence_->push_back( Magick::Image( image ) );
1987 
1988  image=next_image;
1989  } while( image );
1990 
1991  return;
1992  }
1993  }
1994 
1996  //
1997  // Template definitions for documented API
1998  //
2000 
2001  template <class InputIterator>
2002  void animateImages( InputIterator first_,
2003  InputIterator last_ ) {
2005  linkImages( first_, last_ );
2006  MagickCore::AnimateImages( first_->imageInfo(), first_->image() );
2007  MagickCore::GetImageException( first_->image(), exceptionInfo );
2008  unlinkImages( first_, last_ );
2009  ThrowPPException(first_->quiet());
2010  }
2011 
2012  // Append images from list into single image in either horizontal or
2013  // vertical direction.
2014  template <class InputIterator>
2015  void appendImages( Image *appendedImage_,
2016  InputIterator first_,
2017  InputIterator last_,
2018  bool stack_ = false) {
2020  linkImages( first_, last_ );
2021  MagickCore::Image* image = MagickCore::AppendImages( first_->image(),
2022  (MagickBooleanType) stack_,
2023  exceptionInfo );
2024  unlinkImages( first_, last_ );
2025  appendedImage_->replaceImage( image );
2026  ThrowPPException(appendedImage_->quiet());
2027  }
2028 
2029  // Adds the names of the artifacts of the image to the container.
2030  template <class Container>
2031  void artifactNames(Container *names_,const Image* image_)
2032  {
2033  char*
2034  name;
2035 
2036  names_->clear();
2037 
2038  MagickCore::ResetImageArtifactIterator(image_->constImage());
2039  name=MagickCore::GetNextImageArtifact(image_->constImage());
2040  while (name != (char *) NULL)
2041  {
2042  names_->push_back(std::string(name));
2043  name=MagickCore::GetNextImageArtifact(image_->constImage());
2044  }
2045  }
2046 
2047  // Adds the names of the attributes of the image to the container.
2048  template <class Container>
2049  void attributeNames(Container *names_,const Image* image_)
2050  {
2051  char*
2052  name;
2053 
2054  names_->clear();
2055 
2056  MagickCore::ResetImagePropertyIterator(image_->constImage());
2057  name=MagickCore::GetNextImageProperty(image_->constImage());
2058  while (name != (char *) NULL)
2059  {
2060  names_->push_back(std::string(name));
2061  name=MagickCore::GetNextImageProperty(image_->constImage());
2062  }
2063  }
2064 
2065  // Average a set of images.
2066  // All the input images must be the same size in pixels.
2067  template <class InputIterator>
2068  void averageImages( Image *averagedImage_,
2069  InputIterator first_,
2070  InputIterator last_ ) {
2072  linkImages( first_, last_ );
2073  MagickCore::Image* image = MagickCore::EvaluateImages( first_->image(),
2074  MagickCore::MeanEvaluateOperator, exceptionInfo );
2075  unlinkImages( first_, last_ );
2076  averagedImage_->replaceImage( image );
2077  ThrowPPException(averagedImage_->quiet());
2078  }
2079 
2080  // Merge a sequence of images.
2081  // This is useful for GIF animation sequences that have page
2082  // offsets and disposal methods. A container to contain
2083  // the updated image sequence is passed via the coalescedImages_
2084  // option.
2085  template <class InputIterator, class Container >
2086  void coalesceImages( Container *coalescedImages_,
2087  InputIterator first_,
2088  InputIterator last_ ) {
2090 
2091  // Build image list
2092  linkImages( first_, last_ );
2093  MagickCore::Image* images = MagickCore::CoalesceImages( first_->image(),
2094  exceptionInfo);
2095  // Unlink image list
2096  unlinkImages( first_, last_ );
2097 
2098  // Ensure container is empty
2099  coalescedImages_->clear();
2100 
2101  // Move images to container
2102  insertImages( coalescedImages_, images );
2103 
2104  // Report any error
2105  ThrowPPException(first_->quiet());
2106  }
2107 
2108  // Return format coders matching specified conditions.
2109  //
2110  // The default (if no match terms are supplied) is to return all
2111  // available format coders.
2112  //
2113  // For example, to return all readable formats:
2114  // list<CoderInfo> coderList;
2115  // coderInfoList( &coderList, CoderInfo::TrueMatch, CoderInfo::AnyMatch, CoderInfo::AnyMatch)
2116  //
2117  template <class Container >
2118  void coderInfoList( Container *container_,
2122  ) {
2123  // Obtain first entry in MagickInfo list
2124  size_t number_formats;
2126  char **coder_list =
2127  MagickCore::GetMagickList( "*", &number_formats, exceptionInfo );
2128  if( !coder_list )
2129  {
2130  throwException(exceptionInfo);
2131  throwExceptionExplicit(MagickCore::MissingDelegateError,
2132  "Coder array not returned!", 0 );
2133  }
2134 
2135  // Clear out container
2136  container_->clear();
2137 
2138  for ( ::ssize_t i=0; i < (::ssize_t) number_formats; i++)
2139  {
2140  const MagickCore::MagickInfo *magick_info =
2141  MagickCore::GetMagickInfo( coder_list[i], exceptionInfo );
2142  coder_list[i]=(char *)
2143  MagickCore::RelinquishMagickMemory( coder_list[i] );
2144 
2145  // Skip stealth coders
2146  if ( magick_info->stealth )
2147  continue;
2148 
2149  try {
2150  CoderInfo coderInfo( magick_info->name );
2151 
2152  // Test isReadable_
2153  if ( isReadable_ != CoderInfo::AnyMatch &&
2154  (( coderInfo.isReadable() && isReadable_ != CoderInfo::TrueMatch ) ||
2155  ( !coderInfo.isReadable() && isReadable_ != CoderInfo::FalseMatch )) )
2156  continue;
2157 
2158  // Test isWritable_
2159  if ( isWritable_ != CoderInfo::AnyMatch &&
2160  (( coderInfo.isWritable() && isWritable_ != CoderInfo::TrueMatch ) ||
2161  ( !coderInfo.isWritable() && isWritable_ != CoderInfo::FalseMatch )) )
2162  continue;
2163 
2164  // Test isMultiFrame_
2165  if ( isMultiFrame_ != CoderInfo::AnyMatch &&
2166  (( coderInfo.isMultiFrame() && isMultiFrame_ != CoderInfo::TrueMatch ) ||
2167  ( !coderInfo.isMultiFrame() && isMultiFrame_ != CoderInfo::FalseMatch )) )
2168  continue;
2169 
2170  // Append matches to container
2171  container_->push_back( coderInfo );
2172  }
2173  // Intentionally ignore missing module errors
2174  catch ( Magick::ErrorModule )
2175  {
2176  continue;
2177  }
2178  }
2179  coder_list=(char **) MagickCore::RelinquishMagickMemory( coder_list );
2180  ThrowPPException(false);
2181  }
2182 
2183  //
2184  // Fill container with color histogram.
2185  // Entries are of type "std::pair<Color,size_t>". Use the pair
2186  // "first" member to access the Color and the "second" member to access
2187  // the number of times the color occurs in the image.
2188  //
2189  // For example:
2190  //
2191  // Using <map>:
2192  //
2193  // Image image("image.miff");
2194  // map<Color,size_t> histogram;
2195  // colorHistogram( &histogram, image );
2196  // std::map<Color,size_t>::const_iterator p=histogram.begin();
2197  // while (p != histogram.end())
2198  // {
2199  // cout << setw(10) << (int)p->second << ": ("
2200  // << setw(quantum_width) << (int)p->first.redQuantum() << ","
2201  // << setw(quantum_width) << (int)p->first.greenQuantum() << ","
2202  // << setw(quantum_width) << (int)p->first.blueQuantum() << ")"
2203  // << endl;
2204  // p++;
2205  // }
2206  //
2207  // Using <vector>:
2208  //
2209  // Image image("image.miff");
2210  // std::vector<std::pair<Color,size_t> > histogram;
2211  // colorHistogram( &histogram, image );
2212  // std::vector<std::pair<Color,size_t> >::const_iterator p=histogram.begin();
2213  // while (p != histogram.end())
2214  // {
2215  // cout << setw(10) << (int)p->second << ": ("
2216  // << setw(quantum_width) << (int)p->first.redQuantum() << ","
2217  // << setw(quantum_width) << (int)p->first.greenQuantum() << ","
2218  // << setw(quantum_width) << (int)p->first.blueQuantum() << ")"
2219  // << endl;
2220  // p++;
2221  // }
2222 
2223  template <class Container >
2224  void colorHistogram( Container *histogram_, const Image image)
2225  {
2227 
2228  // Obtain histogram array
2229  size_t colors;
2230  MagickCore::ColorPacket *histogram_array =
2231  MagickCore::GetImageHistogram( image.constImage(), &colors, exceptionInfo );
2232  ThrowPPException(image.quiet());
2233 
2234  // Clear out container
2235  histogram_->clear();
2236 
2237  // Transfer histogram array to container
2238  for ( size_t i=0; i < colors; i++)
2239  {
2240  histogram_->insert( histogram_->end(), std::pair<const Color,size_t>
2241  ( Color(histogram_array[i].pixel), (size_t) histogram_array[i].count) );
2242  }
2243 
2244  // Deallocate histogram array
2245  histogram_array=(MagickCore::ColorPacket *)
2246  MagickCore::RelinquishMagickMemory(histogram_array);
2247  }
2248 
2249  // Combines one or more images into a single image. The grayscale value of
2250  // the pixels of each image in the sequence is assigned in order to the
2251  // specified channels of the combined image. The typical ordering would be
2252  // image 1 => Red, 2 => Green, 3 => Blue, etc.
2253  template <class InputIterator >
2254  void combineImages( Image *combinedImage_,
2255  InputIterator first_,
2256  InputIterator last_,
2257  const ChannelType channel_ ) {
2259  linkImages( first_, last_ );
2260  MagickCore::Image* image = CombineImages( first_->image(), channel_, exceptionInfo );
2261  unlinkImages( first_, last_ );
2262  combinedImage_->replaceImage( image );
2263  ThrowPPException(combinedImage_->quiet());
2264  }
2265 
2266  template <class Container>
2267  void cropToTiles(Container *tiledImages_,const Image image_,
2268  const Geometry &geometry_)
2269  {
2271  MagickCore::Image* images=CropImageToTiles(image_.constImage(),
2272  static_cast<std::string>(geometry_).c_str(),exceptionInfo);
2273  tiledImages_->clear();
2274  insertImages(tiledImages_,images);
2275  ThrowPPException(image_.quiet());
2276  }
2277 
2278  // Break down an image sequence into constituent parts. This is
2279  // useful for creating GIF or MNG animation sequences.
2280  template <class InputIterator, class Container >
2281  void deconstructImages( Container *deconstructedImages_,
2282  InputIterator first_,
2283  InputIterator last_ ) {
2285 
2286  // Build image list
2287  linkImages( first_, last_ );
2288  MagickCore::Image* images = DeconstructImages( first_->image(),
2289  exceptionInfo);
2290  // Unlink image list
2291  unlinkImages( first_, last_ );
2292 
2293  // Ensure container is empty
2294  deconstructedImages_->clear();
2295 
2296  // Move images to container
2297  insertImages( deconstructedImages_, images );
2298 
2299  // Report any error
2300  ThrowPPException(first_->quiet());
2301  }
2302 
2303  //
2304  // Display an image sequence
2305  //
2306  template <class InputIterator>
2307  void displayImages( InputIterator first_,
2308  InputIterator last_ ) {
2310  linkImages( first_, last_ );
2311  MagickCore::DisplayImages( first_->imageInfo(), first_->image() );
2312  MagickCore::GetImageException( first_->image(), exceptionInfo );
2313  unlinkImages( first_, last_ );
2314  ThrowPPException(first_->quiet());
2315  }
2316 
2317  // Applies a value to the image with an arithmetic, relational,
2318  // or logical operator to an image. Use these operations to lighten or darken
2319  // an image, to increase or decrease contrast in an image, or to produce the
2320  // "negative" of an image.
2321  template <class InputIterator >
2322  void evaluateImages( Image *evaluatedImage_,
2323  InputIterator first_,
2324  InputIterator last_,
2325  const MagickEvaluateOperator operator_ ) {
2327  linkImages( first_, last_ );
2328  MagickCore::Image* image = EvaluateImages( first_->image(), operator_, exceptionInfo );
2329  unlinkImages( first_, last_ );
2330  evaluatedImage_->replaceImage( image );
2331  ThrowPPException(evaluatedImage_->quiet());
2332  }
2333 
2334  // Merge a sequence of image frames which represent image layers.
2335  // This is useful for combining Photoshop layers into a single image.
2336  template <class InputIterator>
2337  void flattenImages( Image *flattendImage_,
2338  InputIterator first_,
2339  InputIterator last_ ) {
2341  linkImages( first_, last_ );
2342  MagickCore::Image* image = MagickCore::MergeImageLayers( first_->image(),
2343  FlattenLayer,exceptionInfo );
2344  unlinkImages( first_, last_ );
2345  flattendImage_->replaceImage( image );
2346  ThrowPPException(flattendImage_->quiet());
2347  }
2348 
2349  // Implements the discrete Fourier transform (DFT) of the image either as a
2350  // magnitude / phase or real / imaginary image pair.
2351  template <class Container >
2352  void forwardFourierTransformImage( Container *fourierImages_,
2353  const Image &image_ ) {
2355 
2356  // Build image list
2357  MagickCore::Image* images = ForwardFourierTransformImage(
2358  image_.constImage(), MagickTrue, exceptionInfo);
2359 
2360  // Ensure container is empty
2361  fourierImages_->clear();
2362 
2363  // Move images to container
2364  insertImages( fourierImages_, images );
2365 
2366  // Report any error
2367  ThrowPPException(image_.quiet());
2368  }
2369  template <class Container >
2370  void forwardFourierTransformImage( Container *fourierImages_,
2371  const Image &image_, const bool magnitude_ ) {
2373 
2374  // Build image list
2375  MagickCore::Image* images = ForwardFourierTransformImage(
2376  image_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
2377  exceptionInfo);
2378 
2379  // Ensure container is empty
2380  fourierImages_->clear();
2381 
2382  // Move images to container
2383  insertImages( fourierImages_, images );
2384 
2385  // Report any error
2386  ThrowPPException(image_.quiet());
2387  }
2388 
2389  // Applies a mathematical expression to a sequence of images.
2390  template <class InputIterator>
2391  void fxImages(Image *fxImage_,InputIterator first_,InputIterator last_,
2392  const std::string expression)
2393  {
2395  *image;
2396 
2398  linkImages(first_,last_);
2399  image=FxImageChannel(first_->constImage(),DefaultChannels,
2400  expression.c_str(),exceptionInfo);
2401  unlinkImages(first_,last_);
2402  fxImage_->replaceImage(image);
2403  ThrowPPException(fxImage_->quiet());
2404  }
2405 
2406  // Replace the colors of a sequence of images with the closest color
2407  // from a reference image.
2408  // Set dither_ to true to enable dithering. Set measureError_ to
2409  // true in order to evaluate quantization error.
2410  template <class InputIterator>
2411  void mapImages( InputIterator first_,
2412  InputIterator last_,
2413  const Image& mapImage_,
2414  bool dither_ = false,
2415  bool measureError_ = false ) {
2416 
2418  MagickCore::QuantizeInfo quantizeInfo;
2419  MagickCore::GetQuantizeInfo( &quantizeInfo );
2420  quantizeInfo.dither = dither_ ? MagickCore::MagickTrue : MagickCore::MagickFalse;
2421  linkImages( first_, last_ );
2422  MagickCore::RemapImages( &quantizeInfo, first_->image(),
2423  (mapImage_.isValid() ? mapImage_.constImage() : (const MagickCore::Image*) NULL));
2424  MagickCore::GetImageException( first_->image(), exceptionInfo );
2425  if ( exceptionInfo->severity != MagickCore::UndefinedException )
2426  {
2427  unlinkImages( first_, last_ );
2428  throwException(exceptionInfo,mapImage_.quiet());
2429  }
2430 
2431  MagickCore::Image* image = first_->image();
2432  while( image )
2433  {
2434  // Calculate quantization error
2435  if ( measureError_ )
2436  {
2437  MagickCore::GetImageQuantizeError( image );
2438  if ( image->exception.severity > MagickCore::UndefinedException )
2439  {
2440  unlinkImages( first_, last_ );
2441  throwException(exceptionInfo,mapImage_.quiet());
2442  }
2443  }
2444 
2445  // Udate DirectClass representation of pixels
2446  MagickCore::SyncImage( image );
2447  if ( image->exception.severity > MagickCore::UndefinedException )
2448  {
2449  unlinkImages( first_, last_ );
2450  throwException(exceptionInfo,mapImage_.quiet());
2451  }
2452 
2453  // Next image
2454  image=image->next;
2455  }
2456 
2457  unlinkImages( first_, last_ );
2458  (void) MagickCore::DestroyExceptionInfo( exceptionInfo );
2459  }
2460 
2461  // Composes all the image layers from the current given
2462  // image onward to produce a single image of the merged layers.
2463  template <class InputIterator >
2464  void mergeImageLayers( Image *mergedImage_,
2465  InputIterator first_,
2466  InputIterator last_,
2467  const ImageLayerMethod method_ ) {
2469  linkImages( first_, last_ );
2470  MagickCore::Image* image = MergeImageLayers( first_->image(), method_, exceptionInfo );
2471  unlinkImages( first_, last_ );
2472  mergedImage_->replaceImage( image );
2473  ThrowPPException(mergedImage_->quiet());
2474  }
2475 
2476  // Create a composite image by combining several separate images.
2477  template <class Container, class InputIterator>
2478  void montageImages(Container *montageImages_,InputIterator first_,
2479  InputIterator last_,const Montage &options_)
2480  {
2482  *images;
2483 
2484  MagickCore::MontageInfo
2485  *montageInfo;
2486 
2487  montageInfo=static_cast<MagickCore::MontageInfo*>(
2488  MagickCore::AcquireMagickMemory(sizeof(MagickCore::MontageInfo)));
2489 
2490  // Update montage options with those set in montageOpts_
2491  options_.updateMontageInfo(*montageInfo);
2492 
2493  // Update options which must transfer to image options
2494  if (options_.label().length() != 0)
2495  first_->label(options_.label());
2496 
2497  // Create linked image list
2498  linkImages(first_,last_);
2499 
2500  // Do montage
2502  images=MagickCore::MontageImages(first_->image(),montageInfo,
2503  exceptionInfo);
2504 
2505  // Unlink linked image list
2506  unlinkImages(first_,last_);
2507 
2508  // Reset output container to pristine state
2509  montageImages_->clear();
2510 
2511  if (images != (MagickCore::Image *) NULL)
2512  insertImages(montageImages_,images);
2513 
2514  // Clean up any allocated data in montageInfo
2515  MagickCore::DestroyMontageInfo(montageInfo);
2516 
2517  // Report any montage error
2518  ThrowPPException(first_->quiet());
2519 
2520  // Apply transparency to montage images
2521  if (montageImages_->size() > 0 && options_.transparentColor().isValid())
2522  for_each(montageImages_->begin(),montageImages_->end(),transparentImage(
2523  options_.transparentColor()));
2524  }
2525 
2526  // Morph a set of images
2527  template <class InputIterator, class Container >
2528  void morphImages( Container *morphedImages_,
2529  InputIterator first_,
2530  InputIterator last_,
2531  size_t frames_ ) {
2533 
2534  // Build image list
2535  linkImages( first_, last_ );
2536  MagickCore::Image* images = MagickCore::MorphImages( first_->image(), frames_,
2537  exceptionInfo);
2538  // Unlink image list
2539  unlinkImages( first_, last_ );
2540 
2541  // Ensure container is empty
2542  morphedImages_->clear();
2543 
2544  // Move images to container
2545  insertImages( morphedImages_, images );
2546 
2547  // Report any error
2548  ThrowPPException(first_->quiet());
2549  }
2550 
2551  // Inlay a number of images to form a single coherent picture.
2552  template <class InputIterator>
2553  void mosaicImages( Image *mosaicImage_,
2554  InputIterator first_,
2555  InputIterator last_ ) {
2557  linkImages( first_, last_ );
2558  MagickCore::Image* image = MagickCore::MergeImageLayers( first_->image(),
2559  MosaicLayer,exceptionInfo );
2560  unlinkImages( first_, last_ );
2561  mosaicImage_->replaceImage( image );
2562  ThrowPPException(mosaicImage_->quiet());
2563  }
2564 
2565  // Compares each image the GIF disposed forms of the previous image in
2566  // the sequence. From this it attempts to select the smallest cropped
2567  // image to replace each frame, while preserving the results of the
2568  // GIF animation.
2569  template <class InputIterator, class Container >
2570  void optimizeImageLayers( Container *optimizedImages_,
2571  InputIterator first_,
2572  InputIterator last_ ) {
2574 
2575  linkImages( first_, last_ );
2576  MagickCore::Image* images = OptimizeImageLayers( first_->image(), exceptionInfo );
2577 
2578  unlinkImages( first_, last_ );
2579 
2580  optimizedImages_->clear();
2581 
2582  insertImages( optimizedImages_, images );
2583 
2584  ThrowPPException(first_->quiet());
2585  }
2586 
2587  // optimizeImagePlusLayers is exactly as optimizeImageLayers, but may
2588  // also add or even remove extra frames in the animation, if it improves
2589  // the total number of pixels in the resulting GIF animation.
2590  template <class InputIterator, class Container >
2591  void optimizePlusImageLayers( Container *optimizedImages_,
2592  InputIterator first_,
2593  InputIterator last_ ) {
2595 
2596  linkImages( first_, last_ );
2597  MagickCore::Image* images = OptimizePlusImageLayers( first_->image(), exceptionInfo );
2598 
2599  unlinkImages( first_, last_ );
2600 
2601  optimizedImages_->clear();
2602 
2603  insertImages( optimizedImages_, images );
2604 
2605  ThrowPPException(first_->quiet());
2606  }
2607 
2608  // Compares each image the GIF disposed forms of the previous image in the
2609  // sequence. Any pixel that does not change the displayed result is replaced
2610  // with transparency.
2611  template<class InputIterator>
2612  void optimizeTransparency(InputIterator first_,InputIterator last_)
2613  {
2615 
2616  linkImages(first_,last_);
2617  OptimizeImageTransparency(first_->image(),exceptionInfo);
2618  unlinkImages(first_,last_ );
2619 
2620  ThrowPPException(first_->quiet());
2621  }
2622 
2623  // Adds the names of the profiles from the image to the container.
2624  template <class Container>
2625  void profileNames(Container *names_,const Image* image_)
2626  {
2627  const char
2628  *name;
2629 
2630  names_->clear();
2631 
2632  MagickCore::ResetImageProfileIterator(image_->constImage());
2633  name=MagickCore::GetNextImageProfile(image_->constImage());
2634  while (name != (const char *) NULL)
2635  {
2636  names_->push_back(std::string(name));
2637  name=MagickCore::GetNextImageProfile(image_->constImage());
2638  }
2639  }
2640 
2641  // Quantize colors in images using current quantization settings
2642  // Set measureError_ to true in order to measure quantization error
2643  template <class InputIterator>
2644  void quantizeImages( InputIterator first_,
2645  InputIterator last_,
2646  bool measureError_ = false ) {
2648 
2649  linkImages( first_, last_ );
2650 
2651  MagickCore::QuantizeImages( first_->quantizeInfo(),
2652  first_->image() );
2653  MagickCore::GetImageException( first_->image(), exceptionInfo );
2654  if ( exceptionInfo->severity > MagickCore::UndefinedException )
2655  {
2656  unlinkImages( first_, last_ );
2657  throwException(exceptionInfo,first_->quiet());
2658  }
2659 
2660  MagickCore::Image* image = first_->image();
2661  while( image != 0 )
2662  {
2663  // Calculate quantization error
2664  if ( measureError_ )
2665  MagickCore::GetImageQuantizeError( image );
2666 
2667  // Update DirectClass representation of pixels
2668  MagickCore::SyncImage( image );
2669 
2670  // Next image
2671  image=image->next;
2672  }
2673 
2674  unlinkImages( first_, last_ );
2675  (void) MagickCore::DestroyExceptionInfo( exceptionInfo );
2676  }
2677 
2678  // Read images into existing container (appending to container)
2679  template<class Container>
2680  void readImages(Container *sequence_,const std::string &imageSpec_,
2681  ReadOptions &options)
2682  {
2684  *images;
2685 
2686  MagickCore::ImageInfo
2687  *imageInfo;
2688 
2689  imageInfo=options.imageInfo();
2690  imageSpec_.copy(imageInfo->filename,MaxTextExtent-1);
2691  imageInfo->filename[imageSpec_.length()] = 0;
2693  images=MagickCore::ReadImage(imageInfo,exceptionInfo);
2694  insertImages(sequence_,images);
2695  ThrowPPException(options.quiet());
2696  }
2697 
2698  template<class Container>
2699  void readImages(Container *sequence_,const std::string &imageSpec_)
2700  {
2701  ReadOptions options;
2702  readImages(sequence_,imageSpec_,options);
2703  }
2704 
2705  template<class Container>
2706  void readImages(Container *sequence_,const Blob &blob_,ReadOptions &options)
2707  {
2709  *images;
2710 
2712  images=MagickCore::BlobToImage(options.imageInfo(),blob_.data(),
2713  blob_.length(),exceptionInfo);
2714  insertImages(sequence_,images);
2715  ThrowPPException(options.quiet());
2716  }
2717 
2718  template<class Container>
2719  void readImages(Container *sequence_,const Blob &blob_)
2720  {
2721  ReadOptions options;
2722  readImages(sequence_,blob_,options);
2723  }
2724 
2725  // Returns a separate grayscale image for each channel specified.
2726  template <class Container >
2727  void separateImages( Container *separatedImages_,
2728  const Image &image_,
2729  const ChannelType channel_ ) {
2731 
2732  MagickCore::Image* images = MagickCore::SeparateImages( image_.constImage(), channel_, exceptionInfo );
2733 
2734  separatedImages_->clear();
2735 
2736  insertImages( separatedImages_, images );
2737 
2738  ThrowPPException(image_.quiet());
2739  }
2740 
2741  // Smush images from list into single image in either horizontal or
2742  // vertical direction.
2743  template<class InputIterator>
2744  void smushImages(Image *smushedImage_,InputIterator first_,
2745  InputIterator last_,const ssize_t offset_,bool stack_=false)
2746  {
2748  *newImage;
2749 
2751  linkImages(first_,last_);
2752  newImage=MagickCore::SmushImages(first_->constImage(),
2753  (MagickBooleanType) stack_,offset_,exceptionInfo);
2754  unlinkImages(first_,last_);
2755  smushedImage_->replaceImage(newImage);
2756  ThrowPPException(smushedImage_->quiet());
2757  }
2758 
2759  // Write Images
2760  template <class InputIterator>
2761  void writeImages( InputIterator first_,
2762  InputIterator last_,
2763  const std::string &imageSpec_,
2764  bool adjoin_ = true ) {
2765 
2766  first_->adjoin( adjoin_ );
2767 
2769 
2770  linkImages( first_, last_ );
2771  ::ssize_t errorStat = MagickCore::WriteImages( first_->constImageInfo(),
2772  first_->image(),
2773  imageSpec_.c_str(),
2774  exceptionInfo );
2775  unlinkImages( first_, last_ );
2776 
2777  if ( errorStat != false )
2778  {
2779  (void) MagickCore::DestroyExceptionInfo( exceptionInfo );
2780  return;
2781  }
2782 
2783  ThrowPPException(first_->quiet());
2784  }
2785  // Write images to BLOB
2786  template <class InputIterator>
2787  void writeImages( InputIterator first_,
2788  InputIterator last_,
2789  Blob *blob_,
2790  bool adjoin_ = true) {
2791 
2792  first_->adjoin( adjoin_ );
2793 
2794  linkImages( first_, last_ );
2795 
2797  size_t length = 2048; // Efficient size for small images
2798  void* data = MagickCore::ImagesToBlob( first_->imageInfo(),
2799  first_->image(),
2800  &length,
2801  exceptionInfo);
2802  blob_->updateNoCopy( data, length, Magick::Blob::MallocAllocator );
2803 
2804  unlinkImages( first_, last_ );
2805 
2806  ThrowPPException(first_->quiet());
2807  }
2808 
2809 } // namespace Magick
2810 
2811 #endif // Magick_STL_header
void attributeNames(Container *names_, const Image *image_)
Definition: STL.h:2049
void smushImages(Image *smushedImage_, InputIterator first_, InputIterator last_, const ssize_t offset_, bool stack_=false)
Definition: STL.h:2744
class MagickPPExport Color
Definition: Color.h:15
void evaluateImages(Image *evaluatedImage_, InputIterator first_, InputIterator last_, const MagickEvaluateOperator operator_)
Definition: STL.h:2322
MagickPPExport const char * borderGeometryDefault
Definition: Image.cpp:33
void averageImages(Image *averagedImage_, InputIterator first_, InputIterator last_)
Definition: STL.h:2068
std::list< Magick::Drawable > DrawableList
Definition: Drawable.h:178
void coderInfoList(Container *container_, CoderInfo::MatchType isReadable_=CoderInfo::AnyMatch, CoderInfo::MatchType isWritable_=CoderInfo::AnyMatch, CoderInfo::MatchType isMultiFrame_=CoderInfo::AnyMatch)
Definition: STL.h:2118
void mosaicImages(Image *mosaicImage_, InputIterator first_, InputIterator last_)
Definition: STL.h:2553
void unlinkImages(InputIterator first_, InputIterator last_)
Definition: STL.h:1959
void animateImages(InputIterator first_, InputIterator last_)
Definition: STL.h:2002
MagickPPExport const char * raiseGeometryDefault
Definition: Image.cpp:35
void coalesceImages(Container *coalescedImages_, InputIterator first_, InputIterator last_)
Definition: STL.h:2086
void mergeImageLayers(Image *mergedImage_, InputIterator first_, InputIterator last_, const ImageLayerMethod method_)
Definition: STL.h:2464
void quiet(const bool quiet_)
Definition: Image.cpp:1379
void appendImages(Image *appendedImage_, InputIterator first_, InputIterator last_, bool stack_=false)
Definition: STL.h:2015
void forwardFourierTransformImage(Container *fourierImages_, const Image &image_)
Definition: STL.h:2352
void insertImages(Container *sequence_, MagickCore::Image *images_)
Definition: STL.h:1973
void separateImages(Container *separatedImages_, const Image &image_, const ChannelType channel_)
Definition: STL.h:2727
MagickCore::Image * replaceImage(MagickCore::Image *replacement_)
Definition: Image.cpp:5077
void optimizeImageLayers(Container *optimizedImages_, InputIterator first_, InputIterator last_)
Definition: STL.h:2570
void cropToTiles(Container *tiledImages_, const Image image_, const Geometry &geometry_)
Definition: STL.h:2267
void transparentColor(const Color &transparentColor_)
Definition: Montage.h:319
void flattenImages(Image *flattendImage_, InputIterator first_, InputIterator last_)
Definition: STL.h:2337
void colorHistogram(Container *histogram_, const Image image)
Definition: STL.h:2224
bool isMultiFrame(void) const
Definition: CoderInfo.cpp:101
MagickPPExport void throwException(MagickCore::ExceptionInfo *exception_, const bool quiet_=false)
void montageImages(Container *montageImages_, InputIterator first_, InputIterator last_, const Montage &options_)
Definition: STL.h:2478
void combineImages(Image *combinedImage_, InputIterator first_, InputIterator last_, const ChannelType channel_)
Definition: STL.h:2254
virtual void updateMontageInfo(MagickCore::MontageInfo &montageInfo_) const
Definition: Montage.cpp:41
void quiet(const bool quiet_)
Definition: STL.cpp:869
#define MagickPPExport
Definition: Include.h:255
void writeImages(InputIterator first_, InputIterator last_, const std::string &imageSpec_, bool adjoin_=true)
Definition: STL.h:2761
void mapImages(InputIterator first_, InputIterator last_, const Image &mapImage_, bool dither_=false, bool measureError_=false)
Definition: STL.h:2411
void readImages(Container *sequence_, const std::string &imageSpec_, ReadOptions &options)
Definition: STL.h:2680
const MagickCore::Image * constImage(void) const
Definition: Image.cpp:5028
MagickPPExport const char * frameGeometryDefault
Definition: Image.cpp:34
bool isReadable(void) const
Definition: CoderInfo.cpp:91
MagickPPExport void throwExceptionExplicit(const MagickCore::ExceptionType severity_, const char *reason_, const char *description_=(char *) NULL)
void updateNoCopy(void *data_, const size_t length_, Allocator allocator_=NewAllocator)
Definition: Blob.cpp:148
#define ThrowPPException(quiet)
Definition: Include.h:1510
bool isWritable(void) const
Definition: CoderInfo.cpp:96
void fxImages(Image *fxImage_, InputIterator first_, InputIterator last_, const std::string expression)
Definition: STL.h:2391
void isValid(const bool isValid_)
Definition: Image.cpp:1033
void deconstructImages(Container *deconstructedImages_, InputIterator first_, InputIterator last_)
Definition: STL.h:2281
void morphImages(Container *morphedImages_, InputIterator first_, InputIterator last_, size_t frames_)
Definition: STL.h:2528
void artifactNames(Container *names_, const Image *image_)
Definition: STL.h:2031
size_t length(void) const
Definition: Blob.cpp:123
class MagickPPExport Image
Definition: Drawable.h:647
MagickCore::ImageInfo * imageInfo(void)
Definition: STL.cpp:895
void linkImages(InputIterator first_, InputIterator last_)
Definition: STL.h:1930
Definition: Blob.h:15
void displayImages(InputIterator first_, InputIterator last_)
Definition: STL.h:2307
void label(const std::string &label_)
Definition: Montage.h:238
#define GetPPException
Definition: Include.h:1506
void optimizePlusImageLayers(Container *optimizedImages_, InputIterator first_, InputIterator last_)
Definition: STL.h:2591
void optimizeTransparency(InputIterator first_, InputIterator last_)
Definition: STL.h:2612
void profileNames(Container *names_, const Image *image_)
Definition: STL.h:2625
const void * data(void) const
Definition: Blob.cpp:118
void quantizeImages(InputIterator first_, InputIterator last_, bool measureError_=false)
Definition: STL.h:2644