From patchwork Thu Jun 30 14:35:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16490 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 24A82BE173 for ; Thu, 30 Jun 2022 14:36:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D7DB96564C; Thu, 30 Jun 2022 16:36:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656599767; bh=n4X3SEbhaRTmUqd2WK/p86Vgax6EYiFiLNeERaiLxkQ=; 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=N3xe4j3nfbcIAy+gtRt84z9oYYcf4Qfseijrf4cDslif704V0w3X3AAq444sqMe02 o2z2FwOK94kb4nUd2kZxMMCtWkv5dgAXP4wRcO63jixjwoqfJorVQIh7rO2lguLm6e 4+g303+v4s9QRnF5UogCSy/7ZgXJaEtZ5dl/c1jLBQVsnBFwI+MfSCa/P76oxEDD8d 1C/s4Tesctjx3mSNJF9WiXuCnjui2J0I/CMEKkQHielmn09OSCVYha16V5Yd5jtSNp lqOzWaTeZVDU+TklGXIbDu6wtRSemhH9xmLpqQREr8c1bFxN0EodyLllqkHJPKVNmV J8vVSKIoAuoTQ== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 136DD6564C for ; Thu, 30 Jun 2022 16:36:05 +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="Gd0TpMAG"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id o19-20020a05600c4fd300b003a0489f414cso1796450wmq.4 for ; Thu, 30 Jun 2022 07:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nyiOgrJW6e4HOWfmcUP3xJpxFA0ukWTwpc62dxzTC18=; b=Gd0TpMAG2rviMugW24pCgYzVZC+2IaMnqo2hgfzvQmtVRvDDomCW9b/Gr2R/5HQ9Fv bz9LCpR7J+IVpp/l6V0mjtmLwSI1aZhJFzF6c4cdrO+zsLjBnq6Loxo9K0F7lzJ/q5e4 NUZ6kBI8wu5zd9GbLNmw8GlPW9zwdJovJG9Y9+Z1uGkzOle9bQ/0gZ8nJXmTQ8eVNfuP PRSr+iJWrecOcPZgLgRBXDdQnhKUWfbP5uKFPDolGG4TGP+urduh/kVs4bHQV+SBwLGr ZxDvVkKKD29/hWhLIVNgypQhM2rmEUpgfqukEo2D3ZhxXg/fBL7MtUWMEhc3FDN7SdnE k+nA== 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=nyiOgrJW6e4HOWfmcUP3xJpxFA0ukWTwpc62dxzTC18=; b=BeuOn8OFUk4Ih5zfiZhyYPBp0XBewcMZviS9YSdwfjNFDWE1nMYLmhtfFeXaFVw38L URpudvTnLIFqsNYoyIrNxD59bUrXdLtFgbDk5pcTA1IxExWCkB4i2yWRAMXOUs7EGK7K fb6aU56nl4vyI75lVMrlzMsZUzCbxrW9v4IGF9iwy1PCIqXyt1Z7whXt/CZQsoJeGz4V hzkfF4+sgWW4/50M8ejie7S86PjTEzFY5fauqOpl718A3WhJrcsZsf0yxYV3B8rCv+iU izevuHc4BXHR7nA124C/hGBnvyRpLrP0HG05L15icizbPCJ6Kp8LAIhc+idGuUT9n46G zDfA== X-Gm-Message-State: AJIora9jXF12ixdX+jIlQijoJbZPFRZfwPdVJM0PGfr2HXntfvsAK1n1 DYy54gRX2Io9HwpFC85+GS0tYUiJYz6YGg== X-Google-Smtp-Source: AGRyM1vbLeWdjZ4sSz8HQeAgDofLfyaV0jJ/lCVaagsOmxUxgNF+1JIkgo5QRFXI7x9qAjMBIO/Ztg== X-Received: by 2002:a1c:7c18:0:b0:3a0:39b1:3403 with SMTP id x24-20020a1c7c18000000b003a039b13403mr13072413wmc.84.1656599764584; Thu, 30 Jun 2022 07:36:04 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id r5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 07:36:04 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 16:35:43 +0200 Message-Id: <20220630143543.39599-9-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630143543.39599-1-dse@thaumatec.com> References: <20220630143543.39599-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 8/8] ipa: rkisp1: Add "Windows" Metering mode to auto focus algorithm 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" Allow manually setting auto focus window. 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 | 74 ++++++++++++++++++++++-- src/ipa/rkisp1/algorithms/af.h | 9 +++ src/ipa/rkisp1/rkisp1.cpp | 20 +++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 + 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp index 8da970e3..22507918 100644 --- a/src/ipa/rkisp1/algorithms/af.cpp +++ b/src/ipa/rkisp1/algorithms/af.cpp @@ -20,20 +20,54 @@ namespace libcamera::ipa::rkisp1::algorithms { LOG_DEFINE_CATEGORY(RkISP1Af) + +static rkisp1_cif_isp_window rectangleToIspWindow(const Rectangle &rectangle) +{ + rkisp1_cif_isp_window ispwindow; + + ispwindow.h_offs = rectangle.x; + ispwindow.v_offs = rectangle.y; + ispwindow.h_size = rectangle.width; + ispwindow.v_size = rectangle.height; + + return ispwindow; +} + /** * \copydoc libcamera::ipa::Algorithm::configure */ int Af::configure([[maybe_unused]] IPAContext &context, - [[maybe_unused]] const IPACameraSensorInfo &configInfo) + const IPACameraSensorInfo &configInfo) { + /* Default AF window of 3/4 size of the screen placed at the center */ + defaultWindow_ = Rectangle(configInfo.outputSize.width / 8, + configInfo.outputSize.height / 8, + 3 * configInfo.outputSize.width / 4, + 3 * configInfo.outputSize.height / 4); + updateCurrentWindow(defaultWindow_); + return 0; } /** * \copydoc libcamera::ipa::Algorithm::prepare */ -void Af::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] rkisp1_params_cfg *params) +void Af::prepare([[maybe_unused]] IPAContext &context, rkisp1_params_cfg *params) { + if (updateAfwindow_) { + params->meas.afc_config.num_afm_win = 1; + params->meas.afc_config.thres = 128; + params->meas.afc_config.var_shift = 4; + /* \todo Allow setting thres and var_shift in tuning file */ + + params->meas.afc_config.afm_win[0] = rectangleToIspWindow(currentWindow_); + + 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; + + updateAfwindow_ = false; + } } /** @@ -55,14 +89,42 @@ void Af::process(IPAContext &context, context.frameContext.af.focus = lensPosition; } -void Af::setMetering([[maybe_unused]] controls::AfMeteringEnum metering) +void Af::setMetering(controls::AfMeteringEnum metering) { - LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!"; + if (metering == meteringMode_) + return; + + if (metering == controls::AfMeteringWindows) { + updateCurrentWindow(userWindow_); + } else { + updateCurrentWindow(defaultWindow_); + } + + meteringMode_ = metering; +} + +void Af::setWindows(Span windows) +{ + if (windows.size() != 1) { + LOG(RkISP1Af, Error) << "Only one AF window is supported"; + return; + } + + /* \todo Check if window size is valid for ISP */ + + LOG(RkISP1Af, Debug) << "setWindows: " << userWindow_; + + userWindow_ = windows[0]; + + if (meteringMode_ == controls::AfMeteringWindows) { + updateCurrentWindow(userWindow_); + } } -void Af::setWindows([[maybe_unused]] Span windows) +void Af::updateCurrentWindow(const Rectangle &window) { - LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!"; + currentWindow_ = window; + updateAfwindow_ = true; } REGISTER_IPA_ALGORITHM(Af, "Af") diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h index c470c9b2..c709ee98 100644 --- a/src/ipa/rkisp1/algorithms/af.h +++ b/src/ipa/rkisp1/algorithms/af.h @@ -27,6 +27,15 @@ public: void setMetering(controls::AfMeteringEnum metering) override; void setWindows(Span windows) override; + +private: + void updateCurrentWindow(const Rectangle &window); + + controls::AfMeteringEnum meteringMode_ = controls::AfMeteringAuto; + Rectangle currentWindow_; + Rectangle defaultWindow_; + Rectangle userWindow_; + bool updateAfwindow_ = false; }; } /* namespace libcamera::ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 53b53f12..99ac1fb7 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -319,6 +319,26 @@ void IPARkISP1::queueRequest([[maybe_unused]] const uint32_t frame, af->setMode(static_cast(ctrlValue.get())); break; } + case controls::AF_METERING: { + Af *af = getAlgorithm(); + if (!af) { + LOG(IPARkISP1, Warning) << "Could not set AF_WINDOWS - no AF algorithm"; + break; + } + + af->setMetering(static_cast(ctrlValue.get())); + break; + } + case controls::AF_WINDOWS: { + Af *af = getAlgorithm(); + if (!af) { + LOG(IPARkISP1, Warning) << "Could not set AF_WINDOWS - no AF algorithm"; + break; + } + + af->setWindows(ctrlValue.get>()); + break; + } case controls::AF_TRIGGER: { Af *af = getAlgorithm(); if (!af) { diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 99d66b1d..7ab03057 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -961,6 +961,8 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) ControlInfoMap::Map ctrls({ { &controls::AeEnable, ControlInfo(false, true) }, { &controls::AfMode, ControlInfo(controls::AfModeValues) }, + { &controls::AfMetering, ControlInfo(controls::AfMeteringValues) }, + { &controls::AfWindows, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, { &controls::AfTrigger, ControlInfo(controls::AfTriggerValues) }, { &controls::AfPause, ControlInfo(controls::AfPauseValues) } });