Generic Image Library: make_dynamic_image_reader.hpp Source File

###  | #  |

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
16namespace boost { namespace gil {
17
18template <typename String, typename FormatTag>
19inline
20auto 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
40template <typename FormatTag>
41inline
42auto 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
57template <typename FormatTag>
58inline
59auto 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
66template <typename Device, typename FormatTag>
67inline
68auto 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
86template <typename String, typename FormatTag>
87inline
88auto 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
102template <typename FormatTag>
103inline
104auto 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
110template <typename FormatTag>
111inline
112auto 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
118template <typename Device, typename FormatTag>
119inline
120auto 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
boost
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36