summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rgb_xyz_test.cc108
1 files changed, 81 insertions, 27 deletions
diff --git a/test/rgb_xyz_test.cc b/test/rgb_xyz_test.cc
index 5dcfe673..961edc95 100644
--- a/test/rgb_xyz_test.cc
+++ b/test/rgb_xyz_test.cc
@@ -45,25 +45,46 @@ using std::cout;
using boost::shared_ptr;
using boost::optional;
using boost::scoped_array;
+using boost::shared_array;
-/** Convert a test image from sRGB to XYZ and check that the transforms are right */
-BOOST_AUTO_TEST_CASE (rgb_xyz_test)
+template <class T>
+void
+input_gamma (T& v)
+{
+ if (v < 0.04045) {
+ v /= 12.92;
+ } else {
+ v = pow ((v + 0.055) / 1.055, 2.4);
+ }
+}
+
+
+shared_array<uint8_t>
+random_data (dcp::Size size, int components)
{
srand (0);
- dcp::Size const size (640, 480);
+ shared_array<uint8_t> data (new uint8_t[size.width * size.height * components * 2]);
- scoped_array<uint8_t> rgb (new uint8_t[size.width * size.height * 6]);
for (int y = 0; y < size.height; ++y) {
- uint16_t* p = reinterpret_cast<uint16_t*> (rgb.get() + y * size.width * 6);
+ uint16_t* p = reinterpret_cast<uint16_t*> (data.get() + y * size.width * components * 2);
for (int x = 0; x < size.width; ++x) {
/* Write a 12-bit random number for each component */
- for (int c = 0; c < 3; ++c) {
- *p = (rand () & 0xfff) << 4;
- ++p;
+ for (int c = 0; c < components; ++c) {
+ *p++ = (rand () & 0xfff) << 4;
}
}
}
+ return data;
+}
+
+
+/** Convert a test image from sRGB to XYZ and check that the transforms are right */
+BOOST_AUTO_TEST_CASE (rgb_xyz_test)
+{
+ dcp::Size const size (640, 480);
+
+ shared_array<uint8_t> rgb = random_data (size, 3);
shared_ptr<dcp::OpenJPEGImage> xyz = dcp::rgb_to_xyz (rgb.get(), size, size.width * 6, dcp::ColourConversion::srgb_to_xyz ());
for (int y = 0; y < size.height; ++y) {
@@ -74,25 +95,9 @@ BOOST_AUTO_TEST_CASE (rgb_xyz_test)
double cg = *p++ / 65535.0;
double cb = *p++ / 65535.0;
- /* Input gamma */
-
- if (cr < 0.04045) {
- cr /= 12.92;
- } else {
- cr = pow ((cr + 0.055) / 1.055, 2.4);
- }
-
- if (cg < 0.04045) {
- cg /= 12.92;
- } else {
- cg = pow ((cg + 0.055) / 1.055, 2.4);
- }
-
- if (cb < 0.04045) {
- cb /= 12.92;
- } else {
- cb = pow ((cb + 0.055) / 1.055, 2.4);
- }
+ input_gamma (cr);
+ input_gamma (cg);
+ input_gamma (cb);
/* Matrix */
@@ -119,6 +124,55 @@ BOOST_AUTO_TEST_CASE (rgb_xyz_test)
}
}
+
+/** Convert a test image from sRGB to XYZ using the SSE/AVX code and check that the transforms are right */
+BOOST_AUTO_TEST_CASE (rgb_xyz_test_avx2)
+{
+ srand (0);
+ dcp::Size const size (647, 481);
+
+ shared_array<uint8_t> rgb = random_data (size, 4);
+ shared_ptr<dcp::OpenJPEGImage> xyz = dcp::rgb_to_xyz_avx2 (rgb.get(), size, dcp::ColourConversion::srgb_to_xyz());
+
+ uint16_t* p = reinterpret_cast<uint16_t*> (rgb.get());
+ for (int y = 0; y < size.height; ++y) {
+ for (int x = 0; x < size.width; ++x) {
+
+ float cr = *p++ / 65535.0;
+ float cg = *p++ / 65535.0;
+ float cb = *p++ / 65535.0;
+ p++;
+
+ input_gamma (cr);
+ input_gamma (cg);
+ input_gamma (cb);
+
+ /* Matrix */
+
+ float cx = cr * 0.4124564 + cg * 0.3575761 + cb * 0.1804375;
+ float cy = cr * 0.2126729 + cg * 0.7151522 + cb * 0.0721750;
+ float cz = cr * 0.0193339 + cg * 0.1191920 + cb * 0.9503041;
+
+ /* Compand */
+
+ cx *= 48 / 52.37;
+ cy *= 48 / 52.37;
+ cz *= 48 / 52.37;
+
+ /* Output gamma */
+
+ cx = pow (cx, 1 / 2.6);
+ cy = pow (cy, 1 / 2.6);
+ cz = pow (cz, 1 / 2.6);
+
+ BOOST_REQUIRE_CLOSE (cx * 4095, xyz->data(0)[y * size.width + x], 3);
+ BOOST_REQUIRE_CLOSE (cy * 4095, xyz->data(1)[y * size.width + x], 3);
+ BOOST_REQUIRE_CLOSE (cz * 4095, xyz->data(2)[y * size.width + x], 3);
+ }
+ }
+}
+
+
static list<string> notes;
static void