Boost GIL


make_dynamic_image_reader.hpp
1 //
2 // Copyright 2012 Christian Henning
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_MAKE_DYNAMIC_IMAGE_READER_HPP
9 #define BOOST_GIL_IO_MAKE_DYNAMIC_IMAGE_READER_HPP
10 
11 #include <boost/gil/detail/mp11.hpp>
12 #include <boost/gil/io/get_reader.hpp>
13 
14 #include <type_traits>
15 
16 namespace boost { namespace gil {
17 
18 template <typename String, typename FormatTag>
19 inline
20 auto make_dynamic_image_reader(
21  String const& file_name, image_read_settings<FormatTag> const& settings,
22  typename std::enable_if
23  <
24  mp11::mp_and
25  <
26  detail::is_supported_path_spec<String>,
27  is_format_tag<FormatTag>
28  >::value
29  >::type* /*dummy*/ = nullptr)
30  -> typename get_dynamic_image_reader<String, FormatTag>::type
31 {
32  using device_t = typename get_read_device<String, FormatTag>::type;
33  device_t device(
34  detail::convert_to_native_string(file_name),
35  typename detail::file_stream_device<FormatTag>::read_tag());
36 
37  return typename get_dynamic_image_reader<String, FormatTag>::type(device, settings);
38 }
39 
40 template <typename FormatTag>
41 inline
42 auto make_dynamic_image_reader(
43  std::wstring const& file_name, image_read_settings<FormatTag> const& settings)
44  -> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
45 {
46  char const* str = detail::convert_to_native_string(file_name);
47 
48  using device_t = typename get_read_device<std::wstring, FormatTag>::type;
49  device_t device(str, typename detail::file_stream_device<FormatTag>::read_tag());
50 
51  delete[] str; // TODO: RAII
52 
53  return
54  typename get_dynamic_image_reader<std::wstring, FormatTag>::type(device, settings);
55 }
56 
57 template <typename FormatTag>
58 inline
59 auto make_dynamic_image_reader(
60  detail::filesystem::path const& path, image_read_settings<FormatTag> const& settings)
61  -> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
62 {
63  return make_dynamic_image_reader(path.wstring(), settings);
64 }
65 
66 template <typename Device, typename FormatTag>
67 inline
68 auto make_dynamic_image_reader(
69  Device& file, image_read_settings<FormatTag> const& settings,
70  typename std::enable_if
71  <
72  mp11::mp_and
73  <
74  detail::is_adaptable_input_device<FormatTag, Device>,
75  is_format_tag<FormatTag>
76  >::value
77  >::type* /*dummy*/ = nullptr)
78  -> typename get_dynamic_image_reader<Device, FormatTag>::type
79 {
80  typename get_read_device<Device, FormatTag>::type device(file);
81  return typename get_dynamic_image_reader<Device, FormatTag>::type(device, settings);
82 }
83 
84 // without image_read_settings
85 
86 template <typename String, typename FormatTag>
87 inline
88 auto make_dynamic_image_reader(String const& file_name, FormatTag const&,
89  typename std::enable_if
90  <
91  mp11::mp_and
92  <
93  detail::is_supported_path_spec<String>,
94  is_format_tag<FormatTag>
95  >::value
96  >::type* /*dummy*/ = nullptr)
97  -> typename get_dynamic_image_reader<String, FormatTag>::type
98 {
99  return make_dynamic_image_reader(file_name, image_read_settings<FormatTag>());
100 }
101 
102 template <typename FormatTag>
103 inline
104 auto make_dynamic_image_reader(std::wstring const& file_name, FormatTag const&)
105  -> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
106 {
107  return make_dynamic_image_reader(file_name, image_read_settings<FormatTag>());
108 }
109 
110 template <typename FormatTag>
111 inline
112 auto make_dynamic_image_reader(detail::filesystem::path const& path, FormatTag const&)
113  -> typename get_dynamic_image_reader<std::wstring, FormatTag>::type
114 {
115  return make_dynamic_image_reader(path.wstring(), image_read_settings<FormatTag>());
116 }
117 
118 template <typename Device, typename FormatTag>
119 inline
120 auto make_dynamic_image_reader(Device& file, FormatTag const&,
121  typename std::enable_if
122  <
123  mp11::mp_and
124  <
125  detail::is_adaptable_input_device<FormatTag, Device>,
126  is_format_tag<FormatTag>
127  >::value
128  >::type* /*dummy*/ = nullptr)
129  -> typename get_dynamic_image_reader<Device, FormatTag>::type
130 {
131  return make_dynamic_image_reader(file, image_read_settings<FormatTag>());
132 }
133 
134 }} // namespace boost::gil
135 
136 #endif
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36