From patchwork Wed Jul 3 13:49:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 20510 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 014E1BD87C for ; Wed, 3 Jul 2024 13:50:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AB46963339; Wed, 3 Jul 2024 15:50:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="F90E28fe"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED11962E25 for ; Wed, 3 Jul 2024 15:50:14 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:9263:c199:9587:576]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BFFA43D6; Wed, 3 Jul 2024 15:49:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720014586; bh=14LbDAN6T5tIXqacl03ylzHMz+akW+S3DqGC85tHzXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F90E28fe1/nM8RDu++sENsY3aIBKrIyD0cMe0NRP2RqOKD5FfuF4busGnNkNGRDO0 NfGYiaNq5dLF+ox0NFTdFjVcsSdiYSFwGB1SY5AVO3Cqa5HU45RP+qinCCW2pk0VK1 Dw2/XVX/TlEY/UEkYTxpk7La9x4tP16XAWzfr62I= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham , Laurent Pinchart Subject: [PATCH v3 3/6] ipa: rkisp1: blc: Query black levels from camera sensor helper Date: Wed, 3 Jul 2024 15:49:51 +0200 Message-ID: <20240703135000.242227-4-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240703135000.242227-1-stefan.klug@ideasonboard.com> References: <20240703135000.242227-1-stefan.klug@ideasonboard.com> 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" As the camera sensor helper now has the ability to provide the black level, use it. Black levels can still be overwritten by the tuning file, but the direction is to remove them from the tuning files and move them into the sensor helpers. Additionally interpret all values based on 16bits. The conversion to the scale required by the hardware is done in process(). It ensures all the values inside libcamera are the same scale and is in preparation for the i.MX8MP where black levels are based on a 20bit scale. Note that this breaks existing tuning files. The tuning files distributed with libcamera will be fixed in a later patch. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/rkisp1/algorithms/blc.cpp | 54 ++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp index d2e743541c99..b17b549c55df 100644 --- a/src/ipa/rkisp1/algorithms/blc.cpp +++ b/src/ipa/rkisp1/algorithms/blc.cpp @@ -46,10 +46,47 @@ BlackLevelCorrection::BlackLevelCorrection() int BlackLevelCorrection::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) { - blackLevelRed_ = tuningData["R"].get(256); - blackLevelGreenR_ = tuningData["Gr"].get(256); - blackLevelGreenB_ = tuningData["Gb"].get(256); - blackLevelBlue_ = tuningData["B"].get(256); + std::optional levelRed = tuningData["R"].get(); + std::optional levelGreenR = tuningData["Gr"].get(); + std::optional levelGreenB = tuningData["Gb"].get(); + std::optional levelBlue = tuningData["B"].get(); + bool tuningHasLevels = levelRed && levelGreenR && levelGreenB && levelBlue; + + auto blackLevel = context.camHelper->blackLevel(); + if (!blackLevel) { + /* + * Not all camera sensor helpers have been updated with black + * levels. Print a warning and fall back to the levels from the + * tuning data to preserve backward compatibility. This should + * be removed once all helpers provide the data. + */ + LOG(RkISP1Blc, Warning) + << "No black levels provided by camera sensor helper" + << ", please fix"; + + blackLevelRed_ = levelRed.value_or(4096); + blackLevelGreenR_ = levelGreenR.value_or(4096); + blackLevelGreenB_ = levelGreenB.value_or(4096); + blackLevelBlue_ = levelBlue.value_or(4096); + } else if (tuningHasLevels) { + /* + * If black levels are provided in the tuning file, use them to + * avoid breaking existing camera tuning. This is deprecated and + * will be removed. + */ + LOG(RkISP1Blc, Warning) + << "Deprecated: black levels overwritten by tuning file"; + + blackLevelRed_ = *levelRed; + blackLevelGreenR_ = *levelGreenR; + blackLevelGreenB_ = *levelGreenB; + blackLevelBlue_ = *levelBlue; + } else { + blackLevelRed_ = *blackLevel; + blackLevelGreenR_ = *blackLevel; + blackLevelGreenB_ = *blackLevel; + blackLevelBlue_ = *blackLevel; + } tuningParameters_ = true; @@ -77,10 +114,11 @@ void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context, return; params->others.bls_config.enable_auto = 0; - params->others.bls_config.fixed_val.r = blackLevelRed_; - params->others.bls_config.fixed_val.gr = blackLevelGreenR_; - params->others.bls_config.fixed_val.gb = blackLevelGreenB_; - params->others.bls_config.fixed_val.b = blackLevelBlue_; + /* The rkisp1 uses 12bit based black levels. Scale down accordingly. */ + params->others.bls_config.fixed_val.r = blackLevelRed_ >> 4; + params->others.bls_config.fixed_val.gr = blackLevelGreenR_ >> 4; + params->others.bls_config.fixed_val.gb = blackLevelGreenB_ >> 4; + params->others.bls_config.fixed_val.b = blackLevelBlue_ >> 4; params->module_en_update |= RKISP1_CIF_ISP_MODULE_BLS; params->module_ens |= RKISP1_CIF_ISP_MODULE_BLS;