]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/test/extension/io/bmp/bmp_make.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / gil / test / extension / io / bmp / bmp_make.cpp
1 //
2 // Copyright 2013 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 #define BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
9 #define BOOST_FILESYSTEM_VERSION 3
10 #include <boost/gil.hpp>
11 #include <boost/gil/extension/io/bmp.hpp>
12
13 #include <boost/gil.hpp>
14 #include <boost/gil/detail/mp11.hpp>
15
16 #include <boost/core/ignore_unused.hpp>
17 #include <boost/core/lightweight_test.hpp>
18
19 #include <fstream>
20 #include <string>
21 #include <type_traits>
22
23 #include "paths.hpp"
24
25 namespace fs = boost::filesystem;
26 namespace gil = boost::gil;
27
28 void test_make_reader_backend()
29 {
30 {
31 static_assert(
32 std::is_same<gil::detail::is_supported_path_spec<char*>::type, std::true_type>::value,
33 "");
34
35 gil::get_reader_backend<const char*, gil::bmp_tag>::type backend_char =
36 gil::make_reader_backend(bmp_filename.c_str(), gil::bmp_tag());
37 gil::get_reader_backend<std::string, gil::bmp_tag>::type backend_string =
38 gil::make_reader_backend(bmp_filename, gil::bmp_tag());
39
40 FILE* file = fopen(bmp_filename.c_str(), "rb");
41 gil::get_reader_backend<FILE*, gil::bmp_tag>::type backend_file =
42 gil::make_reader_backend(file, gil::bmp_tag());
43
44 std::ifstream in(bmp_filename.c_str(), std::ios::binary);
45 gil::get_reader_backend<std::ifstream, gil::bmp_tag>::type backend_ifstream =
46 gil::make_reader_backend(in, gil::bmp_tag());
47
48 fs::path my_path(bmp_filename);
49 gil::get_reader_backend<std::wstring, gil::bmp_tag>::type backend_wstring =
50 gil::make_reader_backend(my_path.wstring(), gil::bmp_tag());
51 gil::get_reader_backend<fs::path, gil::bmp_tag>::type backend_path =
52 gil::make_reader_backend(my_path, gil::bmp_tag());
53 }
54 {
55 gil::get_reader_backend<const char*, gil::bmp_tag>::type backend_char =
56 gil::make_reader_backend(bmp_filename.c_str(), gil::image_read_settings<gil::bmp_tag>());
57 gil::get_reader_backend<std::string, gil::bmp_tag>::type backend_string =
58 gil::make_reader_backend(bmp_filename, gil::image_read_settings<gil::bmp_tag>());
59
60 FILE* file = fopen(bmp_filename.c_str(), "rb");
61 gil::get_reader_backend<FILE*, gil::bmp_tag>::type backend_file =
62 gil::make_reader_backend(file, gil::image_read_settings<gil::bmp_tag>());
63
64 std::ifstream in(bmp_filename.c_str(), std::ios::binary);
65 gil::get_reader_backend<std::ifstream, gil::bmp_tag>::type backend_ifstream =
66 gil::make_reader_backend(in, gil::image_read_settings<gil::bmp_tag>());
67
68 fs::path my_path(bmp_filename);
69 gil::get_reader_backend<std::wstring, gil::bmp_tag>::type backend_wstring =
70 gil::make_reader_backend(my_path.wstring(), gil::image_read_settings<gil::bmp_tag>());
71 gil::get_reader_backend<fs::path, gil::bmp_tag>::type backend_path =
72 gil::make_reader_backend(my_path, gil::image_read_settings<gil::bmp_tag>());
73 }
74 }
75
76 void test_make_reader()
77 {
78 {
79 gil::get_reader_backend<const char*, gil::bmp_tag>::type reader_char = gil::make_reader(
80 bmp_filename.c_str(), gil::bmp_tag(), gil::detail::read_and_no_convert());
81 gil::get_reader_backend<std::string, gil::bmp_tag>::type reader_string =
82 gil::make_reader(bmp_filename, gil::bmp_tag(), gil::detail::read_and_no_convert());
83
84 FILE* file = fopen(bmp_filename.c_str(), "rb");
85 gil::get_reader_backend<FILE*, gil::bmp_tag>::type reader_file =
86 gil::make_reader(file, gil::bmp_tag(), gil::detail::read_and_no_convert());
87
88 std::ifstream in(bmp_filename.c_str(), std::ios::binary);
89 gil::get_reader_backend<std::ifstream, gil::bmp_tag>::type reader_ifstream =
90 gil::make_reader(in, gil::bmp_tag(), gil::detail::read_and_no_convert());
91
92 fs::path my_path(bmp_filename);
93 gil::get_reader_backend<std::wstring, gil::bmp_tag>::type reader_wstring =
94 gil::make_reader(my_path.wstring(), gil::bmp_tag(), gil::detail::read_and_no_convert());
95 gil::get_reader_backend<fs::path, gil::bmp_tag>::type reader_path =
96 gil::make_reader(my_path, gil::bmp_tag(), gil::detail::read_and_no_convert());
97 }
98 {
99 gil::get_reader_backend<const char*, gil::bmp_tag>::type reader_char = gil::make_reader(
100 bmp_filename.c_str(), gil::image_read_settings<gil::bmp_tag>(),
101 gil::detail::read_and_no_convert());
102 gil::get_reader_backend<std::string, gil::bmp_tag>::type reader_string = gil::make_reader(
103 bmp_filename, gil::image_read_settings<gil::bmp_tag>(),
104 gil::detail::read_and_no_convert());
105
106 FILE* file = fopen(bmp_filename.c_str(), "rb");
107 gil::get_reader_backend<FILE*, gil::bmp_tag>::type reader_file = gil::make_reader(
108 file, gil::image_read_settings<gil::bmp_tag>(), gil::detail::read_and_no_convert());
109
110 std::ifstream in(bmp_filename.c_str(), std::ios::binary);
111 gil::get_reader_backend<std::ifstream, gil::bmp_tag>::type reader_ifstream =
112 gil::make_reader(
113 in, gil::image_read_settings<gil::bmp_tag>(), gil::detail::read_and_no_convert());
114
115 fs::path my_path(bmp_filename);
116 gil::get_reader_backend<std::wstring, gil::bmp_tag>::type reader_wstring = gil::make_reader(
117 my_path.wstring(), gil::image_read_settings<gil::bmp_tag>(),
118 gil::detail::read_and_no_convert());
119 gil::get_reader_backend<fs::path, gil::bmp_tag>::type reader_path = gil::make_reader(
120 my_path, gil::image_read_settings<gil::bmp_tag>(), gil::detail::read_and_no_convert());
121 }
122 }
123
124 void test_make_dynamic_image_reader()
125 {
126 {
127 gil::get_dynamic_image_reader<const char*, gil::bmp_tag>::type reader_char =
128 gil::make_dynamic_image_reader(bmp_filename.c_str(), gil::bmp_tag());
129 gil::get_dynamic_image_reader<std::string, gil::bmp_tag>::type reader_string =
130 gil::make_dynamic_image_reader(bmp_filename, gil::bmp_tag());
131
132 FILE* file = fopen(bmp_filename.c_str(), "rb");
133 gil::get_dynamic_image_reader<FILE*, gil::bmp_tag>::type reader_file =
134 gil::make_dynamic_image_reader(file, gil::bmp_tag());
135
136 std::ifstream in(bmp_filename.c_str(), std::ios::binary);
137 gil::get_dynamic_image_reader<std::ifstream, gil::bmp_tag>::type reader_ifstream =
138 gil::make_dynamic_image_reader(in, gil::bmp_tag());
139
140 fs::path my_path(bmp_filename);
141 gil::get_dynamic_image_reader<std::wstring, gil::bmp_tag>::type reader_wstring =
142 gil::make_dynamic_image_reader(my_path.wstring(), gil::bmp_tag());
143 gil::get_dynamic_image_reader<fs::path, gil::bmp_tag>::type reader_path =
144 gil::make_dynamic_image_reader(my_path, gil::bmp_tag());
145 }
146 {
147 gil::get_dynamic_image_reader<const char*, gil::bmp_tag>::type reader_char =
148 gil::make_dynamic_image_reader(
149 bmp_filename.c_str(), gil::image_read_settings<gil::bmp_tag>());
150 gil::get_dynamic_image_reader<std::string, gil::bmp_tag>::type reader_string =
151 gil::make_dynamic_image_reader(bmp_filename, gil::image_read_settings<gil::bmp_tag>());
152
153 FILE* file = fopen(bmp_filename.c_str(), "rb");
154 gil::get_dynamic_image_reader<FILE*, gil::bmp_tag>::type reader_file =
155 gil::make_dynamic_image_reader(file, gil::image_read_settings<gil::bmp_tag>());
156
157 std::ifstream in(bmp_filename.c_str(), std::ios::binary);
158 gil::get_dynamic_image_reader<std::ifstream, gil::bmp_tag>::type reader_ifstream =
159 gil::make_dynamic_image_reader(in, gil::image_read_settings<gil::bmp_tag>());
160
161 fs::path my_path(bmp_filename);
162 gil::get_dynamic_image_reader<std::wstring, gil::bmp_tag>::type reader_wstring =
163 gil::make_dynamic_image_reader(
164 my_path.wstring(), gil::image_read_settings<gil::bmp_tag>());
165 gil::get_dynamic_image_reader<fs::path, gil::bmp_tag>::type reader_path =
166 gil::make_dynamic_image_reader(my_path, gil::image_read_settings<gil::bmp_tag>());
167 }
168 }
169
170 void test_make_writer()
171 {
172 // Empty files may be created, but noo image data is written.
173 {
174 using writer_t = gil::get_writer<char const*, gil::bmp_tag>::type;
175
176 static_assert(
177 std::is_same<gil::detail::is_writer<writer_t>::type, std::true_type>::value, "");
178 }
179 {
180 gil::get_writer<const char*, gil::bmp_tag>::type writer_char =
181 gil::make_writer((bmp_out + "make_test.bmp").c_str(), gil::bmp_tag());
182 gil::get_writer<std::string, gil::bmp_tag>::type writer_string =
183 gil::make_writer((bmp_out + "make_test.bmp"), gil::bmp_tag());
184
185 FILE* file = fopen((bmp_out + "make_test.bmp").c_str(), "wb");
186 gil::get_writer<FILE*, gil::bmp_tag>::type writer_file =
187 gil::make_writer(file, gil::bmp_tag());
188
189 std::ofstream out((bmp_out + "make_test.bmp").c_str(), std::ios::binary);
190 gil::get_writer<std::ofstream, gil::bmp_tag>::type writer_ofstream =
191 gil::make_writer(out, gil::image_write_info<gil::bmp_tag>());
192 boost::ignore_unused(writer_ofstream);
193
194 fs::path my_path((bmp_out + "make_test.bmp").c_str());
195 gil::get_writer<std::wstring, gil::bmp_tag>::type writer_wstring =
196 gil::make_writer(my_path.wstring(), gil::bmp_tag());
197 gil::get_writer<fs::path, gil::bmp_tag>::type writer_path =
198 gil::make_writer(my_path, gil::bmp_tag());
199 }
200 {
201 gil::get_writer<const char*, gil::bmp_tag>::type writer_char =
202 gil::make_writer((bmp_out + "make_test.bmp").c_str(), gil::image_write_info<gil::bmp_tag>());
203 gil::get_writer<std::string, gil::bmp_tag>::type writer_string =
204 gil::make_writer((bmp_out + "make_test.bmp"), gil::image_write_info<gil::bmp_tag>());
205
206 FILE* file = fopen((bmp_out + std::string("make_test.bmp")).c_str(), "wb");
207 gil::get_writer<FILE*, gil::bmp_tag>::type writer_file =
208 gil::make_writer(file, gil::image_write_info<gil::bmp_tag>());
209
210 std::ofstream out((bmp_out + "make_test.bmp").c_str(), std::ios::binary);
211 gil::get_writer<std::ofstream, gil::bmp_tag>::type writer_ofstream =
212 gil::make_writer(out, gil::image_write_info<gil::bmp_tag>());
213 boost::ignore_unused(writer_ofstream);
214
215 fs::path my_path(bmp_out + "make_test.bmp");
216 gil::get_writer<std::wstring, gil::bmp_tag>::type writer_wstring =
217 gil::make_writer(my_path.wstring(), gil::image_write_info<gil::bmp_tag>());
218 gil::get_writer<fs::path, gil::bmp_tag>::type writer_path =
219 gil::make_writer(my_path, gil::image_write_info<gil::bmp_tag>());
220 }
221 }
222
223 void test_make_dynamic_image_writer()
224 {
225 // Empty files may be created, but noo image data is written.
226 {
227 gil::get_dynamic_image_writer<const char*, gil::bmp_tag>::type writer_char =
228 gil::make_dynamic_image_writer(
229 (bmp_out + std::string("make_test.bmp")).c_str(), gil::bmp_tag());
230 gil::get_dynamic_image_writer<std::string, gil::bmp_tag>::type writer_string =
231 gil::make_dynamic_image_writer(bmp_out + "make_test.bmp", gil::bmp_tag());
232
233 FILE* file = fopen((bmp_out + std::string("make_test.bmp")).c_str(), "wb");
234 gil::get_dynamic_image_writer<FILE*, gil::bmp_tag>::type writer_file =
235 gil::make_dynamic_image_writer(file, gil::bmp_tag());
236
237 std::ofstream out((bmp_out + "make_test.bmp").c_str(), std::ios::binary);
238 gil::get_dynamic_image_writer<std::ofstream, gil::bmp_tag>::type writer_ofstream =
239 gil::make_dynamic_image_writer(out, gil::bmp_tag());
240 boost::ignore_unused(writer_ofstream);
241
242 fs::path my_path(bmp_out + "make_test.bmp");
243 gil::get_dynamic_image_writer<std::wstring, gil::bmp_tag>::type writer_wstring =
244 gil::make_dynamic_image_writer(my_path.wstring(), gil::bmp_tag());
245 gil::get_dynamic_image_writer<fs::path, gil::bmp_tag>::type writer_path =
246 gil::make_dynamic_image_writer(my_path, gil::bmp_tag());
247 }
248 {
249 gil::get_dynamic_image_writer<const char*, gil::bmp_tag>::type writer_char =
250 gil::make_dynamic_image_writer(
251 (bmp_out + std::string("make_test.bmp")).c_str(), gil::image_write_info<gil::bmp_tag>());
252
253 gil::get_dynamic_image_writer<std::string, gil::bmp_tag>::type writer_string =
254 gil::make_dynamic_image_writer(
255 bmp_out + "make_test.bmp", gil::image_write_info<gil::bmp_tag>());
256
257 FILE* file = fopen((bmp_out + std::string("make_test.bmp")).c_str(), "wb");
258 gil::get_dynamic_image_writer<FILE*, gil::bmp_tag>::type writer_file =
259 gil::make_dynamic_image_writer(file, gil::image_write_info<gil::bmp_tag>());
260
261 std::ofstream out((bmp_out + "make_test.bmp").c_str(), std::ios::binary);
262 gil::get_dynamic_image_writer<std::ofstream, gil::bmp_tag>::type writer_ofstream =
263 gil::make_dynamic_image_writer(out, gil::image_write_info<gil::bmp_tag>());
264 boost::ignore_unused(writer_ofstream);
265
266 fs::path my_path(bmp_out + "make_test.bmp");
267 gil::get_dynamic_image_writer<std::wstring, gil::bmp_tag>::type writer_wstring =
268 gil::make_dynamic_image_writer(my_path.wstring(), gil::image_write_info<gil::bmp_tag>());
269 gil::get_dynamic_image_writer<fs::path, gil::bmp_tag>::type writer_path =
270 gil::make_dynamic_image_writer(my_path, gil::image_write_info<gil::bmp_tag>());
271 }
272 }
273
274 int main(int argc, char *argv[])
275 {
276 try
277 {
278 test_make_reader_backend();
279 test_make_reader();
280 test_make_dynamic_image_reader();
281 test_make_writer();
282 test_make_dynamic_image_writer();
283 }
284 catch (std::exception const& e)
285 {
286 BOOST_ERROR(e.what());
287 }
288 return boost::report_errors();
289 }