From patchwork Wed Jun 22 15:19:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16325 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 CA33CBE173 for ; Wed, 22 Jun 2022 15:19:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3F93E6563A; Wed, 22 Jun 2022 17:19:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655911165; bh=3Ii/EC6Crwfa61DMI8UWdPMO7Asz9MwoR1YFNELjJbE=; 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=iL4xoZW9Em7FykxKjkXOYIcZbOjMGMYxkaL2Zlq3eFkx7fzYWplYX6Vra6NwSlUIi +/m7y/9hC9Sgc0T6gUbTdHitB3+ajxerPKDThbhTHnyxuR43MR16qYjgavWXZ4gmyV KcfBWQcznOTHnUJAeTck6/SdbnDkqTG5rEovv7i+g3F+/PDlDinpNYvlSr8bMqDBaX YRcuunx0bWdk2rGkT+k/WIuDoQewvWL3KHIcNLJyUJv2pBgvKohyTXURBX6c8FtkaH QjIXGBvP1FLIPnefk1oIrGBlOp1hj8TNtu4nN1kMAblvuY0H1EtNKnfffBkJ7q9B7E 4POcKH09jo4sw== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B44A1633A7 for ; Wed, 22 Jun 2022 17:19:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="Hhv3ocGq"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id r20so3470784wra.1 for ; Wed, 22 Jun 2022 08:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AE6oXn0AJ2vVpFGOXOrAOauwGaTg8VttfgGqOkuBWk0=; b=Hhv3ocGq9n0oyTO4+rPGUTHYOx4gmwuNdDvH/qyewObwvkbZwnb17dTJmaRDdPqH2S jSuLaWOo8mvXc6eXqw129YzpaNjVIEO8odf/WGL31m+PaYtlllNpu8WUR7mP8sSUdDs4 wFcrbWcLDysTZa+ps5+FjF83sUNN6R+Tc2EqG3xxoB7OhW1by96PAEgrc0X4Or1Soc/z wXXYXsQLAqXk1Q3TO2RINKoyr3HCy23FpkSn7wLS862a2gGLEk+1MLw0utLTxRayjDaT NPiiXDsSnRe3TYMZvAbI158DXLA49ByRFwI84J04env7bHS/hW3UXDaepnGOnP/2DTAw BDWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AE6oXn0AJ2vVpFGOXOrAOauwGaTg8VttfgGqOkuBWk0=; b=TLf8JNc116PQOjB/suXoLRFqaK2QTotg3yHA+LKyY2azQyas35TR4sOrUKJXVYjZtI 4zx+A30jkgGo7VgE8m/HlLZwbDCMNLYwt3h+3yGYEr5/1k9seoeCilQznznLUVg3SNVy 0xuKxPu+N5mB8S89kcqxCy2C0dQe/6mPt0K82rzt14F9n4oFn3S8wQCLiEIJNoS8zL5h 97Bus74cDNbM1bZfEOznc07r6CCItN3xfAtCWOkB5rW1thL90ArHGr0GDRMRyumh5cRm ZW8WLdQIIb0+abywolx7XOdrrIVY47vWQ3FWoDWdN6LED5K+ATh1DKeniZdHqHXtjCEi RSag== X-Gm-Message-State: AJIora9+DjZV/aRpsXK3ikHfmePKqQWJZMt1boZseZ2kFkOdOC7h8m3G UiulkcxS+seWNxMQ+vfyCCH9wUregIV0Eg== X-Google-Smtp-Source: AGRyM1uS4AuXwkFv4w5ZfFomqTNfiuNtrOmTmiDGY2rZfNk67TWfg3eznO/7iQq3u4mQNGZ/cXPF7w== X-Received: by 2002:a05:6000:22a:b0:21b:9bc4:b166 with SMTP id l10-20020a056000022a00b0021b9bc4b166mr3897295wrz.287.1655911162113; Wed, 22 Jun 2022 08:19:22 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:4175:47f:ec:c265]) by smtp.gmail.com with ESMTPSA id bi11-20020a05600c3d8b00b0039c362311d2sm1745388wmb.9.2022.06.22.08.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 08:19:21 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 17:19:14 +0200 Message-Id: <20220622151918.451635-2-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220622151918.451635-1-fsylvestre@baylibre.com> References: <20220622151918.451635-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] libcamera: yaml_parser: Add getList() function 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: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Allow to retrieve a YAML list of any already supported types in a std::vector. Signed-off-by: Florian Sylvestre Reviewed-by: Paul Elder --- include/libcamera/internal/yaml_parser.h | 16 ++++++ src/libcamera/yaml_parser.cpp | 73 ++++++++++++++++++++++++ test/yaml-parser.cpp | 6 ++ 3 files changed, 95 insertions(+) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 064cf443..ea9189bd 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -167,6 +167,22 @@ public: #endif T get(const T &defaultValue, bool *ok = nullptr) const; +#ifndef __DOXYGEN__ + template::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value> * = nullptr> +#else + template +#endif + std::vector getList(bool *ok = nullptr) const; + DictAdapter asDict() const { return DictAdapter{ dictionary_ }; } ListAdapter asList() const { return ListAdapter{ list_ }; } diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 5c45e44e..95c0038b 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -117,6 +117,23 @@ std::size_t YamlObject::size() const * \return Value as a bool type */ +/** + * \fn template YamlObject::getList( + * bool *ok) const + * \brief Parse the YamlObject as a list of \a T. + * \param[out] ok The result of whether the parse succeeded + * + * This function parses the value of the YamlObject as a list of \a T objects, + * and returns the value as a \a std::vector. If parsing fails \a ok is set + * to false and a default empty vector is returned. Otherwise, the + * YamlObject list of values is returned, and \a ok is set to true. + * + * The \a ok pointer is optional and can be a nullptr if the caller doesn't + * need to know if parsing succeeded. + * + * \return Value as a std::vector type + */ + #ifndef __DOXYGEN__ template<> @@ -323,6 +340,62 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const return Size(width, height); } +template::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value> *> +std::vector YamlObject::getList(bool *ok) const +{ + setOk(ok, false); + + std::vector defaultValue; + + if (type_ != Type::List) + return defaultValue; + + std::vector value = std::vector(list_.size()); + + /* + * Provide somme dummy defaultValue to get() function + * and rely on the ok variable to know if the parsing + * was correct. + */ + T defaultArgument = T(); + bool result; + for (unsigned int i = 0; i < list_.size(); ++i) { + result = true; + value[i] = list_[i]->get(defaultArgument, &result); + + if (!result) + return defaultValue; + } + + setOk(ok, true); + return value; +} + +template std::vector YamlObject::getList(bool *ok) const; + +template std::vector YamlObject::getList(bool *ok) const; + +template std::vector YamlObject::getList(bool *ok) const; + +template std::vector YamlObject::getList(bool *ok) const; + +template std::vector YamlObject::getList(bool *ok) const; + +template std::vector YamlObject::getList(bool *ok) const; + +template std::vector YamlObject::getList(bool *ok) const; + +template std::vector YamlObject::getList(bool *ok) const; + #endif /* __DOXYGEN__ */ /** diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 38f84823..bb96a11b 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -524,6 +524,12 @@ protected: return TestFail; } + std::vector values = firstElement.getList(); + if (values.size() != 2 || values[0] != 1 || values[1] != 2) { + cerr << "getList() failed to return correct vector" << std::endl; + return TestFail; + } + auto &secondElement = level2Obj[1]; if (!secondElement.isDictionary() || !secondElement.contains("one") || From patchwork Wed Jun 22 15:19:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16326 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 371A8BE173 for ; Wed, 22 Jun 2022 15:19:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DE3176563F; Wed, 22 Jun 2022 17:19:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655911167; bh=24RVhavebKniWYuCdDXVg65LTNOBDF3d6tMEDxsO1hw=; 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=ob/NwN6TPsrvrqTBaVDWhaZW5/J+JUkZXFpkxnINdO9dMRo/uGCMSbMggw7AEZ/0f kbC86F1KlXZohew//u8leb1LInUMARllxhzjgDy4ZFjWq3QqDzrXxBmJZtqgtb9K3E m+aWZaaG1d5N4SHQIDiqOvgvqIN3ev7KiYa4NZHPEm2vdy6rkelaGY1DhyCsplbvqC XgvmCZZv/O7dT+1EKWM7xIYUU6r+qf8epQqxbLHmLX4LMISAoCXH5bUMeyKsQyJmnu PMIrKOMvwsMC/3nE2QFcLl/7tegSdrFk4tHlS2Tffno873mdndJUxw7KvT+CXVRcuI cmZXeOzwkOEAQ== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D9C2633A7 for ; Wed, 22 Jun 2022 17:19:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="eWz5w/Zx"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id m1so16130810wrb.2 for ; Wed, 22 Jun 2022 08:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yNaK4lL7ptTiR8Dc2zGHrSfnzbtoITkNc2JISFFG+I0=; b=eWz5w/Zx8Ef7ubtowMrAYF5nXHtEHej0dMEUZkq+2uoMZHJ73AQa/QYzrGoy+BPlko Ch53Aimu8AOwjD/SJlZ04TYlLFPH4hdAO+ML2tt5NJaWFYPXfAb3Bp7bimSUuZJTpLUh GbyTyCu1tP9ua5uGSUTbvdwiMmi/pExtYmJgG9tx+S7ItDVeooK79PL2v40Rbsi3Fa6m TlxiNbWqwPFuOTnMF80q7LKHt4eBdY0JLHdj4IoDxetKGY9cYC9gKcFGe4wc/iAndl9o PY+qp/XToktluncuTl4XYVLZkMIMcxTg0YpTCFjz44NfZnjRjlggG561lGE/r86Q5C+5 0zrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yNaK4lL7ptTiR8Dc2zGHrSfnzbtoITkNc2JISFFG+I0=; b=fcY+kDbE8aKs3JCecqUsBXCpTXbgdWtJNqkVGtbDN1zZQtacDm1rtJaUn/i8fQsSVV NeJSnCaJAwdUSaE3cJnZnAcC9AmJKoieH3GOV/vFNHdKkTiLa7MhPkC64a5xfjAacI80 Oq0e2xg6Sh+U71v6I8jCwZhIn3Kto/nGILsaJ7GzHRFGN79KAdZSuYjDgZdgQqQGvz5o OxfQbGGBcVxbR101h9GCXgt9yA8uWHn/1x8Li5gMYZothebhYzef7gNMKiKQOKqYtxH4 AZc+3pFQuS9KIbab1zmvO0FEt85ys5zfD2dwVl16EYiasjd1a/nN7niTiDfxLF7yK19A HJkg== X-Gm-Message-State: AJIora8v0fScXq64o3dXlkPLpTPvtaHv3W8KZgOnDQJns8eTTTvDmazq GIvhH9gamqZ4jeZeuOFCnr5aFbaCKcEzaw== X-Google-Smtp-Source: AGRyM1tlWOuObTr2c113LLcl3nEm31+XxNg0kSEVZeYmsyAEa4ImjQ9opF2oHImwYEH56bHrr8QLLw== X-Received: by 2002:adf:ea43:0:b0:21b:9243:be8c with SMTP id j3-20020adfea43000000b0021b9243be8cmr3761987wrn.650.1655911162976; Wed, 22 Jun 2022 08:19:22 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:4175:47f:ec:c265]) by smtp.gmail.com with ESMTPSA id bi11-20020a05600c3d8b00b0039c362311d2sm1745388wmb.9.2022.06.22.08.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 08:19:22 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 17:19:15 +0200 Message-Id: <20220622151918.451635-3-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220622151918.451635-1-fsylvestre@baylibre.com> References: <20220622151918.451635-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] ipa: rkisp1: Add support of Gamma Sensor Linearization 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: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The GammaSensorLinearization algorithm improves the image dynamic using a coefficient table in the YAML tuning file. Signed-off-by: Florian Sylvestre --- src/ipa/rkisp1/algorithms/gsl.cpp | 142 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/gsl.h | 38 +++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 6 ++ src/ipa/rkisp1/rkisp1.cpp | 1 + 5 files changed, 188 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/gsl.cpp create mode 100644 src/ipa/rkisp1/algorithms/gsl.h diff --git a/src/ipa/rkisp1/algorithms/gsl.cpp b/src/ipa/rkisp1/algorithms/gsl.cpp new file mode 100644 index 00000000..7ff3d360 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/gsl.cpp @@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * gsl.cpp - RkISP1 Gamma Sensor Linearization control + */ + +#include "gsl.h" + +#include + +#include "libcamera/internal/yaml_parser.h" +#include "linux/rkisp1-config.h" + +/** + * \file gsl.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class GammaSensorLinearization + * \brief RkISP1 Gamma Sensor Linearization control + * + * This algorithm improves the image dynamic using a coefficient table in the + * Yaml tuning file, the table contains: + * - 'x-intervals': These values corresponds to GAMMA_DX_n values (from + * GAMMA_DX_0 to GAMMA_DX_16 fields in RKISP1_CIF_ISP_GAMMA_DX_LO and + * RKISP1_CIF_ISP_GAMMA_DX_HI rkisp1 registers). + * Note: rkisp1 use each value to compute a X interval equal to 2^(value+4) + * - 'y' values for each component (red, green , blue) on 12 bits resolution. + */ + +LOG_DEFINE_CATEGORY(RkISP1Gsl) + +#define DEGAMMA_X_INTERVALS 16 + +GammaSensorLinearization::GammaSensorLinearization() + : tuningParameters_(false) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context, + const YamlObject &tuningData) +{ + std::vector xIntervals_ = tuningData["x-intervals"].getList(); + if (xIntervals_.size() != DEGAMMA_X_INTERVALS) { + LOG(RkISP1Gsl, Error) + << "Issue while parsing 'x'" + << "in tuning file (list size:" + << xIntervals_.size() << "/" + << DEGAMMA_X_INTERVALS << ")"; + return -EINVAL; + } + + /* Compute gammaDx_ intervals from xIntervals_ values */ + gammaDx_[0] = 0; + gammaDx_[1] = 0; + for (int i = 0; i < DEGAMMA_X_INTERVALS; ++i) { + gammaDx_[i / 8] |= (xIntervals_[i] & 0x07) << ((i % 8) * 4); + } + + const YamlObject &yObject = tuningData["y"]; + + if (!yObject.isDictionary()) { + LOG(RkISP1Gsl, Error) + << "Issue while parsing 'y' in tuning file: " + << "entry must be a dictionary"; + return -EINVAL; + } + + curveYr_ = yObject["red"].getList(); + if (curveYr_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { + LOG(RkISP1Gsl, Error) + << "Issue while parsing 'y:red'" + << "in tuning file (list size: " + << curveYr_.size() << "/" + << RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE << ")"; + return -EINVAL; + } + + curveYg_ = yObject["green"].getList(); + if (curveYg_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { + LOG(RkISP1Gsl, Error) + << "Issue while parsing 'y:green'" + << "in tuning file (list size: " + << curveYg_.size() << "/" + << RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE << ")"; + return -EINVAL; + } + + curveYb_ = yObject["blue"].getList(); + if (curveYb_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { + LOG(RkISP1Gsl, Error) + << "Issue while parsing 'y:blue'" + << "in tuning file (list size: " + << curveYb_.size() << "/" + << RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE << ")"; + return -EINVAL; + } + + tuningParameters_ = true; + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void GammaSensorLinearization::prepare(IPAContext &context, + rkisp1_params_cfg *params) +{ + if (context.frameContext.frameCount > 0) + return; + + if (!tuningParameters_) + return; + + params->others.sdg_config.xa_pnts.gamma_dx0 = gammaDx_[0]; + params->others.sdg_config.xa_pnts.gamma_dx1 = gammaDx_[1]; + + std::copy(curveYr_.begin(), curveYr_.end(), + params->others.sdg_config.curve_r.gamma_y); + std::copy(curveYg_.begin(), curveYg_.end(), + params->others.sdg_config.curve_g.gamma_y); + std::copy(curveYb_.begin(), curveYb_.end(), + params->others.sdg_config.curve_b.gamma_y); + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_SDG; + params->module_ens |= RKISP1_CIF_ISP_MODULE_SDG; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_SDG; +} + +REGISTER_IPA_ALGORITHM(GammaSensorLinearization) + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/gsl.h b/src/ipa/rkisp1/algorithms/gsl.h new file mode 100644 index 00000000..df16a89b --- /dev/null +++ b/src/ipa/rkisp1/algorithms/gsl.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * gsl.h - RkISP1 Gamma Sensor Linearization control + */ + +#pragma once + +#include + +#include "algorithm.h" + +namespace libcamera { + +struct IPACameraSensorInfo; + +namespace ipa::rkisp1::algorithms { + +class GammaSensorLinearization : public Algorithm +{ +public: + GammaSensorLinearization(); + ~GammaSensorLinearization() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + +private: + bool tuningParameters_; + uint32_t gammaDx_[2]; + std::vector curveYr_; + std::vector curveYg_; + std::vector curveYb_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 7ec53d89..0597c353 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -4,4 +4,5 @@ rkisp1_ipa_algorithms = files([ 'agc.cpp', 'awb.cpp', 'blc.cpp', + 'gsl.cpp', ]) diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index 232d8ae8..6cb84ed9 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -10,4 +10,10 @@ algorithms: Gr: 256 Gb: 256 B: 256 + - GammaSensorLinearization: + x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] + y: + red: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096 ] + green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096 ] + blue: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096 ] ... diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index d052954e..622a0d61 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -31,6 +31,7 @@ #include "algorithms/algorithm.h" #include "algorithms/awb.h" #include "algorithms/blc.h" +#include "algorithms/gsl.h" #include "libipa/camera_sensor_helper.h" #include "ipa_context.h" From patchwork Wed Jun 22 15:19:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16327 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 25623BE173 for ; Wed, 22 Jun 2022 15:19:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C00ED65639; Wed, 22 Jun 2022 17:19:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655911170; bh=yqq+UBp20k1C+9wZ1HmBhedkGwYdaBaRwvsHvWjiKvM=; 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=xSxBManRyQkRT2fcA0VESDa0o5vyatVMrt7XDSoKmqqfJC6m+ACjcG5ZImzRxfddK N0igSLL8Appadyfrg0zaNS3G7dP5v8/PrckFg5NIrgg2boLuVONDkS1lTd53PRN8Ix scOUX54h0mGo6y+HeSms+0r/JId9YUuWYFaDovdmlLVU6VmxivZ5Cw5qUhlx6FoAQb rjKvYv8G1FfmZnT7vPN4iO6DbBOwABD8sKEgLVtcIZYjCJg22J+dbu2X2z6jFOFeYF RKGbDH/3+SQdymwq0Cy14ubpmKpEVvrEYo22lrPgUohGrzDm+X2lS3U73/0KSlaJea 6+unZ3Lny+Plw== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AB7D165633 for ; Wed, 22 Jun 2022 17:19:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="Xlf8UMKY"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id k22so17458767wrd.6 for ; Wed, 22 Jun 2022 08:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0RPtkDZxBIg4j/flfTGF68aYP828g80Oux51XyfzmZc=; b=Xlf8UMKYp7hoKwbt9UqvWlhFHKo73iyC0kN6608fmbX7/ZfM00zHlxBFbWaqJYVRQp Yu/RT8sF6WRyEQs0QIamAfo4uwrLlHyWd8QUCwRoSAKGzJUQNfw3PjiOk46C44JxXRlE E5tMMSwdY0Og90UAGJ7Ez30SD5W9lKizgf6geXQEyA1MXJPj32ToAMUmURNq+b4JKnud gttvrojwsT3zdCdeOGoC8PIIpzmCobsVE6QXJGLRSyWPIytuEJCg3loGfhtEgb0s70Mi O4I+tn9Mz09yG377YUwwVB99xsTQxpHapjgjf+wiEkam06YkBY/qukBvNjuogsZavykt k4CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0RPtkDZxBIg4j/flfTGF68aYP828g80Oux51XyfzmZc=; b=lLzAF3ahv/TbIMtvOGnvsvKgXVEqfUb/+9uABUX5Bz2bx2pVT4ihvm+HadLUhkApyq 27tHWXfDIdsWVh8jzACZ36duZ5BJJCZEykFMUIyT6IFf08XlSUDVIMpeIFZIBRQZDQQI H4Gq2yZ8Ph7wGvOZpIphODLkmA/l5LZidYTPWgRuaovtjMK+A1Hu9JngLj/YqnQIV3if SnifSo80zlCTVDVmKbxbTj7ZBg/HpwxoWDBcuSKY7uDKGokrarS58X+LUw0DAEnZ4SUt Cs2Gwxou6U2Q2NuUqiPh0Zwy2nbjc0JmU3hvpQIXx92ZTzWvVjETVXzU8YMwSgnmgSg6 bsgg== X-Gm-Message-State: AJIora+VQoxMpKvgGTVrvAi6KhmLMxxoAKXlGk0sN7zNvqcwuPQc2z+c HRHwxlCL7RS1gRT8+QKvxc9OJlD6SIM7Xw== X-Google-Smtp-Source: AGRyM1tAWObT9B/gbDWK9OMKLTlJdIoY9RbP6tWwswLX/vgE3Wn5lfs6yROixXN4Fof4564BaIWD8A== X-Received: by 2002:adf:e4c9:0:b0:21b:9336:16b9 with SMTP id v9-20020adfe4c9000000b0021b933616b9mr3989479wrm.696.1655911163863; Wed, 22 Jun 2022 08:19:23 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:4175:47f:ec:c265]) by smtp.gmail.com with ESMTPSA id bi11-20020a05600c3d8b00b0039c362311d2sm1745388wmb.9.2022.06.22.08.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 08:19:23 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 17:19:16 +0200 Message-Id: <20220622151918.451635-4-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220622151918.451635-1-fsylvestre@baylibre.com> References: <20220622151918.451635-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] ipa: rkisp1: Add support of Lens Shading Correction 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: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Lens Shading Correction algorithm applies a correction on the pixels based on values defined in the YAML tuning file. Signed-off-by: Florian Sylvestre --- src/ipa/rkisp1/algorithms/lsc.cpp | 171 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/lsc.h | 44 +++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 81 ++++++++++++ src/ipa/rkisp1/rkisp1.cpp | 1 + 5 files changed, 298 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/lsc.cpp create mode 100644 src/ipa/rkisp1/algorithms/lsc.h diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp new file mode 100644 index 00000000..f68243a1 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -0,0 +1,171 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * lsc.cpp - RkISP1 Lens Shading Correction control + */ + +#include "lsc.h" + +#include + +#include "libcamera/internal/yaml_parser.h" +#include "linux/rkisp1-config.h" + +/** + * \file lsc.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class LensShadingCorrection + * \brief RkISP1 Lens Shading Correction control + * + * Due to the optical characteristics of the lens, the light intensity received + * by the sensor is not uniform. + * + * The Lens Shading Correction algorithm applies a correction on the pixels for + * each component based on measurement done during the camera tuning process. + */ + +LOG_DEFINE_CATEGORY(RkISP1Lsc) + +LensShadingCorrection::LensShadingCorrection() + : tuningParameters_(false) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int LensShadingCorrection::init([[maybe_unused]] IPAContext &context, + const YamlObject &tuningData) +{ + xSizeTbl_ = tuningData["x-size"].getList(); + if (xSizeTbl_.size() != RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'x-size'" + << "in tuning file (list size:" + << xSizeTbl_.size() << "/" + << RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE << ")"; + return -EINVAL; + } + + ySizeTbl_ = tuningData["y-size"].getList(); + if (ySizeTbl_.size() != RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'y-size'" + << "in tuning file (list size:" + << ySizeTbl_.size() << "/" + << RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE << ")"; + return -EINVAL; + } + + xGradTbl_ = tuningData["x-grad"].getList(); + if (xGradTbl_.size() != RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'x-grad'" + << "in tuning file (list size:" + << xGradTbl_.size() << "/" + << RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE << ")"; + return -EINVAL; + } + + yGradTbl_ = tuningData["y-grad"].getList(); + if (yGradTbl_.size() != RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'y-grad'" + << "in tuning file (list size:" + << yGradTbl_.size() << "/" + << RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE << ")"; + return -EINVAL; + } + + rDataTbl_ = tuningData["r"].getList(); + if (rDataTbl_.size() != RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'r'" + << "in tuning file (list size:" + << rDataTbl_.size() << "/" + << RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX << ")"; + return -EINVAL; + } + + grDataTbl_ = tuningData["gr"].getList(); + if (grDataTbl_.size() != RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'gr'" + << "in tuning file (list size:" + << grDataTbl_.size() << "/" + << RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX << ")"; + return -EINVAL; + } + + gbDataTbl_ = tuningData["gb"].getList(); + if (gbDataTbl_.size() != RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'gb'" + << "in tuning file (list size:" + << gbDataTbl_.size() << "/" + << RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX << ")"; + return -EINVAL; + } + + bDataTbl_ = tuningData["b"].getList(); + if (bDataTbl_.size() != RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX) { + LOG(RkISP1Lsc, Error) + << "Issue while parsing 'b'" + << "in tuning file (list size:" + << bDataTbl_.size() << "/" + << RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX << ")"; + return -EINVAL; + } + + tuningParameters_ = true; + + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void LensShadingCorrection::prepare(IPAContext &context, + rkisp1_params_cfg *params) +{ + if (context.frameContext.frameCount > 0) + return; + + if (!tuningParameters_) + return; + + std::copy(xSizeTbl_.begin(), xSizeTbl_.end(), + params->others.lsc_config.x_size_tbl); + std::copy(ySizeTbl_.begin(), ySizeTbl_.end(), + params->others.lsc_config.y_size_tbl); + std::copy(xGradTbl_.begin(), xGradTbl_.end(), + params->others.lsc_config.x_grad_tbl); + std::copy(yGradTbl_.begin(), yGradTbl_.end(), + params->others.lsc_config.y_grad_tbl); + + std::copy(rDataTbl_.begin(), rDataTbl_.end(), + ¶ms->others.lsc_config.r_data_tbl[0][0]); + std::copy(grDataTbl_.begin(), grDataTbl_.end(), + ¶ms->others.lsc_config.gr_data_tbl[0][0]); + std::copy(gbDataTbl_.begin(), gbDataTbl_.end(), + ¶ms->others.lsc_config.gb_data_tbl[0][0]); + std::copy(bDataTbl_.begin(), bDataTbl_.end(), + ¶ms->others.lsc_config.b_data_tbl[0][0]); + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_LSC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_LSC; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_LSC; +} + +REGISTER_IPA_ALGORITHM(LensShadingCorrection) + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h new file mode 100644 index 00000000..7f620ffa --- /dev/null +++ b/src/ipa/rkisp1/algorithms/lsc.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * gsl.h - RkISP1 Lens Shading Correction control + */ + +#pragma once + +#include + +#include "algorithm.h" + +namespace libcamera { + +struct IPACameraSensorInfo; + +namespace ipa::rkisp1::algorithms { + +class LensShadingCorrection : public Algorithm +{ +public: + LensShadingCorrection(); + ~LensShadingCorrection() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + +private: + bool tuningParameters_; + + std::vector rDataTbl_; + std::vector grDataTbl_; + std::vector gbDataTbl_; + std::vector bDataTbl_; + + std::vector xGradTbl_; + std::vector yGradTbl_; + std::vector xSizeTbl_; + std::vector ySizeTbl_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 0597c353..64e11dce 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -5,4 +5,5 @@ rkisp1_ipa_algorithms = files([ 'awb.cpp', 'blc.cpp', 'gsl.cpp', + 'lsc.cpp', ]) diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index 6cb84ed9..154ed3b5 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -16,4 +16,85 @@ algorithms: red: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096 ] green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096 ] blue: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096 ] + - LensShadingCorrection: + x-size: [ 512, 1024, 1536, 2048, 2560, 3072, 3584, 4096 ] + y-size: [ 512, 1024, 1536, 2048, 2560, 3072, 3584, 4096 ] + x-grad: [ 0, 0, 0, 0, 0, 0, 0, 0 ] + y-grad: [ 0, 0, 0, 0, 0, 0, 0, 0 ] + r: [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ] + gr: [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ] + gb: [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ] + b: [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ] ... diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 622a0d61..996edc0a 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -32,6 +32,7 @@ #include "algorithms/awb.h" #include "algorithms/blc.h" #include "algorithms/gsl.h" +#include "algorithms/lsc.h" #include "libipa/camera_sensor_helper.h" #include "ipa_context.h" From patchwork Wed Jun 22 15:19:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16328 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 1CCFCBE173 for ; Wed, 22 Jun 2022 15:19:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A947665642; Wed, 22 Jun 2022 17:19:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655911171; bh=zQAmQWnuUi/+U5I36BjiAgoDzHjVMM6fD+DwMQ3JIgY=; 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=QrqbIyiWu0njPdDlyiiGivtqTtNB9GDSm1fhc3Q9z/Ybe0QbMmcy+0awJFAv2sKUC MT+UEq3ZrhPBAlXDDYL2vqmz35pg8U4abdyt8usQsA2+dCiofkJn2RqxPUZ+gwMTQB gvCzKFH++U+0Apj7Iv4YCQ97m6xZjPR4SMCtiew/t+12eBuf4n5U67wuDF34QEjEkJ YLW/yVkQvo6pgTM/jQrn3+N339I1m8MNO2cWT69C4vu7XRTIbVgfPHOp/fbQG4061Y 52LbDnyqjWbynKaVRoKCoqZgq8dUtsScPCxzG3GdVlXE8m9hJ+T3ZmYfbOH3nEYP1M SwQsY3PA308Ig== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AF5886563E for ; Wed, 22 Jun 2022 17:19:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="xtSQG0sZ"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id o8so23914900wro.3 for ; Wed, 22 Jun 2022 08:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2L/Pa182ZwtTPjgsQFSJPPJ4EZ2ubQpHO7YGh6L85RU=; b=xtSQG0sZVErRZc4BqD5PMdy8n14c1WbLs1GcLevvV3WkPvGk9kcRln1BO5g/RnqdQw Kel3JPQ7F+vqC8nV2ZSV49OUHSLX/Znpr4zwvffSOMV+wD+T/5SS2bFON7tU8nINQVZn zxtvmHvX0Pxtcr9cBQkm9nZrxbWEgQ1LxMlOn+/y0iAgDm5x23dlfVST4kjyXpMAY7dt FNZt3JgoCvsahYUnh5U9fhqmso/eW6WkuCPxZx7NcJ6i+NAh58OBiqVQ8dbpKERVxNaZ AGPQdYFbvG1jp1rxNwEIkuioCCE1RU9v8DEUwTP16/BrC1VDg1FSEfQ7Y27tsZv8mLUi w9rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2L/Pa182ZwtTPjgsQFSJPPJ4EZ2ubQpHO7YGh6L85RU=; b=yH5hBTB9MsGqANiqZc9wtcbM/n/O4pkA0GKNbnJ59K3AP/nTi0rSDT63jAGW0nVCbf RLWYkKl9TqfA+ZCh9ebhB76jozPugE/zv1/2z8RQb3WYxMCZ97yXxKM31kwr4lPIosNL oAZR5QHy/7xWo1ZqMZXuBfffeMmrFxInBjscBgpz+wpUei/vNFlBGIPW43PLB5BVh3xw STIzP3xY6cMgkLHhdM7Vj3/xFn8sHIOe2SPM0h8Q0L5CIrcLOIyrbqDl2Tn15KyDHlN6 gcLPy4VJnn2BeCdEf704cF3tiesZJZG6AirDyuNgckabhpF1ER+9frmMfaMPhmWQVdpl PVdw== X-Gm-Message-State: AJIora+qQDiKg5B5QqqOLGzPkhk17H/bOrnHxJUZvb0m8Hc7WjWLWmz7 g9KBi8HBRoowgVadfDRFtk2VhApmh88uAw== X-Google-Smtp-Source: AGRyM1v3b7BQ6wjd5IA0zp67CF7hmzmD28Xgh6qcHCSyOQDjQaYr4/+D6AS/Pj7FLlOI4plvh3RK1g== X-Received: by 2002:a5d:6791:0:b0:21b:9e4b:2f95 with SMTP id v17-20020a5d6791000000b0021b9e4b2f95mr3920709wru.399.1655911164854; Wed, 22 Jun 2022 08:19:24 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:4175:47f:ec:c265]) by smtp.gmail.com with ESMTPSA id bi11-20020a05600c3d8b00b0039c362311d2sm1745388wmb.9.2022.06.22.08.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 08:19:24 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 17:19:17 +0200 Message-Id: <20220622151918.451635-5-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220622151918.451635-1-fsylvestre@baylibre.com> References: <20220622151918.451635-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] include: linux: Update rkisp1 kernel header for DPCC configuration 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: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To improve the kernel interface, a proposal has been made to the linux-kernel [1] to improve the configuration of the Defective Pixel Cluster Correction (DPCC). [1] https://lore.kernel.org/linux-media/20220616160456.21549-1-laurent.pinchart@ideasonboard.com/ Update the local copy of the rkisp1-config.h to match the proposal. Signed-off-by: Florian Sylvestre Acked-by: Paul Elder --- include/linux/rkisp1-config.h | 77 +++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/include/linux/rkisp1-config.h b/include/linux/rkisp1-config.h index 9be67d63..0ed3dca8 100644 --- a/include/linux/rkisp1-config.h +++ b/include/linux/rkisp1-config.h @@ -117,7 +117,46 @@ /* * Defect Pixel Cluster Correction */ -#define RKISP1_CIF_ISP_DPCC_METHODS_MAX 3 +#define RKISP1_CIF_ISP_DPCC_METHODS_MAX 3 + +#define RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE (1U << 2) + +#define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER (1U << 0) +#define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_RB_CENTER (1U << 1) +#define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_G_3X3 (1U << 2) +#define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_RB_3X3 (1U << 3) + +/* 0-2 for sets 1-3 */ +#define RKISP1_CIF_ISP_DPCC_SET_USE_STAGE1_USE_SET(n) ((n) << 0) +#define RKISP1_CIF_ISP_DPCC_SET_USE_STAGE1_USE_FIX_SET (1U << 3) + +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_GREEN_ENABLE (1U << 0) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE (1U << 1) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_GREEN_ENABLE (1U << 2) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE (1U << 3) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_GREEN_ENABLE (1U << 4) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_RED_BLUE_ENABLE (1U << 8) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE (1U << 9) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_RED_BLUE_ENABLE (1U << 10) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE (1U << 11) +#define RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_RED_BLUE_ENABLE (1U << 12) + +#define RKISP1_CIF_ISP_DPCC_LINE_THRESH_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_LINE_THRESH_RB(v) ((v) << 8) +#define RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_RB(v) ((v) << 8) +#define RKISP1_CIF_ISP_DPCC_PG_FAC_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_PG_FAC_RB(v) ((v) << 8) +#define RKISP1_CIF_ISP_DPCC_RND_THRESH_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_RND_THRESH_RB(v) ((v) << 8) +#define RKISP1_CIF_ISP_DPCC_RG_FAC_G(v) ((v) << 0) +#define RKISP1_CIF_ISP_DPCC_RG_FAC_RB(v) ((v) << 8) + +#define RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_G(n, v) ((v) << ((n) * 4)) +#define RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_RB(n, v) ((v) << ((n) * 4 + 2)) + +#define RKISP1_CIF_ISP_DPCC_RND_OFFS_n_G(n, v) ((v) << ((n) * 4)) +#define RKISP1_CIF_ISP_DPCC_RND_OFFS_n_RB(n, v) ((v) << ((n) * 4 + 2)) /* * Denoising pre filter @@ -250,16 +289,20 @@ struct rkisp1_cif_isp_bls_config { }; /** - * struct rkisp1_cif_isp_dpcc_methods_config - Methods Configuration used by DPCC + * struct rkisp1_cif_isp_dpcc_methods_config - DPCC methods set configuration * - * Methods Configuration used by Defect Pixel Cluster Correction + * This structure stores the configuration of one set of methods for the DPCC + * algorithm. Multiple methods can be selected in each set (independently for + * the Green and Red/Blue components) through the @method field, the result is + * the logical AND of all enabled methods. The remaining fields set thresholds + * and factors for each method. * - * @method: Method enable bits - * @line_thresh: Line threshold - * @line_mad_fac: Line MAD factor - * @pg_fac: Peak gradient factor - * @rnd_thresh: Rank Neighbor Difference threshold - * @rg_fac: Rank gradient factor + * @method: Method enable bits (RKISP1_CIF_ISP_DPCC_METHODS_SET_*) + * @line_thresh: Line threshold (RKISP1_CIF_ISP_DPCC_LINE_THRESH_*) + * @line_mad_fac: Line Mean Absolute Difference factor (RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_*) + * @pg_fac: Peak gradient factor (RKISP1_CIF_ISP_DPCC_PG_FAC_*) + * @rnd_thresh: Rank Neighbor Difference threshold (RKISP1_CIF_ISP_DPCC_RND_THRESH_*) + * @rg_fac: Rank gradient factor (RKISP1_CIF_ISP_DPCC_RG_FAC_*) */ struct rkisp1_cif_isp_dpcc_methods_config { __u32 method; @@ -273,14 +316,16 @@ struct rkisp1_cif_isp_dpcc_methods_config { /** * struct rkisp1_cif_isp_dpcc_config - Configuration used by DPCC * - * Configuration used by Defect Pixel Cluster Correction + * Configuration used by Defect Pixel Cluster Correction. Three sets of methods + * can be configured and selected through the @set_use field. The result is the + * logical OR of all enabled sets. * - * @mode: dpcc output mode - * @output_mode: whether use hard coded methods - * @set_use: stage1 methods set - * @methods: methods config - * @ro_limits: rank order limits - * @rnd_offs: differential rank offsets for rank neighbor difference + * @mode: DPCC mode (RKISP1_CIF_ISP_DPCC_MODE_*) + * @output_mode: Interpolation output mode (RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_*) + * @set_use: Methods sets selection (RKISP1_CIF_ISP_DPCC_SET_USE_*) + * @methods: Methods sets configuration + * @ro_limits: Rank order limits (RKISP1_CIF_ISP_DPCC_RO_LIMITS_*) + * @rnd_offs: Differential rank offsets for rank neighbor difference (RKISP1_CIF_ISP_DPCC_RND_OFFS_*) */ struct rkisp1_cif_isp_dpcc_config { __u32 mode; From patchwork Wed Jun 22 15:19:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16329 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 14D6CBE173 for ; Wed, 22 Jun 2022 15:19:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 90CBB65643; Wed, 22 Jun 2022 17:19:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655911172; bh=oKrAJXDSGX9TwezqpW6j9CcYhJJXAGFLa7L0WV21B48=; 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=pdw+VJN/x+weA9FyOZu/8YMJQAUQC3cr7fkKeOyqxZyct0U2mgT3kqphmhs509Br2 uvljPNTXsQLa52byppoXMYThyYfx2r/zshWefNXxiIKh9djQBybjQEidtNmLZUrwxX V6uyNCwLgAQ2WSAKL7I4EGirLGlyo03pt6+Cm9fN0PciUgJ9oy4Vf4Zt1/O1Ajnohr 6/WtFKtrHkKJZbdTXS+IjNbn5xTOsqTAK450Ix9MfW7zs8AfVB//pplsbrRuEO1f20 cqvQRgdJtUiV1380Vpk/BtzqebeD4AKA+wWqHLIWbL6pemVhBFoFr50o32DTshMDpW /Qf++TLdJ2dRw== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 69CA465635 for ; Wed, 22 Jun 2022 17:19:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="zDDFQcRH"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id e5so9451772wma.0 for ; Wed, 22 Jun 2022 08:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K3mocUXbefz47SFp+9TlUYh33KB+Qe1ha2RZFxPqELU=; b=zDDFQcRHEslTsrchgAONrbkqTomVEN3CzV0Dloc+BPu+JZyHJ9zeBcJLHJFRjJk/Kr i+VCxIEqTGoUV0AisZHzfWaDO/cY5eCZyhvkt+udYfIcAgONKY2jfj4iaytAP5KDSmvZ BVqgItt84oLQtTf3/clivgHrFsqfat4nDu1bADXS2uFCCCj8uRf4Y+jAf0XS8YBwLIij sTL2mW/f3xio1Sydb+CsQMI6m23qeJPv77hgI/2qQR8mw52UvhBp+tK4nDOIHZYgwb0Z rskCiIQl2I2ReVHDA5+EcGbZ3ESMlgv0PXJcwxnZttdzEvwSaV/cXqU36Wz1AMe2+77P xqdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K3mocUXbefz47SFp+9TlUYh33KB+Qe1ha2RZFxPqELU=; b=3J6DcQJ3PnA+4LghLfcbpBiXkqb1T/PfrVkb/JaLC2yMboIA2HDDnfhidgVCnY3KP/ 4kFUBfDrwIWJxQcLrzlm/HIu6izdGeWM0VJ+0P3uYLZ8U099x2KwhoW6FE0eVWYzd8cg hwC7RovQT+64xd+OFCYkRkjaqMg63elC2yjed6JGX1MlyrWK2ypAPgwQrOkGXTM/5eYG yq3eCnPG0J1rS9z+0UMODAzID8XGB9y/n5ldcn3bNQwLBKNF/bFUIICBI5b3WF96Mkj7 ZYEfSwvPVsG36t7wgNrIlH+wijeXFTX9zkwlTAB9hWgCPBUgnvgAGEm7LRtQfQlgQYdI 5uXQ== X-Gm-Message-State: AJIora/fDEWDJ0QcZYJ2Ll03ys6xvMohSuSAWnXGwYfUyetJsy2H3WjL u0IWDzg1dvBlBKHxALojZjyfgk+hVY8LuQ== X-Google-Smtp-Source: AGRyM1uW5bAHkYbcwqFnUl+k8lZV7GStjoeiQ5VZzriIMP+Xv0YcmYBG1nSs7JiJaajUXYLASzc/Iw== X-Received: by 2002:a7b:cb58:0:b0:39e:f121:f7d4 with SMTP id v24-20020a7bcb58000000b0039ef121f7d4mr4535360wmj.174.1655911165693; Wed, 22 Jun 2022 08:19:25 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:4175:47f:ec:c265]) by smtp.gmail.com with ESMTPSA id bi11-20020a05600c3d8b00b0039c362311d2sm1745388wmb.9.2022.06.22.08.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 08:19:25 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 17:19:18 +0200 Message-Id: <20220622151918.451635-6-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220622151918.451635-1-fsylvestre@baylibre.com> References: <20220622151918.451635-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] ipa: rkisp1: Add support of Defect Pixel Cluster Correction 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: Florian Sylvestre via libcamera-devel From: Florian Sylvestre Reply-To: Florian Sylvestre Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Defect Pixel Cluster Correction algorithm is responsible to minimize the impact of defective pixels. The on-the-fly method is actually used, based on coefficient provided by the tuning file. Signed-off-by: Florian Sylvestre --- src/ipa/rkisp1/algorithms/dpcc.cpp | 273 ++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/dpcc.h | 35 ++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 60 ++++++ src/ipa/rkisp1/rkisp1.cpp | 1 + 5 files changed, 370 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/dpcc.cpp create mode 100644 src/ipa/rkisp1/algorithms/dpcc.h diff --git a/src/ipa/rkisp1/algorithms/dpcc.cpp b/src/ipa/rkisp1/algorithms/dpcc.cpp new file mode 100644 index 00000000..0c78ba9d --- /dev/null +++ b/src/ipa/rkisp1/algorithms/dpcc.cpp @@ -0,0 +1,273 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * lsc.cpp - RkISP1 Defect Pixel Cluster Correction control + */ + +#include "dpcc.h" + +#include + +#include "libcamera/internal/yaml_parser.h" +#include "linux/rkisp1-config.h" + +/** + * \file dpcc.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class DefectPixelClusterCorrection + * \brief RkISP1 Defect Pixel Cluster Correction control + * + * Depending of the sensor quality, some pixels can be defective and then + * appear significantly brighter or darker than the other pixels. + * + * The Defect Pixel Cluster Correction algorithms is responsible to minimize + * the impact of the pixels. + * This can be done with algorithms applied at run time (on-the-fly method) or + * with a table of defective pixels. Only first method is supported for the + * moment. + */ + +LOG_DEFINE_CATEGORY(RkISP1Dpcc) + +DefectPixelClusterCorrection::DefectPixelClusterCorrection() + : tuningParameters_(false) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int DefectPixelClusterCorrection::init([[maybe_unused]] IPAContext &context, + const YamlObject &tuningData) +{ + bool fixedSet = tuningData["fixed-set"].get(true); + tuning_.set_use = + fixedSet ? RKISP1_CIF_ISP_DPCC_SET_USE_STAGE1_USE_FIX_SET : 0; + + /* Get all defined sets to apply (up to 3). */ + const YamlObject &setsObject = tuningData["sets"]; + if (!setsObject.isList()) { + LOG(RkISP1Dpcc, Error) + << "'sets' list parameternot found in tuning file"; + return -EINVAL; + } + + if (setsObject.size() > RKISP1_CIF_ISP_DPCC_METHODS_MAX) { + LOG(RkISP1Dpcc, Error) + << "'sets' size in tuning file (" << setsObject.size() + << ") exceed HW maximum capacity(3)"; + return -EINVAL; + } + + tuning_.ro_limits = 0; + tuning_.rnd_offs = 0; + + for (std::size_t i = 0; i < setsObject.size(); ++i) { + uint16_t value; + + /* Enable set if described in Yaml tuning file. */ + tuning_.set_use |= 0x1 << i; + + /* Disable all methods by default. */ + tuning_.methods[i].method = 0; + + /* PG Method */ + const YamlObject &pgObject = setsObject[i]["pg-factor"]; + tuning_.methods[i].pg_fac = 0; + + if (pgObject.contains("green")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_GREEN_ENABLE; + + value = pgObject["green"].get(0); + tuning_.methods[i].pg_fac |= + RKISP1_CIF_ISP_DPCC_PG_FAC_G(value); + } + + if (pgObject.contains("red-blue")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_RED_BLUE_ENABLE; + + value = pgObject["red-blue"].get(0); + tuning_.methods[i].pg_fac |= + RKISP1_CIF_ISP_DPCC_PG_FAC_RB(value); + } + + /* RO Method */ + const YamlObject &roObject = setsObject[i]["ro-limits"]; + + if (roObject.contains("green")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_GREEN_ENABLE; + + value = roObject["green"].get(0); + tuning_.ro_limits |= + RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_G(i, value); + } + + if (roObject.contains("red-blue")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_RED_BLUE_ENABLE; + + value = roObject["red-blue"].get(0); + tuning_.ro_limits |= + RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_RB(i, value); + } + + /* RG Method */ + const YamlObject &rgObject = setsObject[i]["rg-factor"]; + tuning_.methods[i].rg_fac = 0; + + if (rgObject.contains("green")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_GREEN_ENABLE; + + value = rgObject["green"].get(0); + tuning_.methods[i].rg_fac |= + RKISP1_CIF_ISP_DPCC_RG_FAC_G(value); + } + + if (rgObject.contains("red-blue")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_RED_BLUE_ENABLE; + + value = rgObject["red-blue"].get(0); + tuning_.methods[i].rg_fac |= + RKISP1_CIF_ISP_DPCC_RG_FAC_RB(value); + } + + /* RND Method */ + const YamlObject &rndOffsetsObject = setsObject[i]["rnd-offsets"]; + + if (rndOffsetsObject.contains("green")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE; + + value = rndOffsetsObject["green"].get(0); + tuning_.rnd_offs |= + RKISP1_CIF_ISP_DPCC_RND_OFFS_n_G(i, value); + } + + if (rndOffsetsObject.contains("red-blue")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE; + + value = rndOffsetsObject["red-blue"].get(0); + tuning_.rnd_offs |= + RKISP1_CIF_ISP_DPCC_RND_OFFS_n_RB(i, value); + } + + const YamlObject &rndThresholdObject = setsObject[i]["rnd-threshold"]; + tuning_.methods[i].rnd_thresh = 0; + + if (rndThresholdObject.contains("green")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE; + + value = rndThresholdObject["green"].get(0); + tuning_.methods[i].rnd_thresh |= + RKISP1_CIF_ISP_DPCC_RND_THRESH_G(value); + } + + if (rndThresholdObject.contains("red-blue")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE; + + value = rndThresholdObject["red-blue"].get(0); + tuning_.methods[i].rnd_thresh |= + RKISP1_CIF_ISP_DPCC_RND_THRESH_RB(value); + } + + /* LC Method */ + const YamlObject &lcThresholdObject = setsObject[i]["line-threshold"]; + tuning_.methods[i].line_thresh = 0; + + if (lcThresholdObject.contains("green")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE; + + value = lcThresholdObject["green"].get(0); + tuning_.methods[i].line_thresh |= + RKISP1_CIF_ISP_DPCC_LINE_THRESH_G(value); + } + + if (lcThresholdObject.contains("red-blue")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE; + + value = lcThresholdObject["red-blue"].get(0); + tuning_.methods[i].line_thresh |= + RKISP1_CIF_ISP_DPCC_LINE_THRESH_RB(value); + } + + const YamlObject &lcTMadFactorObject = setsObject[i]["line-mad-factor"]; + tuning_.methods[i].line_mad_fac = 0; + + if (lcTMadFactorObject.contains("green")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE; + + value = lcTMadFactorObject["green"].get(0); + tuning_.methods[i].line_mad_fac |= + RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_G(value); + } + + if (lcTMadFactorObject.contains("red-blue")) { + tuning_.methods[i].method |= + RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE; + + value = lcTMadFactorObject["red-blue"].get(0); + tuning_.methods[i].line_mad_fac |= + RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_RB(value); + } + } + + tuningParameters_ = true; + + return 0; +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void DefectPixelClusterCorrection::prepare(IPAContext &context, + rkisp1_params_cfg *params) +{ + if (context.frameContext.frameCount > 0) + return; + + if (!tuningParameters_) + return; + + params->others.dpcc_config.mode = + RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE; + params->others.dpcc_config.output_mode = + RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER | + RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_RB_CENTER; + params->others.dpcc_config.rnd_offs = tuning_.rnd_offs; + params->others.dpcc_config.ro_limits = tuning_.ro_limits; + params->others.dpcc_config.set_use = tuning_.set_use; + + for (std::size_t i = 0; i < RKISP1_CIF_ISP_DPCC_METHODS_MAX; ++i) { + memcpy(¶ms->others.dpcc_config.methods[i], + &tuning_.methods[i], + sizeof(rkisp1_cif_isp_dpcc_methods_config)); + } + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_DPCC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_DPCC; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_DPCC; +} + +REGISTER_IPA_ALGORITHM(DefectPixelClusterCorrection) + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/dpcc.h b/src/ipa/rkisp1/algorithms/dpcc.h new file mode 100644 index 00000000..6c6c6aaa --- /dev/null +++ b/src/ipa/rkisp1/algorithms/dpcc.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * dpcc.h - RkISP1 Defect Pixel Cluster Correction control + */ + +#pragma once + +#include + +#include "algorithm.h" + +namespace libcamera { + +struct IPACameraSensorInfo; + +namespace ipa::rkisp1::algorithms { + +class DefectPixelClusterCorrection : public Algorithm +{ +public: + DefectPixelClusterCorrection(); + ~DefectPixelClusterCorrection() = default; + + int init(IPAContext &context, const YamlObject &tuningData) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; + +private: + bool tuningParameters_; + rkisp1_cif_isp_dpcc_config tuning_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 64e11dce..87007493 100644 --- a/src/ipa/rkisp1/algorithms/meson.build +++ b/src/ipa/rkisp1/algorithms/meson.build @@ -4,6 +4,7 @@ rkisp1_ipa_algorithms = files([ 'agc.cpp', 'awb.cpp', 'blc.cpp', + 'dpcc.cpp', 'gsl.cpp', 'lsc.cpp', ]) diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index 154ed3b5..51228218 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -97,4 +97,64 @@ algorithms: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ] + - DefectPixelClusterCorrection: + fixed-set: false + sets: + # PG, LC, RO, RND, RG + - line-threshold: + green: 8 + red-blue: 8 + line-mad-factor: + green: 4 + red-blue: 4 + pg-factor: + green: 8 + red-blue: 8 + rnd-threshold: + green: 10 + red-blue: 10 + rg-factor: + green: 32 + red-blue: 32 + ro-limits: + green: 1 + red-blue: 1 + rnd-offsets: + green: 2 + red-blue: 2 + # PG, LC, RO + - line-threshold: + green: 24 + red-blue: 32 + line-mad-factor: + green: 16 + red-blue: 24 + pg-factor: + green: 6 + red-blue: 8 + ro-limits: + green: 2 + red-blue: 2 + # PG, LC, RO, RND, RG + - line-threshold: + green: 32 + red-blue: 32 + line-mad-factor: + green: 4 + red-blue: 4 + pg-factor: + green: 10 + red-blue: 10 + rnd-threshold: + green: 6 + red-blue: 8 + rg-factor: + green: 4 + red-blue: 4 + ro-limits: + green: 1 + red-blue: 2 + rnd-offsets: + green: 2 + red-blue: 2 ... diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 996edc0a..a32bb9d1 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -31,6 +31,7 @@ #include "algorithms/algorithm.h" #include "algorithms/awb.h" #include "algorithms/blc.h" +#include "algorithms/dpcc.h" #include "algorithms/gsl.h" #include "algorithms/lsc.h" #include "libipa/camera_sensor_helper.h"