From patchwork Fri Mar 27 09:02:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 26377 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7CBBBBE086 for ; Fri, 27 Mar 2026 09:03:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8E5B662CC7; Fri, 27 Mar 2026 10:03:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="bFBRX3ra"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 18A7F62BB6 for ; Fri, 27 Mar 2026 10:03:33 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-439b9cf8cb5so1787443f8f.0 for ; Fri, 27 Mar 2026 02:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1774602212; x=1775207012; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UEZETtG4ffw9sHAocFyZ21y9cv6n/0uCvf9GHpNh1yM=; b=bFBRX3raYDioAoCTUkm9Z9ho3DLGzER3gV5KfUqg4YQHWOOSPlNSaE3YqY1DBQaB8B mNHVTeunup0e+gP1+seSEQYRZCdTHicfuJXbsIze6irlCJ4rNIlNj+v1SG2TTsLBGPr0 f44WTgG/bsOgcCX0q1HVgNIBbGpJUfNDetmhSO+KerxhehWJnYSQDXpLHxPUtrk9P10i sfqItT39JZ48H+3ODW/9UE7L/4Ysc/XkCD8enZZuXHqTQIVZGO2eZdMZuPfPOL8HBQ8i 9b4ON/Qk8VI5MI5h0fAPfJgcJKftRUKHRCPmHowqDpCkZDAXDQwoIur4IMX3XWsyQ/9J jUCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774602212; x=1775207012; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UEZETtG4ffw9sHAocFyZ21y9cv6n/0uCvf9GHpNh1yM=; b=QjGxhz8WdbqXaVjokpwRgOEGTQcbk30LZzpaEVyuezYfnmUHOkYDg2QZc+Nl5BnO3x NuLkGLpsf16/OHkFv8+Na31FNNbI+2LEfaAz4dV86N4cvyZ5KcO/Ce68avjlf0l4ofmI 2Cu0dBeR9H1pyRAzyxrzcecJs5l6qnwXDvZRz8FdkgNBzpqvIf/1YbmcGon4K6pI0jQD Wk1n9oUJEqe4pYVH1RW2JzHhzIZ0v9YrfWSuRaSAvUtwmlET7pzPgKa47SCW+A5WX6eH 0huu9ZSlnYl1jHeqcy+Qb8hzCgwEsOZ3rPegYll0wTg3+VMBd27WbZWyhQJmqJYcev+6 qk4Q== X-Gm-Message-State: AOJu0YwxGM9zPK9L5FR+JPulIftEoOyYy7pJjRLtSrVWkaPvrnQria8L GvmNYUQkKmNQB8Yzd854/Z+SVg4lVeYFUgP1Ff8/J3rGeet0l8IatrT/0Ha/GG/S2F6hduLinWI 7sk+C X-Gm-Gg: ATEYQzzg0Rlh4lI7Rc6H+FwP1y2jpb5JjOJXH5OWy+VjbmEKGQiQonE24N8EjToX5Pb mHwv2sYS5ifOW92Dw+shDNHTnJGEdGjTcMyy+45qq8v/YC5daf32+bhdci9hmY5IlZUMqL/TQ7v +8S2PRFwt81B+jkb3hGQoYj8SKL2EKcS+bSFi167xT+1OsVvF1b6mvBSC70iCCHJIJr+pb1sm94 T2qFeNAPWjCki/UxadBeqYeJ280RmN2XLRiorvxOIjcrqEoG+a3Jr0PD5IZGo5L4z43KlsSa6/K Rodpt5yT0djl0tM9NpQRx3d/iG5S28tff9FeP8BPjblJwLCY4rNDq67yXaYsSuJIDuMQuepR6Gj Qdz8uV2amoAxzXq17K+SMGeAhIz2Gdipxd6aFFw4uNfd4QxYLnyhZPHmQwlcnbahI3SrJ1Utb79 vhR2gXAM74ZPH2apMR+4cgcALb6g/suai6lS+4r/SU26YF7BkpYj9Aqtq9uuiHQpLSwK/MgWRcV WhAmagxuRL/Gyd9A/7sdMt/0Czhr9bwt3Hq/w== X-Received: by 2002:a05:6000:26c1:b0:43b:50bd:bca3 with SMTP id ffacd0b85a97d-43b9ea1a398mr2330801f8f.1.1774602212209; Fri, 27 Mar 2026 02:03:32 -0700 (PDT) Received: from localhost.localdomain ([2a06:61c0:f337:0:9c1f:b517:931a:3b19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b919cefd7sm13953835f8f.17.2026.03.27.02.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 02:03:31 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH v2] ipa: rpi: Fix gamma lookup table generation for PiSP platform Date: Fri, 27 Mar 2026 09:02:43 +0000 Message-ID: <20260327090323.2250-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- src/ipa/rpi/pisp/pisp.cpp | 42 +++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/ipa/rpi/pisp/pisp.cpp b/src/ipa/rpi/pisp/pisp.cpp index ec7593ff..2abb59fa 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); - 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; + unsigned int slope = nextY - y; + if (slope >= (1u << SlopeBits)) { + slope = (1u << SlopeBits) - 1; + LOG(IPARPI, Info) + << "Maximum Gamma slope exceeded, adjusting!"; + nextY = y + slope; } - lut[i] = y; - lastY = y; + lut[i] = y | (slope << PosBits); } return 0;