2 // Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
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
8 #ifndef BOOST_GIL_IO_READ_IMAGE_HPP
9 #define BOOST_GIL_IO_READ_IMAGE_HPP
11 #include <boost/gil/extension/toolbox/dynamic_images.hpp>
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>
20 #include <type_traits>
22 namespace boost { namespace gil {
26 /// \brief Reads an image without conversion. Image memory is allocated.
27 /// \param reader An image reader.
28 /// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
29 /// \throw std::ios_base::failure
30 template <typename Reader, typename Image>
32 void read_image(Reader reader, Image& img,
33 typename std::enable_if
37 detail::is_reader<Reader>,
38 is_format_tag<typename Reader::format_tag_t>,
41 typename get_pixel_type<typename Image::view_t>::type,
42 typename Reader::format_tag_t
45 >::type* /*dummy*/ = nullptr)
47 reader.init_image(img, reader._settings);
48 reader.apply(view(img));
51 /// \brief Reads an image without conversion. Image memory is allocated.
52 /// \param file It's a device. Must satisfy is_input_device metafunction.
53 /// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
54 /// \param settings Specifies read settings depending on the image format.
55 /// \throw std::ios_base::failure
56 template <typename Device, typename Image, typename FormatTag>
61 image_read_settings<FormatTag> const& settings,
62 typename std::enable_if
66 detail::is_read_device<FormatTag, Device>,
67 is_format_tag<FormatTag>,
70 typename get_pixel_type<typename Image::view_t>::type,
74 >::type* /*dummy*/ = nullptr)
77 typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
79 reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
80 read_image(reader, img);
83 /// \brief Reads an image without conversion. Image memory is allocated.
84 /// \param file It's a device. Must satisfy is_input_device metafunction.
85 /// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
86 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
87 /// \throw std::ios_base::failure
88 template <typename Device, typename Image, typename FormatTag>
90 void read_image(Device& file, Image& img, FormatTag const& tag,
91 typename std::enable_if
95 detail::is_read_device<FormatTag, Device>,
96 is_format_tag<FormatTag>,
99 typename get_pixel_type<typename Image::view_t>::type,
103 >::type* /*dummy*/ = nullptr)
106 typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
108 reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
109 read_image(reader, img);
112 /// \brief Reads an image without conversion. Image memory is allocated.
113 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
114 /// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
115 /// \param settings Specifies read settings depending on the image format.
116 /// \throw std::ios_base::failure
117 template <typename String, typename Image, typename FormatTag>
120 String const& file_name,
122 image_read_settings<FormatTag> const& settings,
123 typename std::enable_if
127 detail::is_supported_path_spec<String>,
128 is_format_tag<FormatTag>,
131 typename get_pixel_type<typename Image::view_t>::type,
135 >::type* /*dummy*/ = nullptr)
138 typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
140 reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
141 read_image(reader, img);
144 /// \brief Reads an image without conversion. Image memory is allocated.
145 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
146 /// \param img The image in which the data is read into. Must satisfy is_read_supported metafunction.
147 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
148 /// \throw std::ios_base::failure
149 template <typename String, typename Image, typename FormatTag>
151 void read_image(String const& file_name, Image& img, FormatTag const& tag,
152 typename std::enable_if
154 mp11::mp_and<detail::is_supported_path_spec<String>,
155 is_format_tag<FormatTag>,
158 typename get_pixel_type<typename Image::view_t>::type,
162 >::type* /*dummy*/ = nullptr)
165 typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
167 reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
168 read_image(reader, img);
173 template <typename Reader, typename Images>
175 void read_image(Reader& reader, any_image<Images>& images,
176 typename std::enable_if
180 detail::is_dynamic_image_reader<Reader>,
181 is_format_tag<typename Reader::format_tag_t>
183 >::type* /*dummy*/ = nullptr)
185 reader.apply(images);
188 /// \brief Reads an image without conversion. Image memory is allocated.
189 /// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
190 /// \param images Dynamic image (mp11::mp_list). See boost::gil::dynamic_image extension.
191 /// \param settings Specifies read settings depending on the image format.
192 /// \throw std::ios_base::failure
193 template <typename Device, typename Images, typename FormatTag>
197 any_image<Images>& images,
198 image_read_settings<FormatTag> const& settings,
199 typename std::enable_if
203 detail::is_read_device<FormatTag, Device>,
204 is_format_tag<FormatTag>
206 >::type* /*dummy*/ = nullptr)
208 using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
210 reader_t reader = make_dynamic_image_reader(file, settings);
211 read_image(reader, images);
214 /// \brief Reads an image without conversion. Image memory is allocated.
215 /// \param file It's a device. Must satisfy is_adaptable_input_device metafunction.
216 /// \param images Dynamic image (mp11::mp_list). See boost::gil::dynamic_image extension.
217 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
218 /// \throw std::ios_base::failure
219 template <typename Device, typename Images, typename FormatTag>
221 void read_image(Device& file, any_image<Images>& images, FormatTag const& tag,
222 typename std::enable_if
226 detail::is_read_device<FormatTag, Device>,
227 is_format_tag<FormatTag>
229 >::type* /*dummy*/ = nullptr)
231 using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
233 reader_t reader = make_dynamic_image_reader(file, tag);
234 read_image(reader, images);
237 /// \brief Reads an image without conversion. Image memory is allocated.
238 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
239 /// \param images Dynamic image (mp11::mp_list). See boost::gil::dynamic_image extension.
240 /// \param settings Specifies read settings depending on the image format.
241 /// \throw std::ios_base::failure
242 template <typename String, typename Images, typename FormatTag>
245 String const& file_name,
246 any_image<Images>& images,
247 image_read_settings<FormatTag> const& settings,
248 typename std::enable_if
252 detail::is_supported_path_spec<String>,
253 is_format_tag<FormatTag>
255 >::type* /*dummy*/ = nullptr)
257 using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
259 reader_t reader = make_dynamic_image_reader(file_name, settings);
260 read_image(reader, images);
263 /// \brief Reads an image without conversion. Image memory is allocated.
264 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
265 /// \param images Dynamic image (mp11::mp_list). See boost::gil::dynamic_image extension.
266 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
267 /// \throw std::ios_base::failure
268 template <typename String, typename Images, typename FormatTag>
270 void read_image(String const& file_name, any_image<Images>& images, FormatTag const& tag,
271 typename std::enable_if
275 detail::is_supported_path_spec<String>,
276 is_format_tag<FormatTag>
278 >::type* /*dummy*/ = nullptr)
280 using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
282 reader_t reader = make_dynamic_image_reader(file_name, tag);
283 read_image(reader, images);
286 }} // namespace boost::gil