From patchwork Wed Dec 17 10:01:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25597 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 B0EA6C32F3 for ; Wed, 17 Dec 2025 10:02:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1801461F57; Wed, 17 Dec 2025 11:02:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="BMQhyfA5"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B0F3361F3E for ; Wed, 17 Dec 2025 11:02:12 +0100 (CET) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-47774d3536dso3952965e9.0 for ; Wed, 17 Dec 2025 02:02:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765965732; x=1766570532; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0x9sYofuRKBarctBdgKuhUSV0fpuyAnEk7YI+eA7X6s=; b=BMQhyfA5VEFVSeASPLCTfSLHdNy2VOrayMuzyI0xwbsaR6s4y95mfKEY5dvmL4PkgE VAejpWlj1uT2t+hU+8hGJgb5IHSz0/dFb42HqnpKnxPy08twN0P+GWwXd2U+x/zftZyR fF/4WIbDXpIjSwwWSS0I4GyUbABYuNZR8YqJyCtnsJkiuhH/bt+yWjGsiQDLhpi6jVTx SjjwZfU3Rn9awgmmJMcT3Yg6wSG+1TPpI3SoCpZJhA2e2dr7tNgivvagIhc0qHFoqgYa k8kjKBNYJidroYO9XCNu5JyTnEESqR7M1Ae7ofhZppPf9Nu3XFgbsT2Vw/5ZO2UtgU7u blNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765965732; x=1766570532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0x9sYofuRKBarctBdgKuhUSV0fpuyAnEk7YI+eA7X6s=; b=a6Ktby3CntsJUu8KJZJOHsC9NjfiYLZKtJAB45Qc8irNFQl88LUAEYt7dCJhBYHitS ZiayJYLVOwnsP5QBzj9KkOmP2u+sw3ISxjh5gnPA681HMzJDl5u5CDIqkq4xclcgpwBs tWxyK+av005Sp+zgqxs1YU4tZqvgaxo6gIvMfMhHkazOEA+rSl87fjo4HQEnVKc7/UC5 mqctMIuuoIT4ju7bPenoH7b9I+nqIf0Y1SZNmTATYO6xr4CwpKF57951AJDl9gKtRhSu EF0bV0KMicPvrzcPibrL1fcqhViV7kYY41llTuvU5ouZt0PfqueitDiIFPV0hSgSvso5 z0yw== X-Gm-Message-State: AOJu0YzV7cey+yCxO6Kf3oWuCFBVg3PkWjvK/0ZM4ntgqOiNvqcUMYvH JJ5+WHY/D+N1YmSuxiOiKrpx68dQpkTCUJZdYwcD0wRZKuNTE0yZ8PzVA9tA00GoHvZNXu3emK6 mP93x X-Gm-Gg: AY/fxX4cWXXYZ2inMlNfEXsrYA3+ZZM3UsTLYLekXuAUusQbOi1YldwR7HnI2gFFiyA 7VUMxzTqj5GQSUw7OviDqFJJBisyAvcIdMVafAV2xO+5ZMjOmAZlvf6NRANeeOsWKwKWmxTm2l0 d0lYCCcIu3rv6Deh/B/2aAQ4q2T/nxP7/KxPRpaOnj0QOae9/1tader1q880yDgwKFKVFyhX2r3 MFXp9Zy8kM2vjyfrmO9G5TvvUZc2uYJ5Wp38rF9aWD17H8I5CypzTGlpeS0Fhbdb3gUBqOJ0Nfq EKlUHidT4cBieritgPQSba6HkG+OPxcNv5DVALihrQRnC0NBN/oRuy8k/42l+CwVO4ceDqhafbE YunRR/Hu07IEZjvO7gViaWmn2Ke/0dcDwO7lUI+K/493itrsV/7v8VbjO6NmHHGc51+uijPcx+V 3SZBeueTfuEZReL9UOnZW3oKfenA87Xbi2S3ztoeD3SErAeN6Ybs36OQgaBWaVhsJve48= X-Google-Smtp-Source: AGHT+IGmxqKxLY4833F+Cuxw21nkY+BTpI/aTuShjG3Ea8giSSlaKckFVxS1DkneA3EnVj9iMd8Egw== X-Received: by 2002:a05:600c:4e91:b0:475:ddad:c3a9 with SMTP id 5b1f17b1804b1-47a8f2c2f62mr177622105e9.13.1765965731920; Wed, 17 Dec 2025 02:02:11 -0800 (PST) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47bdc1583fbsm32292585e9.0.2025.12.17.02.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 02:02:11 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Milan Zamazal Subject: [PATCH v9 24/26] libcamera: software_isp: lut: Skip calculation lookup tables if gpuIspEnabled is true Date: Wed, 17 Dec 2025 10:01:36 +0000 Message-ID: <20251217100138.82525-25-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251217100138.82525-1-bryan.odonoghue@linaro.org> References: <20251217100138.82525-1-bryan.odonoghue@linaro.org> 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" On my reference platform Qualcomm RB5 sm8520 the qcam application CPU occupancy drops from ~100% to about 95% of a single core so this one change sheds aprox 5% CPU usage. Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- src/ipa/simple/algorithms/lut.cpp | 70 ++++++++++++++++--------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp index 9aaab54f1..adf411768 100644 --- a/src/ipa/simple/algorithms/lut.cpp +++ b/src/ipa/simple/algorithms/lut.cpp @@ -56,32 +56,34 @@ void Lut::queueRequest(typename Module::Context &context, void Lut::updateGammaTable(IPAContext &context) { - auto &gammaTable = context.activeState.gamma.gammaTable; const auto blackLevel = context.activeState.blc.level; - const unsigned int blackIndex = blackLevel * gammaTable.size() / 256; const auto contrast = context.activeState.knobs.contrast.value_or(1.0); - const float divisor = gammaTable.size() - blackIndex - 1.0; - for (unsigned int i = blackIndex; i < gammaTable.size(); i++) { - double normalized = (i - blackIndex) / divisor; - /* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */ - double contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001)); - /* Apply simple S-curve */ - if (normalized < 0.5) - normalized = 0.5 * std::pow(normalized / 0.5, contrastExp); - else - normalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp); - gammaTable[i] = UINT8_MAX * - std::pow(normalized, context.configuration.gamma); + if (!context.gpuIspEnabled) { + auto &gammaTable = context.activeState.gamma.gammaTable; + const unsigned int blackIndex = blackLevel * gammaTable.size() / 256; + const float divisor = gammaTable.size() - blackIndex - 1.0; + for (unsigned int i = blackIndex; i < gammaTable.size(); i++) { + double normalized = (i - blackIndex) / divisor; + /* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */ + double contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001)); + /* Apply simple S-curve */ + if (normalized < 0.5) + normalized = 0.5 * std::pow(normalized / 0.5, contrastExp); + else + normalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp); + gammaTable[i] = UINT8_MAX * + std::pow(normalized, context.configuration.gamma); + } + /* + * Due to CCM operations, the table lookup may reach indices below the black + * level. Let's set the table values below black level to the minimum + * non-black value to prevent problems when the minimum value is + * significantly non-zero (for example, when the image should be all grey). + */ + std::fill(gammaTable.begin(), gammaTable.begin() + blackIndex, + gammaTable[blackIndex]); } - /* - * Due to CCM operations, the table lookup may reach indices below the black - * level. Let's set the table values below black level to the minimum - * non-black value to prevent problems when the minimum value is - * significantly non-zero (for example, when the image should be all grey). - */ - std::fill(gammaTable.begin(), gammaTable.begin() + blackIndex, - gammaTable[blackIndex]); context.activeState.gamma.blackLevel = blackLevel; context.activeState.gamma.contrast = contrast; @@ -134,17 +136,19 @@ void Lut::prepare(IPAContext &context, auto &green = params->greenCcm; auto &blue = params->blueCcm; params->ccm = ccm; - for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) { - red[i].r = ccmValue(i, ccm[0][0]); - red[i].g = ccmValue(i, ccm[1][0]); - red[i].b = ccmValue(i, ccm[2][0]); - green[i].r = ccmValue(i, ccm[0][1]); - green[i].g = ccmValue(i, ccm[1][1]); - green[i].b = ccmValue(i, ccm[2][1]); - blue[i].r = ccmValue(i, ccm[0][2]); - blue[i].g = ccmValue(i, ccm[1][2]); - blue[i].b = ccmValue(i, ccm[2][2]); - params->gammaLut[i] = gammaTable[i / div]; + if (!context.gpuIspEnabled) { + for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) { + red[i].r = ccmValue(i, ccm[0][0]); + red[i].g = ccmValue(i, ccm[1][0]); + red[i].b = ccmValue(i, ccm[2][0]); + green[i].r = ccmValue(i, ccm[0][1]); + green[i].g = ccmValue(i, ccm[1][1]); + green[i].b = ccmValue(i, ccm[2][1]); + blue[i].r = ccmValue(i, ccm[0][2]); + blue[i].g = ccmValue(i, ccm[1][2]); + blue[i].b = ccmValue(i, ccm[2][2]); + params->gammaLut[i] = gammaTable[i / div]; + } } }