From patchwork Wed Dec 10 00:53:52 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: 25441 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 2363FC3257 for ; Wed, 10 Dec 2025 00:55:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D182A614A3; Wed, 10 Dec 2025 01:55:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="qZ0WmSzy"; dkim-atps=neutral Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 53F5A614A0 for ; Wed, 10 Dec 2025 01:55:16 +0100 (CET) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7b8bbf16b71so6887963b3a.2 for ; Tue, 09 Dec 2025 16:55:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765328115; x=1765932915; 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=qZ0WmSzyvPwGdP5nyUjvS0LcH+CXYT433ZREIHCgYhxAhpPHX4Vu0vXdRC/WjffxX0 ndGSDM58YTkXe3++gKllmbC3AHLVtArIHjMWCG+8HYDdy2oyQb+2/ximBD72Mng1l1QU sT7FwNQWUyNWGy7rqWag+eIJxlA40yVT3FlHT688lNtuYXTuVRsRamL/NS8zPXKmq9WL qzMyvxVfWiNt8i/X0tQa6s5sLvmyaqR6WL8hExwCrYQAyKKIZmk1A24KN/pTVa1Qgi5u nFXL29LQb5dS+teBsVb9aqGLEu4yoczJskb1XDvjqCeA+Tw6UFelCJ4nsd2ZiqisdsUC spng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765328115; x=1765932915; 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=B7L+wYC/3yRKq0CJZpQYhlwi1YLeQO+SWd2LU6zHgkkewlDu/YeECwt1TymMAkog6B 6HUe5NC3ZB4DhL47UewYJzFrvEdC17vpO34gM0WR0GQVQpmD8Kiw+g74o7LtQNOdvlET x8fX1ewc3kQ0Swt+4lmJreXKOF3kEz6QiA6WR8HtwyUg7yxUa5qigFbLP/ThCBL2YPdw GxryV9v5uQU3KTWJOsIvnohv526Ov9gGTInUC7wx4suc4RKryEN6bsSxvmxCyEM3i/ba 35cz3VbGxEBd4z/w3J3lx5y6aFM4SDg5nQGcKImsh8r8UpttGepxK9mKMpbt9KKKM9tp 2Oag== X-Gm-Message-State: AOJu0YzDeHQujTxRdVL7NHglUMRA4zJqoGxXcy7vJGuquLd5UtmpeJ1n GhGAm8TaS9ijXSJWj5pbAfztHlZhd3xKqj+kB0iJqERmPzy1cQnFRNFveY33UVbaxZGW3ZITM19 ypbf5 X-Gm-Gg: ASbGncsyYUaVQuACRdLzJTOs57icwEg3tkA/fCM0VScTMGmXGNb0ezRZmMPBZuEYQgu /Rob4OsCn2t/ia/9bFGA1KfaX4NAn+3TOVGUqTkTtvTUutmtvp+pkRS67kVNxTqJFDz9g4I5vuY f5MnRazvZRphjVfx2X3JRi6N5r3uHhaZAe3ysSrGsAtVBMwjaGfEoH369cNO1GHBu2DUhHfHDEa 4CTRXJRJWmwp79sMVOLeN0pVgw7EL2faLhoFfmB3tNFxeAvQnyVUajEBtRZyPfc1aSYtJOk/4RG WeoCrebqsNDhpCKn+3GfiVIYXFstEDMu6itReX4KpaDVcBvI8057WvPaOyyhXJ9yfv5YhGwCiBd xz0VTnFzZSrEhADW9nxIeFAk6NHxGpWHPLdb2ue8qktQp87EMUJf2m5ETsclqn3wdUK/IgPU9Zx jUAan0U+KE4x9aOgAD41BmN2AYevSWlPmamhbnvlVFfXsU1+7He4jJd3bslb3367Ck X-Google-Smtp-Source: AGHT+IEIhWExzt6GfB5dVk76vELMHuBy7GkUEXM4GCaeNsCmdfcAJ6rYcBEhVH0aRKVXwEwxBkRVIw== X-Received: by 2002:a05:6a21:328f:b0:34e:1009:4216 with SMTP id adf61e73a8af0-366e0dea492mr561778637.24.1765328114542; Tue, 09 Dec 2025 16:55:14 -0800 (PST) Received: from inspiron14p-linux (p96936b06.osaknt01.ap.so-net.ne.jp. [150.147.107.6]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bf6875cc8eesm16057762a12.16.2025.12.09.16.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Dec 2025 16:55:13 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Milan Zamazal Subject: [PATCH v7 24/26] libcamera: software_isp: lut: Skip calculation lookup tables if gpuIspEnabled is true Date: Wed, 10 Dec 2025 00:53:52 +0000 Message-ID: <20251210005354.44726-25-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251210005354.44726-1-bryan.odonoghue@linaro.org> References: <20251210005354.44726-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]; + } } }