From patchwork Fri Mar 24 14:29:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18450 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 2ED08C3260 for ; Fri, 24 Mar 2023 14:29:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 95A4862712; Fri, 24 Mar 2023 15:29:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679668176; bh=ItCp53EbrXJqVrpIw8CXw09ZfGPOxLlLBQIa6SktU/4=; 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=2meKGVau7itneF2Qt9Q1KJ3IyioiJOgfBpIjWuWuR9ZDBU263QnIVQEv49LGku+jW 1pkfc6O7Gec8vDBJ9nen6de1JERlvJnyu6xHc7WjRtTty7tacK+84OAjKAxL5DHoSg FLZxN9qWu3qWOJzsX3dyanh3ohE4iozJiEsiVwCpvT1BA8GTxevdaR63fULd/D/s/M 2JJPQR/TBJVgn87/t4hdKJWc6ErV9vywt3uzpYWomwDBpIlvW0hS1m8x0Dug2KSLs6 dt5O4ol/S6eoEadbfX5I21tPDyUNFL3fU/sVz5BytivCBrV3JUbby55SeGho4ioVGm nM5kKTci4yovA== Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E7B6626E5 for ; Fri, 24 Mar 2023 15:29:28 +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="4ZNCZXI8"; dkim-atps=neutral Received: by mail-lj1-x236.google.com with SMTP id by8so1891267ljb.12 for ; Fri, 24 Mar 2023 07:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1679668168; 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=RW3UZh1I69vi3Jxsfk5UYduKKMBKc8FCToCkGLOtrdE=; b=4ZNCZXI8cRixZzs+EI5cKK25f9ReTVMBYHCmMy1o3zU42Jxy6HgD45FMrglJGQ0S1O foeRmP16OhglVj+iM7lWGL3ZxSVt7uiShs1LxwIayRhrpshAelL3yEUOu2fB9Lr76bIR 9JYL9gMpMUZskpvUsRXTkBcLFJTAm94BFcgGFrbq75tfNUeJVJ2HQr/YbcKXEbRUdAIn D7N66ic68hwPKrahUhhwcFGwM/YVGEwgQV5cK9Af3dNHh4/+FohgVWWqPc//A0vWYSBC p2fVr0kcahZmUSpqH+7HUVewVkkQDxxTt6jYe2q1qECFufW7FiK1MD9VdsYPzARFUqS4 eeUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679668168; 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=RW3UZh1I69vi3Jxsfk5UYduKKMBKc8FCToCkGLOtrdE=; b=BUT5QVhK2gKeLs6qDGlHRwMCUBUqbFCQA55UqeqdAd5tJbXYaEKEL5ddB8EOcI6wI4 o1GSSzgBOMMIRhxB9QXttsLB9BB7Q9B/VJn/+9AfNFz+TTAXJW7ubi1cEvaRR+IzqTaN pr5MXte+DZaIFzyfWZ+ygpE8ZNhQIKcaxTeWHaAbUdRGpE3DwrzREwW4OikpMYFb4Eja Ey0rPYEiK0QRjGEBWNFx+wX71QhU8sUoDMeJkLOkn8FYZ0egzc0uFvwHYqKftpllQQoS 2ZPgGNGnRvmPKET/hb0+JO0D8rglnKh6EcIQ+HLhOl724n8YCplo70FuyIuji/4PdyOy hH4w== X-Gm-Message-State: AAQBX9e7I+Q8L01LCGf6tqZ07K+pBfGoSaL7jAvEa05RCzOlUkzSvvmq CoX69d57eRj+aKM0Hhpz3MwF8NnCIHvrpQn0LBY= X-Google-Smtp-Source: AKy350bvbsC2Zc5XP0ne4qsfM49DtDGCvCdoxoPOiYuI79KoZOdXnxljhbb2lBEvz9Cb4QUn7wucCQ== X-Received: by 2002:a2e:988b:0:b0:295:a2d0:57ed with SMTP id b11-20020a2e988b000000b00295a2d057edmr1168320ljj.4.1679668167897; Fri, 24 Mar 2023 07:29:27 -0700 (PDT) Received: from localhost.localdomain ([91.90.166.178]) by smtp.gmail.com with ESMTPSA id j21-20020a2e8515000000b002a10b2ea089sm981714lji.16.2023.03.24.07.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 07:29:27 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Mar 2023 15:29:05 +0100 Message-Id: <20230324142908.64224-8-dse@thaumatec.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324142908.64224-1-dse@thaumatec.com> References: <20230324142908.64224-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 | 64 +++++++++++++++++++++++++++++++- src/ipa/rkisp1/algorithms/af.h | 13 ++++++- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp index aca127d2..9f7ba72e 100644 --- a/src/ipa/rkisp1/algorithms/af.cpp +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -33,24 +33,55 @@ namespace 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::algorithms::AfHillClimbing for additional tuning * parameters. * * \todo Model the lens delay as number of frames required for the lens position * to stabilize in the CameraLens class. + * \todo Check if requested window size is valid. RkISP supports AF window size + * few pixels smaller than sensor output size. + * \todo Implement support for all available AF windows. RkISP supports up to 3 + * AF windows. */ 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); } @@ -85,6 +116,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 */ @@ -110,6 +167,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 ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h index 3ba66d38..6f5adb19 100644 --- a/src/ipa/rkisp1/algorithms/af.h +++ b/src/ipa/rkisp1/algorithms/af.h @@ -20,21 +20,32 @@ namespace 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, uint32_t frame, IPAFrameContext &frameContext, const ControlList &controls) override; + void prepare(IPAContext &context, uint32_t frame, + IPAFrameContext &frameContext, + rkisp1_params_cfg *params) override; void process(IPAContext &context, uint32_t frame, IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats, ControlList &metadata) override; private: + void updateCurrentWindow(const Rectangle &window); + ipa::algorithms::AfHillClimbing af; - /* Wait number of frames after changing lens position */ + std::optional updateWindow_; + uint32_t ispThreshold_ = 0; + uint32_t ispVarShift_ = 0; + + /* Wait number of frames after changing lens position. */ uint32_t waitFramesLens_ = 0; };