DGtal  0.9.4.1
MagickWriter.h
1 
17 #pragma once
18 
31 #if defined(MagickWriter_RECURSES)
32 #error Recursive header files inclusion detected in MagickWriter.h
33 #else // defined(MagickWriter_RECURSES)
34 
35 #define MagickWriter_RECURSES
36 
37 #if !defined MagickWriter_h
38 
39 #define MagickWriter_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <string>
45 #include "DGtal/base/CUnaryFunctor.h"
46 #include "DGtal/base/BasicFunctors.h"
47 #include "DGtal/io/writers/MagickWriter.h"
48 #include "DGtal/io/Color.h"
49 
50 #ifndef WITH_MAGICK
51 #pragma error "You must activate imagemagick (-DWITH_MAGICK=true) to include this file"
52 #endif
53 #include <Magick++.h>
55 
56 namespace DGtal
57 {
58 
60  // template class MagickWriter
77  template <typename TImage, typename TFunctor = functors::Identity>
78  struct MagickWriter
79  {
80  // ----------------------- Standard services ------------------------------
81  typedef TImage Image;
82  typedef typename TImage::Value Value;
83  typedef TFunctor Functor;
84 
86  BOOST_STATIC_ASSERT( (TImage::Domain::dimension == 2) );
87 
98  static bool exportMagick(const std::string & filename, const Image &anImage,
99  const Functor & aFunctor = Functor())
100  {
101  Magick::InitializeMagick(NULL);
102  int w = (anImage.domain().upperBound()[0] - anImage.domain().lowerBound()[0])+1;
103  int h = (anImage.domain().upperBound()[1] - anImage.domain().lowerBound()[1])+1;
104  Magick::Geometry geom(w,h);
105  Magick::Image image(geom,"white");
106  for(auto point: anImage.domain())
107  {
108  Color c = aFunctor( anImage(point) );
109  Magick::ColorRGB magickc( c.red()/255., c.green()/255., c.blue()/255.) ;
110  image.pixelColor( point[0] + anImage.domain().lowerBound()[0],
111  (h-1) - (point[1] + anImage.domain().lowerBound()[1]),
112  magickc );
113  }
114  image.write(filename);
115  return true;
116  }
117 
118 
119 
120  };
121 }//namespace
122 
123 // //
125 
126 #endif // !defined MagickWriter_h
127 
128 #undef MagickWriter_RECURSES
129 #endif // else defined(MagickWriter_RECURSES)
TImage::Value Value
Definition: MagickWriter.h:82
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89
BOOST_STATIC_ASSERT((TImage::Domain::dimension==2))
static bool exportMagick(const std::string &filename, const Image &anImage, const Functor &aFunctor=Functor())
Definition: MagickWriter.h:98
DGtal is the top-level namespace which contains all DGtal functions and types.
ImageContainerBySTLVector< Domain, Value > Image
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctor, Value, Color >))
Image image(domain)
Aim: Export image using Imagemagick backend.
Definition: MagickWriter.h:78