From 75788462338b1b4f464d075465da3cb372c40004 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 27 Dec 2014 20:02:16 +0000 Subject: Change colourspace handling round a bit: - 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. --- test/colour_conversion_test.cc | 82 ++++++++++++++++++++++++++++++++++++++++++ test/wscript | 1 + 2 files changed, 83 insertions(+) create mode 100644 test/colour_conversion_test.cc (limited to 'test') 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 + + 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 +#include + +using std::pow; +using boost::shared_ptr; +using namespace dcp; + +static void +check_gamma (shared_ptr 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 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 -- cgit v1.2.3