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

source code of boost/libs/gil/test/extension/io/tiff/tiff_tiled_write_macros.hpp