From patchwork Mon Jul 4 15:23: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: 16534 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 06A74BD808 for ; Mon, 4 Jul 2022 15:23:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B06EA6565A; Mon, 4 Jul 2022 17:23:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656948209; bh=QzRrqs99qNCE6wYpDgldZ1zuCI/Mo1WhxRQz6bRcTiA=; 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=MNHFgyL2YlCFTJe0jomBlpeEfh0q0K3komjirmUpMOKpLdHU8djvnjJlIpq1EeDXP A1RK93q0UBJtQhUjf6VRUWIzH3sFZkgaATuXGUR7dOxZFbVewUJmxBWSUzD8Th18Vz h7UThoNjGiSg72kHQTUu2mTFpaUZ17x/+QvnDXA5l/76TEqGQgEmyYjT/zxvqXSsPm 45HN/M+PoNE0a5oZJwXWCLFmAa5bJcuBDf+ViakPEDykXvxp7ih4rdGUMrHBXmV9Z+ toh/qTnX7BxdTq4qJsYZiciE1LdFhfZ9asmRnQ/UrveZ+lJnngyeEI7Od87q+Uo9KC 9+C4DtivY3JWg== Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 01D3565656 for ; Mon, 4 Jul 2022 17:23:28 +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="A1Qpifi4"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id o16-20020a05600c379000b003a02eaea815so6820096wmr.0 for ; Mon, 04 Jul 2022 08:23:27 -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=ZHdKIv5kQQXb0EA7dV48Tixdt7wNv4+1ifWMHIKgfa0=; b=A1Qpifi44YEIjFwXHnwyvnLLUbFVzcj3IrJiyLuLMjIFVQmHVayWp7P7n+gFFaIhMY LXYCH3iurgb3UUJLgnV/cCCartpCb8fXo//G2TjCJEOwh/lz1xqfIpTFT5afwevU3FLV jLH/OFxltoXPZqbM4//chDBkFTYFYyfATop7Zp7/2U3eM6/nq+7OGRoEWuAkL9KLI5n7 aQp9nbUjk01pSQYKg0Id1vMvYctlD6WrE6sj7Eiyrzj4cej0g/r3a9j7V3mvST4R6bt1 OLe+9/sy9CILyeLTyDA/rcBZb+0Xv/ps5D4qV+lc/AhXGlKEh1sxgyeYDcekqrDCq7A8 Gkjw== 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=ZHdKIv5kQQXb0EA7dV48Tixdt7wNv4+1ifWMHIKgfa0=; b=dMn5RtIXUQJF38WQyFSpcxPz5Np6OXKPqlnX0b0mysVLWpxxkYU5kW8050LoFEFikf DNC1da7SmJWpwVQb/7G4e65FURTrIiSW4tctakz/0FETO/mBoC8Jvvh4nwE2PbIZNEvG FlLQ0dFRHoLWHQcaKO9mAAveDVn0cUSXD5a6/L8MiP6C0WqZRNdeuXLF9qVdZceEPmYB m2oEUO+WAVBO/Fkxhri5zJlULnUYw/H7fcRouC4kBIGHJTUXXEiXFSCFQlX/YCMsr/RO EfAAFQtvnct3DTX8kL05d7arhI2O5MRSEzhDwEihxVu72Pdv7T1Kth8xFISBUv/NfHyE OQ6A== X-Gm-Message-State: AJIora9DkrvEvaEEY1GnNVsbZpoQituf4FcnJ5l+gtvq5qQ5rkcjcQLm /ZTdw0XmgfQXelkF81/XlsteTrFuZfHXaA== X-Google-Smtp-Source: AGRyM1uMa37m+ztKEEgliZQu/K0h0GVIAV+x6wtgHDijYuXkBaw4jSretUCN8+oHaBJidNW1RME1kg== X-Received: by 2002:a7b:c381:0:b0:3a2:aef9:8df4 with SMTP id s1-20020a7bc381000000b003a2aef98df4mr4683209wmj.7.1656948207217; Mon, 04 Jul 2022 08:23:27 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 08:23:25 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 4 Jul 2022 17:23:18 +0200 Message-Id: <20220704152318.221213-5-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 4/4] ipa: rkisp1: Add support of ColorProcessing 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" Add ColorProcessing algorithm that is in charge to manage brightness, contrast and saturation controls. These controls are currently based on user controls. Signed-off-by: Florian Sylvestre --- .../rkisp1/algorithms/color_processing.cpp | 101 ++++++++++++++++++ src/ipa/rkisp1/algorithms/color_processing.h | 38 +++++++ 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 | 12 +++ 6 files changed, 154 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/color_processing.cpp create mode 100644 src/ipa/rkisp1/algorithms/color_processing.h diff --git a/src/ipa/rkisp1/algorithms/color_processing.cpp b/src/ipa/rkisp1/algorithms/color_processing.cpp new file mode 100644 index 00000000..a7f2a470 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/color_processing.cpp @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * lsc.cpp - RkISP1 Defect Pixel Cluster Correction control + */ + +#include "color_processing.h" + +#include + +#include + +#include "libcamera/internal/yaml_parser.h" +#include "linux/rkisp1-config.h" + +/** + * \file color-processing.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class ColorProcessing + * \brief RkISP1 Color Processing control + * + * The ColorProcessing algorithm is responsible to apply brightness, contrast + * and saturation corrections. + * The coefficient applied for brightness, contrast and saturation are directly + * provided by user controls. + */ + +LOG_DEFINE_CATEGORY(RkISP1ColorProcessing) + +ColorProcessing::ColorProcessing() + : userBrightness_(0), userContrast_(0), + userSaturation_(0), updateUserControls_(true) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void ColorProcessing::queueRequest([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + const ControlList &controls) +{ + for (auto const &ctrl : controls) { + if (ctrl.first == controls::BRIGHTNESS) { + userBrightness_ = ctrl.second.get(); + updateUserControls_ = true; + + LOG(RkISP1ColorProcessing, Debug) + << "Set brightness to: " + << int(userBrightness_); + } else if (ctrl.first == controls::CONTRAST) { + userContrast_ = ctrl.second.get(); + updateUserControls_ = true; + + LOG(RkISP1ColorProcessing, Debug) + << "Set contrast to: " + << int(userContrast_); + } else if (ctrl.first == controls::SATURATION) { + userSaturation_ = ctrl.second.get(); + updateUserControls_ = true; + + LOG(RkISP1ColorProcessing, Debug) + << "Set saturation to: " + << int(userSaturation_); + } + } +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void ColorProcessing::prepare([[maybe_unused]] IPAContext &context, + rkisp1_params_cfg *params) +{ + /* Check if the algorithm configuration has been updated. */ + if (!updateUserControls_) + return; + + updateUserControls_ = false; + + params->others.cproc_config.brightness = userBrightness_; + params->others.cproc_config.contrast = userContrast_; + params->others.cproc_config.sat = userSaturation_; + + params->module_en_update |= RKISP1_CIF_ISP_MODULE_CPROC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_CPROC; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CPROC; +} + +REGISTER_IPA_ALGORITHM(ColorProcessing, "ColorProcessing") + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/color_processing.h b/src/ipa/rkisp1/algorithms/color_processing.h new file mode 100644 index 00000000..bdb40bd1 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/color_processing.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * dpcc.h - RkISP1 Color Processing control + */ + +#pragma once + +#include +#include + +#include "algorithm.h" + +namespace libcamera { + +struct IPACameraSensorInfo; + +namespace ipa::rkisp1::algorithms { + +class ColorProcessing : public Algorithm +{ +public: + ColorProcessing(); + ~ColorProcessing() = 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 userBrightness_; + uint32_t userContrast_; + uint32_t userSaturation_; + 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 7e078b0d..7f9c3899 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', + 'color_processing.cpp', 'demosaicing.cpp', 'dpcc.cpp', 'gsl.cpp', diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml index 4ae0ffc0..331f9d2d 100644 --- a/src/ipa/rkisp1/data/ov5640.yaml +++ b/src/ipa/rkisp1/data/ov5640.yaml @@ -10,6 +10,7 @@ algorithms: Gr: 256 Gb: 256 B: 256 + - ColorProcessing: - GammaSensorLinearization: x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] y: diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 85a75070..d380c59b 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/color_processing.h" #include "algorithms/demosaicing.h" #include "algorithms/dpcc.h" #include "algorithms/gsl.h" diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 3d0075ee..4e82ab39 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -957,6 +957,18 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) 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::Brightness), + std::forward_as_tuple(-128.0f, 127.0f)); + + ctrls.emplace(std::piecewise_construct, + std::forward_as_tuple(&controls::Contrast), + std::forward_as_tuple(0.0f, 1.992f)); + + ctrls.emplace(std::piecewise_construct, + std::forward_as_tuple(&controls::Saturation), + std::forward_as_tuple(0.0f, 1.992f)); + ctrls.emplace(std::piecewise_construct, std::forward_as_tuple(&controls::draft::NoiseReductionMode), std::forward_as_tuple(controls::draft::NoiseReductionModeValues));