• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2013 Christian Henning
3 // Copyright 2013 Davide Anastasia <davideanastasia@users.sourceforge.net>
4 //
5 // Distributed under the Boost Software License, Version 1.0
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8 //
9 #include <boost/gil.hpp>
10 #include <boost/gil/extension/toolbox/color_spaces/xyz.hpp>
11 
12 #include <boost/core/lightweight_test.hpp>
13 
14 #include <cstdint>
15 #include <limits>
16 
17 #ifndef BOOST_GIL_TEST_DEBUG_OSTREAM
18 #include <iostream>
19 #define BOOST_GIL_TEST_DEBUG_OSTREAM std::cout
20 #endif
21 
22 #include "test_utility_output_stream.hpp"
23 
24 namespace gil = boost::gil;
25 
26 const float SKEW = 0.0001f;
27 
test_rgb32f_xyz32f_1()28 void test_rgb32f_xyz32f_1()
29 {
30     gil::xyz32f_pixel_t xyz32f;
31     gil::rgb32f_pixel_t p32f(.934351f, 0.785446f, .105858f), p32f_b;
32     gil::color_convert(p32f, xyz32f);
33     gil::color_convert(xyz32f, p32f_b);
34 
35     BOOST_GIL_TEST_DEBUG_OSTREAM
36         << p32f[0] << " "
37         << p32f[1] << " "
38         << p32f[2] << " -> "
39         << xyz32f[0] << " "
40         << xyz32f[1] << " "
41         << xyz32f[2] << " -> "
42         << p32f_b[0] << " "
43         << p32f_b[1] << " "
44         << p32f_b[2]
45         << '\n';
46 
47     BOOST_TEST_LT(std::fabs(p32f[0] - p32f_b[0]), SKEW);
48     BOOST_TEST_LT(std::fabs(p32f[1] - p32f_b[1]), SKEW);
49     BOOST_TEST_LT(std::fabs(p32f[2] - p32f_b[2]), SKEW);
50     BOOST_TEST_LT(std::fabs(xyz32f[0] - 0.562669), SKEW);
51     BOOST_TEST_LT(std::fabs(xyz32f[1] - 0.597462), SKEW);
52     BOOST_TEST_LT(std::fabs(xyz32f[2] - 0.096050), SKEW);
53 }
54 
test_rgb32f_xyz32f_2()55 void test_rgb32f_xyz32f_2()
56 {
57     gil::xyz32f_pixel_t xyz32f;
58     gil::rgb32f_pixel_t p32f(.694617f, 0.173810f, 0.218710f), p32f_b;
59     gil::color_convert(p32f, xyz32f);
60     gil::color_convert(xyz32f, p32f_b);
61 
62     BOOST_GIL_TEST_DEBUG_OSTREAM
63         << p32f[0] << " "
64         << p32f[1] << " "
65         << p32f[2] << " -> "
66         << xyz32f[0] << " "
67         << xyz32f[1] << " "
68         << xyz32f[2] << " -> "
69         << p32f_b[0] << " "
70         << p32f_b[1] << " "
71         << p32f_b[2]
72         << '\n';
73 
74     BOOST_TEST_LT(std::fabs(p32f[0] - p32f_b[0]), SKEW);
75     BOOST_TEST_LT(std::fabs(p32f[1] - p32f_b[1]), SKEW);
76     BOOST_TEST_LT(std::fabs(p32f[2] - p32f_b[2]), SKEW);
77     BOOST_TEST_LT(std::fabs(xyz32f[0] - 0.197823), SKEW);
78     BOOST_TEST_LT(std::fabs(xyz32f[1] - 0.114731), SKEW);
79     BOOST_TEST_LT(std::fabs(xyz32f[2] - 0.048848), SKEW);
80 }
81 
test_xyz32f_rgb32f_1()82 void test_xyz32f_rgb32f_1()
83 {
84     gil::xyz32f_pixel_t xyz32f(.332634f, .436288f, .109853f), xyz32f_b;
85     gil::rgb32f_pixel_t p32f;
86     gil::color_convert(xyz32f, p32f);
87     gil::color_convert(p32f, xyz32f_b);
88 
89     BOOST_GIL_TEST_DEBUG_OSTREAM
90         << xyz32f[0] << " "
91         << xyz32f[1] << " "
92         << xyz32f[2] << " -> "
93         << p32f[0] << " "
94         << p32f[1] << " "
95         << p32f[2] << " -> "
96         << xyz32f_b[0] << " "
97         << xyz32f_b[1] << " "
98         << xyz32f_b[2]
99         << '\n';
100 
101     BOOST_TEST_LT(std::fabs(xyz32f_b[0] - xyz32f[0]), SKEW);
102     BOOST_TEST_LT(std::fabs(xyz32f_b[1] - xyz32f[1]), SKEW);
103     BOOST_TEST_LT(std::fabs(xyz32f_b[2] - xyz32f[2]), SKEW);
104     BOOST_TEST_LT(std::fabs(p32f[0] - 0.628242), SKEW);
105     BOOST_TEST_LT(std::fabs(p32f[1] - 0.735771), SKEW);
106     BOOST_TEST_LT(std::fabs(p32f[2] - 0.236473), SKEW);
107 }
108 
test_xyz32f_rgb32f_2()109 void test_xyz32f_rgb32f_2()
110 {
111     gil::xyz32f_pixel_t xyz32f(.375155f, .352705f, .260025f), xyz32f_b;
112     gil::rgb32f_pixel_t p32f;
113     gil::color_convert(xyz32f, p32f);
114     gil::color_convert(p32f, xyz32f_b);
115 
116     BOOST_GIL_TEST_DEBUG_OSTREAM
117         << xyz32f[0] << " "
118         << xyz32f[1] << " "
119         << xyz32f[2] << " -> "
120         << p32f[0] << " "
121         << p32f[1] << " "
122         << p32f[2] << " -> "
123         << xyz32f_b[0] << " "
124         << xyz32f_b[1] << " "
125         << xyz32f_b[2]
126         << '\n';
127 
128     BOOST_TEST_LT(std::fabs(xyz32f_b[0] - xyz32f[0]), SKEW);
129     BOOST_TEST_LT(std::fabs(xyz32f_b[1] - xyz32f[1]), SKEW);
130     BOOST_TEST_LT(std::fabs(xyz32f_b[2] - xyz32f[2]), SKEW);
131     BOOST_TEST_LT(std::fabs(p32f[0] - 0.763580), SKEW);
132     BOOST_TEST_LT(std::fabs(p32f[1] - 0.591622), SKEW);
133     BOOST_TEST_LT(std::fabs(p32f[2] - 0.510392), SKEW);
134 }
135 
test_rgb8u_xyz32f_1()136 void test_rgb8u_xyz32f_1()
137 {
138     gil::xyz32f_pixel_t xyz32f;
139     gil::rgb8_pixel_t p8u(177, 44, 56), p8u_b;
140     gil::color_convert(p8u, xyz32f);
141     gil::color_convert(xyz32f, p8u_b);
142 
143     BOOST_GIL_TEST_DEBUG_OSTREAM
144         << static_cast<int>(p8u[0]) << " "
145         << static_cast<int>(p8u[1]) << " "
146         << static_cast<int>(p8u[2]) << " -> "
147         << xyz32f[0] << " "
148         << xyz32f[1] << " "
149         << xyz32f[2] << " -> "
150         << static_cast<int>(p8u_b[0]) << " "
151         << static_cast<int>(p8u_b[1]) << " "
152         << static_cast<int>(p8u_b[2])
153         << '\n';
154 
155     BOOST_TEST_EQ(p8u[0], p8u_b[0]);
156     BOOST_TEST_EQ(p8u[1], p8u_b[1]);
157     BOOST_TEST_EQ(p8u[2], p8u_b[2]);
158 }
159 
test_rgb8u_xyz32f_2()160 void test_rgb8u_xyz32f_2()
161 {
162     gil::xyz32f_pixel_t xyz32f;
163     gil::rgb8_pixel_t p8u(72, 90, 165), p8u_b;
164     gil::color_convert(p8u, xyz32f);
165     gil::color_convert(xyz32f, p8u_b);
166 
167     BOOST_GIL_TEST_DEBUG_OSTREAM
168         << static_cast<int>(p8u[0]) << " "
169         << static_cast<int>(p8u[1]) << " "
170         << static_cast<int>(p8u[2]) << " -> "
171         << xyz32f[0] << " "
172         << xyz32f[1] << " "
173         << xyz32f[2] << " -> "
174         << static_cast<int>(p8u_b[0]) << " "
175         << static_cast<int>(p8u_b[1]) << " "
176         << static_cast<int>(p8u_b[2])
177         << '\n';
178 
179     BOOST_TEST_EQ(p8u[0], p8u_b[0]);
180     BOOST_TEST_EQ(p8u[1], p8u_b[1]);
181     BOOST_TEST_EQ(p8u[2], p8u_b[2]);
182 }
183 
test_rgb16u_xyz32f_1()184 void test_rgb16u_xyz32f_1()
185 {
186     gil::xyz32f_pixel_t xyz32f;
187     gil::rgb16_pixel_t p16u(12564, 20657, 200), p16u_b;
188     gil::color_convert(p16u, xyz32f);
189     gil::color_convert(xyz32f, p16u_b);
190 
191     BOOST_GIL_TEST_DEBUG_OSTREAM
192         << static_cast<int>(p16u[0]) << " "
193         << static_cast<int>(p16u[1]) << " "
194         << static_cast<int>(p16u[2]) << " -> "
195         << xyz32f[0] << " "
196         << xyz32f[1] << " "
197         << xyz32f[2] << " -> "
198         << static_cast<int>(p16u_b[0]) << " "
199         << static_cast<int>(p16u_b[1]) << " "
200         << static_cast<int>(p16u_b[2])
201         << '\n';
202 
203     BOOST_TEST_EQ(p16u[0], p16u_b[0]);
204     BOOST_TEST_EQ(p16u[1], p16u_b[1]);
205     BOOST_TEST_EQ(p16u[2], p16u_b[2]);
206 }
207 
main()208 int main()
209 {
210     test_rgb32f_xyz32f_1();
211     test_rgb32f_xyz32f_2();
212     test_xyz32f_rgb32f_1();
213     test_xyz32f_rgb32f_2();
214     test_rgb8u_xyz32f_1();
215     test_rgb8u_xyz32f_2();
216     test_rgb16u_xyz32f_1();
217 
218     return ::boost::report_errors();
219 }
220