Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:03

0001 //
0002 // Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 #ifndef BOOST_GIL_IO_READ_IMAGE_HPP
0009 #define BOOST_GIL_IO_READ_IMAGE_HPP
0010 
0011 #include <boost/gil/extension/toolbox/dynamic_images.hpp>
0012 
0013 #include <boost/gil/io/base.hpp>
0014 #include <boost/gil/io/conversion_policies.hpp>
0015 #include <boost/gil/io/device.hpp>
0016 #include <boost/gil/io/get_reader.hpp>
0017 #include <boost/gil/io/path_spec.hpp>
0018 #include <boost/gil/detail/mp11.hpp>
0019 
0020 #include <type_traits>
0021 
0022 namespace boost { namespace gil {
0023 
0024 /// \ingroup IO
0025 
0026 /// \brief Reads an image without conversion. Image memory is allocated.
0027 /// \param reader    An image reader.
0028 /// \param img       The image in which the data is read into. Must satisfy is_read_supported metafunction.
0029 /// \throw std::ios_base::failure
0030 template <typename Reader, typename Image>
0031 inline
0032 void read_image(Reader reader, Image& img,
0033     typename std::enable_if
0034     <
0035         mp11::mp_and
0036         <
0037             detail::is_reader<Reader>,
0038             is_format_tag<typename Reader::format_tag_t>,
0039             is_read_supported
0040             <
0041                 typename get_pixel_type<typename Image::view_t>::type,
0042                 typename Reader::format_tag_t
0043             >
0044         >::value
0045     >::type* /*dummy*/ = nullptr)
0046 {
0047     reader.init_image(img, reader._settings);
0048     reader.apply(view(img));
0049 }
0050 
0051 /// \brief Reads an image without conversion. Image memory is allocated.
0052 /// \param file      It's a device. Must satisfy is_input_device metafunction.
0053 /// \param img       The image in which the data is read into. Must satisfy is_read_supported metafunction.
0054 /// \param settings  Specifies read settings depending on the image format.
0055 /// \throw std::ios_base::failure
0056 template <typename Device, typename Image, typename FormatTag>
0057 inline
0058 void read_image(
0059     Device& file,
0060     Image& img,
0061     image_read_settings<FormatTag> const& settings,
0062     typename std::enable_if
0063     <
0064         mp11::mp_and
0065         <
0066             detail::is_read_device<FormatTag, Device>,
0067             is_format_tag<FormatTag>,
0068             is_read_supported
0069             <
0070                 typename get_pixel_type<typename Image::view_t>::type,
0071                 FormatTag
0072             >
0073         >::value
0074     >::type* /*dummy*/ = nullptr)
0075 {
0076     using reader_t =
0077         typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
0078 
0079     reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
0080     read_image(reader, img);
0081 }
0082 
0083 /// \brief Reads an image without conversion. Image memory is allocated.
0084 /// \param file      It's a device. Must satisfy is_input_device metafunction.
0085 /// \param img       The image in which the data is read into. Must satisfy is_read_supported metafunction.
0086 /// \param tag       Defines the image format. Must satisfy is_format_tag metafunction.
0087 /// \throw std::ios_base::failure
0088 template <typename Device, typename Image, typename FormatTag>
0089 inline
0090 void read_image(Device& file, Image& img, FormatTag const& tag,
0091     typename std::enable_if
0092     <
0093         mp11::mp_and
0094         <
0095             detail::is_read_device<FormatTag, Device>,
0096             is_format_tag<FormatTag>,
0097             is_read_supported
0098             <
0099                 typename get_pixel_type<typename Image::view_t>::type,
0100                 FormatTag
0101             >
0102         >::value
0103     >::type* /*dummy*/ = nullptr)
0104 {
0105     using reader_t =
0106         typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;
0107 
0108     reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
0109     read_image(reader, img);
0110 }
0111 
0112 /// \brief Reads an image without conversion. Image memory is allocated.
0113 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0114 /// \param img       The image in which the data is read into. Must satisfy is_read_supported metafunction.
0115 /// \param settings  Specifies read settings depending on the image format.
0116 /// \throw std::ios_base::failure
0117 template <typename String, typename Image, typename FormatTag>
0118 inline
0119 void read_image(
0120     String const& file_name,
0121     Image& img,
0122     image_read_settings<FormatTag> const& settings,
0123     typename std::enable_if
0124     <
0125         mp11::mp_and
0126         <
0127             detail::is_supported_path_spec<String>,
0128             is_format_tag<FormatTag>,
0129             is_read_supported
0130             <
0131                 typename get_pixel_type<typename Image::view_t>::type,
0132                 FormatTag
0133             >
0134         >::value
0135     >::type* /*dummy*/ = nullptr)
0136 {
0137     using reader_t =
0138         typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
0139 
0140     reader_t reader = make_reader(file_name, settings, detail::read_and_no_convert());
0141     read_image(reader, img);
0142 }
0143 
0144 /// \brief Reads an image without conversion. Image memory is allocated.
0145 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0146 /// \param img       The image in which the data is read into. Must satisfy is_read_supported metafunction.
0147 /// \param tag       Defines the image format. Must satisfy is_format_tag metafunction.
0148 /// \throw std::ios_base::failure
0149 template <typename String, typename Image, typename FormatTag>
0150 inline
0151 void read_image(String const& file_name, Image& img, FormatTag const& tag,
0152     typename std::enable_if
0153     <
0154         mp11::mp_and<detail::is_supported_path_spec<String>,
0155         is_format_tag<FormatTag>,
0156         is_read_supported
0157         <
0158             typename get_pixel_type<typename Image::view_t>::type,
0159             FormatTag
0160         >
0161     >::value
0162 >::type* /*dummy*/ = nullptr)
0163 {
0164     using reader_t =
0165         typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;
0166 
0167     reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
0168     read_image(reader, img);
0169 }
0170 
0171 ///
0172 
0173 template <typename Reader, typename ...Images>
0174 inline
0175 void read_image(Reader& reader, any_image<Images...>& images,
0176     typename std::enable_if
0177     <
0178         mp11::mp_and
0179         <
0180             detail::is_dynamic_image_reader<Reader>,
0181             is_format_tag<typename Reader::format_tag_t>
0182         >::value
0183     >::type* /*dummy*/ = nullptr)
0184 {
0185     reader.apply(images);
0186 }
0187 
0188 /// \brief Reads an image without conversion. Image memory is allocated.
0189 /// \param file      It's a device. Must satisfy is_adaptable_input_device metafunction.
0190 /// \param images    Dynamic image (mp11::mp_list). See boost::gil::dynamic_image extension.
0191 /// \param settings  Specifies read settings depending on the image format.
0192 /// \throw std::ios_base::failure
0193 template <typename Device, typename ...Images, typename FormatTag>
0194 inline
0195 void read_image(
0196     Device& file,
0197     any_image<Images...>& images,
0198     image_read_settings<FormatTag> const& settings,
0199     typename std::enable_if
0200     <
0201         mp11::mp_and
0202         <
0203             detail::is_read_device<FormatTag, Device>,
0204             is_format_tag<FormatTag>
0205         >::value
0206     >::type* /*dummy*/ = nullptr)
0207 {
0208     using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
0209 
0210     reader_t reader = make_dynamic_image_reader(file, settings);
0211     read_image(reader, images);
0212 }
0213 
0214 /// \brief Reads an image without conversion. Image memory is allocated.
0215 /// \param file      It's a device. Must satisfy is_adaptable_input_device metafunction.
0216 /// \param images    Dynamic image (mp11::mp_list). See boost::gil::dynamic_image extension.
0217 /// \param tag       Defines the image format. Must satisfy is_format_tag metafunction.
0218 /// \throw std::ios_base::failure
0219 template <typename Device, typename ...Images, typename FormatTag>
0220 inline
0221 void read_image(Device& file, any_image<Images...>& images, FormatTag const& tag,
0222     typename std::enable_if
0223     <
0224         mp11::mp_and
0225         <
0226             detail::is_read_device<FormatTag, Device>,
0227             is_format_tag<FormatTag>
0228         >::value
0229         >::type* /*dummy*/ = nullptr)
0230 {
0231     using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;
0232 
0233     reader_t reader = make_dynamic_image_reader(file, tag);
0234     read_image(reader, images);
0235 }
0236 
0237 /// \brief Reads an image without conversion. Image memory is allocated.
0238 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0239 /// \param images    Dynamic image (mp11::mp_list). See boost::gil::dynamic_image extension.
0240 /// \param settings  Specifies read settings depending on the image format.
0241 /// \throw std::ios_base::failure
0242 template <typename String, typename ...Images, typename FormatTag>
0243 inline
0244 void read_image(
0245     String const& file_name,
0246     any_image<Images...>& images,
0247     image_read_settings<FormatTag> const& settings,
0248     typename std::enable_if
0249     <
0250         mp11::mp_and
0251         <
0252             detail::is_supported_path_spec<String>,
0253             is_format_tag<FormatTag>
0254         >::value
0255     >::type* /*dummy*/ = nullptr)
0256 {
0257     using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
0258 
0259     reader_t reader = make_dynamic_image_reader(file_name, settings);
0260     read_image(reader, images);
0261 }
0262 
0263 /// \brief Reads an image without conversion. Image memory is allocated.
0264 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0265 /// \param images    Dynamic image (mp11::mp_list). See boost::gil::dynamic_image extension.
0266 /// \param tag       Defines the image format. Must satisfy is_format_tag metafunction.
0267 /// \throw std::ios_base::failure
0268 template <typename String, typename ...Images, typename FormatTag>
0269 inline
0270 void read_image(String const& file_name, any_image<Images...>& images, FormatTag const& tag,
0271     typename std::enable_if
0272     <
0273         mp11::mp_and
0274         <
0275             detail::is_supported_path_spec<String>,
0276             is_format_tag<FormatTag>
0277         >::value
0278     >::type* /*dummy*/ = nullptr)
0279 {
0280     using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;
0281 
0282     reader_t reader = make_dynamic_image_reader(file_name, tag);
0283     read_image(reader, images);
0284 }
0285 
0286 }}  // namespace boost::gil
0287 
0288 #endif