Boost GIL


read_and_convert_view.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_VIEW_HPP
9 #define BOOST_GIL_IO_READ_AND_CONVERT_VIEW_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 
17 #include <boost/mpl/and.hpp>
18 #include <boost/type_traits/is_base_and_derived.hpp>
19 
20 #include <type_traits>
21 
22 namespace boost{ namespace gil {
23 
25 
32 template <typename Reader, typename View>
33 inline
34 void read_and_convert_view(Reader& reader, View const& view,
35  typename std::enable_if
36  <
37  mpl::and_
38  <
39  detail::is_reader<Reader>,
40  is_format_tag<typename Reader::format_tag_t>
41  >::value
42  >::type* /*dummy*/ = nullptr)
43 {
44  reader.check_image_size(view.dimensions());
45  reader.init_view(view, reader._settings);
46  reader.apply(view);
47 }
48 
55 template <typename Device, typename View, typename ColorConverter, typename FormatTag>
56 inline
58  Device& device,
59  View const& view,
60  image_read_settings<FormatTag> const& settings,
61  ColorConverter const& cc,
62  typename std::enable_if
63  <
64  mpl::and_
65  <
67  is_format_tag<FormatTag>
68  >::value
69  >::type* /*dummy*/ = nullptr)
70 {
71  using read_and_convert_t = detail::read_and_convert<ColorConverter>;
73 
74  reader_t reader = make_reader(device, settings, read_and_convert_t{cc});
75  read_and_convert_view(reader, view);
76 }
77 
84 template <typename String, typename View, typename ColorConverter, typename FormatTag>
85 inline
87  String const& file_name,
88  View const& view,
89  image_read_settings<FormatTag> const& settings,
90  ColorConverter const& cc,
91  typename std::enable_if
92  <
93  mpl::and_
94  <
95  is_format_tag<FormatTag>,
96  detail::is_supported_path_spec<String>
97  >::value
98  >::type* /*dummy*/ = nullptr)
99 {
100  using read_and_convert_t = detail::read_and_convert<ColorConverter>;
102 
103  reader_t reader = make_reader(file_name, settings, read_and_convert_t{cc});
104  read_and_convert_view(reader, view);
105 }
106 
113 template <typename String, typename View, typename ColorConverter, typename FormatTag>
114 inline
116  String const& file_name,
117  View const& view,
118  ColorConverter const& cc,
119  FormatTag const& tag,
120  typename std::enable_if
121  <
122  mpl::and_
123  <
124  is_format_tag<FormatTag>,
125  detail::is_supported_path_spec<String>
126  >::value
127  >::type* /*dummy*/ = nullptr)
128 {
129  using read_and_convert_t = detail::read_and_convert<ColorConverter>;
131 
132  reader_t reader = make_reader(file_name, tag, read_and_convert_t{cc});
133  read_and_convert_view(reader, view);
134 }
135 
142 template <typename Device, typename View, typename ColorConverter, typename FormatTag>
143 inline
145  Device& device,
146  View const& view,
147  ColorConverter const& cc,
148  FormatTag const& tag,
149  typename std::enable_if
150  <
151  mpl::and_
152  <
154  is_format_tag<FormatTag>
155  >::value
156  >::type* /*dummy*/ = nullptr)
157 {
158  using read_and_convert_t = detail::read_and_convert<ColorConverter>;
160 
161  reader_t reader = make_reader(device, tag, read_and_convert_t{cc});
162  read_and_convert_view(reader, view);
163 }
164 
170 template <typename String, typename View, typename FormatTag>
171 inline
173  String const& file_name,
174  View const& view,
175  image_read_settings<FormatTag> const& settings,
176  typename std::enable_if
177  <
178  mpl::and_
179  <
180  is_format_tag<FormatTag>,
181  detail::is_supported_path_spec<String>
182  >::value
183  >::type* /*dummy*/ = nullptr)
184 {
185  using read_and_convert_t = detail::read_and_convert<default_color_converter>;
187 
188  reader_t reader = make_reader(file_name, settings, read_and_convert_t{});
189  read_and_convert_view(reader, view);
190 }
191 
197 template <typename Device, typename View, typename FormatTag>
198 inline
200  Device& device,
201  View const& view,
202  image_read_settings<FormatTag> const& settings,
203  typename std::enable_if
204  <
205  mpl::and_
206  <
208  is_format_tag<FormatTag>
209  >::value
210  >::type* /*dummy*/ = nullptr)
211 {
212  using read_and_convert_t = detail::read_and_convert<default_color_converter>;
214 
215  reader_t reader = make_reader(device, settings, read_and_convert_t{});
216  read_and_convert_view(reader, view);
217 }
218 
224 template <typename String, typename View, typename FormatTag>
225 inline
227  String const& file_name,
228  View const& view,
229  FormatTag const& tag,
230  typename std::enable_if
231  <
232  mpl::and_
233  <
234  is_format_tag<FormatTag>,
235  detail::is_supported_path_spec<String>
236  >::value
237  >::type* /*dummy*/ = nullptr)
238 {
239  using read_and_convert_t = detail::read_and_convert<default_color_converter>;
241 
242  reader_t reader = make_reader(file_name, tag, read_and_convert_t{});
243  read_and_convert_view(reader, view);
244 }
245 
251 template <typename Device, typename View, typename FormatTag>
252 inline
254  Device& device,
255  View const& view,
256  FormatTag const& tag,
257  typename std::enable_if
258  <
259  mpl::and_
260  <
262  is_format_tag<FormatTag>
263  >::value
264  >::type* /*dummy*/ = nullptr)
265 {
266  using read_and_convert_t = detail::read_and_convert<default_color_converter>;
268 
269  reader_t reader = make_reader(device, tag, read_and_convert_t{});
270  read_and_convert_view(reader, view);
271 }
272 
273 }} // namespace boost::gill
274 
275 #endif
void read_and_convert_view(Reader &reader, View const &view, typename std::enable_if< mpl::and_< detail::is_reader< Reader >, is_format_tag< typename Reader::format_tag_t > >::value >::type *=nullptr)
Reads and color-converts an image view. No memory is allocated.
Definition: read_and_convert_view.hpp:34
Definition: algorithm.hpp:30
Definition: device.hpp:592
const image< Pixel, IsPlanar, Alloc >::view_t & view(image< Pixel, IsPlanar, Alloc > &img)
Returns the non-constant-pixel view of an image.
Definition: image.hpp:460
Helper metafunction to generate image reader type.
Definition: get_reader.hpp:27