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 #include <boost/gil.hpp>
9 #include <boost/gil/extension/io/tiff.hpp>
10
11 #include <boost/core/lightweight_test.hpp>
12
13 #include <fstream>
14 #include <sstream>
15
16 #include "mandel_view.hpp"
17 #include "paths.hpp"
18 #include "subimage_test.hpp"
19
20 namespace gil = boost::gil;
21
22 #ifdef BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
23
24 #include <boost/preprocessor/cat.hpp>
25 #include <boost/preprocessor/stringize.hpp>
26 #include <boost/preprocessor/tuple/elem.hpp>
27 #include <boost/preprocessor/comparison/less.hpp>
28 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
29
30 #define BOOST_GIL_TEST_NAME_SUBIMAGE_TEST(n, data) \
31 BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(test_, BOOST_PP_CAT(data, _)), n), bit_bit_aligned)
32
33 #define BOOST_GIL_TEST_GENERATE_SUBIMAGE_TEST(z, n, data) \
34 void BOOST_GIL_TEST_NAME_SUBIMAGE_TEST(n, data) () \
35 { \
36 std::string filename_strip(tiff_in_GM + "tiger-" + BOOST_PP_STRINGIZE(data) + "-strip-"); \
37 std::string filename_tile(tiff_in_GM + "tiger-" + BOOST_PP_STRINGIZE(data) + "-tile-"); \
38 std::string padding(""); \
39 if (BOOST_PP_LESS(n, 10) == 1) \
40 padding = "0"; \
41 filename_strip = filename_strip + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
42 filename_tile = filename_tile + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
43 gil::bit_aligned_image1_type<n, gil::gray_layout_t>::type img1, img2, img3; \
44 gil::point_t top_left(10, 10); \
45 gil::point_t dim(32, 32); \
46 gil::image_read_settings<gil::tiff_tag> settings(top_left, dim); \
47 gil::read_image(filename_strip, img1, settings); \
48 gil::read_image(filename_tile, img2, settings); \
49 gil::read_image(filename_strip, img3, gil::tiff_tag()); \
50 BOOST_TEST(gil::equal_pixels(gil::const_view(img1), gil::const_view(img2))); \
51 BOOST_TEST(gil::equal_pixels( \
52 gil::const_view(img1), gil::subimage_view(gil::view(img3), top_left, dim))); \
53 }
54
55 #define BOOST_GIL_TEST_CALL_SUBIMAGE_TEST(z, n, data) \
56 BOOST_GIL_TEST_NAME_SUBIMAGE_TEST(n, data);
57
58 BOOST_PP_REPEAT_FROM_TO(1, 8, BOOST_GIL_TEST_GENERATE_SUBIMAGE_TEST, minisblack)
59 BOOST_PP_REPEAT_FROM_TO(9, 16, BOOST_GIL_TEST_GENERATE_SUBIMAGE_TEST, minisblack)
60 BOOST_PP_REPEAT_FROM_TO(17, 27, BOOST_GIL_TEST_GENERATE_SUBIMAGE_TEST, minisblack)
61 // TODO: there is a bug somewhere when the number of bits is 27 up to 31.
62
test_subimage_test_8()63 void test_subimage_test_8()
64 {
65 gil::gray8_image_t img1, img2, img3;
66 gil::point_t top_left(10, 10);
67 gil::point_t dim(32, 32);
68
69 gil::image_read_settings<gil::tiff_tag> settings(top_left, dim);
70
71 gil::read_image(tiff_in_GM + "tiger-minisblack-strip-08.tif", img1, settings);
72 gil::read_image(tiff_in_GM + "tiger-minisblack-tile-08.tif", img2, settings);
73 gil::read_image(tiff_in_GM + "tiger-minisblack-strip-08.tif", img3, gil::tiff_tag());
74
75 BOOST_TEST(gil::equal_pixels(gil::const_view(img1), gil::const_view(img2)));
76 BOOST_TEST(gil::equal_pixels(gil::const_view(img1), gil::subimage_view(gil::view(img3), top_left, dim)));
77 }
78
test_subimage_test_16()79 void test_subimage_test_16()
80 {
81 gil::gray16_image_t img1, img2, img3;
82 gil::point_t top_left(10, 10);
83 gil::point_t dim(32, 32);
84
85 gil::image_read_settings<gil::tiff_tag> settings(top_left, dim);
86
87 gil::read_image(tiff_in_GM + "tiger-minisblack-strip-16.tif", img1, settings);
88 gil::read_image(tiff_in_GM + "tiger-minisblack-tile-16.tif", img2, settings);
89 gil::read_image(tiff_in_GM + "tiger-minisblack-strip-16.tif", img3, gil::tiff_tag());
90
91 BOOST_TEST(gil::equal_pixels(gil::const_view(img1), gil::const_view(img2)));
92 BOOST_TEST(gil::equal_pixels(gil::const_view(img1), gil::subimage_view(gil::view(img3), top_left, dim)));
93 }
94
test_subimage_test_32()95 void test_subimage_test_32()
96 {
97 using gray32_pixel_t = gil::pixel<unsigned int, gil::gray_layout_t>;
98 gil::image<gray32_pixel_t, false> img1, img2, img3;
99
100 gil::point_t top_left(10, 10);
101 gil::point_t dim(32, 32);
102
103 gil::image_read_settings<gil::tiff_tag> settings(top_left, dim);
104
105 gil::read_image(tiff_in_GM + "tiger-minisblack-strip-32.tif", img1, settings);
106 gil::read_image(tiff_in_GM + "tiger-minisblack-tile-32.tif", img2, settings);
107 gil::read_image(tiff_in_GM + "tiger-minisblack-strip-32.tif", img3, gil::tiff_tag());
108
109 BOOST_TEST(gil::equal_pixels(gil::const_view(img1), gil::const_view(img2)));
110 BOOST_TEST(gil::equal_pixels(gil::const_view(img1), gil::subimage_view(gil::view(img3), top_left, dim)));
111 }
112
main()113 int main()
114 {
115 test_subimage_test_8();
116 test_subimage_test_16();
117 test_subimage_test_32();
118
119 BOOST_PP_REPEAT_FROM_TO(1, 8, BOOST_GIL_TEST_CALL_SUBIMAGE_TEST, minisblack)
120 BOOST_PP_REPEAT_FROM_TO(9, 16, BOOST_GIL_TEST_CALL_SUBIMAGE_TEST, minisblack)
121 BOOST_PP_REPEAT_FROM_TO(17, 27, BOOST_GIL_TEST_CALL_SUBIMAGE_TEST, minisblack)
122
123 return boost::report_errors();
124 }
125
126 #else
main()127 int main() {}
128 #endif // BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
129