From patchwork Fri Aug 12 22:33:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17109 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 242D8C3275 for ; Fri, 12 Aug 2022 22:34:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF2496118E; Sat, 13 Aug 2022 00:34:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660343648; bh=FTkwjcfhwBH+7CVgqtjMApCdzgjDoffvXj3hHP45IPI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NYRSF4VH37a3V9rSYCwsVRWpPz0eVgYvO7wlwz4swsGD+WEI+mdZ0ptlw4UMnjds9 PmSG4vddPS1+ckLmrQo1MWqAr++1eG+mvU5uTWm8zrvHJHD4KP2Z5wWskQAS8YGf/q U1loxhHt7c6ZFIkDOZpH87s4nxSEUiO3bCAScmB++kDPNFkcpy8MJkfRUBifJmrsAO +mr7c/RSZrXbb2sLDAXeJTL+NENrEjnPj6X/3/W3owsYizEbPCMAyvbZKYFa4lTpEt 227MhxKTvgdppDTm8OSbQ/qc5+t6LkJ6n19Rc1VuFLCqlEvJI9QjY2+g1LJm5TSPWC hVaTQ9Fbdp0fQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED68A61189 for ; Sat, 13 Aug 2022 00:34:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rLwl+dXo"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 30CD247C; Sat, 13 Aug 2022 00:34:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1660343646; bh=FTkwjcfhwBH+7CVgqtjMApCdzgjDoffvXj3hHP45IPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rLwl+dXoJ8mR2iK9UVts/V1dDjHf0DSU91FyjBzJeSevEHJDSbfG5IotNSWEkilBl NxuZEtXNas1pfn9AXSxKFOnsOtzyZmj753H1AFB7DZZxN8gbVGyvMUWv9llHIxh/dx qpikxtKuZWfBJa43CUV2gkBo+dKkKCGDakkEuKdY= To: libcamera-devel@lists.libcamera.org Date: Sat, 13 Aug 2022 01:33:49 +0300 Message-Id: <20220812223351.22609-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220812223351.22609-1-laurent.pinchart@ideasonboard.com> References: <20220812223351.22609-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/3] ipa: rkisp1: Add enable field for AWB algorithm in IPA context 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Florian Sylvestre Add an enable variable in the awb struct in IPASessionConfiguration which indicates if the awb algorithm has been configured. This will allow other algorithms to retrieve this information. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/ipa/rkisp1/algorithms/awb.cpp | 2 ++ src/ipa/rkisp1/ipa_context.cpp | 3 +++ src/ipa/rkisp1/ipa_context.h | 1 + 3 files changed, 6 insertions(+) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 9f00364d12b1..d1328f011081 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -48,6 +48,8 @@ int Awb::configure(IPAContext &context, context.configuration.awb.measureWindow.h_size = 3 * configInfo.outputSize.width / 4; context.configuration.awb.measureWindow.v_size = 3 * configInfo.outputSize.height / 4; + context.configuration.awb.enabled = true; + return 0; } diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp index ef8bb8e931c8..23a63f8c6e25 100644 --- a/src/ipa/rkisp1/ipa_context.cpp +++ b/src/ipa/rkisp1/ipa_context.cpp @@ -87,6 +87,9 @@ namespace libcamera::ipa::rkisp1 { * * \var IPASessionConfiguration::awb.measureWindow * \brief AWB measure window + * + * \var IPASessionConfiguration::awb.enabled + * \brief Indicates if the AWB hardware is enabled to apply colour gains */ /** diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 2bdb6a81d7c9..7f7b3e4d88fa 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -29,6 +29,7 @@ struct IPASessionConfiguration { struct { struct rkisp1_cif_isp_window measureWindow; + bool enabled; } awb; struct { From patchwork Fri Aug 12 22:33:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17110 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 928E7BE173 for ; Fri, 12 Aug 2022 22:34:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C9B761191; Sat, 13 Aug 2022 00:34:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660343650; bh=AyFIfxpuH17cgl6wmgQ043p6rXxgbZbKyYIG2E/fGmU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qU9GIzzLu/6dNuYztS9zX4VzpSeKZtaRi/Bg4w2ObhGRMo19CAUfD8XbeYE6ApY1Z TdieFMtvnm8I5uj1fDBQBUoQvlmll+pKSwQ3ufKoslSoHZB3XHOhHea9ox5RtnYDkr UJ8S/1k5it6OSU+j+0Hx041BH++cTP20PnO6/VUaPxapbBEPsxROpdxe1g867WFkHx WDRuXT7oDCvB2BhpaCZxomgLfOZxnFLvqgNFT0XUq1d+jyYEwovbwzwrLiN9/IguZh lktcx49/99OHgF6w3sAXDzAtOiTIV2TRvcANZzfyUcKXX8QCmYiWP3hQzAtYsDg5SG gFvb+7auwG/vQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 19140604ED for ; Sat, 13 Aug 2022 00:34:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bKKEQPvH"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B0CE5505; Sat, 13 Aug 2022 00:34:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1660343647; bh=AyFIfxpuH17cgl6wmgQ043p6rXxgbZbKyYIG2E/fGmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bKKEQPvHsUKDhBGg+QwcDJeznn7HAu5TvRRJQGYhLpIeVU3r6q1rso5k2UOSNFuyN 8XwPQ8hTobj9SKhDCVZvGDeBhWCW9Mw+8LBP1EfPIxV6oTbPd86PFK1NH5da6vjkC9 /ck39eOHt99+K/e6xGIZQNBH95pl/dmaZ+RDI8rs= To: libcamera-devel@lists.libcamera.org Date: Sat, 13 Aug 2022 01:33:50 +0300 Message-Id: <20220812223351.22609-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220812223351.22609-1-laurent.pinchart@ideasonboard.com> References: <20220812223351.22609-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/3] ipa: rkisp1: Add enable field for LSC algorithm in IPA context 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Florian Sylvestre Add an enable variable in the lsc struct in IPASessionConfiguration which indicates if the lsc algorithm has been configured. This will allow other algorithms to retrieve this information. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain --- Changes since v1: - Improve documentation --- src/ipa/rkisp1/algorithms/lsc.cpp | 10 ++++++++++ src/ipa/rkisp1/algorithms/lsc.h | 1 + src/ipa/rkisp1/ipa_context.cpp | 8 ++++++++ src/ipa/rkisp1/ipa_context.h | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp index 05c8c0dab5c8..da287ac7af75 100644 --- a/src/ipa/rkisp1/algorithms/lsc.cpp +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -119,6 +119,16 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context, return 0; } +/** + * \copydoc libcamera::ipa::Algorithm::configure + */ +int LensShadingCorrection::configure(IPAContext &context, + [[maybe_unused]] const IPACameraSensorInfo &configInfo) +{ + context.configuration.lsc.enabled = initialized_; + return 0; +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h index fdb2ec1dd27d..f68602c005c4 100644 --- a/src/ipa/rkisp1/algorithms/lsc.h +++ b/src/ipa/rkisp1/algorithms/lsc.h @@ -20,6 +20,7 @@ public: ~LensShadingCorrection() = default; int init(IPAContext &context, const YamlObject &tuningData) override; + int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override; void prepare(IPAContext &context, rkisp1_params_cfg *params) override; private: diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp index 23a63f8c6e25..1a549c092d73 100644 --- a/src/ipa/rkisp1/ipa_context.cpp +++ b/src/ipa/rkisp1/ipa_context.cpp @@ -92,6 +92,14 @@ namespace libcamera::ipa::rkisp1 { * \brief Indicates if the AWB hardware is enabled to apply colour gains */ +/** + * \var IPASessionConfiguration::lsc + * \brief Lens Shading Correction configuration of the IPA + * + * \var IPASessionConfiguration::lsc.enabled + * \brief Indicates if the LSC hardware is enabled + */ + /** * \var IPASessionConfiguration::sensor * \brief Sensor-specific configuration of the IPA diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 7f7b3e4d88fa..0cd6aadb83ed 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -32,6 +32,10 @@ struct IPASessionConfiguration { bool enabled; } awb; + struct { + bool enabled; + } lsc; + struct { utils::Duration lineDuration; Size size; From patchwork Fri Aug 12 22:33:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17111 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 1B5EDBE173 for ; Fri, 12 Aug 2022 22:34:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CB9FA61197; Sat, 13 Aug 2022 00:34:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660343651; bh=cIQ83XEfKIMCI47TWe6treSCNvw/P7qBcDJXwL9qRXM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=h1R2ENyUI0xmWPYZ19N+dIshp5pKhb5XzPFnzk9m4s7raLRN6RdXOOlMZPSsDrp/S gLRSD28ZI0OQSady7m8O7QP30RSBramB22+YTTI9ZMhknvG+h7zuD6TFMMF2JktAPG Yp3flF+tH95y4ohX2+ItnxDMCsUyF3jiWWbgkM4YG0RWhfBg3wdMeTKV+KggoZm8mQ tz6joT/q/FHiptt6WUa+im5I3WHcKs9EKaqtx+cSs6iLHNQDhhyIhTJvAyw5pAti6A ojWXegrWHJLSoTO2EbRlf+lQXughVZ+gxz/nEBiLjSKDn4N9BX/pyGBEV4nIAoecHZ ec8FOG5XfTd8A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7221A6118D for ; Sat, 13 Aug 2022 00:34:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fgCPGG7w"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F1AB547C; Sat, 13 Aug 2022 00:34:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1660343649; bh=cIQ83XEfKIMCI47TWe6treSCNvw/P7qBcDJXwL9qRXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fgCPGG7w742F1DYORUxv6h5vy+LmlGb1+kIcHYbzoxFQuwj7qRLMLxC54+G4K4JZ2 oeBQnJLeWoDle5KLtBrBAGDFI+bqxvpzvEwz6ZzE4HCIiT0U3Vh/Cjas0GgPFUx7Kv 4+fmnAQcHBjlxUaH8mwkyZnqQQUS6/hm9PW9W/Qs= To: libcamera-devel@lists.libcamera.org Date: Sat, 13 Aug 2022 01:33:51 +0300 Message-Id: <20220812223351.22609-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220812223351.22609-1-laurent.pinchart@ideasonboard.com> References: <20220812223351.22609-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/3] ipa: rkisp1: Add support of Denoise Pre-Filter control 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Florian Sylvestre The denoise pre-filter algorithm is a bilateral filter which combines a range filter and a domain filter. The denoise pre-filter is applied before demosaicing. Signed-off-by: Florian Sylvestre Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain --- Changes since v2: - Change the scope of some variables in Dpf::prepare() - Line-wrap coefficients in tuning file --- src/ipa/rkisp1/algorithms/dpf.cpp | 249 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/dpf.h | 36 ++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 15 ++ src/ipa/rkisp1/ipa_context.cpp | 11 ++ src/ipa/rkisp1/ipa_context.h | 5 + 6 files changed, 317 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/dpf.cpp create mode 100644 src/ipa/rkisp1/algorithms/dpf.h diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp new file mode 100644 index 000000000000..33fe3066b9e3 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -0,0 +1,249 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * dpf.cpp - RkISP1 Denoise Pre-Filter control + */ + +#include "dpf.h" + +#include + +#include + +#include + +#include "linux/rkisp1-config.h" + +/** + * \file dpf.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class Dpf + * \brief RkISP1 Denoise Pre-Filter control + * + * The denoise pre-filter algorithm is a bilateral filter which combines a + * range filter and a domain filter. The denoise pre-filter is applied before + * demosaicing. + */ + +LOG_DEFINE_CATEGORY(RkISP1Dpf) + +Dpf::Dpf() + : initialized_(false), config_({}), strengthConfig_({}) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int Dpf::init([[maybe_unused]] IPAContext &context, + const YamlObject &tuningData) +{ + std::vector values; + + /* + * The domain kernel is configured with a 9x9 kernel for the green + * pixels, and a 13x9 or 9x9 kernel for red and blue pixels. + */ + const YamlObject &dFObject = tuningData["DomainFilter"]; + + /* + * For the green component, we have the 9x9 kernel specified + * as 6 coefficients: + * Y + * ^ + * 4 | 6 5 4 5 6 + * 3 | 5 3 3 5 + * 2 | 5 3 2 3 5 + * 1 | 3 1 1 3 + * 0 - 4 2 0 2 4 + * -1 | 3 1 1 3 + * -2 | 5 3 2 3 5 + * -3 | 5 3 3 5 + * -4 | 6 5 4 5 6 + * +---------|--------> X + * -4....-1 0 1 2 3 4 + */ + values = dFObject["g"].getList().value_or(utils::defopt); + if (values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS) { + LOG(RkISP1Dpf, Error) + << "Invalid 'DomainFilter:g': expected " + << RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS + << " elements, got " << values.size(); + return -EINVAL; + } + + std::copy_n(values.begin(), values.size(), + std::begin(config_.g_flt.spatial_coeff)); + + config_.g_flt.gr_enable = true; + config_.g_flt.gb_enable = true; + + /* + * For the red and blue components, we have the 13x9 kernel specified + * as 6 coefficients: + * + * Y + * ^ + * 4 | 6 5 4 3 4 5 6 + * | + * 2 | 5 4 2 1 2 4 5 + * | + * 0 - 5 3 1 0 1 3 5 + * | + * -2 | 5 4 2 1 2 4 5 + * | + * -4 | 6 5 4 3 4 5 6 + * +-------------|------------> X + * -6 -4 -2 0 2 4 6 + * + * For a 9x9 kernel, columns -6 and 6 are dropped, so coefficient + * number 6 is not used. + */ + values = dFObject["rb"].getList().value_or(utils::defopt); + if (values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS && + values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS - 1) { + LOG(RkISP1Dpf, Error) + << "Invalid 'DomainFilter:rb': expected " + << RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS - 1 + << " or " << RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS + << " elements, got " << values.size(); + return -EINVAL; + } + + config_.rb_flt.fltsize = values.size() == RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS + ? RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9 + : RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9; + + std::copy_n(values.begin(), values.size(), + std::begin(config_.rb_flt.spatial_coeff)); + + config_.rb_flt.r_enable = true; + config_.rb_flt.b_enable = true; + + /* + * The range kernel is configured with a noise level lookup table (NLL) + * which stores a piecewise linear function that characterizes the + * sensor noise profile as a noise level function curve (NLF). + */ + const YamlObject &rFObject = tuningData["NoiseLevelFunction"]; + + values = rFObject["coeff"].getList().value_or(utils::defopt); + if (values.size() != RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS) { + LOG(RkISP1Dpf, Error) + << "Invalid 'RangeFilter:coeff': expected " + << RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS + << " elements, got " << values.size(); + return -EINVAL; + } + + std::copy_n(values.begin(), values.size(), + std::begin(config_.nll.coeff)); + + std::string scaleMode = rFObject["scale-mode"].get(""); + if (scaleMode == "linear") { + config_.nll.scale_mode = RKISP1_CIF_ISP_NLL_SCALE_LINEAR; + } else if (scaleMode == "logarithmic") { + config_.nll.scale_mode = RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC; + } else { + LOG(RkISP1Dpf, Error) + << "Invalid 'RangeFilter:scale-mode': expected " + << "'linear' or 'logarithmic' value, got " + << scaleMode; + return -EINVAL; + } + + const YamlObject &fSObject = tuningData["FilterStrength"]; + + strengthConfig_.r = fSObject["r"].get(64); + strengthConfig_.g = fSObject["g"].get(64); + strengthConfig_.b = fSObject["b"].get(64); + + initialized_ = true; + + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void Dpf::queueRequest(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + const ControlList &controls) +{ + auto &dpf = context.frameContext.dpf; + + const auto &denoise = controls.get(controls::draft::NoiseReductionMode); + if (denoise) { + LOG(RkISP1Dpf, Debug) << "Set denoise to " << *denoise; + + switch (*denoise) { + case controls::draft::NoiseReductionModeOff: + dpf.denoise = false; + dpf.updateParams = true; + break; + case controls::draft::NoiseReductionModeMinimal: + case controls::draft::NoiseReductionModeHighQuality: + case controls::draft::NoiseReductionModeFast: + dpf.denoise = true; + dpf.updateParams = true; + break; + default: + LOG(RkISP1Dpf, Error) + << "Unsupported denoise value " + << *denoise; + } + } +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Dpf::prepare(IPAContext &context, rkisp1_params_cfg *params) +{ + if (!initialized_) + return; + + auto &dpf = context.frameContext.dpf; + + if (context.frameContext.frameCount == 0) { + params->others.dpf_config = config_; + params->others.dpf_strength_config = strengthConfig_; + + const auto &awb = context.configuration.awb; + const auto &lsc = context.configuration.lsc; + auto &mode = params->others.dpf_config.gain.mode; + + if (awb.enabled && lsc.enabled) + mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS; + else if (awb.enabled) + mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS; + else if (lsc.enabled) + mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS; + else + mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED; + + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_DPF | + RKISP1_CIF_ISP_MODULE_DPF_STRENGTH; + } + + if (dpf.updateParams) { + params->module_en_update |= RKISP1_CIF_ISP_MODULE_DPF; + if (dpf.denoise) + params->module_ens |= RKISP1_CIF_ISP_MODULE_DPF; + + dpf.updateParams = false; + } +} + +REGISTER_IPA_ALGORITHM(Dpf, "Dpf") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h new file mode 100644 index 000000000000..128ebd5e02e3 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/dpf.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * dpf.h - RkISP1 Denoise Pre-Filter control + */ + +#pragma once + +#include + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class Dpf : public Algorithm +{ +public: + Dpf(); + ~Dpf() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void queueRequest(IPAContext &context, const uint32_t frame, + const ControlList &controls) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + +private: + bool initialized_; + struct rkisp1_cif_isp_dpf_config config_; + struct rkisp1_cif_isp_dpf_strength_config strengthConfig_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index e48974b454b5..93a483292753 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -6,6 +6,7 @@ rkisp1_ipa_algorithms = files([ 'blc.cpp', 'cproc.cpp', 'dpcc.cpp', + 'dpf.cpp', 'filter.cpp', 'gsl.cpp', 'lsc.cpp', diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index 45d4bb77f8ca..3dc369ac3681 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -156,5 +156,20 @@ algorithms: rnd-offsets: green: 2 red-blue: 2 + - Dpf: + DomainFilter: + g: [ 16, 16, 16, 16, 16, 16 ] + rb: [ 16, 16, 16, 16, 16, 16 ] + NoiseLevelFunction: + coeff: [ + 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, + 1023 + ] + scale-mode: "linear" + FilterStrength: + r: 64 + g: 64 + b: 64 - Filter: ... diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp index 1a549c092d73..17f15fd4e6b5 100644 --- a/src/ipa/rkisp1/ipa_context.cpp +++ b/src/ipa/rkisp1/ipa_context.cpp @@ -164,6 +164,17 @@ namespace libcamera::ipa::rkisp1 { * \brief Indicates if ISP parameters need to be updated */ +/** + * \var IPAFrameContext::dpf + * \brief Context for the Denoise Pre-Filter algorithm + * + * \var IPAFrameContext::dpf.denoise + * \brief Indicates if denoise is activated + * + * \var IPAFrameContext::dpf.updateParams + * \brief Indicates if ISP parameters need to be updated + */ + /** * \var IPAFrameContext::filter * \brief Context for the Filter algorithm diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 0cd6aadb83ed..3a743ac325da 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -69,6 +69,11 @@ struct IPAFrameContext { bool updateParams; } cproc; + struct { + bool denoise; + bool updateParams; + } dpf; + struct { uint8_t denoise; uint8_t sharpness;