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_VIEW_HPP
9 #define BOOST_GIL_IO_READ_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 an image view without conversion. No memory is allocated.
25 /// \param reader An image reader.
26 /// \param view The image view in which the data is read into.
27 /// \param settings Specifies read settings depending on the image format.
28 /// \throw std::ios_base::failure
29 template <typename Reader, typename View>
31 void read_view(Reader reader, View const& view,
32 typename std::enable_if
36 detail::is_reader<Reader>,
37 typename is_format_tag<typename Reader::format_tag_t>::type,
38 typename is_read_supported
40 typename get_pixel_type<View>::type,
41 typename Reader::format_tag_t
44 >::type* /*dummy*/ = nullptr)
46 reader.check_image_size(view.dimensions());
47 reader.init_view(view, reader._settings);
51 /// \brief Reads an image view without conversion. No memory is allocated.
52 /// \param file It's a device. Must satisfy is_input_device metafunction.
53 /// \param view The image view in which the data is read into.
54 /// \param settings Specifies read settings depending on the image format.
55 /// \throw std::ios_base::failure
56 template <typename Device, typename View, typename FormatTag>
61 image_read_settings<FormatTag> const& settings,
62 typename std::enable_if
66 detail::is_read_device<FormatTag, Device>,
67 typename is_format_tag<FormatTag>::type,
68 typename is_read_supported
70 typename get_pixel_type<View>::type,
74 >::type* /*dummy*/ = nullptr)
77 typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
79 reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
80 read_view(reader, view);
83 /// \brief Reads an image view without conversion. No memory is allocated.
84 /// \param file It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
85 /// \param view The image view in which the data is read into.
86 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
87 /// \throw std::ios_base::failure
88 template <typename Device, typename View, typename FormatTag>
90 void read_view(Device& file, View const& view, FormatTag const& tag,
91 typename std::enable_if
95 typename is_format_tag<FormatTag>::type,
96 detail::is_read_device<FormatTag, Device>,
97 typename is_read_supported
99 typename get_pixel_type<View>::type,
102 >::value>::type* /*dummy*/ = nullptr)
105 typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
107 reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
108 read_view(reader, view);
111 /// \brief Reads an image view without conversion. No memory is allocated.
112 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
113 /// \param view The image view in which the data is read into.
114 /// \param settings Specifies read settings depending on the image format.
115 /// \throw std::ios_base::failure
116 template <typename String, typename View, typename FormatTag>
119 String const& file_name,
121 image_read_settings<FormatTag> const& settings,
122 typename std::enable_if
126 typename detail::is_supported_path_spec<String>::type,
127 typename is_format_tag<FormatTag>::type,
128 typename is_read_supported
130 typename get_pixel_type<View>::type,
134 >::type* /*dummy*/ = nullptr)
137 typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
139 reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
140 read_view(reader, view);
143 /// \brief Reads an image view without conversion. No memory is allocated.
144 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
145 /// \param view The image view in which the data is read into.
146 /// \param tag Defines the image format. Must satisfy is_format_tag metafunction.
147 /// \throw std::ios_base::failure
148 template <typename String, typename View, typename FormatTag>
150 void read_view(String const& file_name, View const& view, FormatTag const& tag,
151 typename std::enable_if
155 typename detail::is_supported_path_spec<String>::type,
156 typename is_format_tag<FormatTag>::type,
157 typename is_read_supported
159 typename get_pixel_type<View>::type,
163 >::type* /*dummy*/ = nullptr)
166 typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
168 reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
169 read_view(reader, view);
172 }} // namespace boost::gil