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"