]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/test/extension/io/bmp/bmp_make.cpp
2 // Copyright 2013 Christian Henning
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
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>
13 #include <boost/gil.hpp>
14 #include <boost/gil/detail/mp11.hpp>
16 #include <boost/core/ignore_unused.hpp>
17 #include <boost/core/lightweight_test.hpp>
21 #include <type_traits>
25 namespace fs
= boost::filesystem
;
26 namespace gil
= boost::gil
;
28 void test_make_reader_backend()
32 std::is_same
<gil::detail::is_supported_path_spec
<char*>::type
, std::true_type
>::value
,
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());
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());
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());
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());
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
>());
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
>());
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
>());
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
>());
76 void test_make_reader()
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());
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());
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());
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());
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());
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());
110 std::ifstream
in(bmp_filename
.c_str(), std::ios::binary
);
111 gil::get_reader_backend
<std::ifstream
, gil::bmp_tag
>::type reader_ifstream
=
113 in
, gil::image_read_settings
<gil::bmp_tag
>(), gil::detail::read_and_no_convert());
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());
124 void test_make_dynamic_image_reader()
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());
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());
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());
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());
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
>());
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
>());
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
>());
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
>());
170 void test_make_writer()
172 // Empty files may be created, but noo image data is written.
174 using writer_t
= gil::get_writer
<char const*, gil::bmp_tag
>::type
;
177 std::is_same
<gil::detail::is_writer
<writer_t
>::type
, std::true_type
>::value
, "");
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());
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());
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
);
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());
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
>());
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
>());
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
);
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
>());
223 void test_make_dynamic_image_writer()
225 // Empty files may be created, but noo image data is written.
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());
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());
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
);
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());
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
>());
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
>());
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
>());
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
);
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
>());
274 int main(int argc
, char *argv
[])
278 test_make_reader_backend();
280 test_make_dynamic_image_reader();
282 test_make_dynamic_image_writer();
284 catch (std::exception
const& e
)
286 BOOST_ERROR(e
.what());
288 return boost::report_errors();