summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-12-27 20:02:16 +0000
committerCarl Hetherington <cth@carlh.net>2014-12-28 00:46:04 +0000
commit75788462338b1b4f464d075465da3cb372c40004 (patch)
tree24046b4554f71ae399bbd310f5df2db2c4e69f47 /test
parent8520636e803e9eb17c9f73272f340d0e1c17ad67 (diff)
Change colourspace handling round a bit:1.0-colour-cleanup
- move the essence of GammaLUT into TransferFunction and handle different bit depths more neatly - add ColourConversion to describe input gamma correction, colour transformation and then output gamma correction in one class. - add default ColourConversions for sRGB->XYZ, Rec709->XYZ and XYZ->RGB.
Diffstat (limited to 'test')
-rw-r--r--test/colour_conversion_test.cc82
-rw-r--r--test/wscript1
2 files changed, 83 insertions, 0 deletions
diff --git a/test/colour_conversion_test.cc b/test/colour_conversion_test.cc
new file mode 100644
index 00000000..060148a6
--- /dev/null
+++ b/test/colour_conversion_test.cc
@@ -0,0 +1,82 @@
+/*
+ Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "gamma_transfer_function.h"
+#include "colour_conversion.h"
+#include "modified_gamma_transfer_function.h"
+#include <boost/test/unit_test.hpp>
+#include <cmath>
+
+using std::pow;
+using boost::shared_ptr;
+using namespace dcp;
+
+static void
+check_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, float gamma)
+{
+ float const * lut = tf->lut (bit_depth);
+ int const count = pow (2, bit_depth);
+
+ for (int i = 0; i < count; ++i) {
+ BOOST_CHECK_CLOSE (lut[i], pow (float(i) / (count - 1), gamma), 0.001);
+ }
+}
+
+static void
+check_modified_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, float power, float threshold, float A, float B)
+{
+ float const * lut = tf->lut (bit_depth);
+ int const count = pow (2, bit_depth);
+
+ for (int i = 0; i < count; ++i) {
+ float const x = float(i) / (count - 1);
+ if (x > threshold) {
+ BOOST_CHECK_CLOSE (lut[i], pow ((x + A) / (1 + A), power), 0.001);
+ } else {
+ BOOST_CHECK_CLOSE (lut[i], (x / B), 0.001);
+ }
+ }
+}
+
+BOOST_AUTO_TEST_CASE (colour_conversion_test1)
+{
+ ColourConversion cc = ColourConversion::srgb_to_xyz;
+
+ check_modified_gamma (cc.in(), 8, 2.4, 0.04045, 0.055, 12.92);
+ check_modified_gamma (cc.in(), 12, 2.4, 0.04045, 0.055, 12.92);
+ check_modified_gamma (cc.in(), 16, 2.4, 0.04045, 0.055, 12.92);
+
+ check_gamma (cc.out(), 8, 2.6);
+ check_gamma (cc.out(), 12, 2.6);
+ check_gamma (cc.out(), 16, 2.6);
+}
+
+BOOST_AUTO_TEST_CASE (colour_conversion_test2)
+{
+ ColourConversion cc = ColourConversion::rec709_to_xyz;
+
+ check_modified_gamma (cc.in(), 8, 2.4, 0.081, 0.099, 4.5);
+ check_modified_gamma (cc.in(), 12, 2.4, 0.081, 0.099, 4.5);
+ check_modified_gamma (cc.in(), 16, 2.4, 0.081, 0.099, 4.5);
+
+ check_gamma (cc.out(), 8, 2.6);
+ check_gamma (cc.out(), 12, 2.6);
+ check_gamma (cc.out(), 16, 2.6);
+}
+
diff --git a/test/wscript b/test/wscript
index 0ac8b800..dbbb51d5 100644
--- a/test/wscript
+++ b/test/wscript
@@ -28,6 +28,7 @@ def build(bld):
argb_frame_test.cc
certificates_test.cc
colour_test.cc
+ colour_conversion_test.cc
cpl_sar_test.cc
dcp_test.cc
dcp_time_test.cc