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_AND_CONVERT_IMAGE_HPP
9 #define BOOST_GIL_IO_READ_AND_CONVERT_IMAGE_HPP
11 #include <boost/gil/io/base.hpp>
12 #include <boost/gil/io/conversion_policies.hpp>
13 #include <boost/gil/io/device.hpp>
14 #include <boost/gil/io/get_reader.hpp>
15 #include <boost/gil/io/path_spec.hpp>
16 #include <boost/gil/detail/mp11.hpp>
18 #include <type_traits>
20 namespace boost{ namespace gil {
24 /// \brief Reads and color-converts an image. Image memory is allocated.
25 /// \param reader An image reader.
26 /// \param img The image in which the data is read into.
27 /// \param settings Specifies read settings depending on the image format.
28 /// \param cc Color converter function object.
29 /// \throw std::ios_base::failure
30 template <typename Reader, typename Image>
32 void read_and_convert_image(Reader& reader, Image& img,
33 typename std::enable_if
37 detail::is_reader<Reader>,
38 is_format_tag<typename Reader::format_tag_t>
40 >::type* /*dummy*/ = nullptr)
42 reader.init_image(img, reader._settings);
43 reader.apply(view(img));
46 /// \brief Reads and color-converts an image. Image memory is allocated.
47 /// \param device Must satisfy is_input_device metafunction.
48 /// \param img The image in which the data is read into.
49 /// \param settings Specifies read settings depending on the image format.
50 /// \param cc Color converter function object.
51 /// \throw std::ios_base::failure
52 template <typename Device, typename Image, typename ColorConverter, typename FormatTag>
54 void read_and_convert_image(
57 image_read_settings<FormatTag> const& settings,
58 ColorConverter const& cc,
59 typename std::enable_if
63 detail::is_read_device<FormatTag, Device>,
64 is_format_tag<FormatTag>
66 >::type* /*dummy*/ = nullptr)
68 using read_and_convert_t = detail::read_and_convert<ColorConverter>;
69 using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
71 reader_t reader = make_reader(device, settings, read_and_convert_t{cc});
72 read_and_convert_image(reader, img);
75 /// \brief Reads and color-converts an image. Image memory is allocated.
76 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
77 /// \param img The image in which the data is read into.
78 /// \param settings Specifies read settings depending on the image format.
79 /// \param cc Color converter function object.
80 /// \throw std::ios_base::failure
81 template <typename String, typename Image, typename ColorConverter, typename FormatTag>
83 void read_and_convert_image(
84 String const& file_name,
86 image_read_settings<FormatTag> const& settings,
87 ColorConverter const& cc,
88 typename std::enable_if
92 is_format_tag<FormatTag>,
93 detail::is_supported_path_spec<String>
95 >::type* /*dummy*/ = nullptr)
97 using read_and_convert_t = detail::read_and_convert<ColorConverter>;
98 using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
100 reader_t reader = make_reader(file_name, settings, read_and_convert_t{cc});
101 read_and_convert_image(reader, img);
104 /// \brief Reads and color-converts an image. Image memory is allocated.
105 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
106 /// \param img The image in which the data is read into.
107 /// \param cc Color converter function object.
108 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
109 /// \throw std::ios_base::failure
110 template <typename String, typename Image, typename ColorConverter, typename FormatTag>
112 void read_and_convert_image(
113 String const& file_name,
115 ColorConverter const& cc,
116 FormatTag const& tag,
117 typename std::enable_if
121 is_format_tag<FormatTag>,
122 detail::is_supported_path_spec<String>
124 >::type* /*dummy*/ = nullptr)
126 using read_and_convert_t = detail::read_and_convert<ColorConverter>;
127 using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
129 reader_t reader = make_reader(file_name, tag, read_and_convert_t{cc});
130 read_and_convert_image(reader, img);
133 /// \brief Reads and color-converts an image. Image memory is allocated.
134 /// \param device Must satisfy is_input_device metafunction or is_adaptable_input_device.
135 /// \param img The image in which the data is read into.
136 /// \param cc Color converter function object.
137 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
138 /// \throw std::ios_base::failure
139 template <typename Device, typename Image, typename ColorConverter, typename FormatTag>
141 void read_and_convert_image(
144 ColorConverter const& cc,
145 FormatTag const& tag,
146 typename std::enable_if
150 detail::is_read_device<FormatTag, Device>,
151 is_format_tag<FormatTag>
153 >::type* /*dummy*/ = nullptr)
155 using read_and_convert_t = detail::read_and_convert<ColorConverter>;
156 using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
158 reader_t reader = make_reader(device, tag, read_and_convert_t{cc});
159 read_and_convert_image(reader, img);
162 /// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
163 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
164 /// \param img The image in which the data is read into.
165 /// \param settings Specifies read settings depending on the image format.
166 /// \throw std::ios_base::failure
167 template <typename String, typename Image, typename FormatTag>
168 inline void read_and_convert_image(
169 String const& file_name,
171 image_read_settings<FormatTag> const& settings,
172 typename std::enable_if
176 is_format_tag<FormatTag>,
177 detail::is_supported_path_spec<String>
179 >::type* /*dummy*/ = nullptr)
181 using read_and_convert_t = detail::read_and_convert<default_color_converter>;
182 using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
184 reader_t reader = make_reader(file_name, settings, read_and_convert_t{});
185 read_and_convert_image(reader, img);
188 /// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
189 /// \param device It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
190 /// \param img The image in which the data is read into.
191 /// \param settings Specifies read settings depending on the image format.
192 /// \throw std::ios_base::failure
193 template <typename Device, typename Image, typename FormatTag>
194 inline void read_and_convert_image(
197 image_read_settings<FormatTag> const& settings,
198 typename std::enable_if
202 detail::is_read_device<FormatTag, Device>,
203 is_format_tag<FormatTag>
205 >::type* /*dummy*/ = nullptr)
207 using read_and_convert_t = detail::read_and_convert<default_color_converter>;
208 using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
210 reader_t reader = make_reader(device, settings, read_and_convert_t{});
211 read_and_convert_image(reader, img);
214 /// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
215 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
216 /// \param img The image in which the data is read into.
217 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
218 /// \throw std::ios_base::failure
219 template <typename String, typename Image, typename FormatTag>
221 void read_and_convert_image(
222 String const& file_name,
224 FormatTag const& tag,
225 typename std::enable_if
229 is_format_tag<FormatTag>,
230 detail::is_supported_path_spec<String>
232 >::type* /*dummy*/ = nullptr)
234 using read_and_convert_t = detail::read_and_convert<default_color_converter>;
235 using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
237 reader_t reader = make_reader(file_name, tag, read_and_convert_t{});
238 read_and_convert_image(reader, img);
241 /// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
242 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
243 /// \param img The image in which the data is read into.
244 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
245 /// \throw std::ios_base::failure
246 template <typename Device, typename Image, typename FormatTag>
247 inline void read_and_convert_image(
250 FormatTag const& tag,
251 typename std::enable_if
255 detail::is_read_device<FormatTag, Device>,
256 is_format_tag<FormatTag>
258 >::type* /*dummy*/ = nullptr)
260 using read_and_convert_t = detail::read_and_convert<default_color_converter>;
261 using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
263 reader_t reader = make_reader(device, tag, read_and_convert_t{});
264 read_and_convert_image(reader, img);
267 }} // namespace boost::gil