Boost GIL


read_and_convert_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_AND_CONVERT_IMAGE_HPP
9 #define BOOST_GIL_IO_READ_AND_CONVERT_IMAGE_HPP
10 
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>
17 
18 #include <type_traits>
19 
20 namespace boost{ namespace gil {
21 
23 
30 template <typename Reader, typename Image>
31 inline
32 void read_and_convert_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>
39  >::value
40  >::type* /*dummy*/ = nullptr)
41 {
42  reader.init_image(img, reader._settings);
43  reader.apply(view(img));
44 }
45 
52 template <typename Device, typename Image, typename ColorConverter, typename FormatTag>
53 inline
55  Device& device,
56  Image& img,
57  image_read_settings<FormatTag> const& settings,
58  ColorConverter const& cc,
59  typename std::enable_if
60  <
61  mp11::mp_and
62  <
63  detail::is_read_device<FormatTag, Device>,
64  is_format_tag<FormatTag>
65  >::value
66  >::type* /*dummy*/ = nullptr)
67 {
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;
70 
71  reader_t reader = make_reader(device, settings, read_and_convert_t{cc});
72  read_and_convert_image(reader, img);
73 }
74 
81 template <typename String, typename Image, typename ColorConverter, typename FormatTag>
82 inline
84  String const& file_name,
85  Image& img,
86  image_read_settings<FormatTag> const& settings,
87  ColorConverter const& cc,
88  typename std::enable_if
89  <
90  mp11::mp_and
91  <
92  is_format_tag<FormatTag>,
93  detail::is_supported_path_spec<String>
94  >::value
95  >::type* /*dummy*/ = nullptr)
96 {
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;
99 
100  reader_t reader = make_reader(file_name, settings, read_and_convert_t{cc});
101  read_and_convert_image(reader, img);
102 }
103 
110 template <typename String, typename Image, typename ColorConverter, typename FormatTag>
111 inline
113  String const& file_name,
114  Image& img,
115  ColorConverter const& cc,
116  FormatTag const& tag,
117  typename std::enable_if
118  <
119  mp11::mp_and
120  <
121  is_format_tag<FormatTag>,
122  detail::is_supported_path_spec<String>
123  >::value
124  >::type* /*dummy*/ = nullptr)
125 {
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;
128 
129  reader_t reader = make_reader(file_name, tag, read_and_convert_t{cc});
130  read_and_convert_image(reader, img);
131 }
132 
139 template <typename Device, typename Image, typename ColorConverter, typename FormatTag>
140 inline
142  Device& device,
143  Image& img,
144  ColorConverter const& cc,
145  FormatTag const& tag,
146  typename std::enable_if
147  <
148  mp11::mp_and
149  <
150  detail::is_read_device<FormatTag, Device>,
151  is_format_tag<FormatTag>
152  >::value
153  >::type* /*dummy*/ = nullptr)
154 {
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;
157 
158  reader_t reader = make_reader(device, tag, read_and_convert_t{cc});
159  read_and_convert_image(reader, img);
160 }
161 
167 template <typename String, typename Image, typename FormatTag>
168 inline void read_and_convert_image(
169  String const& file_name,
170  Image& img,
171  image_read_settings<FormatTag> const& settings,
172  typename std::enable_if
173  <
174  mp11::mp_and
175  <
176  is_format_tag<FormatTag>,
177  detail::is_supported_path_spec<String>
178  >::value
179  >::type* /*dummy*/ = nullptr)
180 {
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;
183 
184  reader_t reader = make_reader(file_name, settings, read_and_convert_t{});
185  read_and_convert_image(reader, img);
186 }
187 
193 template <typename Device, typename Image, typename FormatTag>
194 inline void read_and_convert_image(
195  Device& device,
196  Image& img,
197  image_read_settings<FormatTag> const& settings,
198  typename std::enable_if
199  <
200  mp11::mp_and
201  <
202  detail::is_read_device<FormatTag, Device>,
203  is_format_tag<FormatTag>
204  >::value
205  >::type* /*dummy*/ = nullptr)
206 {
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;
209 
210  reader_t reader = make_reader(device, settings, read_and_convert_t{});
211  read_and_convert_image(reader, img);
212 }
213 
219 template <typename String, typename Image, typename FormatTag>
220 inline
222  String const& file_name,
223  Image& img,
224  FormatTag const& tag,
225  typename std::enable_if
226  <
227  mp11::mp_and
228  <
229  is_format_tag<FormatTag>,
230  detail::is_supported_path_spec<String>
231  >::value
232  >::type* /*dummy*/ = nullptr)
233 {
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;
236 
237  reader_t reader = make_reader(file_name, tag, read_and_convert_t{});
238  read_and_convert_image(reader, img);
239 }
240 
246 template <typename Device, typename Image, typename FormatTag>
247 inline void read_and_convert_image(
248  Device& device,
249  Image& img,
250  FormatTag const& tag,
251  typename std::enable_if
252  <
253  mp11::mp_and
254  <
255  detail::is_read_device<FormatTag, Device>,
256  is_format_tag<FormatTag>
257  >::value
258  >::type* /*dummy*/ = nullptr)
259 {
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;
262 
263  reader_t reader = make_reader(device, tag, read_and_convert_t{});
264  read_and_convert_image(reader, img);
265 }
266 
267 }} // namespace boost::gil
268 
269 #endif
void read_and_convert_image(Reader &reader, Image &img, typename std::enable_if< mp11::mp_and< detail::is_reader< Reader >, is_format_tag< typename Reader::format_tag_t > >::value >::type *=nullptr)
Reads and color-converts an image. Image memory is allocated.
Definition: read_and_convert_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