From patchwork Tue Mar 14 14:48:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18398 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 6F185C329E for ; Tue, 14 Mar 2023 14:50:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5324062728; Tue, 14 Mar 2023 15:50:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678805405; bh=RYSIynGlDgflsC6y+mnJZbE9L7co31kh2vCYt83mD0Y=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=R0ToUK81KijAmo6M1deIOieDoJ29ylB/Hn3OCNyzpvmPbQpaIf539gkdwPRVtrERS 45edXmL0rglxy7dEEkPU4HFlEeg6PZ9EhTWC4l6MABZDVkERsYbHPRscEvLGhWMTJw 7dmNoc+jbE5dI7bj9fa6tsTFVFe7Nes7fiCsVQiIqL0hF7MkcL31o1hC2pJ7AYTce+ GOneBVS9YkjRDDrXO2VxbfRptp9fwkVfTOCB7LOornYAx68mj237zTUg6Bl6AF6iLw MvTr5w/QzpzF4EcBq2XyK28hduWq6NRQureMgYr9Cbmm8katoGig6sqZG+wJS94XUL c1ba5EO7uokgQ== Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C03C46270A for ; Tue, 14 Mar 2023 15:49:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=thaumatec-com.20210112.gappssmtp.com header.i=@thaumatec-com.20210112.gappssmtp.com header.b="QlMKpjtW"; dkim-atps=neutral Received: by mail-lj1-x230.google.com with SMTP id f16so16272877ljq.10 for ; Tue, 14 Mar 2023 07:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1678805394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LIMALetFO7wAVuqtZcDoxVbIpR8Q7JtG3uCyJPy1QWQ=; b=QlMKpjtWamjxgnE/9Njmk/dFO2HT3by3QsRXqGEldxDXg31wTbByB4JTN9rPbp9kg7 Snkg8wHMmKS/1/Lf3DdAN/jlFbPSupVj9RZAV9ZxgcFy2dG76kpcCyKFj+3i4tzZF8oF 8YPIyrodd+li3EI/DWJ0ctR+P3mzmXQpCi4uHxfw7pdfcjldWkVjvnWgLEoa7awSkNso 00IkWmBTckf+e4zKbq1CrbN0OJZ+oZS4/dsYwRUBijkrEgbBt+i1jcz3iYoCUOKaC9BU pM2epLGmSTufMEyrJtCddlexqkCHc8UvPvIXCETZMU0wVqpXPGbAgBcwK6jJxeZiH1Sm r0BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678805394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LIMALetFO7wAVuqtZcDoxVbIpR8Q7JtG3uCyJPy1QWQ=; b=AWwWU+vfH9Zb+r/T2W70PKi1Jma4wWEGGQVjv7BLkyTG1Hk3rsz9XSN674B8HO5Q5o cPXi1YMrnkImpaVLkmxjWlfVevu/64pgG5+FwNDouZYZL9dh3j2GyeQ0Q1jBbXYDFvpv HBghps81Zi47CCFfkTMvjCuxLkdF/egBa7HERrM4fu8saoPeetHLqHiXRPi0PVGky3Fb TBA8YQZPMEl59BRg/T+V23Qm5mWiH2XZd8jpSWBsFzmVIXdeNVWDnFnlw4KdBEapv/7X xs0lgJNHCLOFC2vo3bAQkaDYmJH5WOTvP2RYSQ7GAxZkJVbrVcyIBI95zh42YiaZIGC9 kMAg== X-Gm-Message-State: AO0yUKUPycC9uweQEotuQyVBiTpZhFYeCtnSRpBGqw4ywkJo8HHmWebU cwRuSXiCoQ5aQu62l6GUzhSqCYQ2pDbJEmwDNCE= X-Google-Smtp-Source: AK7set+YhA7EpitO3VtL65P7R58fNxZt0SuO9W39EysUlpoOU0Jv1LbglmxNagEt0PuYlSBwOnesRQ== X-Received: by 2002:a2e:7006:0:b0:294:6a83:fb28 with SMTP id l6-20020a2e7006000000b002946a83fb28mr12243828ljc.41.1678805394701; Tue, 14 Mar 2023 07:49:54 -0700 (PDT) Received: from localhost.localdomain ([91.90.166.178]) by smtp.gmail.com with ESMTPSA id q25-20020a2eb4b9000000b00295a35f30e1sm470961ljm.115.2023.03.14.07.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 07:49:54 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 14 Mar 2023 15:48:31 +0100 Message-Id: <20230314144834.85193-8-dse@thaumatec.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314144834.85193-1-dse@thaumatec.com> References: <20230314144834.85193-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 07/10] ipa: rkisp1: af: Add "Windows" Metering mode 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: Daniel Semkowicz via libcamera-devel From: Daniel Semkowicz Reply-To: Daniel Semkowicz Cc: jacopo.mondi@ideasonboard.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add platform related code for configuring auto focus window on the rkisp1. Connect to the windowUpdateRequested() signal exposed by the AfHillClimbing and configure the window on each signal emission. This enables support of AfMetering and AfWindows controls on the rkisp1 platform. Currently, only one window is enabled, but ISP allows up to three of them. Signed-off-by: Daniel Semkowicz --- src/ipa/rkisp1/algorithms/af.cpp | 63 +++++++++++++++++++++++++++++++- src/ipa/rkisp1/algorithms/af.h | 11 ++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp index abf5d91f..794fa59e 100644 --- a/src/ipa/rkisp1/algorithms/af.cpp +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -31,18 +31,48 @@ namespace libcamera::ipa::rkisp1::algorithms { * amount of time on each movement. This parameter should be set according * to the worst case - the number of frames it takes to move lens between * limit positions. + * - **isp-threshold:** Threshold used for minimizing the influence of noise. + * This affects the ISP sharpness calculation. + * - **isp-var-shift:** The number of bits for the shift operation at the end + * of the calculation chain. This affects the ISP sharpness calculation. + * + * \sa libcamera::ipa::common::algorithms::AfHillClimbing for additional tuning + * parameters. */ LOG_DEFINE_CATEGORY(RkISP1Af) +namespace { + +constexpr rkisp1_cif_isp_window rectangleToIspWindow(const Rectangle &rectangle) +{ + return rkisp1_cif_isp_window{ + .h_offs = static_cast(rectangle.x), + .v_offs = static_cast(rectangle.y), + .h_size = static_cast(rectangle.width), + .v_size = static_cast(rectangle.height) + }; +} + +} /* namespace */ + +Af::Af() +{ + af.windowUpdateRequested.connect(this, &Af::updateCurrentWindow); +} + /** * \copydoc libcamera::ipa::Algorithm::init */ int Af::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) { waitFramesLens_ = tuningData["wait-frames-lens"].get(1); + ispThreshold_ = tuningData["isp-threshold"].get(128); + ispVarShift_ = tuningData["isp-var-shift"].get(4); - LOG(RkISP1Af, Debug) << "waitFramesLens_: " << waitFramesLens_; + LOG(RkISP1Af, Debug) << "waitFramesLens_: " << waitFramesLens_ + << ", ispThreshold_: " << ispThreshold_ + << ", ispVarShift_: " << ispVarShift_; return af.init(tuningData); } @@ -77,6 +107,32 @@ void Af::queueRequest([[maybe_unused]] IPAContext &context, af.queueRequest(controls); } +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Af::prepare([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + rkisp1_params_cfg *params) +{ + if (updateWindow_) { + params->meas.afc_config.num_afm_win = 1; + params->meas.afc_config.thres = ispThreshold_; + params->meas.afc_config.var_shift = ispVarShift_; + params->meas.afc_config.afm_win[0] = + rectangleToIspWindow(*updateWindow_); + + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_AFC; + params->module_ens |= RKISP1_CIF_ISP_MODULE_AFC; + params->module_en_update |= RKISP1_CIF_ISP_MODULE_AFC; + + updateWindow_.reset(); + + /* Wait one frame for the ISP to apply changes */ + af.setFramesToSkip(1); + } +} + /** * \copydoc libcamera::ipa::Algorithm::process */ @@ -102,6 +158,11 @@ void Af::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, } } +void Af::updateCurrentWindow(const Rectangle &window) +{ + updateWindow_ = window; +} + REGISTER_IPA_ALGORITHM(Af, "Af") } /* namespace libcamera::ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h index 85de0a64..df2ca31a 100644 --- a/src/ipa/rkisp1/algorithms/af.h +++ b/src/ipa/rkisp1/algorithms/af.h @@ -18,20 +18,31 @@ namespace libcamera::ipa::rkisp1::algorithms { class Af : public Algorithm { public: + Af(); + int init(IPAContext &context, const YamlObject &tuningData) override; int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override; void queueRequest(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ControlList &controls) override; + void prepare(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + rkisp1_params_cfg *params) override; void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats, ControlList &metadata) override; private: + void updateCurrentWindow(const Rectangle &window); + ipa::common::algorithms::AfHillClimbing af; + std::optional updateWindow_; + uint32_t ispThreshold_; + uint32_t ispVarShift_; + /* Wait number of frames after changing lens position */ uint32_t waitFramesLens_; };