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_VIEW_HPP
9 #define BOOST_GIL_IO_READ_AND_CONVERT_VIEW_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 view. No 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 View>
32 void read_and_convert_view(Reader& reader, View const& view,
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.check_image_size(view.dimensions());
43 reader.init_view(view, reader._settings);
47 /// \brief Reads and color-converts an image view. No memory is allocated.
48 /// \param file It's a device. Must satisfy is_input_device metafunction.
49 /// \param view The image view in which the data is read into.
50 /// \param settings Specifies read settings depending on the image format.
51 /// \param cc Color converter function object.
52 /// \throw std::ios_base::failure
53 template <typename Device, typename View, typename ColorConverter, typename FormatTag>
55 void read_and_convert_view(
58 image_read_settings<FormatTag> const& settings,
59 ColorConverter const& cc,
60 typename std::enable_if
64 detail::is_read_device<FormatTag, Device>,
65 is_format_tag<FormatTag>
67 >::type* /*dummy*/ = nullptr)
69 using read_and_convert_t = detail::read_and_convert<ColorConverter>;
70 using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
72 reader_t reader = make_reader(device, settings, read_and_convert_t{cc});
73 read_and_convert_view(reader, view);
76 /// \brief Reads and color-converts an image view. No memory is allocated.
77 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
78 /// \param view The image view in which the data is read into.
79 /// \param settings Specifies read settings depending on the image format.
80 /// \param cc Color converter function object.
81 /// \throw std::ios_base::failure
82 template <typename String, typename View, typename ColorConverter, typename FormatTag>
84 void read_and_convert_view(
85 String const& file_name,
87 image_read_settings<FormatTag> const& settings,
88 ColorConverter const& cc,
89 typename std::enable_if
93 is_format_tag<FormatTag>,
94 detail::is_supported_path_spec<String>
96 >::type* /*dummy*/ = nullptr)
98 using read_and_convert_t = detail::read_and_convert<ColorConverter>;
99 using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
101 reader_t reader = make_reader(file_name, settings, read_and_convert_t{cc});
102 read_and_convert_view(reader, view);
105 /// \brief Reads and color-converts an image view. No memory is allocated.
106 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
107 /// \param view The image view in which the data is read into.
108 /// \param cc Color converter function object.
109 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
110 /// \throw std::ios_base::failure
111 template <typename String, typename View, typename ColorConverter, typename FormatTag>
113 void read_and_convert_view(
114 String const& file_name,
116 ColorConverter const& cc,
117 FormatTag const& tag,
118 typename std::enable_if
122 is_format_tag<FormatTag>,
123 detail::is_supported_path_spec<String>
125 >::type* /*dummy*/ = nullptr)
127 using read_and_convert_t = detail::read_and_convert<ColorConverter>;
128 using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
130 reader_t reader = make_reader(file_name, tag, read_and_convert_t{cc});
131 read_and_convert_view(reader, view);
134 /// \brief Reads and color-converts an image view. No memory is allocated.
135 /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
136 /// \param view The image view in which the data is read into.
137 /// \param cc Color converter function object.
138 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
139 /// \throw std::ios_base::failure
140 template <typename Device, typename View, typename ColorConverter, typename FormatTag>
142 void read_and_convert_view(
145 ColorConverter const& cc,
146 FormatTag const& tag,
147 typename std::enable_if
151 detail::is_read_device<FormatTag, Device>,
152 is_format_tag<FormatTag>
154 >::type* /*dummy*/ = nullptr)
156 using read_and_convert_t = detail::read_and_convert<ColorConverter>;
157 using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
159 reader_t reader = make_reader(device, tag, read_and_convert_t{cc});
160 read_and_convert_view(reader, view);
163 /// \brief Reads and color-converts an image view. No memory is allocated.
164 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
165 /// \param view The image view in which the data is read into.
166 /// \param settings Specifies read settings depending on the image format.
167 /// \throw std::ios_base::failure
168 template <typename String, typename View, typename FormatTag>
170 void read_and_convert_view(
171 String const& file_name,
173 image_read_settings<FormatTag> const& settings,
174 typename std::enable_if
178 is_format_tag<FormatTag>,
179 detail::is_supported_path_spec<String>
181 >::type* /*dummy*/ = nullptr)
183 using read_and_convert_t = detail::read_and_convert<default_color_converter>;
184 using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
186 reader_t reader = make_reader(file_name, settings, read_and_convert_t{});
187 read_and_convert_view(reader, view);
190 /// \brief Reads and color-converts an image view. No memory is allocated.
191 /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
192 /// \param view The image view in which the data is read into.
193 /// \param settings Specifies read settings depending on the image format.
194 /// \throw std::ios_base::failure
195 template <typename Device, typename View, typename FormatTag>
197 void read_and_convert_view(
200 image_read_settings<FormatTag> const& settings,
201 typename std::enable_if
205 detail::is_read_device<FormatTag, Device>,
206 is_format_tag<FormatTag>
208 >::type* /*dummy*/ = nullptr)
210 using read_and_convert_t = detail::read_and_convert<default_color_converter>;
211 using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
213 reader_t reader = make_reader(device, settings, read_and_convert_t{});
214 read_and_convert_view(reader, view);
217 /// \brief Reads and color-converts an image view. No memory is allocated.
218 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
219 /// \param view The image view in which the data is read into.
220 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
221 /// \throw std::ios_base::failure
222 template <typename String, typename View, typename FormatTag>
224 void read_and_convert_view(
225 String const& file_name,
227 FormatTag const& tag,
228 typename std::enable_if
232 is_format_tag<FormatTag>,
233 detail::is_supported_path_spec<String>
235 >::type* /*dummy*/ = nullptr)
237 using read_and_convert_t = detail::read_and_convert<default_color_converter>;
238 using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
240 reader_t reader = make_reader(file_name, tag, read_and_convert_t{});
241 read_and_convert_view(reader, view);
244 /// \brief Reads and color-converts an image view. No memory is allocated.
245 /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
246 /// \param view The image view in which the data is read into.
247 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
248 /// \throw std::ios_base::failure
249 template <typename Device, typename View, typename FormatTag>
251 void read_and_convert_view(
254 FormatTag const& tag,
255 typename std::enable_if
259 detail::is_read_device<FormatTag, Device>,
260 is_format_tag<FormatTag>
262 >::type* /*dummy*/ = nullptr)
264 using read_and_convert_t = detail::read_and_convert<default_color_converter>;
265 using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
267 reader_t reader = make_reader(device, tag, read_and_convert_t{});
268 read_and_convert_view(reader, view);
271 }} // namespace boost::gill