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