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/test/unit_test.hpp>
19 #include "mandel_view.hpp"
21 #include "subimage_test.hpp"
23 // This test file will only test the library's interface.
24 // It's more of a compile time test than a runtime test.
27 using namespace boost;
29 namespace fs = boost::filesystem;
31 using tag_t = tiff_tag;
33 BOOST_AUTO_TEST_SUITE( gil_io_tiff_tests )
35 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
37 BOOST_AUTO_TEST_CASE( read_image_info_test )
40 using backend_t = get_reader_backend<std::string const, tag_t>::type;
42 backend_t backend = read_image_info( tiff_filename
46 BOOST_CHECK_EQUAL( backend._info._width , 1000u );
47 BOOST_CHECK_EQUAL( backend._info._height, 600u );
51 ifstream in( tiff_filename.c_str(), ios::binary );
53 using backend_t = get_reader_backend<ifstream, tag_t>::type;
55 backend_t backend = read_image_info( in
59 BOOST_CHECK_EQUAL( backend._info._width , 1000u );
60 BOOST_CHECK_EQUAL( backend._info._height, 600u );
64 TIFF* file = TIFFOpen( tiff_filename.c_str(), "r" );
66 using backend_t = get_reader_backend<FILE*, tag_t>::type;
68 backend_t backend = read_image_info( file
72 BOOST_CHECK_EQUAL( backend._info._width , 1000u );
73 BOOST_CHECK_EQUAL( backend._info._height, 600u );
77 fs::path my_path( tiff_filename );
79 using backend_t = get_reader_backend<fs::path, tag_t>::type;
81 backend_t backend = read_image_info( my_path
86 BOOST_CHECK_EQUAL( backend._info._width , 1000u );
87 BOOST_CHECK_EQUAL( backend._info._height, 600u );
91 BOOST_AUTO_TEST_CASE( read_image_test )
95 read_image( tiff_filename, img, tag_t() );
97 BOOST_CHECK_EQUAL( img.width() , 1000u );
98 BOOST_CHECK_EQUAL( img.height(), 600u );
103 ifstream in( tiff_filename.c_str(), ios::binary );
106 read_image( in, img, tag_t() );
108 BOOST_CHECK_EQUAL( img.width() , 1000u );
109 BOOST_CHECK_EQUAL( img.height(), 600u );
113 TIFF* file = TIFFOpen( tiff_filename.c_str(), "r" );
116 read_image( file, img, tag_t() );
118 BOOST_CHECK_EQUAL( img.width() , 1000u );
119 BOOST_CHECK_EQUAL( img.height(), 600u );
123 BOOST_AUTO_TEST_CASE( read_and_convert_image_test )
127 read_and_convert_image( tiff_filename, img, tag_t() );
129 BOOST_CHECK_EQUAL( img.width() , 1000u );
130 BOOST_CHECK_EQUAL( img.height(), 600u );
134 ifstream in( tiff_filename.c_str(), ios::binary );
137 read_and_convert_image( in, img, tag_t() );
139 BOOST_CHECK_EQUAL( img.width() , 1000u );
140 BOOST_CHECK_EQUAL( img.height(), 600u );
144 TIFF* file = TIFFOpen( tiff_filename.c_str(), "r" );
147 read_and_convert_image( file, img, tag_t() );
149 BOOST_CHECK_EQUAL( img.width() , 1000u );
150 BOOST_CHECK_EQUAL( img.height(), 600u );
154 BOOST_AUTO_TEST_CASE( read_and_convert_image_test_2 )
157 read_and_convert_image( tiff_filename, img, tag_t() );
160 read_image( tiff_filename, img2, tag_t() );
163 BOOST_CHECK( equal_pixels( const_view( img )
164 , color_converted_view< gray8_pixel_t>( const_view( img2 ) )
169 BOOST_AUTO_TEST_CASE( read_view_test )
172 rgba8_image_t img( 1000, 600 );
173 read_view( tiff_filename, view( img ), tag_t() );
177 ifstream in( tiff_filename.c_str(), ios::binary );
179 rgba8_image_t img( 1000, 600 );
180 read_view( in, view( img ), tag_t() );
182 BOOST_CHECK_EQUAL( img.width() , 1000u );
183 BOOST_CHECK_EQUAL( img.height(), 600u );
187 TIFF* file = TIFFOpen( tiff_filename.c_str(), "r" );
189 rgba8_image_t img( 1000, 600 );
190 read_view( file, view( img ), tag_t() );
194 BOOST_AUTO_TEST_CASE( read_and_convert_view_test )
197 rgb8_image_t img( 1000, 600 );
198 read_and_convert_view( tiff_filename, view( img ), tag_t() );
202 ifstream in( tiff_filename.c_str(), ios::binary );
204 rgb8_image_t img( 1000, 600 );
205 read_and_convert_view( in, view( img ), tag_t() );
207 BOOST_CHECK_EQUAL( img.width() , 1000u );
208 BOOST_CHECK_EQUAL( img.height(), 600u );
212 TIFF* file = TIFFOpen( tiff_filename.c_str(), "r" );
214 rgb8_image_t img( 1000, 600 );
215 read_and_convert_view( file, view( img ), tag_t() );
219 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
221 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
222 BOOST_AUTO_TEST_CASE( write_view_test )
225 string filename( tiff_out + "write_test_string.tif" );
228 , create_mandel_view( 320, 240
229 , rgb8_pixel_t( 0, 0, 255 )
230 , rgb8_pixel_t( 0, 255, 0 )
237 string filename( tiff_out + "write_test_ofstream.tif" );
238 ofstream out( filename.c_str(), ios_base::binary );
241 , create_mandel_view( 320, 240
242 , rgb8_pixel_t( 0, 0, 255 )
243 , rgb8_pixel_t( 0, 255, 0 )
250 string filename( tiff_out + "write_test_tiff.tif" );
251 TIFF* file = TIFFOpen( filename.c_str(), "w" );
254 , create_mandel_view( 320, 240
255 , rgb8_pixel_t( 0, 0, 255 )
256 , rgb8_pixel_t( 0, 255, 0 )
263 string filename( tiff_out + "write_test_info.tif" );
265 image_write_info< tiff_tag > info;
267 , create_mandel_view( 320, 240
268 , rgb8_pixel_t( 0, 0, 255 )
269 , rgb8_pixel_t( 0, 255, 0 )
275 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
277 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
279 BOOST_AUTO_TEST_CASE( stream_test )
282 ifstream in( tiff_filename.c_str(), ios::binary );
285 read_image( in, img, tag_t() );
287 // 2. Write image to in-memory buffer.
288 stringstream out_buffer( ios_base::in | ios_base::out | ios_base::binary );
289 write_view( out_buffer, view( img ), tag_t() );
291 // 3. Copy in-memory buffer to another.
292 stringstream in_buffer( ios_base::in | ios_base::out | ios_base::binary );
293 in_buffer << out_buffer.rdbuf();
295 // 4. Read in-memory buffer to gil image
297 read_image( in_buffer, dst, tag_t() );
299 // 5. Write out image.
300 string filename( tiff_out + "stream_test.tif" );
301 ofstream out( filename.c_str(), ios_base::binary );
302 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
303 write_view( out, view( dst ), tag_t() );
304 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
307 BOOST_AUTO_TEST_CASE( stream_test_2 )
310 if( !in_buf.open( tiff_filename.c_str(), ios::in | ios::binary ) )
312 BOOST_CHECK( false );
315 istream in( &in_buf );
318 read_image( in, img, tag_t() );
321 BOOST_AUTO_TEST_CASE( subimage_test )
323 run_subimage_test< rgba8_image_t, tag_t >( tiff_filename
328 run_subimage_test< rgba8_image_t, tag_t >( tiff_filename
334 BOOST_AUTO_TEST_CASE( dynamic_image_test )
336 // This test has been disabled for now because of
337 // compilation issues with MSVC10.
339 using my_img_types = mpl::vector
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()