2 // Copyright 2013 Christian Henning
3 // Copyright 2013 Davide Anastasia <davideanastasia@users.sourceforge.net>
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
9 #include <boost/gil.hpp>
10 #include <boost/gil/extension/toolbox/color_spaces/xyz.hpp>
12 #include <boost/test/unit_test.hpp>
18 using namespace boost;
21 const float SKEW = 0.0001f;
23 BOOST_AUTO_TEST_SUITE( toolbox_tests )
25 BOOST_AUTO_TEST_CASE(rgb32f_xyz32f_1)
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);
32 BOOST_TEST_MESSAGE( p32f[0] << " "
37 << xyz32f[2] << " -> "
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 );
50 BOOST_AUTO_TEST_CASE(rgb32f_xyz32f_2)
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);
57 BOOST_TEST_MESSAGE( p32f[0] << " "
62 << xyz32f[2] << " -> "
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 );
75 BOOST_AUTO_TEST_CASE(xyz32f_rgb32f_1)
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);
82 BOOST_TEST_MESSAGE( xyz32f[0] << " "
84 << xyz32f[2] << " -> "
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 );
100 BOOST_AUTO_TEST_CASE(xyz32f_rgb32f_2)
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);
107 BOOST_TEST_MESSAGE( xyz32f[0] << " "
109 << xyz32f[2] << " -> "
113 << xyz32f_b[0] << " "
114 << xyz32f_b[1] << " "
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 );
125 BOOST_AUTO_TEST_CASE(rgb8u_xyz32f_1)
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);
132 BOOST_TEST_MESSAGE( static_cast<int>(p8u[0]) << " "
133 << static_cast<int>(p8u[1]) << " "
134 << static_cast<int>(p8u[2]) << " -> "
137 << xyz32f[2] << " -> "
138 << static_cast<int>(p8u_b[0]) << " "
139 << static_cast<int>(p8u_b[1]) << " "
140 << static_cast<int>(p8u_b[2]) );
142 BOOST_CHECK(p8u[0] == p8u_b[0]);
143 BOOST_CHECK(p8u[1] == p8u_b[1]);
144 BOOST_CHECK(p8u[2] == p8u_b[2]);
147 BOOST_AUTO_TEST_CASE(rgb8u_xyz32f_2)
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);
155 static_cast<int>(p8u[0]) << " "
156 << static_cast<int>(p8u[1]) << " "
157 << static_cast<int>(p8u[2]) << " -> "
160 << xyz32f[2] << " -> "
161 << static_cast<int>(p8u_b[0]) << " "
162 << static_cast<int>(p8u_b[1]) << " "
163 << static_cast<int>(p8u_b[2]) );
165 BOOST_CHECK(p8u[0] == p8u_b[0]);
166 BOOST_CHECK(p8u[1] == p8u_b[1]);
167 BOOST_CHECK(p8u[2] == p8u_b[2]);
170 BOOST_AUTO_TEST_CASE(rgb16u_xyz32f_1)
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);
178 static_cast<int>(p16u[0]) << " "
179 << static_cast<int>(p16u[1]) << " "
180 << static_cast<int>(p16u[2]) << " -> "
183 << xyz32f[2] << " -> "
184 << static_cast<int>(p16u_b[0]) << " "
185 << static_cast<int>(p16u_b[1]) << " "
186 << static_cast<int>(p16u_b[2]) );
188 BOOST_CHECK(p16u[0] == p16u_b[0]);
189 BOOST_CHECK(p16u[1] == p16u_b[1]);
190 BOOST_CHECK(p16u[2] == p16u_b[2]);
193 BOOST_AUTO_TEST_SUITE_END()