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/test/unit_test.hpp>
13
14 #include <cstdint>
15 #include <iostream>
16 #include <limits>
17
18 using namespace boost;
19 using namespace std;
20
21 const float SKEW = 0.0001f;
22
23 BOOST_AUTO_TEST_SUITE( toolbox_tests )
24
BOOST_AUTO_TEST_CASE(rgb32f_xyz32f_1)25 BOOST_AUTO_TEST_CASE(rgb32f_xyz32f_1)
26 {
27 gil::xyz32f_pixel_t xyz32f;
28 gil::rgb32f_pixel_t p32f(.934351f, 0.785446f, .105858f), p32f_b;
29 gil::color_convert(p32f, xyz32f);
30 gil::color_convert(xyz32f, p32f_b);
31
32 BOOST_TEST_MESSAGE( p32f[0] << " "
33 << p32f[1] << " "
34 << p32f[2] << " -> "
35 << xyz32f[0] << " "
36 << xyz32f[1] << " "
37 << xyz32f[2] << " -> "
38 << p32f_b[0] << " "
39 << p32f_b[1] << " "
40 << p32f_b[2] );
41
42 BOOST_CHECK( abs(p32f[0] - p32f_b[0]) < SKEW );
43 BOOST_CHECK( abs(p32f[1] - p32f_b[1]) < SKEW );
44 BOOST_CHECK( abs(p32f[2] - p32f_b[2]) < SKEW );
45 BOOST_CHECK( abs( xyz32f[0] - 0.562669) < SKEW );
46 BOOST_CHECK( abs( xyz32f[1] - 0.597462) < SKEW );
47 BOOST_CHECK( abs( xyz32f[2] - 0.096050) < SKEW );
48 }
49
BOOST_AUTO_TEST_CASE(rgb32f_xyz32f_2)50 BOOST_AUTO_TEST_CASE(rgb32f_xyz32f_2)
51 {
52 gil::xyz32f_pixel_t xyz32f;
53 gil::rgb32f_pixel_t p32f(.694617f, 0.173810f, 0.218710f), p32f_b;
54 gil::color_convert(p32f, xyz32f);
55 gil::color_convert(xyz32f, p32f_b);
56
57 BOOST_TEST_MESSAGE( p32f[0] << " "
58 << p32f[1] << " "
59 << p32f[2] << " -> "
60 << xyz32f[0] << " "
61 << xyz32f[1] << " "
62 << xyz32f[2] << " -> "
63 << p32f_b[0] << " "
64 << p32f_b[1] << " "
65 << p32f_b[2] );
66
67 BOOST_CHECK( abs(p32f[0] - p32f_b[0]) < SKEW );
68 BOOST_CHECK( abs(p32f[1] - p32f_b[1]) < SKEW );
69 BOOST_CHECK( abs(p32f[2] - p32f_b[2]) < SKEW );
70 BOOST_CHECK( abs( xyz32f[0] - 0.197823) < SKEW );
71 BOOST_CHECK( abs( xyz32f[1] - 0.114731) < SKEW );
72 BOOST_CHECK( abs( xyz32f[2] - 0.048848) < SKEW );
73 }
74
BOOST_AUTO_TEST_CASE(xyz32f_rgb32f_1)75 BOOST_AUTO_TEST_CASE(xyz32f_rgb32f_1)
76 {
77 gil::xyz32f_pixel_t xyz32f(.332634f, .436288f, .109853f), xyz32f_b;
78 gil::rgb32f_pixel_t p32f;
79 gil::color_convert(xyz32f, p32f);
80 gil::color_convert(p32f, xyz32f_b);
81
82 BOOST_TEST_MESSAGE( xyz32f[0] << " "
83 << xyz32f[1] << " "
84 << xyz32f[2] << " -> "
85 << p32f[0] << " "
86 << p32f[1] << " "
87 << p32f[2] << " -> "
88 << xyz32f_b[0] << " "
89 << xyz32f_b[1] << " "
90 << xyz32f_b[2] );
91
92 BOOST_CHECK( abs(xyz32f_b[0] - xyz32f[0]) < SKEW );
93 BOOST_CHECK( abs(xyz32f_b[1] - xyz32f[1]) < SKEW );
94 BOOST_CHECK( abs(xyz32f_b[2] - xyz32f[2]) < SKEW );
95 BOOST_CHECK( abs( p32f[0] - 0.628242) < SKEW );
96 BOOST_CHECK( abs( p32f[1] - 0.735771) < SKEW );
97 BOOST_CHECK( abs( p32f[2] - 0.236473) < SKEW );
98 }
99
BOOST_AUTO_TEST_CASE(xyz32f_rgb32f_2)100 BOOST_AUTO_TEST_CASE(xyz32f_rgb32f_2)
101 {
102 gil::xyz32f_pixel_t xyz32f(.375155f, .352705f, .260025f), xyz32f_b;
103 gil::rgb32f_pixel_t p32f;
104 gil::color_convert(xyz32f, p32f);
105 gil::color_convert(p32f, xyz32f_b);
106
107 BOOST_TEST_MESSAGE( xyz32f[0] << " "
108 << xyz32f[1] << " "
109 << xyz32f[2] << " -> "
110 << p32f[0] << " "
111 << p32f[1] << " "
112 << p32f[2] << " -> "
113 << xyz32f_b[0] << " "
114 << xyz32f_b[1] << " "
115 << xyz32f_b[2] );
116
117 BOOST_CHECK( abs(xyz32f_b[0] - xyz32f[0]) < SKEW );
118 BOOST_CHECK( abs(xyz32f_b[1] - xyz32f[1]) < SKEW );
119 BOOST_CHECK( abs(xyz32f_b[2] - xyz32f[2]) < SKEW );
120 BOOST_CHECK( abs( p32f[0] - 0.763580) < SKEW );
121 BOOST_CHECK( abs( p32f[1] - 0.591622) < SKEW );
122 BOOST_CHECK( abs( p32f[2] - 0.510392) < SKEW );
123 }
124
BOOST_AUTO_TEST_CASE(rgb8u_xyz32f_1)125 BOOST_AUTO_TEST_CASE(rgb8u_xyz32f_1)
126 {
127 gil::xyz32f_pixel_t xyz32f;
128 gil::rgb8_pixel_t p8u(177, 44, 56), p8u_b;
129 gil::color_convert(p8u, xyz32f);
130 gil::color_convert(xyz32f, p8u_b);
131
132 BOOST_TEST_MESSAGE( static_cast<int>(p8u[0]) << " "
133 << static_cast<int>(p8u[1]) << " "
134 << static_cast<int>(p8u[2]) << " -> "
135 << xyz32f[0] << " "
136 << xyz32f[1] << " "
137 << xyz32f[2] << " -> "
138 << static_cast<int>(p8u_b[0]) << " "
139 << static_cast<int>(p8u_b[1]) << " "
140 << static_cast<int>(p8u_b[2]) );
141
142 BOOST_CHECK(p8u[0] == p8u_b[0]);
143 BOOST_CHECK(p8u[1] == p8u_b[1]);
144 BOOST_CHECK(p8u[2] == p8u_b[2]);
145 }
146
BOOST_AUTO_TEST_CASE(rgb8u_xyz32f_2)147 BOOST_AUTO_TEST_CASE(rgb8u_xyz32f_2)
148 {
149 gil::xyz32f_pixel_t xyz32f;
150 gil::rgb8_pixel_t p8u(72, 90, 165), p8u_b;
151 gil::color_convert(p8u, xyz32f);
152 gil::color_convert(xyz32f, p8u_b);
153
154 BOOST_TEST_MESSAGE(
155 static_cast<int>(p8u[0]) << " "
156 << static_cast<int>(p8u[1]) << " "
157 << static_cast<int>(p8u[2]) << " -> "
158 << xyz32f[0] << " "
159 << xyz32f[1] << " "
160 << xyz32f[2] << " -> "
161 << static_cast<int>(p8u_b[0]) << " "
162 << static_cast<int>(p8u_b[1]) << " "
163 << static_cast<int>(p8u_b[2]) );
164
165 BOOST_CHECK(p8u[0] == p8u_b[0]);
166 BOOST_CHECK(p8u[1] == p8u_b[1]);
167 BOOST_CHECK(p8u[2] == p8u_b[2]);
168 }
169
BOOST_AUTO_TEST_CASE(rgb16u_xyz32f_1)170 BOOST_AUTO_TEST_CASE(rgb16u_xyz32f_1)
171 {
172 gil::xyz32f_pixel_t xyz32f;
173 gil::rgb16_pixel_t p16u(12564, 20657, 200), p16u_b;
174 gil::color_convert(p16u, xyz32f);
175 gil::color_convert(xyz32f, p16u_b);
176
177 BOOST_TEST_MESSAGE(
178 static_cast<int>(p16u[0]) << " "
179 << static_cast<int>(p16u[1]) << " "
180 << static_cast<int>(p16u[2]) << " -> "
181 << xyz32f[0] << " "
182 << xyz32f[1] << " "
183 << xyz32f[2] << " -> "
184 << static_cast<int>(p16u_b[0]) << " "
185 << static_cast<int>(p16u_b[1]) << " "
186 << static_cast<int>(p16u_b[2]) );
187
188 BOOST_CHECK(p16u[0] == p16u_b[0]);
189 BOOST_CHECK(p16u[1] == p16u_b[1]);
190 BOOST_CHECK(p16u[2] == p16u_b[2]);
191 }
192
193 BOOST_AUTO_TEST_SUITE_END()
194