From patchwork Wed Jul 13 08:43:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16606 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 07578BE173 for ; Wed, 13 Jul 2022 08:43:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD8E66332A; Wed, 13 Jul 2022 10:43:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657701828; bh=UvlVZ/vpdaAmDJy+dX5wpOU7CW0QJe5+AsRwk0vzqfQ=; 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=NGjRYbmKfAH7BUBdxp8u5jx+E/dUzaH4MYePSUNwcSrux2+yZHrNTeD1JNtRoIVbW OqlF4CW0kZ/E0mA//ICEKC2EASwmiL4X4uNmDWTrnEL0h1ioUMNiEvFDERWSPqYrxW XLWRy5WyogM9bHXSX22pZ4bQHsjLYPDQHQx5+8KFVmCWft4UmnScKN+qgV9H+WqsbO tUQK0FnW42bXum/9zXpcapu5oju5pELEz5JSYWpGMcneySWmnmC+aLiO3QdWYvI38v lhM4SX8zkqVHOaLpn3AF554GdLb2mRI+jEDNajG0Ub+XCjFtA7M9XfCehWp04Nxm0d gU294VZM96msg== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6682F6330D for ; Wed, 13 Jul 2022 10:43:46 +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="V51P9+oo"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id o4so14493674wrh.3 for ; Wed, 13 Jul 2022 01:43:46 -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=TEqk0tsZjracHmr4JA/9Bxzjw1uP65H1h7ztdKdW0u4=; b=V51P9+oolwahP3K1nyP+nz/Iv1tNA4DV6iKNXUwxG/FsBtmmcpuHTKB2S9WX7Fn5Kz l+Iyh2L75uBHnY5wd0tPtmbp6Sd9zmlIob886QZO1SufiGNonhrLAsCBwyYwyp5qq9dM O6XWDLDoD2T6AOQW83TRw7+4Jdl2vL7evV0TTbucqSrNhU+kW4ESEVIbdaIcuCoSEloZ 90u5VVWt5ZG7vTVMOqEjdIhk6oFafCurH+Bc/3DCe3gkUYrcqgifpK2cMbCd3vohPP8I OV1zNlCnv9Xfif4wL2FDHtlw2lX90Bo4nMKKRzIgar5GmcnA3SrmXSa4hRox5Ap2eS0v 4rKA== 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=TEqk0tsZjracHmr4JA/9Bxzjw1uP65H1h7ztdKdW0u4=; b=vbeKE/uqS7ACR4uNlhtmdtkFtS55lLw05Udl0bfK2/CbCPO19js1D0SiP49LgLFmJx pNZX+p7hU238K6WoOf81afaocGoHzNnvP7BziY74P5q6RTTgq6pUa2B3CCHce1jLxfd5 oTCCZ/myRMy3aB0dSD/Q7cb/h98wZvv//zShCIHJpOYZ+sgV1L241Pr813EdhJ1Ep/rr +slmnFCaqOB0puCVpEDUb4tTon+bqTyPuyz903AqVCKyPyK5fFIbhOCXLUA38Ucxl1Uv IJKIrlk6QL9whdI9r80myFhWRpJ9gjxlI7TH/ODOkrd8I3biaavO/LFAtgG/CMOtz2Ul kZLw== X-Gm-Message-State: AJIora8sgu6PZtWZLLdXLiy1Sf3e19gvui6X/tXXzNkHd7l3lxoSjHkk 06XmCi81bEZ2FHpi3jA3nMOHHpd7ahw11A== X-Google-Smtp-Source: AGRyM1t5nR4OcZS72AFxvKwd5s4+Ok2rxNCuJHU7pNO//joGCIaZkNM5ZnvG5SLGIqpjaVzUTXYfgg== X-Received: by 2002:a05:6000:1849:b0:21d:9ad7:f27f with SMTP id c9-20020a056000184900b0021d9ad7f27fmr1990321wri.445.1657701825995; Wed, 13 Jul 2022 01:43:45 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id bg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:43:45 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Jul 2022 10:43:14 +0200 Message-Id: <20220713084317.24268-9-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713084317.24268-1-dse@thaumatec.com> References: <20220713084317.24268-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/11] 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 6e047804..cd4f0e08 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 e9afbb98..eeb806c0 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) } });