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_TEST_MODULE tiff_test
9 #define BOOST_FILESYSTEM_VERSION 3
10 #define BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
12 #include <boost/gil/extension/io/tiff.hpp>
14 #include <boost/mp11.hpp>
15 #include <boost/test/unit_test.hpp>
20 #include "mandel_view.hpp"
22 #include "subimage_test.hpp"
24 // This test file will only test the library's interface.
25 // It's more of a compile time test than a runtime test.
28 using namespace boost
;
30 namespace fs
= boost::filesystem
;
32 using tag_t
= tiff_tag
;
34 BOOST_AUTO_TEST_SUITE( gil_io_tiff_tests
)
36 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
38 BOOST_AUTO_TEST_CASE( read_image_info_test
)
41 using backend_t
= get_reader_backend
<std::string
const, tag_t
>::type
;
43 backend_t backend
= read_image_info( tiff_filename
47 BOOST_CHECK_EQUAL( backend
._info
._width
, 1000u );
48 BOOST_CHECK_EQUAL( backend
._info
._height
, 600u );
52 ifstream
in( tiff_filename
.c_str(), ios::binary
);
54 using backend_t
= get_reader_backend
<ifstream
, tag_t
>::type
;
56 backend_t backend
= read_image_info( in
60 BOOST_CHECK_EQUAL( backend
._info
._width
, 1000u );
61 BOOST_CHECK_EQUAL( backend
._info
._height
, 600u );
65 TIFF
* file
= TIFFOpen( tiff_filename
.c_str(), "r" );
67 using backend_t
= get_reader_backend
<FILE*, tag_t
>::type
;
69 backend_t backend
= read_image_info( file
73 BOOST_CHECK_EQUAL( backend
._info
._width
, 1000u );
74 BOOST_CHECK_EQUAL( backend
._info
._height
, 600u );
78 fs::path
my_path( tiff_filename
);
80 using backend_t
= get_reader_backend
<fs::path
, tag_t
>::type
;
82 backend_t backend
= read_image_info( my_path
87 BOOST_CHECK_EQUAL( backend
._info
._width
, 1000u );
88 BOOST_CHECK_EQUAL( backend
._info
._height
, 600u );
92 BOOST_AUTO_TEST_CASE( read_image_test
)
96 read_image( tiff_filename
, img
, tag_t() );
98 BOOST_CHECK_EQUAL( img
.width() , 1000u );
99 BOOST_CHECK_EQUAL( img
.height(), 600u );
104 ifstream
in( tiff_filename
.c_str(), ios::binary
);
107 read_image( in
, img
, tag_t() );
109 BOOST_CHECK_EQUAL( img
.width() , 1000u );
110 BOOST_CHECK_EQUAL( img
.height(), 600u );
114 TIFF
* file
= TIFFOpen( tiff_filename
.c_str(), "r" );
117 read_image( file
, img
, tag_t() );
119 BOOST_CHECK_EQUAL( img
.width() , 1000u );
120 BOOST_CHECK_EQUAL( img
.height(), 600u );
124 BOOST_AUTO_TEST_CASE( read_and_convert_image_test
)
128 read_and_convert_image( tiff_filename
, img
, tag_t() );
130 BOOST_CHECK_EQUAL( img
.width() , 1000u );
131 BOOST_CHECK_EQUAL( img
.height(), 600u );
135 ifstream
in( tiff_filename
.c_str(), ios::binary
);
138 read_and_convert_image( in
, img
, tag_t() );
140 BOOST_CHECK_EQUAL( img
.width() , 1000u );
141 BOOST_CHECK_EQUAL( img
.height(), 600u );
145 TIFF
* file
= TIFFOpen( tiff_filename
.c_str(), "r" );
148 read_and_convert_image( file
, img
, tag_t() );
150 BOOST_CHECK_EQUAL( img
.width() , 1000u );
151 BOOST_CHECK_EQUAL( img
.height(), 600u );
155 BOOST_AUTO_TEST_CASE( read_and_convert_image_test_2
)
158 read_and_convert_image( tiff_filename
, img
, tag_t() );
161 read_image( tiff_filename
, img2
, tag_t() );
164 BOOST_CHECK( equal_pixels( const_view( img
)
165 , color_converted_view
< gray8_pixel_t
>( const_view( img2
) )
170 BOOST_AUTO_TEST_CASE( read_view_test
)
173 rgba8_image_t
img( 1000, 600 );
174 read_view( tiff_filename
, view( img
), tag_t() );
178 ifstream
in( tiff_filename
.c_str(), ios::binary
);
180 rgba8_image_t
img( 1000, 600 );
181 read_view( in
, view( img
), tag_t() );
183 BOOST_CHECK_EQUAL( img
.width() , 1000u );
184 BOOST_CHECK_EQUAL( img
.height(), 600u );
188 TIFF
* file
= TIFFOpen( tiff_filename
.c_str(), "r" );
190 rgba8_image_t
img( 1000, 600 );
191 read_view( file
, view( img
), tag_t() );
195 BOOST_AUTO_TEST_CASE( read_and_convert_view_test
)
198 rgb8_image_t
img( 1000, 600 );
199 read_and_convert_view( tiff_filename
, view( img
), tag_t() );
203 ifstream
in( tiff_filename
.c_str(), ios::binary
);
205 rgb8_image_t
img( 1000, 600 );
206 read_and_convert_view( in
, view( img
), tag_t() );
208 BOOST_CHECK_EQUAL( img
.width() , 1000u );
209 BOOST_CHECK_EQUAL( img
.height(), 600u );
213 TIFF
* file
= TIFFOpen( tiff_filename
.c_str(), "r" );
215 rgb8_image_t
img( 1000, 600 );
216 read_and_convert_view( file
, view( img
), tag_t() );
220 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
222 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
223 BOOST_AUTO_TEST_CASE( write_view_test
)
226 string
filename( tiff_out
+ "write_test_string.tif" );
229 , create_mandel_view( 320, 240
230 , rgb8_pixel_t( 0, 0, 255 )
231 , rgb8_pixel_t( 0, 255, 0 )
238 string
filename( tiff_out
+ "write_test_ofstream.tif" );
239 ofstream
out( filename
.c_str(), ios_base::binary
);
242 , create_mandel_view( 320, 240
243 , rgb8_pixel_t( 0, 0, 255 )
244 , rgb8_pixel_t( 0, 255, 0 )
251 string
filename( tiff_out
+ "write_test_tiff.tif" );
252 TIFF
* file
= TIFFOpen( filename
.c_str(), "w" );
255 , create_mandel_view( 320, 240
256 , rgb8_pixel_t( 0, 0, 255 )
257 , rgb8_pixel_t( 0, 255, 0 )
264 string
filename( tiff_out
+ "write_test_info.tif" );
266 image_write_info
< tiff_tag
> info
;
268 , create_mandel_view( 320, 240
269 , rgb8_pixel_t( 0, 0, 255 )
270 , rgb8_pixel_t( 0, 255, 0 )
276 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
278 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
280 BOOST_AUTO_TEST_CASE( stream_test
)
283 ifstream
in( tiff_filename
.c_str(), ios::binary
);
286 read_image( in
, img
, tag_t() );
288 // 2. Write image to in-memory buffer.
289 stringstream
out_buffer( ios_base::in
| ios_base::out
| ios_base::binary
);
290 write_view( out_buffer
, view( img
), tag_t() );
292 // 3. Copy in-memory buffer to another.
293 stringstream
in_buffer( ios_base::in
| ios_base::out
| ios_base::binary
);
294 in_buffer
<< out_buffer
.rdbuf();
296 // 4. Read in-memory buffer to gil image
298 read_image( in_buffer
, dst
, tag_t() );
300 // 5. Write out image.
301 string
filename( tiff_out
+ "stream_test.tif" );
302 ofstream
out( filename
.c_str(), ios_base::binary
);
303 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
304 write_view( out
, view( dst
), tag_t() );
305 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
308 BOOST_AUTO_TEST_CASE( stream_test_2
)
311 if( !in_buf
.open( tiff_filename
.c_str(), ios::in
| ios::binary
) )
313 BOOST_CHECK( false );
316 istream
in( &in_buf
);
319 read_image( in
, img
, tag_t() );
322 BOOST_AUTO_TEST_CASE( subimage_test
)
324 run_subimage_test
< rgba8_image_t
, tag_t
>( tiff_filename
329 run_subimage_test
< rgba8_image_t
, tag_t
>( tiff_filename
335 BOOST_AUTO_TEST_CASE( dynamic_image_test
)
337 // FIXME: This test has been disabled for now because of compilation issues with MSVC10.
339 using my_img_types
= mp11::mp_list
347 any_image
< my_img_types
> runtime_image
;
349 read_image( tiff_filename
.c_str()
354 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
355 write_view( tiff_out
+ "dynamic_image_test.tif"
356 , view( runtime_image
)
359 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
362 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
364 BOOST_AUTO_TEST_SUITE_END()