Use an integer LUT for PiecewiseLUT2, hence removing a lrint and a multiply from...
authorCarl Hetherington <cth@carlh.net>
Sat, 21 Oct 2023 21:05:56 +0000 (23:05 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 21 Oct 2023 22:05:28 +0000 (00:05 +0200)
src/piecewise_lut.h
src/rgb_xyz.cc
test/rgb_xyz_test.cc

index f2f21a92e456c59d6aa5ead06bccb8a45ac50bf6..3bea6bb8bdbd3ac1f6d3afecfa48b07b4f0bac59 100644 (file)
@@ -47,24 +47,24 @@ namespace dcp {
 class PiecewiseLUT2
 {
 public:
-       PiecewiseLUT2(std::shared_ptr<const TransferFunction> fn, double boundary, int low_bits, int high_bits, bool inverse)
+       PiecewiseLUT2(std::shared_ptr<const TransferFunction> 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<int>(std::pow(2.0f, low_bits)) - 1)
                , _high_scale(static_cast<int>(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<double> _low;
-       std::vector<double> _high;
+       std::vector<int> _low;
+       std::vector<int> _high;
        int _low_scale;
        int _high_scale;
 };
index cd0c7f60b007b5812ee5d180d3e284cf64729cac..9aeed76178904e2e393e63201d78cc6f6362e137 100644 (file)
@@ -262,7 +262,7 @@ PiecewiseLUT2
 dcp::make_inverse_gamma_lut(shared_ptr<const TransferFunction> 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);
                }
        }
 
index cf3eb9ffa35201034a721d295101465595a9f6af..1899b1c313ea386e3fbc2df3365a8b1989b2ba2c 100644 (file)
@@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE (rgb_xyz_lut_test)
        auto lut = dcp::make_inverse_gamma_lut(conversion.out());
 
        for (double x = 0; x < 1; x += 0.000001) {
-               BOOST_CHECK(std::abs(lrint(lut.lookup(x) * 4095) - lrint(pow(x, 1 / 2.6) * 4095)) < 2);
+               BOOST_CHECK(std::abs(lut.lookup(x) - lrint(pow(x, 1 / 2.6) * 4095)) < 2);
        }
 }