Imported Upstream version 1.71.0
[platform/upstream/boost.git] / libs / gil / io / test / tiff_tiled_write_macros.hpp
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 #ifndef BOOST_GIL_TIFF_TILED_WRITE_MACROS_HPP
9 #define BOOST_GIL_TIFF_TILED_WRITE_MACROS_HPP
10
11 #include <boost/gil.hpp>
12 #include <boost/gil/extension/io/tiff.hpp>
13
14 #include <boost/mpl/vector.hpp>
15 #include <boost/preprocessor/cat.hpp>
16 #include <boost/preprocessor/stringize.hpp>
17 #include <boost/preprocessor/tuple/elem.hpp>
18 #include <boost/preprocessor/comparison/less.hpp>
19 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
20
21 #include "paths.hpp"
22
23 using tag_t = boost::gil::tiff_tag;
24
25 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
26
27 #define GENERATE_WRITE_TILE_BIT_ALIGNED_RGB(z, n, data)\
28     BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_rgb_tile_and_compare_with_,data),_strip_),n), bit_bit_aligned) )\
29     { \
30       using namespace std; \
31       using namespace boost; \
32       using namespace gil; \
33       string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-contig-" ); \
34       string path( tiff_in_GM ); \
35       string padding(""); \
36       if(BOOST_PP_LESS(n, 10)==1) \
37         padding = "0"; \
38       filename += padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
39       path += filename; \
40       bit_aligned_image3_type< n, n, n, rgb_layout_t >::type img_strip, img_saved; \
41       read_image( path, img_strip, tag_t() ); \
42       image_write_info<tag_t> info; \
43       info._is_tiled = true; \
44       info._tile_width = info._tile_length = 16; \
45       write_view( tiff_out + filename, view(img_strip), info ); \
46       read_image( tiff_out + filename, img_saved, tag_t() ); \
47       BOOST_CHECK_EQUAL( equal_pixels( const_view(img_strip), const_view(img_saved) ), true); \
48     } \
49
50 // Special case for minisblack images
51 #define GENERATE_WRITE_TILE_BIT_ALIGNED_MINISBLACK(z, n, data)\
52     BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_minisblack_tile_and_compare_with_,data),_strip_),n), bit_bit_aligned) )\
53     { \
54       using namespace std; \
55       using namespace boost; \
56       using namespace gil; \
57       string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
58       string path( tiff_in_GM ); \
59       string padding(""); \
60       if(BOOST_PP_LESS(n, 10)==1) \
61         padding = "0"; \
62       filename = filename + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
63       path += filename; \
64       bit_aligned_image1_type< n, gray_layout_t >::type img_strip, img_saved; \
65       read_image( path, img_strip, tag_t() ); \
66       image_write_info<tag_t> info; \
67       info._is_tiled = true; \
68       info._tile_width = info._tile_length = 16; \
69       write_view( tiff_out + filename, view(img_strip), info ); \
70       read_image( tiff_out + filename, img_saved, tag_t() ); \
71       BOOST_CHECK_EQUAL( equal_pixels( const_view(img_strip), const_view(img_saved) ), true); \
72     } \
73
74 // Special case for palette images
75 #define GENERATE_WRITE_TILE_BIT_ALIGNED_PALETTE(z, n, data)\
76     BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_palette_tile_and_compare_with_,data),_strip_),n), bit) )\
77     { \
78       using namespace std; \
79       using namespace boost; \
80       using namespace gil; \
81       string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
82       string path( tiff_in_GM ); \
83       string padding(""); \
84       if(BOOST_PP_LESS(n, 10)==1) \
85         padding = "0"; \
86       filename = filename + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
87       path += filename; \
88       rgb16_image_t img_strip, img_saved; \
89       read_image( path, img_strip, tag_t() ); \
90       image_write_info<tag_t> info; \
91       info._is_tiled = true; \
92       info._tile_width = info._tile_length = 16; \
93       write_view( tiff_out + filename, view(img_strip), info ); \
94       read_image( tiff_out + filename, img_saved, tag_t() ); \
95       BOOST_CHECK_EQUAL( equal_pixels( const_view(img_strip), const_view(img_saved) ), true); \
96     } \
97
98 #else
99
100 #define GENERATE_WRITE_TILE_BIT_ALIGNED_RGB(z, n, data)\
101     BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_rgb_tile_and_compare_with_,data),_strip_),n), bit_bit_aligned) )\
102     { \
103       using namespace std; \
104       using namespace boost; \
105       using namespace gil; \
106       string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-contig-" ); \
107       string path( tiff_in_GM ); \
108       string padding(""); \
109       if(BOOST_PP_LESS(n, 10)==1) \
110         padding = "0"; \
111       filename += padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
112       path += filename; \
113       bit_aligned_image3_type< n, n, n, rgb_layout_t >::type img_strip, img_saved; \
114       read_image( path, img_strip, tag_t() ); \
115       image_write_info<tag_t> info; \
116       info._is_tiled = true; \
117       info._tile_width = info._tile_length = 16; \
118     } \
119
120 // Special case for minisblack images
121 #define GENERATE_WRITE_TILE_BIT_ALIGNED_MINISBLACK(z, n, data)\
122     BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_minisblack_tile_and_compare_with_,data),_strip_),n), bit_bit_aligned) )\
123     { \
124       using namespace std; \
125       using namespace boost; \
126       using namespace gil; \
127       string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
128       string path( tiff_in_GM ); \
129       string padding(""); \
130       if(BOOST_PP_LESS(n, 10)==1) \
131         padding = "0"; \
132       filename = filename + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
133       path += filename; \
134       bit_aligned_image1_type< n, gray_layout_t >::type img_strip, img_saved; \
135       read_image( path, img_strip, tag_t() ); \
136       image_write_info<tag_t> info; \
137       info._is_tiled = true; \
138       info._tile_width = info._tile_length = 16; \
139     } \
140
141 // Special case for palette images
142 #define GENERATE_WRITE_TILE_BIT_ALIGNED_PALETTE(z, n, data)\
143     BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_palette_tile_and_compare_with_,data),_strip_),n), bit) )\
144     { \
145       using namespace std; \
146       using namespace boost; \
147       using namespace gil; \
148       string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
149       string path( tiff_in_GM ); \
150       string padding(""); \
151       if(BOOST_PP_LESS(n, 10)==1) \
152         padding = "0"; \
153       filename = filename + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
154       path += filename; \
155       rgb16_image_t img_strip, img_saved; \
156       read_image( path, img_strip, tag_t() ); \
157       image_write_info<tag_t> info; \
158       info._is_tiled = true; \
159       info._tile_width = info._tile_length = 16; \
160     } \
161
162 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
163
164 #endif // BOOST_GIL_TIFF_TILED_READ_MACROS_HPP