From patchwork Thu Sep 8 01:41:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17330 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 44A8DC3272 for ; Thu, 8 Sep 2022 01:42:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0B22B620E5; Thu, 8 Sep 2022 03:42:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662601369; bh=tO0gsFWQuTe0wdKJLk3/87qbHIdw/Lnh0RzFFOyT1i0=; 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=ZNUhnNRggvYRmPP0bcoM9CiFtGwqk21jgexSplcxnoYcEhrh7ZPu6OVOz3bXEyXgv U7cJNzxl+nTGMU2DrdABVmC81i9LU6HW6P/JQsTAe+yarI8HvGk349MYzNI2wVQVCi nBiYZJtVP3MHSRJ1ktKQXUzCImray74GOrDUklvzGhntznuV373FcMCB3f5hcCDBbC rJx+UduARnlw2MssW3WMpw11L1JO5DFQuGqm+V9mrULrHNEecJBoxY99pxzdRwWi8W z2fgRqncDsiCDsS6ycjZfqnkGUXVuzV6Y3dj7BRwsraxENMnFUE84uLWUs1FZ3/EyK ZsdPDLnpVTn6A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D2E9620E7 for ; Thu, 8 Sep 2022 03:42:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CNgF287f"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DE7176CC for ; Thu, 8 Sep 2022 03:42:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1662601367; bh=tO0gsFWQuTe0wdKJLk3/87qbHIdw/Lnh0RzFFOyT1i0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CNgF287fCCGe3O6JV3EyQin5CW/VrJ3UXULxo8Qg1hXoFrI/zOZ6yiONG22hmdyDa Zw+RArKckD/hWWMMK9aUP/18Nq3BYE4nOX04oeHARxIbhraUbJCifs5KLG/rv/iw4g Fy2Se5FCg1BhdqeiRpwT6PWuW+qI0U4nqgEh6wL0= To: libcamera-devel@lists.libcamera.org Date: Thu, 8 Sep 2022 04:41:49 +0300 Message-Id: <20220908014200.28728-22-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220908014200.28728-1-laurent.pinchart@ideasonboard.com> References: <20220908014200.28728-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 21/32] ipa: rkisp1: cproc: Store per-frame information in frame context 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Rework the algorithm's usage of the active state, to store the value of controls for the last queued request in the queueRequest() function, and store a copy of the values in the corresponding frame context. The latter is used in the prepare() function to populate the ISP parameters with values corresponding to the right frame. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/ipa/rkisp1/algorithms/cproc.cpp | 51 ++++++++++++++++++----------- src/ipa/rkisp1/ipa_context.cpp | 21 ++++++++++-- src/ipa/rkisp1/ipa_context.h | 8 ++++- 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp index 22a70e0b70c7..9c442cd56b3f 100644 --- a/src/ipa/rkisp1/algorithms/cproc.cpp +++ b/src/ipa/rkisp1/algorithms/cproc.cpp @@ -38,55 +38,66 @@ LOG_DEFINE_CATEGORY(RkISP1CProc) */ void ColorProcessing::queueRequest(IPAContext &context, [[maybe_unused]] const uint32_t frame, - [[maybe_unused]] RkISP1FrameContext &frameContext, + RkISP1FrameContext &frameContext, const ControlList &controls) { auto &cproc = context.activeState.cproc; + bool update = false; const auto &brightness = controls.get(controls::Brightness); if (brightness) { - cproc.brightness = std::clamp(std::lround(*brightness * 128), -128, 127); - cproc.updateParams = true; + int value = std::clamp(std::lround(*brightness * 128), -128, 127); + if (cproc.brightness != value) { + cproc.brightness = value; + update = true; + } - LOG(RkISP1CProc, Debug) << "Set brightness to " << *brightness; + LOG(RkISP1CProc, Debug) << "Set brightness to " << value; } const auto &contrast = controls.get(controls::Contrast); if (contrast) { - cproc.contrast = std::clamp(std::lround(*contrast * 128), 0, 255); - cproc.updateParams = true; + int value = std::clamp(std::lround(*contrast * 128), 0, 255); + if (cproc.contrast != value) { + cproc.contrast = value; + update = true; + } - LOG(RkISP1CProc, Debug) << "Set contrast to " << *contrast; + LOG(RkISP1CProc, Debug) << "Set contrast to " << value; } const auto saturation = controls.get(controls::Saturation); if (saturation) { - cproc.saturation = std::clamp(std::lround(*saturation * 128), 0, 255); - cproc.updateParams = true; + int value = std::clamp(std::lround(*saturation * 128), 0, 255); + if (cproc.saturation != value) { + cproc.saturation = value; + update = true; + } - LOG(RkISP1CProc, Debug) << "Set saturation to " << *saturation; + LOG(RkISP1CProc, Debug) << "Set saturation to " << value; } + + frameContext.cproc.brightness = cproc.brightness; + frameContext.cproc.contrast = cproc.contrast; + frameContext.cproc.saturation = cproc.saturation; + frameContext.cproc.update = update; } /** * \copydoc libcamera::ipa::Algorithm::prepare */ -void ColorProcessing::prepare(IPAContext &context, +void ColorProcessing::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] const uint32_t frame, - [[maybe_unused]] RkISP1FrameContext &frameContext, + RkISP1FrameContext &frameContext, rkisp1_params_cfg *params) { - auto &cproc = context.activeState.cproc; - /* Check if the algorithm configuration has been updated. */ - if (!cproc.updateParams) + if (!frameContext.cproc.update) return; - cproc.updateParams = false; - - params->others.cproc_config.brightness = cproc.brightness; - params->others.cproc_config.contrast = cproc.contrast; - params->others.cproc_config.sat = cproc.saturation; + params->others.cproc_config.brightness = frameContext.cproc.brightness; + params->others.cproc_config.contrast = frameContext.cproc.contrast; + params->others.cproc_config.sat = frameContext.cproc.saturation; params->module_en_update |= RKISP1_CIF_ISP_MODULE_CPROC; params->module_ens |= RKISP1_CIF_ISP_MODULE_CPROC; diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp index cd1443e1ed46..936b77709417 100644 --- a/src/ipa/rkisp1/ipa_context.cpp +++ b/src/ipa/rkisp1/ipa_context.cpp @@ -160,9 +160,6 @@ namespace libcamera::ipa::rkisp1 { * * \var IPAActiveState::cproc.saturation * \brief Saturation level - * - * \var IPAActiveState::cproc.updateParams - * \brief Indicates if ISP parameters need to be updated */ /** @@ -236,6 +233,24 @@ namespace libcamera::ipa::rkisp1 { * \brief Whether the Auto White Balance algorithm is enabled */ +/** + * \var RkISP1FrameContext::cproc + * \brief Color Processing parameters for this frame + * + * \struct RkISP1FrameContext::cproc.brightness + * \brief Brightness level + * + * \var RkISP1FrameContext::cproc.contrast + * \brief Contrast level + * + * \var RkISP1FrameContext::cproc.saturation + * \brief Saturation level + * + * \var RkISP1FrameContext::cproc.update + * \brief Indicates if the color processing parameters have been updated + * compared to the previous frame + */ + /** * \var RkISP1FrameContext::sensor * \brief Sensor configuration that used been used for this frame diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index d97aae9a97b4..78edb607d039 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -75,7 +75,6 @@ struct IPAActiveState { int8_t brightness; uint8_t contrast; uint8_t saturation; - bool updateParams; } cproc; struct { @@ -107,6 +106,13 @@ struct RkISP1FrameContext : public FrameContext { bool autoEnabled; } awb; + struct { + int8_t brightness; + uint8_t contrast; + uint8_t saturation; + bool update; + } cproc; + struct { uint32_t exposure; double gain;