From patchwork Fri Mar 31 08:19:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 18514 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 C088FC329C for ; Fri, 31 Mar 2023 08:19:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 819906276E; Fri, 31 Mar 2023 10:19:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680250799; bh=5I/UFgqh1r9xAS4KT5H61rUndV9Jb7t0H6WnthnATRc=; 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=s8s41oJ9vUBskioX5dwXudBJbPmWKKOmgUDFP90pGP0vbvHNRKM2+9WciJqZhzvKd glDCzUoMVv0N7CEK7i8XM3uiZih1as094xWomQMgtDzSHMFirdodrqcuBoVC+O8k3m 6hb3XfasEAvM3DQMM9L/V4NkkDhKOMwcuYZ3nvGQ2f5qwURA8eWePhUklsPCLbRIhq lU3n6jDGAq40CpTQBD5kxfY3/etCYvzdKJNsPVtpRXjEn7zeq09adrg1fv7wTQScxA C2Gj/iyhURww0totKJCLOufYgF0LsoWSd3Gh3D8ZCcjR4VOwpE2ZhD0CJIgmW5APUs sSe3JkzL1Zscw== Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 50CF462756 for ; Fri, 31 Mar 2023 10:19:51 +0200 (CEST) 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="pMGgcgmw"; dkim-atps=neutral Received: by mail-lf1-x130.google.com with SMTP id h11so20918204lfu.8 for ; Fri, 31 Mar 2023 01:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250790; x=1682842790; 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=i7HiaDitI9UaV/98RgLZ0YhDRIfpVqYfYoOGSzOSw40=; b=pMGgcgmwYMfr5vOy/3rcnpQzUqu7FUfOIzLRe+/aq5m9EbXwLvExIp10wd+mkccwke 8vxTLGri/MXTQGMh20dikuQ8t52eyxm+Gi2+KbXFglKddZibFE1O/vL9XecMdbPHz++L +jqddpLL9ULZNiKMZkb2YaO5iVSZ4Yqu9U3AUqHz30pzqvkV/xs/PFE3RadQTgpl0eY4 a482OHTJi+4hJzzr0LLmqpW7EIWYO7Zh/KnzqapTKoPOD9jR624HUOdFUE0U6ANJrbsH miMN6BUe9Mz5sXR+LTH2Y8NGYuUdKmprUfcQYkPxFCsVctZbIEj1P4YGMImQg7ujSihV TdRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680250790; x=1682842790; 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=i7HiaDitI9UaV/98RgLZ0YhDRIfpVqYfYoOGSzOSw40=; b=fKoY66pFRhDGCXAmRDA04k3+j5YW3ersd4xYGgMC7PnDHxD12LAEFQ2YoJo0V7T6QQ koGuihIdTUqL/roEcMIso8B5BOt9pZ9eyhVLV9tdGZUDnoS6YVO/6h43QwynHFB92/zP sK52j9UO88D5b7VtpXklXoISoYHOnR/B/JGtfLjKIBZLrGVauaZmmDO4wwZX0rF8jxHc sTc9podMvCRNnx1lxSq8fdDgrHavhT6NzEiclwxUt4lNaqvH1Hx0P0RHnRYyrOzCq6BC 48XNwyNhEfOr9wZ00IbZHADh9pBmyt1GzjUNPFA90PYB+wvDEtJJEoaGucbDh2XAOLEb UB8w== X-Gm-Message-State: AAQBX9eukUbwxwOxIAQUaw9zV/aJOb3/BY53uatmCse5aA9JKZSBbuDz ASSqcs3TqayYZOCnnPBMJZLMtot7JH4psQokdB00Ow== X-Google-Smtp-Source: AKy350aE9pmcBoveZkTN/KNl4GjPYLmh2+veYU6HM/qnXb1q3G6mFWiqgAEVhUcPSkfAZDORRIOPJg== X-Received: by 2002:a19:5502:0:b0:4ea:e262:b94e with SMTP id n2-20020a195502000000b004eae262b94emr7132028lfe.21.1680250790693; Fri, 31 Mar 2023 01:19:50 -0700 (PDT) Received: from localhost.localdomain ([91.90.166.178]) by smtp.gmail.com with ESMTPSA id t1-20020ac24c01000000b004e84a8c3d86sm281459lfq.42.2023.03.31.01.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 01:19:50 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 10:19:27 +0200 Message-Id: <20230331081930.19289-8-dse@thaumatec.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230331081930.19289-1-dse@thaumatec.com> References: <20230331081930.19289-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 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 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 fde924d4..b6f6eee4 100644 --- a/src/ipa/rkisp1/algorithms/af.cpp +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -32,16 +32,43 @@ 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 */ @@ -54,8 +81,12 @@ int Af::init(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(lensConfig->minFocusPosition, lensConfig->maxFocusPosition, tuningData); @@ -89,6 +120,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.skipFrames(1); + } +} + /** * \copydoc libcamera::ipa::Algorithm::process */ @@ -114,6 +171,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; };