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_AND_CONVERT_IMAGE_HPP
0009 #define BOOST_GIL_IO_READ_AND_CONVERT_IMAGE_HPP
0010 
0011 #include <boost/gil/io/base.hpp>
0012 #include <boost/gil/io/conversion_policies.hpp>
0013 #include <boost/gil/io/device.hpp>
0014 #include <boost/gil/io/get_reader.hpp>
0015 #include <boost/gil/io/path_spec.hpp>
0016 #include <boost/gil/detail/mp11.hpp>
0017 
0018 #include <type_traits>
0019 
0020 namespace boost{ namespace gil {
0021 
0022 /// \ingroup IO
0023 
0024 /// \brief Reads and color-converts an image. Image memory is allocated.
0025 /// \param reader    An image reader.
0026 /// \param img       The image in which the data is read into.
0027 /// \param settings  Specifies read settings depending on the image format.
0028 /// \param cc        Color converter function object.
0029 /// \throw std::ios_base::failure
0030 template <typename Reader, typename Image>
0031 inline
0032 void read_and_convert_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         >::value
0040     >::type* /*dummy*/ = nullptr)
0041 {
0042     reader.init_image(img, reader._settings);
0043     reader.apply(view(img));
0044 }
0045 
0046 /// \brief Reads and color-converts an image. Image memory is allocated.
0047 /// \param device    Must satisfy is_input_device metafunction.
0048 /// \param img       The image in which the data is read into.
0049 /// \param settings  Specifies read settings depending on the image format.
0050 /// \param cc        Color converter function object.
0051 /// \throw std::ios_base::failure
0052 template <typename Device, typename Image, typename ColorConverter, typename FormatTag>
0053 inline
0054 void read_and_convert_image(
0055     Device& device,
0056     Image& img,
0057     image_read_settings<FormatTag> const& settings,
0058     ColorConverter const& cc,
0059     typename std::enable_if
0060     <
0061         mp11::mp_and
0062         <
0063             detail::is_read_device<FormatTag, Device>,
0064             is_format_tag<FormatTag>
0065         >::value
0066     >::type* /*dummy*/ = nullptr)
0067 {
0068     using read_and_convert_t = detail::read_and_convert<ColorConverter>;
0069     using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
0070 
0071     reader_t reader = make_reader(device, settings, read_and_convert_t{cc});
0072     read_and_convert_image(reader, img);
0073 }
0074 
0075 /// \brief Reads and color-converts an image. Image memory is allocated.
0076 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0077 /// \param img       The image in which the data is read into.
0078 /// \param settings  Specifies read settings depending on the image format.
0079 /// \param cc        Color converter function object.
0080 /// \throw std::ios_base::failure
0081 template <typename String, typename Image, typename ColorConverter, typename FormatTag>
0082 inline
0083 void read_and_convert_image(
0084     String const& file_name,
0085     Image& img,
0086     image_read_settings<FormatTag> const& settings,
0087     ColorConverter const& cc,
0088     typename std::enable_if
0089     <
0090         mp11::mp_and
0091         <
0092             is_format_tag<FormatTag>,
0093             detail::is_supported_path_spec<String>
0094         >::value
0095     >::type* /*dummy*/ = nullptr)
0096 {
0097     using read_and_convert_t = detail::read_and_convert<ColorConverter>;
0098     using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
0099 
0100     reader_t reader = make_reader(file_name, settings, read_and_convert_t{cc});
0101     read_and_convert_image(reader, img);
0102 }
0103 
0104 /// \brief Reads and color-converts an image. Image memory is allocated.
0105 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0106 /// \param img       The image in which the data is read into.
0107 /// \param cc        Color converter function object.
0108 /// \param tag       Defines the image format. Must satisfy is_format_tag metafunction.
0109 /// \throw std::ios_base::failure
0110 template <typename String, typename Image, typename ColorConverter, typename FormatTag>
0111 inline
0112 void read_and_convert_image(
0113     String const& file_name,
0114     Image& img,
0115     ColorConverter const& cc,
0116     FormatTag const& tag,
0117     typename std::enable_if
0118     <
0119         mp11::mp_and
0120         <
0121             is_format_tag<FormatTag>,
0122             detail::is_supported_path_spec<String>
0123         >::value
0124     >::type* /*dummy*/ = nullptr)
0125 {
0126     using read_and_convert_t = detail::read_and_convert<ColorConverter>;
0127     using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
0128 
0129     reader_t reader = make_reader(file_name, tag, read_and_convert_t{cc});
0130     read_and_convert_image(reader, img);
0131 }
0132 
0133 /// \brief Reads and color-converts an image. Image memory is allocated.
0134 /// \param device Must satisfy is_input_device metafunction or is_adaptable_input_device.
0135 /// \param img    The image in which the data is read into.
0136 /// \param cc     Color converter function object.
0137 /// \param tag    Defines the image format. Must satisfy is_format_tag metafunction.
0138 /// \throw std::ios_base::failure
0139 template <typename Device, typename Image, typename ColorConverter, typename FormatTag>
0140 inline
0141 void read_and_convert_image(
0142     Device& device,
0143     Image& img,
0144     ColorConverter const& cc,
0145     FormatTag const& tag,
0146     typename std::enable_if
0147     <
0148         mp11::mp_and
0149         <
0150             detail::is_read_device<FormatTag, Device>,
0151             is_format_tag<FormatTag>
0152         >::value
0153     >::type* /*dummy*/ = nullptr)
0154 {
0155     using read_and_convert_t = detail::read_and_convert<ColorConverter>;
0156     using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
0157 
0158     reader_t reader = make_reader(device, tag, read_and_convert_t{cc});
0159     read_and_convert_image(reader, img);
0160 }
0161 
0162 /// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
0163 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0164 /// \param img       The image in which the data is read into.
0165 /// \param settings  Specifies read settings depending on the image format.
0166 /// \throw std::ios_base::failure
0167 template <typename String, typename Image, typename FormatTag>
0168 inline void read_and_convert_image(
0169     String const& file_name,
0170     Image& img,
0171     image_read_settings<FormatTag> const& settings,
0172     typename std::enable_if
0173     <
0174         mp11::mp_and
0175         <
0176             is_format_tag<FormatTag>,
0177             detail::is_supported_path_spec<String>
0178         >::value
0179     >::type* /*dummy*/ = nullptr)
0180 {
0181     using read_and_convert_t = detail::read_and_convert<default_color_converter>;
0182     using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
0183 
0184     reader_t reader = make_reader(file_name, settings, read_and_convert_t{});
0185     read_and_convert_image(reader, img);
0186 }
0187 
0188 /// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
0189 /// \param device    It's a device. Must satisfy is_input_device metafunction or is_adaptable_input_device.
0190 /// \param img       The image in which the data is read into.
0191 /// \param settings  Specifies read settings depending on the image format.
0192 /// \throw std::ios_base::failure
0193 template <typename Device, typename Image, typename FormatTag>
0194 inline void read_and_convert_image(
0195     Device& device,
0196     Image& img,
0197     image_read_settings<FormatTag> const& settings,
0198     typename std::enable_if
0199     <
0200         mp11::mp_and
0201         <
0202             detail::is_read_device<FormatTag, Device>,
0203             is_format_tag<FormatTag>
0204         >::value
0205     >::type* /*dummy*/ = nullptr)
0206 {
0207     using read_and_convert_t = detail::read_and_convert<default_color_converter>;
0208     using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
0209 
0210     reader_t reader = make_reader(device, settings, read_and_convert_t{});
0211     read_and_convert_image(reader, img);
0212 }
0213 
0214 /// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
0215 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0216 /// \param img       The image in which the data is read into.
0217 /// \param tag       Defines the image format. Must satisfy is_format_tag metafunction.
0218 /// \throw std::ios_base::failure
0219 template <typename String, typename Image, typename FormatTag>
0220 inline
0221 void read_and_convert_image(
0222     String const& file_name,
0223     Image& img,
0224     FormatTag const& tag,
0225     typename std::enable_if
0226     <
0227         mp11::mp_and
0228         <
0229             is_format_tag<FormatTag>,
0230             detail::is_supported_path_spec<String>
0231         >::value
0232     >::type* /*dummy*/ = nullptr)
0233 {
0234     using read_and_convert_t = detail::read_and_convert<default_color_converter>;
0235     using reader_t = typename get_reader<String, FormatTag, read_and_convert_t>::type;
0236 
0237     reader_t reader = make_reader(file_name, tag, read_and_convert_t{});
0238     read_and_convert_image(reader, img);
0239 }
0240 
0241 /// \brief Reads and color-converts an image. Image memory is allocated. Default color converter is used.
0242 /// \param file_name File name. Must satisfy is_supported_path_spec metafunction.
0243 /// \param img       The image in which the data is read into.
0244 /// \param tag       Defines the image format. Must satisfy is_format_tag metafunction.
0245 /// \throw std::ios_base::failure
0246 template <typename Device, typename Image, typename FormatTag>
0247 inline void read_and_convert_image(
0248     Device& device,
0249     Image& img,
0250     FormatTag const& tag,
0251     typename std::enable_if
0252     <
0253         mp11::mp_and
0254         <
0255             detail::is_read_device<FormatTag, Device>,
0256             is_format_tag<FormatTag>
0257         >::value
0258     >::type* /*dummy*/ = nullptr)
0259 {
0260     using read_and_convert_t = detail::read_and_convert<default_color_converter>;
0261     using reader_t = typename get_reader<Device, FormatTag, read_and_convert_t>::type;
0262 
0263     reader_t reader = make_reader(device, tag, read_and_convert_t{});
0264     read_and_convert_image(reader, img);
0265 }
0266 
0267 }} // namespace boost::gil
0268 
0269 #endif