Boost GIL


read_image.hpp
1 //
2 // Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #ifndef BOOST_GIL_IO_READ_IMAGE_HPP
9 #define BOOST_GIL_IO_READ_IMAGE_HPP
10 
11 #include <boost/gil/extension/toolbox/dynamic_images.hpp>
12 
13 #include <boost/gil/io/base.hpp>
14 #include <boost/gil/io/conversion_policies.hpp>
15 #include <boost/gil/io/device.hpp>
16 #include <boost/gil/io/get_reader.hpp>
17 #include <boost/gil/io/path_spec.hpp>
18 
19 #include <boost/mpl/and.hpp>
20 #include <boost/type_traits/is_base_and_derived.hpp>
21 
22 #include <type_traits>
23 
24 namespace boost { namespace gil {
25 
27 
32 template <typename Reader, typename Image>
33 inline
34 void read_image(Reader reader, Image& img,
35  typename std::enable_if
36  <
37  mpl::and_
38  <
39  detail::is_reader<Reader>,
40  is_format_tag<typename Reader::format_tag_t>,
42  <
43  typename get_pixel_type<typename Image::view_t>::type,
44  typename Reader::format_tag_t
45  >
46  >::value
47  >::type* /*dummy*/ = nullptr)
48 {
49  reader.init_image(img, reader._settings);
50  reader.apply(view(img));
51 }
52 
58 template <typename Device, typename Image, typename FormatTag>
59 inline
60 void read_image(
61  Device& file,
62  Image& img,
63  image_read_settings<FormatTag> const& settings,
64  typename std::enable_if
65  <
66  mpl::and_
67  <
69  is_format_tag<FormatTag>,
71  <
72  typename get_pixel_type<typename Image::view_t>::type,
73  FormatTag
74  >
75  >::value
76  >::type* /*dummy*/ = nullptr)
77 {
78  using reader_t =
80 
81  reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
82  read_image(reader, img);
83 }
84 
90 template <typename Device, typename Image, typename FormatTag>
91 inline
92 void read_image(Device& file, Image& img, FormatTag const& tag,
93  typename std::enable_if
94  <
95  mpl::and_
96  <
98  is_format_tag<FormatTag>,
100  <
101  typename get_pixel_type<typename Image::view_t>::type,
102  FormatTag
103  >
104  >::value
105  >::type* /*dummy*/ = nullptr)
106 {
107  using reader_t =
109 
110  reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
111  read_image(reader, img);
112 }
113 
119 template <typename String, typename Image, typename FormatTag>
120 inline
121 void read_image(
122  String const& file_name,
123  Image& img,
124  image_read_settings<FormatTag> const& settings,
125  typename std::enable_if
126  <
127  mpl::and_
128  <
129  detail::is_supported_path_spec<String>,
130  is_format_tag<FormatTag>,
132  <
133  typename get_pixel_type<typename Image::view_t>::type,
134  FormatTag
135  >
136  >::value
137  >::type* /*dummy*/ = nullptr)
138 {
139  using reader_t =
141 
142  reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
143  read_image(reader, img);
144 }
145 
151 template <typename String, typename Image, typename FormatTag>
152 inline
153 void read_image(String const& file_name, Image& img, FormatTag const& tag,
154  typename std::enable_if
155  <
156  mpl::and_<detail::is_supported_path_spec<String>,
157  is_format_tag<FormatTag>,
159  <
160  typename get_pixel_type<typename Image::view_t>::type,
161  FormatTag
162  >
163  >::value
164 >::type* /*dummy*/ = nullptr)
165 {
166  using reader_t =
168 
169  reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
170  read_image(reader, img);
171 }
172 
174 
175 template <typename Reader, typename Images>
176 inline
177 void read_image(Reader& reader, any_image<Images>& images,
178  typename std::enable_if
179  <
180  mpl::and_
181  <
182  detail::is_dynamic_image_reader<Reader>,
183  is_format_tag<typename Reader::format_tag_t>
184  >::value
185  >::type* /*dummy*/ = nullptr)
186 {
187  reader.apply(images);
188 }
189 
195 template <typename Device, typename Images, typename FormatTag>
196 inline
197 void read_image(
198  Device& file,
199  any_image<Images>& images,
200  image_read_settings<FormatTag> const& settings,
201  typename std::enable_if
202  <
203  mpl::and_
204  <
206  is_format_tag<FormatTag>
207  >::value
208  >::type* /*dummy*/ = nullptr)
209 {
210  using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
211 
212  reader_t reader = make_dynamic_image_reader(file, settings);
213  read_image(reader, images);
214 }
215 
221 template <typename Device, typename Images, typename FormatTag>
222 inline
223 void read_image(Device& file, any_image<Images>& images, FormatTag const& tag,
224  typename std::enable_if
225  <
226  mpl::and_
227  <
229  is_format_tag<FormatTag>
230  >::value
231  >::type* /*dummy*/ = nullptr)
232 {
233  using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
234 
235  reader_t reader = make_dynamic_image_reader(file, tag);
236  read_image(reader, images);
237 }
238 
244 template <typename String, typename Images, typename FormatTag>
245 inline
246 void read_image(
247  String const& file_name,
248  any_image<Images>& images,
249  image_read_settings<FormatTag> const& settings,
250  typename std::enable_if
251  <
252  mpl::and_
253  <
254  detail::is_supported_path_spec<String>,
255  is_format_tag<FormatTag>
256  >::value
257  >::type* /*dummy*/ = nullptr)
258 {
259  using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
260 
261  reader_t reader = make_dynamic_image_reader(file_name, settings);
262  read_image(reader, images);
263 }
264 
270 template <typename String, typename Images, typename FormatTag>
271 inline
272 void read_image(String const& file_name, any_image<Images>& images, FormatTag const& tag,
273  typename std::enable_if
274  <
275  mpl::and_
276  <
277  detail::is_supported_path_spec<String>,
278  is_format_tag<FormatTag>
279  >::value
280  >::type* /*dummy*/ = nullptr)
281 {
282  using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
283 
284  reader_t reader = make_dynamic_image_reader(file_name, tag);
285  read_image(reader, images);
286 }
287 
288 }} // namespace boost::gil
289 
290 #endif
Helper metafunction to generate dynamic image reader type.
Definition: get_reader.hpp:71
Definition: algorithm.hpp:30
Represents a run-time specified image. Note it does NOT model ImageConcept.
Definition: any_image.hpp:67
void read_image(Reader reader, Image &img, typename std::enable_if< mpl::and_< detail::is_reader< Reader >, is_format_tag< typename Reader::format_tag_t >, is_read_supported< typename get_pixel_type< typename Image::view_t >::type, typename Reader::format_tag_t > >::value >::type *=nullptr)
Reads an image without conversion. Image memory is allocated.
Definition: read_image.hpp:34
Definition: base.hpp:80
Definition: device.hpp:592
const image< Pixel, IsPlanar, Alloc >::view_t & view(image< Pixel, IsPlanar, Alloc > &img)
Returns the non-constant-pixel view of an image.
Definition: image.hpp:460
Helper metafunction to generate image reader type.
Definition: get_reader.hpp:27