From patchwork Tue Jan 6 17:00:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25674 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 7817FC3213 for ; Tue, 6 Jan 2026 17:01:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 21E6962033; Tue, 6 Jan 2026 18:01:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="tk54yVWa"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C78CB6201C for ; Tue, 6 Jan 2026 18:01:29 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-47bdbc90dcaso8809785e9.1 for ; Tue, 06 Jan 2026 09:01:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1767718889; x=1768323689; 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=psNP2vqDkJBYOqosGTGOW6EtApQ+kyXWy6fpn8pZtNw=; b=tk54yVWaUgUYStdJWZyKiawG1Jvs/UqMFC4jkIxevPVasTsmhMptjrRcMRh0kZqHG8 KTNSGC/LTnRzRQU7MWSIhCumIEjUvMSyKA/MIqJwJ4D31mIMTqa3picA7Gux+VFYssNB 2+RXXlPUcrj/DL5UOxq6qgX74/hRHGiea2j1lgP2/yJV4RJ0sTaJUUIXqWBTTwclYulu rrux4JYOLqYBXfTfUeS0QjVul4Qitfy1H0iQcnIgyVPZ+2Rwnh0CBHr4dZ8mIGVU3ksZ 9E5g8up4g/EJy762Fk2QlFlpKBcMxxxS0RiLnOJviGzjPgSp0AhwuPzMDDzvDZzHvn5o Hsxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767718889; x=1768323689; 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=psNP2vqDkJBYOqosGTGOW6EtApQ+kyXWy6fpn8pZtNw=; b=AWDiRr/8Iwjt4T2mNTYbOu4PESyolW3xnEWtBMOOBOV6vbB9+ivuh41V2+dEwq7LRz akGq4uW4eH9+nQZO6n8TN7P9+kDrt8tl90HKosE3a9Lsev758ONt3Q8/TVd0LZAGtn9B LHm49vPLBiQH6R+ULcMo4/lwIB7sbkpQsbqjogHTBXbGnVYDIUWR7nhVdpWathykJiF9 1CkBNjnBJ2m2juK7hg1prNOVyW3T91HeMBIevj2hwRzZHJhNnk0G75t2RJqYUk+9LSYV nlyJhG0YAGvEbGsk3fxi10tvb424H0KyZj6K7ifZO9teY7UyJ9I2KC23f0rvti+cVmS+ XxdQ== X-Gm-Message-State: AOJu0YyLA8BpNxociNu5ZKmXnHKs+9VVb6hHRF/WhvIniv/PVBKuTvQr 1PneAx058/DK35mYyfs+1rYS4n2J/T0O673O3jLlK5ZxDdS+QmXaovIbXythLYeKW4Oe7GSxp+1 uL5vxESQ= X-Gm-Gg: AY/fxX5r6Ca+yG/nXciW96fziiwirRfUcFSpiu/Dz7rhZk6Pqtd10OJSTZawviD3Xjy Tt23XHLDsa49U+zuAChINgvFYE75WBYtgm4/oZ4GFVKbhUhRgZvFf87xJ0F/Dm43GtsiQ/91o2r 34WuEUoEjz1LCze2DWWv9+EbyIvhNjrnjpxuMOE58TqfXBlRgveSGqrbubc7W7DH3yftNz54lUe dsVyMc3Q6ooAaoN/2aLtHYqiUp10n8mznFDrAHrvCsPF2t9nM9+j7QUtrHdJRj7s7z6Nuy+Yg0f Nv5oVVaIQlto88Hm8SK8WHJZw9AJBCrMMIUw2HqUI3ZBAIKsHU24XRI6ic0+ElQeKw9fYm6qMCn FS9/61sijhZJHnyN+tAwUXLE3BgHj1/sH4Dj2Vkgjv7BzTVNIqMcJkK5OHQzP5XqM899XoG3RkX rHPD1x7ZuWfVLUdd5A1Z4uRxCoesAj22gVh1B4ab/Ux/xNR2Dfx/r3qoKYG6EWB4Itw10= X-Google-Smtp-Source: AGHT+IHQAMRlOnKgd/tLsYCT9fskVYUJH3wDT3/4tugoJhXY8VAKQ+2NQJOTimyBAPOibVneTJsgnQ== X-Received: by 2002:a05:600c:1d24:b0:479:2a09:9262 with SMTP id 5b1f17b1804b1-47d7f077676mr41871795e9.9.1767718887582; Tue, 06 Jan 2026 09:01:27 -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 ffacd0b85a97d-432bd0dadcfsm5515322f8f.3.2026.01.06.09.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 09:01:27 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Milan Zamazal Subject: [PATCH v11 20/24] libcamera: software_isp: lut: Skip calculation lookup tables if gpuIspEnabled is true Date: Tue, 6 Jan 2026 17:00:55 +0000 Message-ID: <20260106170059.56193-21-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260106170059.56193-1-bryan.odonoghue@linaro.org> References: <20260106170059.56193-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 | 67 ++++++++++++++++--------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp index 7d015ac89..7418daa1e 100644 --- a/src/ipa/simple/algorithms/lut.cpp +++ b/src/ipa/simple/algorithms/lut.cpp @@ -56,33 +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); /* 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)); - 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) */ - /* 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; + /* 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.contrastExp = contrastExp; @@ -135,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]; + } } }