Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // Copyright 2012 Christian Henning
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_MAKE_DYNAMIC_IMAGE_READER_HPP
0009 #define BOOST_GIL_IO_MAKE_DYNAMIC_IMAGE_READER_HPP
0010 
0011 #include <boost/gil/detail/mp11.hpp>
0012 #include <boost/gil/io/get_reader.hpp>
0013 
0014 #include <type_traits>
0015 
0016 namespace boost { namespace gil {
0017 
0018 template <typename String, typename FormatTag>
0019 inline
0020 auto make_dynamic_image_reader(
0021     String const& file_name, image_read_settings<FormatTag> const& settings,
0022     typename std::enable_if
0023     <
0024         mp11::mp_and
0025         <
0026             detail::is_supported_path_spec<String>,
0027             is_format_tag<FormatTag>
0028         >::value
0029     >::type* /*dummy*/ = nullptr)
0030     -> typename get_dynamic_image_reader<String, FormatTag>::type
0031 {
0032     using device_t = typename get_read_device<String, FormatTag>::type;
0033     device_t device(
0034         detail::convert_to_native_string(file_name),
0035         typename detail::file_stream_device<FormatTag>::read_tag());
0036 
0037     return typename get_dynamic_image_reader<String, FormatTag>::type(device, settings);
0038 }
0039 
0040 template <typename FormatTag>
0041 inline
0042 auto make_dynamic_image_reader(
0043     std::wstring const& file_name, image_read_settings<FormatTag> const& settings)
0044     -> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
0045 {
0046     char const* str = detail::convert_to_native_string(file_name);
0047 
0048     using device_t = typename get_read_device<std::wstring, FormatTag>::type;
0049     device_t device(str, typename detail::file_stream_device<FormatTag>::read_tag());
0050 
0051     delete[] str; // TODO: RAII
0052 
0053     return
0054         typename get_dynamic_image_reader<std::wstring, FormatTag>::type(device, settings);
0055 }
0056 
0057 template <typename FormatTag>
0058 inline
0059 auto make_dynamic_image_reader(
0060     detail::filesystem::path const& path, image_read_settings<FormatTag> const& settings)
0061     -> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
0062 {
0063     return make_dynamic_image_reader(path.wstring(), settings);
0064 }
0065 
0066 template <typename Device, typename FormatTag>
0067 inline
0068 auto make_dynamic_image_reader(
0069     Device& file, image_read_settings<FormatTag> const& settings,
0070     typename std::enable_if
0071     <
0072         mp11::mp_and
0073         <
0074             detail::is_adaptable_input_device<FormatTag, Device>,
0075             is_format_tag<FormatTag>
0076         >::value
0077     >::type* /*dummy*/ = nullptr)
0078     -> typename get_dynamic_image_reader<Device, FormatTag>::type
0079 {
0080     typename get_read_device<Device, FormatTag>::type device(file);
0081     return typename get_dynamic_image_reader<Device, FormatTag>::type(device, settings);
0082 }
0083 
0084 // without image_read_settings
0085 
0086 template <typename String, typename FormatTag>
0087 inline
0088 auto make_dynamic_image_reader(String const& file_name, FormatTag const&,
0089     typename std::enable_if
0090     <
0091         mp11::mp_and
0092         <
0093             detail::is_supported_path_spec<String>,
0094             is_format_tag<FormatTag>
0095         >::value
0096     >::type* /*dummy*/ = nullptr)
0097     -> typename get_dynamic_image_reader<String, FormatTag>::type
0098 {
0099     return make_dynamic_image_reader(file_name, image_read_settings<FormatTag>());
0100 }
0101 
0102 template <typename FormatTag>
0103 inline
0104 auto make_dynamic_image_reader(std::wstring const& file_name, FormatTag const&)
0105     -> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
0106 {
0107     return make_dynamic_image_reader(file_name, image_read_settings<FormatTag>());
0108 }
0109 
0110 template <typename FormatTag>
0111 inline
0112 auto make_dynamic_image_reader(detail::filesystem::path const& path, FormatTag const&)
0113     -> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
0114 {
0115     return make_dynamic_image_reader(path.wstring(), image_read_settings<FormatTag>());
0116 }
0117 
0118 template <typename Device, typename FormatTag>
0119 inline
0120 auto make_dynamic_image_reader(Device& file, FormatTag const&,
0121     typename std::enable_if
0122     <
0123         mp11::mp_and
0124         <
0125             detail::is_adaptable_input_device<FormatTag, Device>,
0126             is_format_tag<FormatTag>
0127         >::value
0128     >::type* /*dummy*/ = nullptr)
0129     ->  typename get_dynamic_image_reader<Device, FormatTag>::type
0130 {
0131     return make_dynamic_image_reader(file, image_read_settings<FormatTag>());
0132 }
0133 
0134 }} // namespace boost::gil
0135 
0136 #endif