Generic Image Library: make_dynamic_image_writer.hpp Source File

###  | #  |

make_dynamic_image_writer.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_WRITER_HPP
9#define BOOST_GIL_IO_MAKE_DYNAMIC_IMAGE_WRITER_HPP
10
11#include <boost/gil/detail/mp11.hpp>
12#include <boost/gil/io/get_writer.hpp>
13
14#include <type_traits>
15
16namespace boost { namespace gil {
17
18template <typename String, typename FormatTag>
19inline
20auto make_dynamic_image_writer(
21 String const& file_name, image_write_info<FormatTag> const& info,
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_writer<String, FormatTag>::type
31{
32 using deveice_t = typename get_write_device<String, FormatTag>::type;
33 deveice_t device(
34 detail::convert_to_native_string(file_name),
35 typename detail::file_stream_device<FormatTag>::write_tag());
36
37 return typename get_dynamic_image_writer<String, FormatTag>::type(device, info);
38}
39
40template< typename FormatTag >
41inline
42auto make_dynamic_image_writer(std::wstring const& file_name, image_write_info<FormatTag> const& info)
43 -> typename get_dynamic_image_writer< std::wstring, FormatTag>::type
44{
45 const char* str = detail::convert_to_native_string( file_name );
46
47 typename get_write_device< std::wstring
48 , FormatTag
49 >::type device( str
50 , typename detail::file_stream_device< FormatTag >::write_tag()
51 );
52
53 delete[] str; // TODO: RAII
54
55 return typename get_dynamic_image_writer< std::wstring
56 , FormatTag
57 >::type( device
58 , info
59 );
60}
61
62template <typename FormatTag>
63inline
64auto make_dynamic_image_writer(detail::filesystem::path const& path, image_write_info<FormatTag> const& info)
65 -> typename get_dynamic_image_writer<std::wstring, FormatTag>::type
66{
67 return make_dynamic_image_writer(path.wstring(), info);
68}
69
70template <typename Device, typename FormatTag>
71inline
72auto make_dynamic_image_writer(Device& file, image_write_info<FormatTag> const& info,
73 typename std::enable_if
74 <
75 mp11::mp_and
76 <
77 typename detail::is_adaptable_output_device<FormatTag, Device>::type,
78 is_format_tag<FormatTag>
79 >::value
80 >::type* /*dummy*/ = nullptr)
81 -> typename get_dynamic_image_writer<Device, FormatTag>::type
82{
83 typename get_write_device<Device, FormatTag>::type device(file);
84 return typename get_dynamic_image_writer<Device, FormatTag>::type(device, info);
85}
86
87// no image_write_info
88
89template <typename String, typename FormatTag>
90inline
91auto make_dynamic_image_writer(String const& file_name, FormatTag const&,
92 typename std::enable_if
93 <
94 mp11::mp_and
95 <
96 detail::is_supported_path_spec<String>,
97 is_format_tag<FormatTag>
98 >::value
99 >::type* /*dummy*/ = nullptr)
100 -> typename get_dynamic_image_writer<String, FormatTag>::type
101{
102 return make_dynamic_image_writer(file_name, image_write_info<FormatTag>());
103}
104
105template <typename FormatTag>
106inline
107auto make_dynamic_image_writer(std::wstring const& file_name, FormatTag const&)
108 -> typename get_dynamic_image_writer<std::wstring, FormatTag>::type
109{
110 return make_dynamic_image_writer( file_name
111 , image_write_info< FormatTag >()
112 );
113}
114
115template <typename FormatTag>
116inline
117auto make_dynamic_image_writer(detail::filesystem::path const& path, FormatTag const&)
118 -> typename get_dynamic_image_writer<std::wstring, FormatTag>::type
119{
120 return make_dynamic_image_writer(path.wstring(), image_write_info<FormatTag>());
121}
122
123template <typename Device, typename FormatTag>
124inline
125auto make_dynamic_image_writer(Device& file, FormatTag const&,
126 typename std::enable_if
127 <
128 mp11::mp_and
129 <
130 typename detail::is_adaptable_output_device<FormatTag, Device>::type,
131 is_format_tag<FormatTag>
132 >::value
133 >::type* /*dummy*/ = nullptr)
134 -> typename get_dynamic_image_writer<Device, FormatTag>::type
135{
136 return make_dynamic_image_writer(file, image_write_info<FormatTag>());
137}
138
139}} // namespace boost::gil
140
141#endif
boost
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36
boost::gil::get_dynamic_image_writer
Helper metafunction to generate dynamic image writer type.
Definition get_writer.hpp:63