From patchwork Thu Mar 26 16:40:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 26376 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 3A3EABDCBD for ; Thu, 26 Mar 2026 16:42:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6F6A962857; Thu, 26 Mar 2026 17:42:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="OZVjvdLS"; 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 94D0762781 for ; Thu, 26 Mar 2026 17:42:44 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-439b94a19fdso1134253f8f.0 for ; Thu, 26 Mar 2026 09:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1774543364; x=1775148164; 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=nuYRDSgG0GT1fzVy5Qr5oT0sDbFnzsGae5sS6qP+qNU=; b=OZVjvdLS8j49M2bhjPhjyw6/LmvS13RvU7Ml7sZsq+/C24kcWCAZNUvZXYGx32FiNj xoZS9belajjADMOhnUM4pQKKHuHWOd8JHyQFml77BSw9Mi4n3b4R9OtAsMq28QWx3DYN d5tJSARn4uToD+VxADhyO1C6ywzGbF5XAdhs0iPH+k20dDKk04awz6pZT1G4XLmmsQ7r xiN3bJMAnzF7U7XsFYuzfrm9f4MDKqQe9y/WCc5ZUsrVBCdnz4S/YJW4eQPnFLnZCdKa FalBFd67RDqGxKD4POaitYk+hd36VVgRF02abbaODP4geBp7LwsbC9rixkvKGIjASpgQ UdAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774543364; x=1775148164; 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=nuYRDSgG0GT1fzVy5Qr5oT0sDbFnzsGae5sS6qP+qNU=; b=Eh9boYmi8MRxVAhROgJaJYyZGLGa5rUsbgTjqbSZsQ3Q7cKUSevx9OHdEFZw/qu8z2 7/QfS2Zkt2jZYunvElvj3mnhhOZY1krHP2RyTWUdk8IQcCaZKuF27Yz4G8ITpW353TUr qzGhM+TLtXruk/Dq28L3+OcsLowq1mdtP4z9/VtVIuPN1UxdzLZT9D0kvkjP0SfN4/PL HJNvUY5LFxou1U+1T9aQkkqpMGS+bqitDHec6ywNRQo6YW65HvTqCWwpwUNOYxvel1kB LGV4nyARbZX+X/nDvf2DhqLgB8JCsKC14rQwzArKwBDEwg74n1jnsqKUXuQUd6k+vTNE 0bSw== X-Gm-Message-State: AOJu0YyQRpgTQ2Sn//2UFY7C1FaKFOlhhYymkoKAtPL6OccG+6V0SsBC X8XQK58dg/AnvB0wUMAoOgIezNuVq+XsvVtvoQFtKaCvzWeHDrGOiCLTeeFokqUfEC8lZYh70wj 7G9B4 X-Gm-Gg: ATEYQzw6kDSH9KyWReyEQl1jKYUD8hsm3Ja0nfPSk/aiA36LVywpfmVCi+lveNGvlq8 q/aYzeKjxVP/64cZvHdL627sFEUXHw5l0RyYj0weL7ZZ2aXrKDwxKbUBfSaC1AH1gkGZUOUodoH tVP16KS/r/0M2dXJsSoHCYHkbR0W9/JSWO0zFtRXdo0wy2NgqP1rRw2e/RbWHfYxlBWWciRRALt wAtwi/NZlc9fyIYBMV1U1gW4JPxc1WLvom1bLhi74mN88hvghsueo9iQR6EikMjJids3Bfgb678 8pToAQUS4iFJiEGFZXqKDD0JlwNkisxwG1sWUQr8Ss5B8QFmQKtwkzAjKJiEs6bTKtcXSk6FDKM bkuAUkUF/eDyiH+3343u0qe3M9FtZBaluLBdb1+NSvkSvcb+OmQ83wfxbpwRnTfkrJR5vpdkCfO cck+G0IVKb3zMxGNsCB8Y4mF9RduyxMf8tfsVtL0jEz1bzxa2wkHHkY8Na2XgAT/B2p1p+T01bn ZI58R7L74TzHDygG6EFmWkwZKwSE2gg9hxV930ihnPxBhACV91i X-Received: by 2002:a05:6000:400c:b0:43b:4077:c18b with SMTP id ffacd0b85a97d-43b88a1e36bmr12684317f8f.46.1774543363710; Thu, 26 Mar 2026 09:42:43 -0700 (PDT) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:88ea:c658:5b20:5e46]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b9194311asm10645942f8f.10.2026.03.26.09.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 09:42:43 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH v1] ipa: rpi: Fix gamma lookup table generation for PiSP platform Date: Thu, 26 Mar 2026 16:40:39 +0000 Message-ID: <20260326164241.4212-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 --- 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..851f9b30 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 = 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 = std::min(65535u, (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;