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_subimage_test_module
10 #include <boost/gil/extension/io/tiff.hpp>
12 #include <boost/test/unit_test.hpp>
17 #include "mandel_view.hpp"
19 #include "subimage_test.hpp"
22 using namespace boost;
25 using tag_t = tiff_tag;
27 #include <boost/preprocessor/cat.hpp>
28 #include <boost/preprocessor/stringize.hpp>
29 #include <boost/preprocessor/tuple/elem.hpp>
30 #include <boost/preprocessor/comparison/less.hpp>
31 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
32 #define GENERATE_SUBIMAGE_TEST(z, n, data)\
33 BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(subimage_test,data),n), bit_bit_aligned) )\
35 using namespace std; \
36 using namespace boost; \
37 using namespace gil; \
38 string filename_strip( tiff_in_GM + "tiger-" + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
39 string filename_tile ( tiff_in_GM + "tiger-" + BOOST_PP_STRINGIZE(data) + "-tile-" ); \
41 if(BOOST_PP_LESS(n, 10)==1) \
43 filename_strip = filename_strip + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
44 filename_tile = filename_tile + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
45 bit_aligned_image1_type< n, gray_layout_t >::type img1, img2, img3; \
46 point_t top_left( 10, 10 ); \
47 point_t dim( 32, 32 ); \
48 image_read_settings< tag_t > settings( top_left, dim ); \
49 read_image( filename_strip, img1, settings ); \
50 read_image( filename_tile, img2 , settings ); \
51 read_image( filename_strip, img3, tag_t() ); \
52 BOOST_CHECK( equal_pixels( const_view( img1 ), const_view( img2 ))); \
53 BOOST_CHECK( equal_pixels( const_view( img1 ), subimage_view( view( img3 ), top_left, dim ))); \
56 BOOST_AUTO_TEST_SUITE( gil_io_tiff_tests )
58 #ifdef BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
60 BOOST_PP_REPEAT_FROM_TO( 1, 8, GENERATE_SUBIMAGE_TEST, minisblack )
61 BOOST_PP_REPEAT_FROM_TO( 9, 16, GENERATE_SUBIMAGE_TEST, minisblack )
62 BOOST_PP_REPEAT_FROM_TO( 17, 27, GENERATE_SUBIMAGE_TEST, minisblack )
63 // @todo: there is a bug somewhere when the number of bits is 27 up to 31.
66 BOOST_AUTO_TEST_CASE( subimage_test_8 )
68 gray8_image_t img1, img2, img3;
70 point_t top_left( 10, 10 );
71 point_t dim( 32, 32 );
73 image_read_settings< tag_t > settings( top_left, dim );
75 read_image( tiff_in_GM + "tiger-minisblack-strip-08.tif", img1, settings );
76 read_image( tiff_in_GM + "tiger-minisblack-tile-08.tif" , img2, settings );
77 read_image( tiff_in_GM + "tiger-minisblack-strip-08.tif", img3, tag_t() );
79 BOOST_CHECK( equal_pixels( const_view( img1 ), const_view( img2 )));
80 BOOST_CHECK( equal_pixels( const_view( img1 ), subimage_view( view( img3 ), top_left, dim )));
83 BOOST_AUTO_TEST_CASE( subimage_test_16 )
85 gray16_image_t img1, img2, img3;
87 point_t top_left( 10, 10 );
88 point_t dim( 32, 32 );
90 image_read_settings< tag_t > settings( top_left, dim );
92 read_image( tiff_in_GM + "tiger-minisblack-strip-16.tif", img1, settings );
93 read_image( tiff_in_GM + "tiger-minisblack-tile-16.tif" , img2, settings );
94 read_image( tiff_in_GM + "tiger-minisblack-strip-16.tif", img3, tag_t() );
96 BOOST_CHECK( equal_pixels( const_view( img1 ), const_view( img2 )));
97 BOOST_CHECK( equal_pixels( const_view( img1 ), subimage_view( view( img3 ), top_left, dim )));
100 BOOST_AUTO_TEST_CASE( subimage_test_32 )
102 using gray32_pixel_t = pixel<unsigned int, gray_layout_t>;
103 image< gray32_pixel_t, false > img1, img2, img3;
105 point_t top_left( 10, 10 );
106 point_t dim( 32, 32 );
108 image_read_settings< tag_t > settings( top_left, dim );
110 read_image( tiff_in_GM + "tiger-minisblack-strip-32.tif", img1, settings );
111 read_image( tiff_in_GM + "tiger-minisblack-tile-32.tif" , img2, settings );
112 read_image( tiff_in_GM + "tiger-minisblack-strip-32.tif", img3, tag_t() );
114 BOOST_CHECK( equal_pixels( const_view( img1 ), const_view( img2 )));
115 BOOST_CHECK( equal_pixels( const_view( img1 ), subimage_view( view( img3 ), top_left, dim )));
118 #endif // BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
120 BOOST_AUTO_TEST_SUITE_END()