DGtal  1.0.0
MagickReader.h
1 
17 #pragma once
18 
31 #if defined(MagickReader_RECURSES)
32 #error Recursive header files inclusion detected in MagickReader.h
33 #else // defined(MagickReader_RECURSES)
34 
35 #define MagickReader_RECURSES
36 
37 #if !defined MagickReader_h
38 
39 #define MagickReader_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <string>
45 #include <cstdio>
46 
47 #if defined(WITH_MAGICK)
48 // Specific inclusion method to fix warning with GraphicsMagic 1.3.31 and Clang.
49 // The warning comes from two "diagnostic pop" with missing corresponding push.
50 // "MagickLibAddendum" is defined in ImageMagick since 9 years but not in GraphicsMagic.
51 # if !defined(MagickLibAddendum) && defined(__clang__)
52 # pragma clang diagnostic push
53 # pragma clang diagnostic push
54 # include <Magick++.h>
55 # if MagickLibVersion != 0x221900
56 # pragma clang diagnostic pop
57 # pragma clang diagnostic pop
58 # endif
59 # else
60 # include <Magick++.h>
61 # endif
62 #else // defined WITH_MAGICK
63 # error "DGtal has not been built with imagemagick support. Consider adding -DWITH_MAGICK=true when building the project with cmake."
64 #endif // defined WITH_MAGICK
65 
66 
67 #include "DGtal/base/CUnaryFunctor.h"
68 #include "DGtal/base/Common.h"
70 
71 namespace DGtal
72 {
73  namespace functors
74  {
75  template<typename TValue>
76  struct MagickCast
77  {
79  TValue operator()(const Color &col) const
80  {
81  return myCast( col.red() + col.green() + col.blue() );
82  }
83  };
84 
85  template<>
86  struct MagickCast<Color>
87  {
88  Color operator()(const Color &col) const
89  {
90  return col;
91  }
92  };
93  }
94 
96  // template class MagickReader
110  template <typename TImageContainer, typename TFunctor= functors::MagickCast< typename TImageContainer::Value > >
112  {
113  // ----------------------- Standard services ------------------------------
114  public:
115 
116  typedef TImageContainer ImageContainer;
118  typedef typename TImageContainer::Value Value;
119  typedef TFunctor Functor ;
120 
121  BOOST_STATIC_ASSERT( (ImageContainer::Domain::dimension == 2));
122 
134  static ImageContainer importImage(const std::string & filename,
135  const Functor & aFunctor = Functor(),
136  bool topbotomOrder = true);
137 
138  }; // end of class MagickReader
139 
140 
141 } // namespace DGtal
142 
143 
145 // Includes inline functions.
146 #include "DGtal/io/readers/MagickReader.ih"
147 
148 // //
150 
151 #endif // !defined MagickReader_h
152 
153 #undef MagickReader_RECURSES
154 #endif // else defined(MagickReader_RECURSES)
BOOST_STATIC_ASSERT((ImageContainer::Domain::dimension==2))
TValue operator()(const Color &col) const
Definition: MagickReader.h:79
Color operator()(const Color &col) const
Definition: MagickReader.h:88
Aim: implements methods to read a 2D image using the ImageMagick library.
Definition: MagickReader.h:111
static ImageContainer importImage(const std::string &filename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
DGtal is the top-level namespace which contains all DGtal functions and types.
TImageContainer::Domain::Vector Vector
Definition: MagickReader.h:117
FreemanChain< int >::Vector Vector
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
TImageContainer ImageContainer
Definition: MagickReader.h:116
TImageContainer::Value Value
Definition: MagickReader.h:118
void blue(const unsigned char aBlueValue)