Boost GIL


write_view.hpp
1 //
2 // Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
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_WRITE_VIEW_HPP
9 #define BOOST_GIL_IO_WRITE_VIEW_HPP
10 
11 #include <boost/gil/io/base.hpp>
12 #include <boost/gil/io/conversion_policies.hpp>
13 #include <boost/gil/io/device.hpp>
14 #include <boost/gil/io/get_writer.hpp>
15 #include <boost/gil/io/path_spec.hpp>
16 #include <boost/gil/detail/mp11.hpp>
17 
18 #include <type_traits>
19 
20 namespace boost{ namespace gil {
21 
23 template<typename Writer, typename View>
24 inline
25 void write_view(Writer& writer, View const& view,
26  typename std::enable_if
27  <
28  mp11::mp_and
29  <
30  typename detail::is_writer<Writer>::type,
31  typename is_format_tag<typename Writer::format_tag_t>::type,
32  typename is_write_supported
33  <
34  typename get_pixel_type<View>::type,
35  typename Writer::format_tag_t
36  >::type
37  >::value
38  >::type* /* ptr */ = nullptr)
39 {
40  writer.apply(view);
41 }
42 
44 template<typename Device, typename View, typename FormatTag>
45 inline
46 void write_view(Device& device, View const& view, FormatTag const& tag,
47  typename std::enable_if
48  <
49  mp11::mp_and
50  <
51  typename detail::is_write_device<FormatTag, Device>::type,
52  typename is_format_tag<FormatTag>::type,
53  typename is_write_supported
54  <
55  typename get_pixel_type<View>::type,
56  FormatTag
57  >::type
58  >::value
59  >::type* /* ptr */ = nullptr)
60 {
61  using writer_t = typename get_writer<Device, FormatTag>::type;
62  writer_t writer = make_writer(device, tag);
63  write_view(writer, view);
64 }
65 
67 template<typename String, typename View, typename FormatTag>
68 inline
69 void write_view(String const& file_name, View const& view, FormatTag const& tag,
70  typename std::enable_if
71  <
72  mp11::mp_and
73  <
74  typename detail::is_supported_path_spec<String>::type,
75  typename is_format_tag<FormatTag>::type,
76  typename is_write_supported
77  <
78  typename get_pixel_type<View>::type,
79  FormatTag
80  >::type
81  >::value
82  >::type* /* ptr */ = nullptr)
83 {
84  using writer_t = typename get_writer<String, FormatTag>::type;
85  writer_t writer = make_writer(file_name, tag);
86  write_view(writer, view);
87 }
88 
90 template<typename Device, typename View, typename FormatTag, typename Log>
91 inline
92 void write_view(
93  Device& device, View const& view, image_write_info<FormatTag, Log> const& info,
94  typename std::enable_if
95  <
96  mp11::mp_and
97  <
98  typename detail::is_write_device<FormatTag, Device>::type,
99  typename is_format_tag<FormatTag>::type,
100  typename is_write_supported
101  <
102  typename get_pixel_type<View>::type,
103  FormatTag
104  >::type
105  >::value
106  >::type* /* ptr */ = nullptr)
107 {
108  using writer_t = typename get_writer<Device, FormatTag>::type;
109  writer_t writer = make_writer(device, info);
110  write_view(writer, view);
111 }
112 
114 template<typename String, typename View, typename FormatTag, typename Log>
115 inline
116 void write_view(
117  String const& file_name, View const& view, image_write_info<FormatTag, Log> const& info,
118  typename std::enable_if
119  <
120  mp11::mp_and
121  <
122  typename detail::is_supported_path_spec<String>::type,
123  typename is_format_tag<FormatTag>::type,
124  typename is_write_supported
125  <
126  typename get_pixel_type<View>::type,
127  FormatTag
128  >::type
129  >::value
130  >::type* /* ptr */ = nullptr)
131 {
132  using writer_t = typename get_writer<String, FormatTag>::type;
133  writer_t writer = make_writer(file_name, info);
134  write_view(writer, view);
135 }
136 
138 
139 // without image_write_info
140 template <typename Writer, typename Views>
141 inline
142 void write_view(Writer& writer, any_image_view<Views> const& view,
143  typename std::enable_if
144  <
145  mp11::mp_and
146  <
147  typename detail::is_dynamic_image_writer<Writer>::type,
148  typename is_format_tag<typename Writer::format_tag_t>::type
149  >::value
150  >::type * /* ptr */ = nullptr)
151 {
152  writer.apply(view);
153 }
154 
155 // without image_write_info
156 template <typename Device, typename Views, typename FormatTag>
157 inline
158 void write_view(
159  Device& device, any_image_view<Views> const& views, FormatTag const& tag,
160  typename std::enable_if
161  <
162  mp11::mp_and
163  <
164  typename detail::is_write_device<FormatTag, Device>::type,
165  typename is_format_tag<FormatTag>::type
166  >::value
167  >::type * /* ptr */ = 0)
168 {
169  using writer_t = typename get_dynamic_image_writer<Device, FormatTag>::type;
170  writer_t writer = make_dynamic_image_writer(device, tag);
171  write_view(writer, views);
172 }
173 
174 template <typename String, typename Views, typename FormatTag>
175 inline
176 void write_view(
177  String const& file_name, any_image_view<Views> const& views, FormatTag const& tag,
178  typename std::enable_if
179  <
180  mp11::mp_and
181  <
182  typename detail::is_supported_path_spec<String>::type,
183  typename is_format_tag<FormatTag>::type
184  >::value
185  >::type * /* ptr */ = nullptr)
186 {
187  using writer_t = typename get_dynamic_image_writer<String, FormatTag>::type;
188  writer_t writer = make_dynamic_image_writer(file_name, tag);
189  write_view(writer, views);
190 }
191 
192 // with image_write_info
194 template <typename Device, typename Views, typename FormatTag, typename Log>
195 inline
196 void write_view(
197  Device& device, any_image_view<Views> const& views, image_write_info<FormatTag, Log> const& info,
198  typename std::enable_if
199  <
200  mp11::mp_and
201  <
202  typename detail::is_write_device<FormatTag, Device>::type,
203  typename is_format_tag<FormatTag>::type
204  >::value
205  >::type * /* ptr */ = 0)
206 {
207  using writer_t = typename get_dynamic_image_writer<Device, FormatTag>::type;
208  writer_t writer = make_dynamic_image_writer(device, info);
209  write_view(writer, views);
210 }
211 
212 template <typename String, typename Views, typename FormatTag, typename Log>
213 inline
214 void write_view(
215  String const& file_name, any_image_view<Views> const& views, image_write_info<FormatTag, Log> const& info,
216  typename std::enable_if
217  <
218  mp11::mp_and
219  <
220  typename detail::is_supported_path_spec<String>::type,
221  typename is_format_tag<FormatTag>::type
222  >::value
223  >::type * /* ptr */ = nullptr)
224 {
225  using writer_t = typename get_dynamic_image_writer<String, FormatTag>::type;
226  writer_t writer = make_dynamic_image_writer(file_name, info);
227  write_view(writer, views);
228 }
229 
230 }} // namespace boost::gil
231 
232 #endif
const image< Pixel, IsPlanar, Alloc >::view_t & view(image< Pixel, IsPlanar, Alloc > &img)
Returns the non-constant-pixel view of an image.
Definition: image.hpp:535