From 033bb2cce362385ee535ed7f898dabfd47d8414c Mon Sep 17 00:00:00 2001 From: David Plowman Date: Fri, 27 Mar 2026 09:02:43 +0000 Subject: [PATCH] ipa: rpi: Fix gamma lookup table generation for PiSP platform generateLut was failing to fill in the final slope value, meaning that fully saturated pixels would full slightly short (the slope of the final piecewise linear segment would default to zero). The loop is slightly reorganised to fix the problem. Signed-off-by: David Plowman Reviewed-by: Nick Hollinghurst Reviewed-by: Naushir Patuck Signed-off-by: Kieran Bingham --- src/ipa/rpi/pisp/pisp.cpp | 44 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/ipa/rpi/pisp/pisp.cpp b/src/ipa/rpi/pisp/pisp.cpp index 63935985..de2a6afe 100644 --- a/src/ipa/rpi/pisp/pisp.cpp +++ b/src/ipa/rpi/pisp/pisp.cpp @@ -80,36 +80,30 @@ int generateLut(const ipa::Pwl &pwl, uint32_t *lut, std::size_t lutSize, if (pwl.empty()) return -EINVAL; - int lastY = 0; + int nextY = pwl.eval(0); for (unsigned int i = 0; i < lutSize; i++) { - int x, y; - if (i < 32) - x = i * 512; - else if (i < 48) - x = (i - 32) * 1024 + 16384; + unsigned int nextI = i + 1; + + int nextX; + if (nextI < 32) + nextX = nextI * 512; + else if (nextI < 48) + nextX = (nextI - 32) * 1024 + 16384; else - x = std::min(65535u, (i - 48) * 2048 + 32768); + nextX = (nextI - 48) * 2048 + 32768; - y = pwl.eval(x); - if (y < 0 || (i && y < lastY)) { - LOG(IPARPI, Error) - << "Malformed PWL for Gamma, disabling!"; - return -1; + int y = nextY; + nextY = pwl.eval(nextX); + + unsigned int slope = nextY - y; + if (slope >= (1u << SlopeBits)) { + slope = (1u << SlopeBits) - 1; + LOG(IPARPI, Info) + << "Maximum Gamma slope exceeded, adjusting!"; + nextY = y + slope; } - if (i) { - unsigned int slope = y - lastY; - if (slope >= (1u << SlopeBits)) { - slope = (1u << SlopeBits) - 1; - LOG(IPARPI, Info) - << ("Maximum Gamma slope exceeded, adjusting!"); - y = lastY + slope; - } - lut[i - 1] |= slope << PosBits; - } - - lut[i] = y; - lastY = y; + lut[i] = y | (slope << PosBits); } return 0;