From e171a0bbaf0dedbab261279561888e7259a40df7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 21 Oct 2023 23:05:56 +0200 Subject: Use an integer LUT for PiecewiseLUT2, hence removing a lrint and a multiply from the rgb -> xyz loop. --- src/piecewise_lut.h | 12 ++++++------ src/rgb_xyz.cc | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/piecewise_lut.h b/src/piecewise_lut.h index f2f21a92..3bea6bb8 100644 --- a/src/piecewise_lut.h +++ b/src/piecewise_lut.h @@ -47,24 +47,24 @@ namespace dcp { class PiecewiseLUT2 { public: - PiecewiseLUT2(std::shared_ptr fn, double boundary, int low_bits, int high_bits, bool inverse) + PiecewiseLUT2(std::shared_ptr fn, double boundary, int low_bits, int high_bits, bool inverse, int scale) : _boundary(boundary) - , _low(fn->double_lut(0, boundary, low_bits, inverse)) - , _high(fn->double_lut(boundary, 1, high_bits, inverse)) + , _low(fn->int_lut(0, boundary, low_bits, inverse, scale)) + , _high(fn->int_lut(boundary, 1, high_bits, inverse, scale)) , _low_scale(static_cast(std::pow(2.0f, low_bits)) - 1) , _high_scale(static_cast(std::pow(2.0f, high_bits)) - 1) { } - inline double lookup(double x) const { + inline int lookup(double x) const { return x < _boundary ? _low[lrint((x / _boundary) * _low_scale)] : _high[lrint(((x - _boundary) / (1 - _boundary)) * _high_scale)]; } private: double _boundary; - std::vector _low; - std::vector _high; + std::vector _low; + std::vector _high; int _low_scale; int _high_scale; }; diff --git a/src/rgb_xyz.cc b/src/rgb_xyz.cc index cd0c7f60..9aeed761 100644 --- a/src/rgb_xyz.cc +++ b/src/rgb_xyz.cc @@ -262,7 +262,7 @@ PiecewiseLUT2 dcp::make_inverse_gamma_lut(shared_ptr fn) { /* The parameters here were chosen by trial and error to reduce errors when running rgb_xyz_lut_test */ - return PiecewiseLUT2(fn, 0.062, 16, 12, true); + return PiecewiseLUT2(fn, 0.062, 16, 12, true, 4095); } @@ -323,9 +323,9 @@ rgb_to_xyz_internal( d.z = min (1.0, d.z); /* Out gamma LUT */ - *xyz_x++ = lrint(lut_out.lookup(d.x) * 4095); - *xyz_y++ = lrint(lut_out.lookup(d.y) * 4095); - *xyz_z++ = lrint(lut_out.lookup(d.z) * 4095); + *xyz_x++ = lut_out.lookup(d.x); + *xyz_y++ = lut_out.lookup(d.y); + *xyz_z++ = lut_out.lookup(d.z); } } -- cgit v1.2.3