]>
Commit | Line | Data |
---|---|---|
92f5a8d4 | 1 | // |
f67539c2 | 2 | // Copyright 2019-2020 Mateusz Loskot <mateusz at loskot dot net> |
92f5a8d4 TL |
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/channel.hpp> | |
92f5a8d4 | 9 | #include <boost/gil/gray.hpp> |
f67539c2 | 10 | #include <boost/gil/packed_pixel.hpp> |
92f5a8d4 TL |
11 | #include <boost/gil/rgb.hpp> |
12 | ||
92f5a8d4 | 13 | #include <boost/mp11.hpp> |
f67539c2 TL |
14 | #include <boost/core/lightweight_test.hpp> |
15 | #include <boost/core/typeinfo.hpp> | |
92f5a8d4 | 16 | |
f67539c2 | 17 | #include "test_fixture.hpp" |
92f5a8d4 TL |
18 | |
19 | namespace gil = boost::gil; | |
f67539c2 | 20 | namespace fixture = boost::gil::test::fixture; |
92f5a8d4 TL |
21 | namespace mp11 = boost::mp11; |
22 | ||
f67539c2 | 23 | void test_packed_pixel_gray3_definition() |
92f5a8d4 TL |
24 | { |
25 | // Verify packed_pixel members | |
26 | ||
f67539c2 | 27 | static_assert(std::is_same<fixture::packed_pixel_gray3::layout_t, gil::gray_layout_t>::value, |
92f5a8d4 TL |
28 | "layout should be bgr"); |
29 | ||
f67539c2 | 30 | static_assert(std::is_same<fixture::packed_pixel_gray3::value_type, fixture::packed_pixel_gray3>::value, |
92f5a8d4 TL |
31 | "value_type member should be of the same type as the packed_pixel specialization"); |
32 | ||
f67539c2 | 33 | static_assert(std::is_reference<fixture::packed_pixel_gray3::reference>::value, |
92f5a8d4 TL |
34 | "reference member should be a reference"); |
35 | ||
f67539c2 | 36 | static_assert(std::is_reference<fixture::packed_pixel_gray3::const_reference>::value, |
92f5a8d4 TL |
37 | "const_reference member should be a reference"); |
38 | ||
f67539c2 TL |
39 | static_assert(std::is_same<decltype(fixture::packed_pixel_gray3::is_mutable), bool const>::value && |
40 | fixture::packed_pixel_gray3::is_mutable, | |
92f5a8d4 TL |
41 | "is_mutable should be boolean"); |
42 | ||
43 | // Verify metafunctions | |
44 | ||
f67539c2 | 45 | static_assert(mp11::mp_size<fixture::packed_channel_references_3>::value == 1, |
92f5a8d4 TL |
46 | "packed_channel_references_vector_type should define one reference to channel start bits"); |
47 | ||
f67539c2 | 48 | using channel1_ref_t = mp11::mp_at_c<fixture::packed_channel_references_3, 0>; |
92f5a8d4 TL |
49 | static_assert(channel1_ref_t::num_bits == 3, |
50 | "1st channel of gray3 pixel should be of 3-bit size"); | |
51 | ||
52 | static_assert(std::is_same | |
53 | < | |
54 | channel1_ref_t, | |
55 | gil::packed_channel_reference<std::uint8_t, 0, 3, true> const | |
56 | >::value, | |
57 | "1st element of packed_channel_references_vector should be packed_channel_reference of 1st channel"); | |
58 | ||
59 | // double check intermediate metafunction packed_channel_reference_type | |
60 | static_assert(std::is_same | |
61 | < | |
62 | gil::detail::packed_channel_reference_type | |
63 | < | |
64 | std::uint8_t, | |
65 | std::integral_constant<int, 0>, | |
66 | std::integral_constant<int, 3> | |
67 | >::type, | |
68 | channel1_ref_t | |
69 | >::value, | |
70 | "packed_channel_reference_type should return packed_channel_reference"); | |
71 | static_assert(std::is_same | |
72 | < | |
73 | gil::detail::packed_channel_reference_type | |
74 | < | |
75 | std::uint8_t, | |
76 | std::integral_constant<int, 0>, | |
77 | std::integral_constant<int, 3> | |
78 | >::type, | |
79 | gil::packed_channel_reference<std::uint8_t, 0, 3, true> const | |
80 | >::value, | |
81 | "packed_channel_reference_type should return packed_channel_reference"); | |
82 | } | |
83 | ||
f67539c2 | 84 | void test_packed_pixel_gray3_assignment() |
92f5a8d4 | 85 | { |
f67539c2 TL |
86 | fixture::packed_pixel_gray3 p1{int{5}}; |
87 | fixture::packed_pixel_gray3 p2; | |
92f5a8d4 | 88 | p2 = p1; |
f67539c2 | 89 | BOOST_TEST_EQ(p1._bitfield, p2._bitfield); |
92f5a8d4 TL |
90 | } |
91 | ||
f67539c2 | 92 | void test_packed_pixel_gray3_equality() |
92f5a8d4 | 93 | { |
f67539c2 TL |
94 | fixture::packed_pixel_gray3 p1{int{5}}; |
95 | fixture::packed_pixel_gray3 p2{int{5}}; | |
96 | BOOST_TEST_EQ(p1, p2); | |
92f5a8d4 | 97 | |
f67539c2 TL |
98 | fixture::packed_pixel_gray3 p3{int{3}}; |
99 | BOOST_TEST_NE(p2, p3); | |
92f5a8d4 TL |
100 | } |
101 | ||
f67539c2 | 102 | void test_packed_pixel_gray3_assignment_gray_channel() |
92f5a8d4 TL |
103 | { |
104 | { | |
f67539c2 | 105 | fixture::packed_pixel_gray3 p1; // default-initialized |
92f5a8d4 | 106 | p1 = int{5}; |
f67539c2 | 107 | BOOST_TEST_EQ(p1._bitfield, int{5}); |
92f5a8d4 TL |
108 | } |
109 | ||
110 | { | |
f67539c2 | 111 | fixture::packed_pixel_gray3 p1{0}; // value-initialized |
92f5a8d4 | 112 | p1 = int{5}; |
f67539c2 | 113 | BOOST_TEST_EQ(p1._bitfield, int{5}); |
92f5a8d4 TL |
114 | } |
115 | } | |
116 | ||
f67539c2 | 117 | void test_packed_pixel_gray3_equality_gray_channel() |
92f5a8d4 | 118 | { |
f67539c2 TL |
119 | fixture::packed_pixel_gray3 p1{int{3}}; |
120 | BOOST_TEST_EQ(p1, int{3}); | |
92f5a8d4 TL |
121 | } |
122 | ||
f67539c2 | 123 | void test_packed_pixel_bgr121_definition() |
92f5a8d4 TL |
124 | { |
125 | // Verify packed_pixel members | |
126 | ||
f67539c2 | 127 | static_assert(std::is_same<fixture::packed_pixel_bgr121::layout_t, gil::bgr_layout_t>::value, |
92f5a8d4 TL |
128 | "layout should be bgr"); |
129 | ||
f67539c2 | 130 | static_assert(std::is_same<fixture::packed_pixel_bgr121::value_type, fixture::packed_pixel_bgr121>::value, |
92f5a8d4 TL |
131 | "value_type member should be of the same type as the packed_pixel specialization"); |
132 | ||
f67539c2 | 133 | static_assert(std::is_reference<fixture::packed_pixel_bgr121::reference>::value, |
92f5a8d4 TL |
134 | "reference member should be a reference"); |
135 | ||
f67539c2 | 136 | static_assert(std::is_reference<fixture::packed_pixel_bgr121::const_reference>::value, |
92f5a8d4 TL |
137 | "const_reference member should be a reference"); |
138 | ||
f67539c2 TL |
139 | static_assert(std::is_same<decltype(fixture::packed_pixel_bgr121::is_mutable), bool const>::value && |
140 | fixture::packed_pixel_bgr121::is_mutable, | |
92f5a8d4 TL |
141 | "is_mutable should be boolean"); |
142 | ||
143 | // Verify metafunctions | |
144 | ||
f67539c2 | 145 | static_assert(mp11::mp_size<fixture::packed_channel_references_121>::value == 3, |
92f5a8d4 TL |
146 | "packed_channel_references_vector_type should define three references to channel start bits"); |
147 | ||
f67539c2 | 148 | using channel1_ref_t = mp11::mp_at_c<fixture::packed_channel_references_121, 0>; |
92f5a8d4 TL |
149 | static_assert(channel1_ref_t::num_bits == 1, |
150 | "1st channel of bgr121 pixel should be of 1-bit size"); | |
151 | ||
f67539c2 | 152 | using channel2_ref_t = mp11::mp_at_c<fixture::packed_channel_references_121, 1>; |
92f5a8d4 TL |
153 | static_assert(channel2_ref_t::num_bits == 2, |
154 | "2nd channel of bgr121 pixel should be of 2-bit size"); | |
155 | ||
f67539c2 | 156 | using channel3_ref_t = mp11::mp_at_c<fixture::packed_channel_references_121, 2>; |
92f5a8d4 TL |
157 | static_assert(channel3_ref_t::num_bits == 1, |
158 | "3rd channel of bgr121 pixel should be of 1-bit size"); | |
159 | ||
160 | static_assert(std::is_same | |
161 | < | |
162 | channel1_ref_t, | |
163 | gil::packed_channel_reference<std::uint8_t, 0, 1, true> const | |
164 | >::value, | |
165 | "1st element of packed_channel_references_vector should be packed_channel_reference of 1st channel"); | |
166 | ||
167 | static_assert(std::is_same | |
168 | < | |
169 | channel2_ref_t, | |
170 | gil::packed_channel_reference<std::uint8_t, 1, 2, true> const | |
171 | >::value, | |
172 | "2nd element of packed_channel_references_vector should be packed_channel_reference of 2nd channel"); | |
173 | ||
174 | static_assert(std::is_same | |
175 | < | |
176 | channel3_ref_t, | |
177 | gil::packed_channel_reference<std::uint8_t, 3, 1, true> const | |
178 | >::value, | |
179 | "3rd element of packed_channel_references_vector should be packed_channel_reference of 3rd channel"); | |
180 | ||
181 | // double check intermediate metafunction packed_channel_reference_type | |
182 | static_assert(std::is_same | |
183 | < | |
184 | gil::detail::packed_channel_reference_type | |
185 | < | |
186 | std::uint8_t, mp11::mp_int<0>, mp11::mp_int<1> | |
187 | >::type, | |
188 | channel1_ref_t | |
189 | >::value, | |
190 | "packed_channel_reference_type should return packed_channel_reference"); | |
191 | static_assert(std::is_same | |
192 | < | |
193 | gil::detail::packed_channel_reference_type | |
194 | < | |
195 | std::uint8_t, mp11::mp_int<0>, mp11::mp_int<1> | |
196 | >::type, | |
197 | gil::packed_channel_reference<std::uint8_t, 0, 1, true> const | |
198 | >::value, | |
199 | "packed_channel_reference_type should return packed_channel_reference"); | |
200 | } | |
201 | ||
f67539c2 | 202 | void test_packed_pixel_bgr121_assignment() |
92f5a8d4 | 203 | { |
f67539c2 TL |
204 | fixture::packed_pixel_bgr121 p1{0, 3, 1}; |
205 | fixture::packed_pixel_bgr121 p2; | |
92f5a8d4 | 206 | p2 = p1; |
f67539c2 | 207 | BOOST_TEST_EQ(p1._bitfield, p2._bitfield); |
92f5a8d4 TL |
208 | } |
209 | ||
f67539c2 | 210 | void test_packed_pixel_bgr121_equality() |
92f5a8d4 | 211 | { |
f67539c2 TL |
212 | fixture::packed_pixel_bgr121 p1{1, 3, 0}; |
213 | fixture::packed_pixel_bgr121 p2{1, 3, 0}; | |
214 | BOOST_TEST_EQ(p1, p2); | |
92f5a8d4 | 215 | |
f67539c2 TL |
216 | fixture::packed_pixel_bgr121 p3{0, 3, 1}; |
217 | BOOST_TEST_NE(p2, p3); | |
92f5a8d4 TL |
218 | } |
219 | ||
f67539c2 | 220 | void test_packed_pixel_rgb535_definition() |
92f5a8d4 TL |
221 | { |
222 | // Verify packed_pixel members | |
223 | ||
f67539c2 | 224 | static_assert(std::is_same<fixture::packed_pixel_rgb535::layout_t, gil::rgb_layout_t>::value, |
92f5a8d4 TL |
225 | "layout should be bgr"); |
226 | ||
f67539c2 | 227 | static_assert(std::is_same<fixture::packed_pixel_rgb535::value_type, fixture::packed_pixel_rgb535>::value, |
92f5a8d4 TL |
228 | "value_type member should be of the same type as the packed_pixel specialization"); |
229 | ||
f67539c2 | 230 | static_assert(std::is_reference<fixture::packed_pixel_rgb535::reference>::value, |
92f5a8d4 TL |
231 | "reference member should be a reference"); |
232 | ||
f67539c2 | 233 | static_assert(std::is_reference<fixture::packed_pixel_rgb535::const_reference>::value, |
92f5a8d4 TL |
234 | "const_reference member should be a reference"); |
235 | ||
f67539c2 TL |
236 | static_assert(std::is_same<decltype(fixture::packed_pixel_rgb535::is_mutable), bool const>::value && |
237 | fixture::packed_pixel_rgb535::is_mutable, | |
92f5a8d4 TL |
238 | "is_mutable should be boolean"); |
239 | ||
240 | // Verify metafunctions | |
241 | ||
f67539c2 | 242 | static_assert(mp11::mp_size<fixture::packed_channel_references_535>::value == 3, |
92f5a8d4 TL |
243 | "packed_channel_references_vector_type should define three references to channel start bits"); |
244 | ||
f67539c2 | 245 | using channel1_ref_t = mp11::mp_at_c<fixture::packed_channel_references_535, 0>; |
92f5a8d4 TL |
246 | static_assert(channel1_ref_t::num_bits == 5, |
247 | "1st channel of rgb535 pixel should be of 5-bit size"); | |
248 | ||
f67539c2 | 249 | using channel2_ref_t = mp11::mp_at_c<fixture::packed_channel_references_535, 1>; |
92f5a8d4 TL |
250 | static_assert(channel2_ref_t::num_bits == 3, |
251 | "2nd channel of rgb535 pixel should be of 3-bit size"); | |
252 | ||
f67539c2 | 253 | using channel3_ref_t = mp11::mp_at_c<fixture::packed_channel_references_535, 2>; |
92f5a8d4 TL |
254 | static_assert(channel3_ref_t::num_bits == 5, |
255 | "3rd channel of rgb535 pixel should be of 5-bit size"); | |
256 | ||
257 | static_assert(std::is_same | |
258 | < | |
259 | channel1_ref_t, | |
260 | gil::packed_channel_reference<std::uint16_t, 0, 5, true> const | |
261 | >::value, | |
262 | "1st element of packed_channel_references_vector should be packed_channel_reference of 1st channel"); | |
263 | ||
264 | static_assert(std::is_same | |
265 | < | |
266 | channel2_ref_t, | |
267 | gil::packed_channel_reference<std::uint16_t, 5, 3, true> const | |
268 | >::value, | |
269 | "2nd element of packed_channel_references_vector should be packed_channel_reference of 2nd channel"); | |
270 | ||
271 | static_assert(std::is_same | |
272 | < | |
273 | channel3_ref_t, | |
274 | gil::packed_channel_reference<std::uint16_t, 8, 5, true> const | |
275 | >::value, | |
276 | "3rd element of packed_channel_references_vector should be packed_channel_reference of 3rd channel"); | |
277 | ||
278 | // double check intermediate metafunction packed_channel_reference_type | |
279 | static_assert(std::is_same | |
280 | < | |
281 | gil::detail::packed_channel_reference_type | |
282 | < | |
283 | std::uint16_t, | |
284 | std::integral_constant<int, 0>, | |
285 | std::integral_constant<int, 5> | |
286 | >::type, | |
287 | channel1_ref_t | |
288 | >::value, | |
289 | "packed_channel_reference_type should return packed_channel_reference"); | |
290 | static_assert(std::is_same | |
291 | < | |
292 | gil::detail::packed_channel_reference_type | |
293 | < | |
294 | std::uint16_t, | |
295 | std::integral_constant<int, 0>, | |
296 | std::integral_constant<int, 5> | |
297 | >::type, | |
298 | gil::packed_channel_reference<std::uint16_t, 0, 5, true> const | |
299 | >::value, | |
300 | "packed_channel_reference_type should return packed_channel_reference"); | |
301 | } | |
302 | ||
f67539c2 | 303 | void test_packed_pixel_rgb535_assignment() |
92f5a8d4 | 304 | { |
f67539c2 TL |
305 | fixture::packed_pixel_rgb535 p1{31, 7, 31}; |
306 | fixture::packed_pixel_rgb535 p2; | |
92f5a8d4 | 307 | p2 = p1; |
f67539c2 | 308 | BOOST_TEST_EQ(p1._bitfield, p2._bitfield); |
92f5a8d4 TL |
309 | } |
310 | ||
f67539c2 | 311 | void test_packed_pixel_rgb535_equality() |
92f5a8d4 | 312 | { |
f67539c2 TL |
313 | fixture::packed_pixel_rgb535 p1{7, 3, 7}; |
314 | fixture::packed_pixel_rgb535 p2{7, 3, 7}; | |
315 | BOOST_TEST_EQ(p1, p2); | |
316 | ||
317 | fixture::packed_pixel_rgb535 p3{7, 7, 7}; | |
318 | BOOST_TEST_NE(p2, p3); | |
319 | } | |
92f5a8d4 | 320 | |
f67539c2 TL |
321 | int main() |
322 | { | |
323 | test_packed_pixel_gray3_definition(); | |
324 | test_packed_pixel_gray3_assignment(); | |
325 | test_packed_pixel_gray3_equality(); | |
326 | test_packed_pixel_gray3_assignment_gray_channel(); | |
327 | test_packed_pixel_gray3_equality_gray_channel(); | |
328 | test_packed_pixel_bgr121_definition(); | |
329 | test_packed_pixel_bgr121_assignment(); | |
330 | test_packed_pixel_bgr121_equality(); | |
331 | test_packed_pixel_rgb535_definition(); | |
332 | test_packed_pixel_rgb535_assignment(); | |
333 | test_packed_pixel_rgb535_equality(); | |
334 | ||
335 | return boost::report_errors(); | |
92f5a8d4 | 336 | } |