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 <cstdint>
14 #include <string>
15 
16 #include "tiff_tiled_write_macros.hpp"
17 
18 namespace gil = boost::gil;
19 
20 #ifdef BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
21 
22 BOOST_PP_REPEAT_FROM_TO(21, 31, GENERATE_WRITE_TILE_BIT_ALIGNED_RGB, rgb)
23 
test_write_tile_and_compare_with_rgb_strip_contig_32()24 void test_write_tile_and_compare_with_rgb_strip_contig_32()
25 {
26     std::string filename_strip(tiff_in_GM + "tiger-rgb-strip-contig-32.tif");
27 
28     using rgb32_pixel_t = gil::pixel<unsigned int, gil::rgb_layout_t>;
29     gil::image<rgb32_pixel_t, false> img_strip, img_saved;
30 
31     gil::read_image(filename_strip, img_strip, gil::tiff_tag());
32 
33     gil::image_write_info<gil::tiff_tag> info;
34     info._is_tiled   = true;
35     info._tile_width = info._tile_length = 16;
36 
37 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
38     gil::write_view(
39         tiff_out + "write_tile_and_compare_with_rgb_strip_contig_32.tif", gil::view(img_strip),
40         info);
41     gil::read_image(
42         tiff_out + "write_tile_and_compare_with_rgb_strip_contig_32.tif", img_saved,
43         gil::tiff_tag());
44 
45     BOOST_TEST(gil::equal_pixels(gil::const_view(img_strip), gil::const_view(img_saved)));
46 #endif  // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
47 }
48 
test_write_tile_and_compare_with_rgb_strip_contig_64()49 void test_write_tile_and_compare_with_rgb_strip_contig_64()
50 {
51     std::string filename_strip(tiff_in_GM + "tiger-rgb-strip-contig-64.tif");
52 
53     using rgb64_pixel_t = gil::pixel<std::uint64_t, gil::rgb_layout_t>;
54     gil::image<rgb64_pixel_t, false> img_strip, img_saved;
55 
56     gil::read_image(filename_strip, img_strip, gil::tiff_tag());
57 
58     gil::image_write_info<gil::tiff_tag> info;
59     info._is_tiled   = true;
60     info._tile_width = info._tile_length = 16;
61 
62 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
63     gil::write_view(
64         tiff_out + "write_tile_and_compare_with_rgb_strip_contig_64.tif", gil::view(img_strip),
65         info);
66     gil::read_image(
67         tiff_out + "write_tile_and_compare_with_rgb_strip_contig_64.tif", img_saved,
68         gil::tiff_tag());
69 
70     BOOST_TEST(gil::equal_pixels(gil::const_view(img_strip), gil::const_view(img_saved)));
71 #endif  // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
72 }
73 
main()74 int main()
75 {
76     test_write_tile_and_compare_with_rgb_strip_contig_32();
77     test_write_tile_and_compare_with_rgb_strip_contig_64();
78 
79     // TODO: Make sure generated test cases are executed. See tiff_subimage_test.cpp. ~mloskot
80 
81     return boost::report_errors();
82 }
83 
84 #else
main()85 int main() {}
86 #endif // BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
87