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 
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 
31 template <typename Reader, typename View>
32 inline
33 void read_view(Reader reader, View const& view,
34  typename std::enable_if
35  <
36  mpl::and_
37  <
38  detail::is_reader<Reader>,
39  typename is_format_tag<typename Reader::format_tag_t>::type,
40  typename is_read_supported
41  <
42  typename get_pixel_type<View>::type,
43  typename Reader::format_tag_t
44  >::type
45  >::value
46  >::type* /*dummy*/ = nullptr)
47 {
48  reader.check_image_size(view.dimensions());
49  reader.init_view(view, reader._settings);
50  reader.apply(view);
51 }
52 
58 template <typename Device, typename View, typename FormatTag>
59 inline
60 void read_view(
61  Device& file,
62  View const& view,
63  image_read_settings<FormatTag> const& settings,
64  typename std::enable_if
65  <
66  mpl::and_
67  <
69  typename is_format_tag<FormatTag>::type,
70  typename is_read_supported
71  <
72  typename get_pixel_type<View>::type,
73  FormatTag
74  >::type
75  >::value
76  >::type* /*dummy*/ = nullptr)
77 {
78  using reader_t =
80 
81  reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
82  read_view(reader, view);
83 }
84 
90 template <typename Device, typename View, typename FormatTag>
91 inline
92 void read_view(Device& file, View const& view, FormatTag const& tag,
93  typename std::enable_if
94  <
95  mpl::and_
96  <
97  typename is_format_tag<FormatTag>::type,
99  typename is_read_supported
100  <
101  typename get_pixel_type<View>::type,
102  FormatTag
103  >::type
104  >::value>::type* /*dummy*/ = nullptr)
105 {
106  using reader_t =
108 
109  reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
110  read_view(reader, view);
111 }
112 
118 template <typename String, typename View, typename FormatTag>
119 inline
120 void read_view(
121  String const& file_name,
122  View const& view,
123  image_read_settings<FormatTag> const& settings,
124  typename std::enable_if
125  <
126  mpl::and_
127  <
128  typename detail::is_supported_path_spec<String>::type,
129  typename is_format_tag<FormatTag>::type,
130  typename is_read_supported
131  <
132  typename get_pixel_type<View>::type,
133  FormatTag
134  >::type
135  >::value
136  >::type* /*dummy*/ = nullptr)
137 {
138  using reader_t =
140 
141  reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
142  read_view(reader, view);
143 }
144 
150 template <typename String, typename View, typename FormatTag>
151 inline
152 void read_view(String const& file_name, View const& view, FormatTag const& tag,
153  typename std::enable_if
154  <
155  mpl::and_
156  <
157  typename detail::is_supported_path_spec<String>::type,
158  typename is_format_tag<FormatTag>::type,
159  typename is_read_supported
160  <
161  typename get_pixel_type<View>::type,
162  FormatTag
163  >::type
164  >::value
165  >::type* /*dummy*/ = nullptr)
166 {
167  using reader_t =
169 
170  reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
171  read_view(reader, view);
172 }
173 
174 }} // namespace boost::gil
175 
176 #endif
Definition: algorithm.hpp:30
Definition: base.hpp:80
Definition: device.hpp:592
void read_view(Reader reader, View const &view, typename std::enable_if< mpl::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:33
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