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 #include <boost/gil/detail/mp11.hpp>
19 
20 #include <type_traits>
21 
22 namespace boost { namespace gil {
23 
25 
30 template <typename Reader, typename Image>
31 inline
32 void read_image(Reader reader, Image& img,
33  typename std::enable_if
34  <
35  mp11::mp_and
36  <
37  detail::is_reader<Reader>,
38  is_format_tag<typename Reader::format_tag_t>,
40  <
41  typename get_pixel_type<typename Image::view_t>::type,
42  typename Reader::format_tag_t
43  >
44  >::value
45  >::type* /*dummy*/ = nullptr)
46 {
47  reader.init_image(img, reader._settings);
48  reader.apply(view(img));
49 }
50 
56 template <typename Device, typename Image, typename FormatTag>
57 inline
58 void read_image(
59  Device& file,
60  Image& img,
61  image_read_settings<FormatTag> const& settings,
62  typename std::enable_if
63  <
64  mp11::mp_and
65  <
66  detail::is_read_device<FormatTag, Device>,
67  is_format_tag<FormatTag>,
68  is_read_supported
69  <
70  typename get_pixel_type<typename Image::view_t>::type,
71  FormatTag
72  >
73  >::value
74  >::type* /*dummy*/ = nullptr)
75 {
76  using reader_t =
77  typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
78 
79  reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
80  read_image(reader, img);
81 }
82 
88 template <typename Device, typename Image, typename FormatTag>
89 inline
90 void read_image(Device& file, Image& img, FormatTag const& tag,
91  typename std::enable_if
92  <
93  mp11::mp_and
94  <
95  detail::is_read_device<FormatTag, Device>,
96  is_format_tag<FormatTag>,
97  is_read_supported
98  <
99  typename get_pixel_type<typename Image::view_t>::type,
100  FormatTag
101  >
102  >::value
103  >::type* /*dummy*/ = nullptr)
104 {
105  using reader_t =
106  typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
107 
108  reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
109  read_image(reader, img);
110 }
111 
117 template <typename String, typename Image, typename FormatTag>
118 inline
119 void read_image(
120  String const& file_name,
121  Image& img,
122  image_read_settings<FormatTag> const& settings,
123  typename std::enable_if
124  <
125  mp11::mp_and
126  <
127  detail::is_supported_path_spec<String>,
128  is_format_tag<FormatTag>,
129  is_read_supported
130  <
131  typename get_pixel_type<typename Image::view_t>::type,
132  FormatTag
133  >
134  >::value
135  >::type* /*dummy*/ = nullptr)
136 {
137  using reader_t =
138  typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
139 
140  reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
141  read_image(reader, img);
142 }
143 
149 template <typename String, typename Image, typename FormatTag>
150 inline
151 void read_image(String const& file_name, Image& img, FormatTag const& tag,
152  typename std::enable_if
153  <
154  mp11::mp_and<detail::is_supported_path_spec<String>,
155  is_format_tag<FormatTag>,
156  is_read_supported
157  <
158  typename get_pixel_type<typename Image::view_t>::type,
159  FormatTag
160  >
161  >::value
162 >::type* /*dummy*/ = nullptr)
163 {
164  using reader_t =
165  typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
166 
167  reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
168  read_image(reader, img);
169 }
170 
172 
173 template <typename Reader, typename ...Images>
174 inline
175 void read_image(Reader& reader, any_image<Images...>& images,
176  typename std::enable_if
177  <
178  mp11::mp_and
179  <
180  detail::is_dynamic_image_reader<Reader>,
181  is_format_tag<typename Reader::format_tag_t>
182  >::value
183  >::type* /*dummy*/ = nullptr)
184 {
185  reader.apply(images);
186 }
187 
193 template <typename Device, typename ...Images, typename FormatTag>
194 inline
195 void read_image(
196  Device& file,
197  any_image<Images...>& images,
198  image_read_settings<FormatTag> const& settings,
199  typename std::enable_if
200  <
201  mp11::mp_and
202  <
203  detail::is_read_device<FormatTag, Device>,
204  is_format_tag<FormatTag>
205  >::value
206  >::type* /*dummy*/ = nullptr)
207 {
208  using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
209 
210  reader_t reader = make_dynamic_image_reader(file, settings);
211  read_image(reader, images);
212 }
213 
219 template <typename Device, typename ...Images, typename FormatTag>
220 inline
221 void read_image(Device& file, any_image<Images...>& images, FormatTag const& tag,
222  typename std::enable_if
223  <
224  mp11::mp_and
225  <
226  detail::is_read_device<FormatTag, Device>,
227  is_format_tag<FormatTag>
228  >::value
229  >::type* /*dummy*/ = nullptr)
230 {
231  using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
232 
233  reader_t reader = make_dynamic_image_reader(file, tag);
234  read_image(reader, images);
235 }
236 
242 template <typename String, typename ...Images, typename FormatTag>
243 inline
244 void read_image(
245  String const& file_name,
246  any_image<Images...>& images,
247  image_read_settings<FormatTag> const& settings,
248  typename std::enable_if
249  <
250  mp11::mp_and
251  <
252  detail::is_supported_path_spec<String>,
253  is_format_tag<FormatTag>
254  >::value
255  >::type* /*dummy*/ = nullptr)
256 {
257  using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
258 
259  reader_t reader = make_dynamic_image_reader(file_name, settings);
260  read_image(reader, images);
261 }
262 
268 template <typename String, typename ...Images, typename FormatTag>
269 inline
270 void read_image(String const& file_name, any_image<Images...>& images, FormatTag const& tag,
271  typename std::enable_if
272  <
273  mp11::mp_and
274  <
275  detail::is_supported_path_spec<String>,
276  is_format_tag<FormatTag>
277  >::value
278  >::type* /*dummy*/ = nullptr)
279 {
280  using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
281 
282  reader_t reader = make_dynamic_image_reader(file_name, tag);
283  read_image(reader, images);
284 }
285 
286 }} // namespace boost::gil
287 
288 #endif
void read_image(Reader reader, Image &img, typename std::enable_if< mp11::mp_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:32
auto view(image< Pixel, IsPlanar, Alloc > &img) -> typename image< Pixel, IsPlanar, Alloc >::view_t const &
Returns the non-constant-pixel view of an image.
Definition: image.hpp:565
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
Definition: base.hpp:78