Imported Upstream version 1.71.0
[platform/upstream/boost.git] / libs / gil / io / test / tiff_subimage_test.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_TEST_MODULE tiff_subimage_test_module
9
10 #include <boost/gil/extension/io/tiff.hpp>
11
12 #include <boost/test/unit_test.hpp>
13
14 #include <fstream>
15 #include <sstream>
16
17 #include "mandel_view.hpp"
18 #include "paths.hpp"
19 #include "subimage_test.hpp"
20
21 using namespace std;
22 using namespace boost;
23 using namespace gil;
24
25 using tag_t = tiff_tag;
26
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) )\
34     { \
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-"  ); \
40       string padding(""); \
41       if(BOOST_PP_LESS(n, 10)==1) \
42         padding = "0"; \
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 ))); \
54     } \
55
56 BOOST_AUTO_TEST_SUITE( gil_io_tiff_tests )
57
58 #ifdef BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
59
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.
64
65
66 BOOST_AUTO_TEST_CASE( subimage_test_8 )
67 {
68     gray8_image_t img1, img2, img3;
69
70     point_t top_left( 10, 10 );
71     point_t dim( 32, 32 );
72
73     image_read_settings< tag_t > settings( top_left, dim );
74
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()  );
78
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 )));
81 }
82
83 BOOST_AUTO_TEST_CASE( subimage_test_16 )
84 {
85     gray16_image_t img1, img2, img3;
86
87     point_t top_left( 10, 10 );
88     point_t dim( 32, 32 );
89
90     image_read_settings< tag_t > settings( top_left, dim );
91
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()  );
95
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 )));
98 }
99
100 BOOST_AUTO_TEST_CASE( subimage_test_32 )
101 {
102     using gray32_pixel_t = pixel<unsigned int, gray_layout_t>;
103     image< gray32_pixel_t, false > img1, img2, img3;
104
105     point_t top_left( 10, 10 );
106     point_t dim( 32, 32 );
107
108     image_read_settings< tag_t > settings( top_left, dim );
109
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()  );
113
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 )));
116 }
117
118 #endif // BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
119
120 BOOST_AUTO_TEST_SUITE_END()