Boost GIL


read_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_VIEW_HPP
9 #define BOOST_GIL_IO_READ_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 #include <boost/gil/detail/mp11.hpp>
17 
18 #include <type_traits>
19 
20 namespace boost { namespace gil {
21 
23 
29 template <typename Reader, typename View>
30 inline
31 void read_view(Reader reader, View const& view,
32  typename std::enable_if
33  <
34  mp11::mp_and
35  <
36  detail::is_reader<Reader>,
37  typename is_format_tag<typename Reader::format_tag_t>::type,
38  typename is_read_supported
39  <
40  typename get_pixel_type<View>::type,
41  typename Reader::format_tag_t
42  >::type
43  >::value
44  >::type* /*dummy*/ = nullptr)
45 {
46  reader.check_image_size(view.dimensions());
47  reader.init_view(view, reader._settings);
48  reader.apply(view);
49 }
50 
56 template <typename Device, typename View, typename FormatTag>
57 inline
58 void read_view(
59  Device& file,
60  View const& view,
61  image_read_settings<FormatTag> const& settings,
62  typename std::enable_if
63  <
64  mp11::mp_and
65  <
66  detail::is_read_device<FormatTag, Device>,
67  typename is_format_tag<FormatTag>::type,
68  typename is_read_supported
69  <
70  typename get_pixel_type<View>::type,
71  FormatTag
72  >::type
73  >::value
74  >::type* /*dummy*/ = nullptr)
75 {
76  using reader_t =
77  typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
78 
79  reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
80  read_view(reader, view);
81 }
82 
88 template <typename Device, typename View, typename FormatTag>
89 inline
90 void read_view(Device& file, View const& view, FormatTag const& tag,
91  typename std::enable_if
92  <
93  mp11::mp_and
94  <
95  typename is_format_tag<FormatTag>::type,
96  detail::is_read_device<FormatTag, Device>,
97  typename is_read_supported
98  <
99  typename get_pixel_type<View>::type,
100  FormatTag
101  >::type
102  >::value>::type* /*dummy*/ = nullptr)
103 {
104  using reader_t =
105  typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
106 
107  reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
108  read_view(reader, view);
109 }
110 
116 template <typename String, typename View, typename FormatTag>
117 inline
118 void read_view(
119  String const& file_name,
120  View const& view,
121  image_read_settings<FormatTag> const& settings,
122  typename std::enable_if
123  <
124  mp11::mp_and
125  <
126  typename detail::is_supported_path_spec<String>::type,
127  typename is_format_tag<FormatTag>::type,
128  typename is_read_supported
129  <
130  typename get_pixel_type<View>::type,
131  FormatTag
132  >::type
133  >::value
134  >::type* /*dummy*/ = nullptr)
135 {
136  using reader_t =
137  typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
138 
139  reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
140  read_view(reader, view);
141 }
142 
148 template <typename String, typename View, typename FormatTag>
149 inline
150 void read_view(String const& file_name, View const& view, FormatTag const& tag,
151  typename std::enable_if
152  <
153  mp11::mp_and
154  <
155  typename detail::is_supported_path_spec<String>::type,
156  typename is_format_tag<FormatTag>::type,
157  typename is_read_supported
158  <
159  typename get_pixel_type<View>::type,
160  FormatTag
161  >::type
162  >::value
163  >::type* /*dummy*/ = nullptr)
164 {
165  using reader_t =
166  typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
167 
168  reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
169  read_view(reader, view);
170 }
171 
172 }} // namespace boost::gil
173 
174 #endif
void read_view(Reader reader, View const &view, typename std::enable_if< mp11::mp_and< detail::is_reader< Reader >, typename is_format_tag< typename Reader::format_tag_t >::type, typename is_read_supported< typename get_pixel_type< View >::type, typename Reader::format_tag_t >::type >::value >::type *=nullptr)
Reads an image view without conversion. No memory is allocated.
Definition: read_view.hpp:31
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
Definition: base.hpp:78