From patchwork Wed Jul 20 15:42:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Sylvestre X-Patchwork-Id: 16709 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 1BC6CBD1F1 for ; Wed, 20 Jul 2022 15:42:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AAF1563317; Wed, 20 Jul 2022 17:42:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658331757; bh=2E3bcs1TIXH8g9pWyRgtMsRwI4PM4PjapWAFqJQQXJ8=; 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=4DXzsAqLFjsMe/x3tDo6uNKMDIaZVF7i7MthNh6OM3FNly6JE5JYfif17Pg3UZL5R 8ngUddLOP3FTS0XiKTRT5JFffkWdvViREMjaD9wD99Bq5D7cowuYPkQPvrrEglJtGX I6rIci0bA/KAwTAkVwrVOZ2XxxTHu/22J/d29R9c+DX7Qftqa+vORCgu1eif3jI+ig 8jSg3JRR3Z02+LYhfkwZh4Zj+WoXd25CPDBOyfKn9rKNmkJIf46jhPbCzV8PVmUvOq +2/D4jwpqMLHwfcpRlDm+nb91WGnSqMAMdn0cR36dSKzrHWMQ1aUrMjqzKr5UzmpTX 0QcvjBs8HAbRA== 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 2D23063317 for ; Wed, 20 Jul 2022 17:42:35 +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="rKbUyXEg"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id ay11-20020a05600c1e0b00b003a3013da120so1601121wmb.5 for ; Wed, 20 Jul 2022 08:42:35 -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=jjruhyoiyW+4uTxXzzsM9Z4EbDLtkiXsS5Kv7O13Nwo=; b=rKbUyXEgHaFqGFKgddCdfTvlM5oJ6C+cDuoQI/JYGxtnOtEubcOZtDK0CYMsT+0EqU GbydqcRVOvkD5AFA20Y8+zfyHhEHlzQD/MSZjRZAe9YpNQK5W8FeUq6QxS1gkKTbnc4k 0U26E8hzDS6cxWeRcVL+yTnoJrN+yCwGtW+fIfb6hUXK5/xJR1tWxXDMoWYUyDhEpqJM 6AjcU+6MJeFS9rAvBs0X2qeaUbt66ghoUVDcbrIR1OmqO+SsfoEFQzOsprSLFOyyYdk7 9A3y7zHmmXhgaACusofkgvPiqRhFRIYnmRHNs3qqlQOiClDqGboh1qVHmCSGVvO3KAe9 Kjqg== 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=jjruhyoiyW+4uTxXzzsM9Z4EbDLtkiXsS5Kv7O13Nwo=; b=vkJa+bs81hcxl8vsfyxkmjv/pCE/x/eYv4fJcTP2K8S7FQK1o7Bmx8vkOzo3AlFo9n lNjJ9c0Lg7BTQ6dEzUPU3+fKGw7CXXN0DKAXMlimwk3Eij9D8vSrO9Avs/t0FzaGtWE+ pY5Al9WpjigPAWXDHRsNG+vZUJdO07/Oy7WvDnc66/q5HqhM7WPpuNM78pz5/VHxPndi LW0wajXdyYntLrdcm8Q/Dxn3w/x8mDKmdCOEM5r8JQMx4W6XcoFdxhixCKpIzi82mM/d eurZi/dOKGj6g/NVYVbgEn+hp+XdgU+o2M/4kZPCRF9EVLpT6V9e2frjvWV4tvdySIGE ka9Q== X-Gm-Message-State: AJIora9bZ+0WcjC+8hYjTQFmCDsrl7faCNZSRBfmPiImTRtHCte8Qq/b m1K3Cn8JSWRdALCL+mSu7fmrypEKxC90awa+ X-Google-Smtp-Source: AGRyM1syEyX66TiSrEYWI4f1TFUat4B6s1Fc9XEm/W9p0+3mkgGYqTY2pMeE0CGPJzfFmA4SkafkGw== X-Received: by 2002:a7b:ce8f:0:b0:3a2:ff2d:915f with SMTP id q15-20020a7bce8f000000b003a2ff2d915fmr4390047wmj.165.1658331754327; Wed, 20 Jul 2022 08:42:34 -0700 (PDT) Received: from BL087.. ([2a01:e34:eea9:e630:516d:f303:6345:b768]) by smtp.gmail.com with ESMTPSA id d2-20020adffbc2000000b0021e489ec78bsm2159294wrs.21.2022.07.20.08.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 08:42:33 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Jul 2022 17:42:21 +0200 Message-Id: <20220720154221.50937-5-fsylvestre@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720154221.50937-1-fsylvestre@baylibre.com> References: <20220720154221.50937-1-fsylvestre@baylibre.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 Reviewed-by: Laurent Pinchart --- src/ipa/rkisp1/algorithms/cproc.cpp | 94 ++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/cproc.h | 30 ++++++++ src/ipa/rkisp1/algorithms/meson.build | 1 + src/ipa/rkisp1/data/ov5640.yaml | 1 + src/ipa/rkisp1/ipa_context.h | 7 ++ src/ipa/rkisp1/rkisp1.cpp | 1 + src/libcamera/pipeline/rkisp1/rkisp1.cpp | 12 +++ 7 files changed, 146 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/cproc.cpp create mode 100644 src/ipa/rkisp1/algorithms/cproc.h diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp new file mode 100644 index 00000000..7e9e8cf1 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/cproc.cpp @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * cproc.cpp - RkISP1 Color Processing control + */ + +#include "cproc.h" + +#include + +#include + +#include + +#include "libcamera/internal/yaml_parser.h" + +/** + * \file cproc.h + */ + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +/** + * \class ColorProcessing + * \brief RkISP1 Color Processing control + * + * The ColorProcessing algorithm is responsible for applying brightness, + * contrast and saturation corrections. The values are directly provided + * through requests by the corresponding controls. + */ + +LOG_DEFINE_CATEGORY(RkISP1CProc) + +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void ColorProcessing::queueRequest([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + const ControlList &controls) +{ + const auto &brightness = controls.get(controls::Brightness); + if (brightness) { + context.frameContext.cproc.brightness = std::clamp(int(*brightness * 128), -128, 127); + context.frameContext.cproc.updateParams = true; + + LOG(RkISP1CProc, Debug) << "Set brightness to " << *brightness; + } + + const auto &contrast = controls.get(controls::Contrast); + if (contrast) { + context.frameContext.cproc.contrast = std::clamp(int(*contrast * 128), 0, 255); + context.frameContext.cproc.updateParams = true; + + LOG(RkISP1CProc, Debug) << "Set contrast to " << *contrast; + } + + const auto saturation = controls.get(controls::Saturation); + if (saturation) { + context.frameContext.cproc.saturation = std::clamp(int(*saturation) * 128, 0, 255); + context.frameContext.cproc.updateParams = true; + + LOG(RkISP1CProc, Debug) << "Set saturation to " << *saturation; + } +} + +/** + * \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 (!context.frameContext.cproc.updateParams) + return; + + context.frameContext.cproc.updateParams = false; + + params->others.cproc_config.brightness = context.frameContext.cproc.brightness; + params->others.cproc_config.contrast = context.frameContext.cproc.contrast; + params->others.cproc_config.sat = context.frameContext.cproc.saturation; + + 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/cproc.h b/src/ipa/rkisp1/algorithms/cproc.h new file mode 100644 index 00000000..4b7e4064 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/cproc.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021-2022, Ideas On Board + * + * cproc.h - RkISP1 Color Processing control + */ + +#pragma once + +#include + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +class ColorProcessing : public Algorithm +{ +public: + ColorProcessing() = default; + ~ColorProcessing() = default; + + void queueRequest(IPAContext &context, const uint32_t frame, + const ControlList &controls) override; + void prepare(IPAContext &context, rkisp1_params_cfg *params) override; +}; + +} /* namespace ipa::rkisp1::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build index 7e078b0d..0ec17e07 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', + 'cproc.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/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 241a4d04..e6a61c45 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -62,6 +62,13 @@ struct IPAFrameContext { bool updateParams; } demosaicing; + struct { + int8_t brightness; + uint8_t contrast; + uint8_t saturation; + bool updateParams; + } cproc; + struct { uint32_t exposure; double gain; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index aeec8f50..c664642f 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/cproc.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 4e000d31..de687f4d 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -972,6 +972,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(-1.0f, 0.993f)); + + ctrls.emplace(std::piecewise_construct, + std::forward_as_tuple(&controls::Contrast), + std::forward_as_tuple(0.0f, 1.993f)); + + ctrls.emplace(std::piecewise_construct, + std::forward_as_tuple(&controls::Saturation), + std::forward_as_tuple(0.0f, 1.993f)); + ctrls.emplace(std::piecewise_construct, std::forward_as_tuple(&controls::draft::NoiseReductionMode), std::forward_as_tuple(controls::draft::NoiseReductionModeValues));