From patchwork Mon Jul 4 15:23: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: 16533 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 821E9BD808 for ; Mon, 4 Jul 2022 15:23:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 340BC65658; Mon, 4 Jul 2022 17:23:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656948208; bh=iXL+jHJnilrNPSpBrMwT2ff6nImvQJ84SN4WCPAgZqo=; 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=L0Fg1eWaaJm7eYbESJ9jgWXa5FRv2puLerCzR9awaCp6TTvBSUwITtHbwxkUhUVIc ntroXFYibVzHz3l4lpCi85XbXEJgBO5291Xl8htXY/VYL0/Y1mCrD5+ufOP939vNUc gahSEOWH9JDap8WxeOdYTYkME4XJpplCna2ZrAfFugPP17uacYeUKGQMDxgyInF0NZ mYxKf+cviUjOb67sd2Hdec4SBUal0AVJ2VQFMz4bwDQzERsSyNC5o6xb8vKSmcvmqy blZ+3zvfpLhF7050zIcbss1T1aqMjt8MkPeHc5nx/KhKIVGcesmEy6pPpMQ8N6GT0a YNVHKwQnDIKjw== Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2BC4F6564A for ; Mon, 4 Jul 2022 17:23: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="4bt4nhVL"; dkim-atps=neutral Received: by mail-wr1-x42d.google.com with SMTP id k7so13928242wrc.12 for ; Mon, 04 Jul 2022 08:23: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=CDoBwHVa9kSCalHII9c48Kh0yJn7kLuxldxFCHrqLsk=; b=4bt4nhVLLB2dtLfzW7lWUl/MjabsXVhLwp4dI8RS1i8GzfBDTOu6VQq+lmDOQJaEs3 zyVFAlKhFm8Cm9WJNj/9h+qtcrbRGz97TeRMWYRNjUjH+pT2CC/iaGc1DiwE9Gt5ivyf N99pXAGADY+qi8eJV9xNSZEv2lRoLVRIzXiDrBWUCBSTmoghPKMhwdmmSdUwBCcTobGB FhTJEfQWb2fqyOxnwZ7iiH6WDFfXLRQ1KmyuIEhLnXQgvdwYGLFC+S/JHGYTusj7F9Vk jPjm/P139C1oCapomWqi/d7k+rYwMvARDOUBX7m35cajn5yoJKe1im7RffleMJxFcVCy XKuA== 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=CDoBwHVa9kSCalHII9c48Kh0yJn7kLuxldxFCHrqLsk=; b=T9/j3LZj5uPhH09Ga+QGruEYYBKYbdLV+vtGE04KCpDasdu2PYw020lXqTE5ldmyW5 TR+X2IAl+9s6dyHdJJp2zAq0SQsX+QiMBxpDsSv5AnDWMHZjQjSQ8/lW7EObgRvGFgT8 9pxO5fK5nSlVayS20ISLGcAlgXVIAb9wGIjY+L27V/VW6sTjtfqayZy0BkJznQreOHyN am6sDqQhmFs8Xq+Vn1wzAuzCDeLuNajI/Ds6qClORNU6k7xblTotlMkYHoRITvK0SX1i eRNl8Gu77ScRGLux2qTPTB6Gm4lRmIeraMw4bayj5cMchw4V32dt+rHnYsh3baqgnxUX e0MQ== X-Gm-Message-State: AJIora+EuXs9uwQo87n+8fWYWSVdSnIODRlAYImeItXdqsmXAW4BNfvA 7t9ieDhA8joN/Lmibp0xN8mEJ7OnogcXWA== X-Google-Smtp-Source: AGRyM1vzpqDwQ/0bDwyjtnLesjrtZoPr6z8ylLUqD+WWAz4pdMw8u8CfB2tGnXUP+t5GKbvBblpsfA== X-Received: by 2002:a5d:6da3:0:b0:21b:aaf5:b814 with SMTP id u3-20020a5d6da3000000b0021baaf5b814mr27176867wrs.140.1656948205424; Mon, 04 Jul 2022 08:23:25 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:ca4a:68b5:560f:5682]) by smtp.gmail.com with ESMTPSA id p15-20020a05600c204f00b0039c5cecf206sm19603199wmg.4.2022.07.04.08.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 08:23:24 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 4 Jul 2022 17:23:17 +0200 Message-Id: <20220704152318.221213-4-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220704152318.221213-1-fsylvestre@baylibre.com> References: <20220704152318.221213-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] ipa: rkisp1: Add support of Demosaicing 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" During the demosaicing step, rkisp1 ISP is processing denoising and sharpness control. Add demosaicing algorithm with denoise and sharpness values based on user controls. Signed-off-by: Florian Sylvestre --- src/ipa/rkisp1/algorithms/demosaicing.cpp | 208 ++++++++++++++++++++++ src/ipa/rkisp1/algorithms/demosaicing.h | 37 ++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 1 + src/ipa/rkisp1/rkisp1.cpp | 1 + src/libcamera/pipeline/rkisp1/rkisp1.cpp | 8 + 6 files changed, 256 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/demosaicing.cpp create mode 100644 src/ipa/rkisp1/algorithms/demosaicing.h diff --git a/src/ipa/rkisp1/algorithms/demosaicing.cpp b/src/ipa/rkisp1/algorithms/demosaicing.cpp new file mode 100644 index 00000000..2597735e --- /dev/null +++ b/src/ipa/rkisp1/algorithms/demosaicing.cpp @@ -0,0 +1,208 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * lsc.cpp - RkISP1 Defect Pixel Cluster Correction control + */ + +#include "demosaicing.h" + +#include + +#include + +#include "libcamera/internal/yaml_parser.h" + +/** + * \file demosaicing.h + */ + +#define ISP_FILT_LUM_WEIGHT_DEFAULT 0x00022040 +#define ISP_FILT_MODE_DEFAULT 0x000004f2 + +/* Default values : should be updated with automatic control implementation. */ +#define SHARPNESS_DEFAULT 2 +#define DENOISE_DEFAULT 2 + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class Demosaicing + * \brief RkISP1 Demosaicing control + * + * The Demosaicing algorithm is responsible to reconstruct a full color image + * from the sensor raw data. During the demosaicing step, rkisp1 ISP is + * processing denoising and sharpness control. + * + * /todo In current version the denoise and sharpness control is based on user + * controls. In a future version it should be controlled automatically by the + * algorithm. + */ + +LOG_DEFINE_CATEGORY(RkISP1Demosaicing) + +Demosaicing::Demosaicing() + : userSharpness_(SHARPNESS_DEFAULT), userDenoise_(DENOISE_DEFAULT), + updateUserControls_(true) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void Demosaicing::queueRequest([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + const ControlList &controls) +{ + for (auto const &ctrl : controls) { + if (ctrl.first == controls::SHARPNESS) { + userSharpness_ = ctrl.second.get(); + updateUserControls_ = true; + + LOG(RkISP1Demosaicing, Debug) + << "Set sharpness to: " + << int(userSharpness_); + } else if (ctrl.first == controls::NOISE_REDUCTION_MODE) { + int32_t denoiseControl = ctrl.second.get(); + + switch (denoiseControl) { + case controls::draft::NoiseReductionModeOff: + userDenoise_ = 0; + break; + case controls::draft::NoiseReductionModeMinimal: + userDenoise_ = 1; + break; + case controls::draft::NoiseReductionModeHighQuality: + case controls::draft::NoiseReductionModeFast: + userDenoise_ = 3; + break; + default: + LOG(RkISP1Demosaicing, Error) + << "Unsupported denoise value: " + << int(denoiseControl); + continue; + } + + updateUserControls_ = true; + + LOG(RkISP1Demosaicing, Debug) + << "Set denoise to: " + << int(userDenoise_); + } + } +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Demosaicing::prepare([[maybe_unused]] IPAContext &context, + rkisp1_params_cfg *params) +{ + /* Check if the algorithm configuration has been updated. */ + if (!updateUserControls_) + return; + + updateUserControls_ = false; + + static constexpr uint16_t filt_fac_sh0[] = { + 0x04, 0x07, 0x0A, 0x0C, 0x10, 0x14, 0x1A, 0x1E, 0x24, 0x2A, 0x30 + }; + + static constexpr uint16_t filt_fac_sh1[] = { + 0x04, 0x08, 0x0C, 0x10, 0x16, 0x1B, 0x20, 0x26, 0x2C, 0x30, 0x3F + }; + + static constexpr uint16_t filt_fac_mid[] = { + 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x10, 0x13, 0x17, 0x1D, 0x22, 0x28 + }; + + static constexpr uint16_t filt_fac_bl0[] = { + 0x02, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x10, 0x15, 0x1A, 0x24 + }; + + static constexpr uint16_t filt_fac_bl1[] = { + 0x00, 0x00, 0x00, 0x02, 0x04, 0x04, 0x06, 0x08, 0x0D, 0x14, 0x20 + }; + + static constexpr uint16_t filt_thresh_sh0[] = { + 0, 18, 26, 36, 41, 75, 90, 120, 170, 250, 1023 + }; + + static constexpr uint16_t filt_thresh_sh1[] = { + 0, 33, 44, 51, 67, 100, 120, 150, 200, 300, 1023 + }; + + static constexpr uint16_t filt_thresh_bl0[] = { + 0, 8, 13, 23, 26, 50, 60, 80, 140, 180, 1023 + }; + + static constexpr uint16_t filt_thresh_bl1[] = { + 0, 2, 5, 10, 15, 20, 26, 51, 100, 150, 1023 + }; + + static constexpr uint16_t stage1_select[] = { + 6, 6, 4, 4, 3, 3, 2, 2, 2, 2, 2 + }; + + static constexpr uint16_t filt_chr_v_mode[] = { + 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 + }; + + static constexpr uint16_t filt_chr_h_mode[] = { + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 + }; + + params->others.flt_config.fac_sh0 = filt_fac_sh0[userSharpness_]; + params->others.flt_config.fac_sh1 = filt_fac_sh1[userSharpness_]; + params->others.flt_config.fac_mid = filt_fac_mid[userSharpness_]; + params->others.flt_config.fac_bl0 = filt_fac_bl0[userSharpness_]; + params->others.flt_config.fac_bl1 = filt_fac_bl1[userSharpness_]; + + params->others.flt_config.lum_weight = ISP_FILT_LUM_WEIGHT_DEFAULT; + params->others.flt_config.mode = ISP_FILT_MODE_DEFAULT; + params->others.flt_config.thresh_sh0 = filt_thresh_sh0[userDenoise_]; + params->others.flt_config.thresh_sh1 = filt_thresh_sh1[userDenoise_]; + params->others.flt_config.thresh_bl0 = filt_thresh_bl0[userDenoise_]; + params->others.flt_config.thresh_bl1 = filt_thresh_bl1[userDenoise_]; + params->others.flt_config.grn_stage1 = stage1_select[userDenoise_]; + params->others.flt_config.chr_v_mode = filt_chr_v_mode[userDenoise_]; + params->others.flt_config.chr_h_mode = filt_chr_h_mode[userDenoise_]; + + if (userDenoise_ == 9) { + if (userSharpness_ > 3) + params->others.flt_config.grn_stage1 = 2; + else + params->others.flt_config.grn_stage1 = 1; + } else if (userDenoise_ == 10) { + if (userSharpness_ > 5) + params->others.flt_config.grn_stage1 = 2; + else if (userSharpness_ > 3) + params->others.flt_config.grn_stage1 = 1; + else + params->others.flt_config.grn_stage1 = 0; + } else if (userDenoise_ > 7) { + if (userSharpness_ > 7) { + params->others.flt_config.fac_bl0 = + params->others.flt_config.fac_bl0 / 2; + params->others.flt_config.fac_bl1 = + params->others.flt_config.fac_bl1 / 4; + } else if (userSharpness_ > 4) { + params->others.flt_config.fac_bl0 = + params->others.flt_config.fac_bl0 * 3 / 4; + params->others.flt_config.fac_bl1 = + params->others.flt_config.fac_bl1 / 2; + } + } + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_FLT; + params->module_ens |= RKISP1_CIF_ISP_MODULE_FLT; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_FLT; +} + +REGISTER_IPA_ALGORITHM(Demosaicing, "Demosaicing") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/demosaicing.h b/src/ipa/rkisp1/algorithms/demosaicing.h new file mode 100644 index 00000000..6d05b0e4 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/demosaicing.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * dpcc.h - RkISP1 Demosaicing control + */ + +#pragma once + +#include +#include + +#include "algorithm.h" + +namespace libcamera { + +struct IPACameraSensorInfo; + +namespace ipa::rkisp1::algorithms { + +class Demosaicing : public Algorithm +{ +public: + Demosaicing(); + ~Demosaicing() = default; + + void queueRequest(IPAContext &context, const uint32_t frame, + const ControlList &controls) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; +private: + uint32_t userSharpness_; + uint32_t userDenoise_; + bool updateUserControls_; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 87007493..7e078b0d 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', + 'demosaicing.cpp', 'dpcc.cpp', 'gsl.cpp', 'lsc.cpp', diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index 51228218..4ae0ffc0 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -157,4 +157,5 @@ algorithms: rnd-offsets: green: 2 red-blue: 2 + - Demosaicing: ... diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 9b0d675c..85a75070 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/demosaicing.h" #include "algorithms/dpcc.h" #include "algorithms/gsl.h" #include "algorithms/lsc.h" diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 72689c88..3d0075ee 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -953,6 +953,14 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) std::make_unique(this, &mainPath_, &selfPath_); ControlInfoMap::Map ctrls; + ctrls.emplace(std::piecewise_construct, + std::forward_as_tuple(&controls::Sharpness), + std::forward_as_tuple(0.0f, 10.0f, 1.0f)); + + ctrls.emplace(std::piecewise_construct, + std::forward_as_tuple(&controls::draft::NoiseReductionMode), + std::forward_as_tuple(controls::draft::NoiseReductionModeValues)); + ctrls.emplace(std::piecewise_construct, std::forward_as_tuple(&controls::AeEnable), std::forward_as_tuple(false, true));