{"id":16606,"url":"https://patchwork.libcamera.org/api/patches/16606/?format=json","web_url":"https://patchwork.libcamera.org/patch/16606/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220713084317.24268-9-dse@thaumatec.com>","date":"2022-07-13T08:43:14","name":"[libcamera-devel,v2,08/11] ipa: rkisp1: Add \"Windows\" Metering mode to auto focus algorithm","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"86f027f7549730e42b233ec6a474aaa05a04ff13","submitter":{"id":126,"url":"https://patchwork.libcamera.org/api/people/126/?format=json","name":"Daniel Semkowicz","email":"dse@thaumatec.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16606/mbox/","series":[{"id":3276,"url":"https://patchwork.libcamera.org/api/series/3276/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3276","date":"2022-07-13T08:43:06","name":"ipa: rkisp1: Add autofocus algorithm","version":2,"mbox":"https://patchwork.libcamera.org/series/3276/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16606/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16606/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 07578BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 13 Jul 2022 08:43:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BD8E66332A;\n\tWed, 13 Jul 2022 10:43:48 +0200 (CEST)","from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6682F6330D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Jul 2022 10:43:46 +0200 (CEST)","by mail-wr1-x436.google.com with SMTP id o4so14493674wrh.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Jul 2022 01:43:46 -0700 (PDT)","from localhost.localdomain (ip092042140082.rev.nessus.at.\n\t[92.42.140.82]) by smtp.gmail.com with ESMTPSA id\n\tbg32-20020a05600c3ca000b003a04d19dab3sm5667468wmb.3.2022.07.13.01.43.44\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 13 Jul 2022 01:43:45 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1657701828;\n\tbh=UvlVZ/vpdaAmDJy+dX5wpOU7CW0QJe5+AsRwk0vzqfQ=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=NGjRYbmKfAH7BUBdxp8u5jx+E/dUzaH4MYePSUNwcSrux2+yZHrNTeD1JNtRoIVbW\n\tOqlF4CW0kZ/E0mA//ICEKC2EASwmiL4X4uNmDWTrnEL0h1ioUMNiEvFDERWSPqYrxW\n\tXLWRy5WyogM9bHXSX22pZ4bQHsjLYPDQHQx5+8KFVmCWft4UmnScKN+qgV9H+WqsbO\n\ttUQK0FnW42bXum/9zXpcapu5oju5pELEz5JSYWpGMcneySWmnmC+aLiO3QdWYvI38v\n\tlhM4SX8zkqVHOaLpn3AF554GdLb2mRI+jEDNajG0Ub+XCjFtA7M9XfCehWp04Nxm0d\n\tgU294VZM96msg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=thaumatec-com.20210112.gappssmtp.com; s=20210112;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=TEqk0tsZjracHmr4JA/9Bxzjw1uP65H1h7ztdKdW0u4=;\n\tb=V51P9+oolwahP3K1nyP+nz/Iv1tNA4DV6iKNXUwxG/FsBtmmcpuHTKB2S9WX7Fn5Kz\n\tl+Iyh2L75uBHnY5wd0tPtmbp6Sd9zmlIob886QZO1SufiGNonhrLAsCBwyYwyp5qq9dM\n\tO6XWDLDoD2T6AOQW83TRw7+4Jdl2vL7evV0TTbucqSrNhU+kW4ESEVIbdaIcuCoSEloZ\n\t90u5VVWt5ZG7vTVMOqEjdIhk6oFafCurH+Bc/3DCe3gkUYrcqgifpK2cMbCd3vohPP8I\n\tOV1zNlCnv9Xfif4wL2FDHtlw2lX90Bo4nMKKRzIgar5GmcnA3SrmXSa4hRox5Ap2eS0v\n\t4rKA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=thaumatec-com.20210112.gappssmtp.com\n\theader.i=@thaumatec-com.20210112.gappssmtp.com header.b=\"V51P9+oo\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=TEqk0tsZjracHmr4JA/9Bxzjw1uP65H1h7ztdKdW0u4=;\n\tb=vbeKE/uqS7ACR4uNlhtmdtkFtS55lLw05Udl0bfK2/CbCPO19js1D0SiP49LgLFmJx\n\tpNZX+p7hU238K6WoOf81afaocGoHzNnvP7BziY74P5q6RTTgq6pUa2B3CCHce1jLxfd5\n\toTCCZ/myRMy3aB0dSD/Q7cb/h98wZvv//zShCIHJpOYZ+sgV1L241Pr813EdhJ1Ep/rr\n\t+slmnFCaqOB0puCVpEDUb4tTon+bqTyPuyz903AqVCKyPyK5fFIbhOCXLUA38Ucxl1Uv\n\tIJKIrlk6QL9whdI9r80myFhWRpJ9gjxlI7TH/ODOkrd8I3biaavO/LFAtgG/CMOtz2Ul\n\tkZLw==","X-Gm-Message-State":"AJIora8sgu6PZtWZLLdXLiy1Sf3e19gvui6X/tXXzNkHd7l3lxoSjHkk\n\t06XmCi81bEZ2FHpi3jA3nMOHHpd7ahw11A==","X-Google-Smtp-Source":"AGRyM1t5nR4OcZS72AFxvKwd5s4+Ok2rxNCuJHU7pNO//joGCIaZkNM5ZnvG5SLGIqpjaVzUTXYfgg==","X-Received":"by 2002:a05:6000:1849:b0:21d:9ad7:f27f with SMTP id\n\tc9-20020a056000184900b0021d9ad7f27fmr1990321wri.445.1657701825995; \n\tWed, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 08/11] ipa: rkisp1: Add \"Windows\"\n\tMetering mode to auto focus algorithm","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Daniel Semkowicz via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Daniel Semkowicz <dse@thaumatec.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Allow manually setting auto focus window. Currently only one window is\nenabled, but ISP allows up to three of them.\n\nSigned-off-by: Daniel Semkowicz <dse@thaumatec.com>\n---\n src/ipa/rkisp1/algorithms/af.cpp         | 74 ++++++++++++++++++++++--\n src/ipa/rkisp1/algorithms/af.h           |  9 +++\n src/ipa/rkisp1/rkisp1.cpp                | 20 +++++++\n src/libcamera/pipeline/rkisp1/rkisp1.cpp |  2 +\n 4 files changed, 99 insertions(+), 6 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp\nindex 6e047804..cd4f0e08 100644\n--- a/src/ipa/rkisp1/algorithms/af.cpp\n+++ b/src/ipa/rkisp1/algorithms/af.cpp\n@@ -20,20 +20,54 @@ namespace libcamera::ipa::rkisp1::algorithms {\n \n LOG_DEFINE_CATEGORY(RkISP1Af)\n \n+\n+static rkisp1_cif_isp_window rectangleToIspWindow(const Rectangle &rectangle)\n+{\n+\trkisp1_cif_isp_window ispwindow;\n+\n+\tispwindow.h_offs = rectangle.x;\n+\tispwindow.v_offs = rectangle.y;\n+\tispwindow.h_size = rectangle.width;\n+\tispwindow.v_size = rectangle.height;\n+\n+\treturn ispwindow;\n+}\n+\n /**\n  * \\copydoc libcamera::ipa::Algorithm::configure\n  */\n int Af::configure([[maybe_unused]] IPAContext &context,\n-\t\t  [[maybe_unused]] const IPACameraSensorInfo &configInfo)\n+\t\t  const IPACameraSensorInfo &configInfo)\n {\n+\t/* Default AF window of 3/4 size of the screen placed at the center */\n+\tdefaultWindow_ = Rectangle(configInfo.outputSize.width / 8,\n+\t\t\t\t   configInfo.outputSize.height / 8,\n+\t\t\t\t   3 * configInfo.outputSize.width / 4,\n+\t\t\t\t   3 * configInfo.outputSize.height / 4);\n+\tupdateCurrentWindow(defaultWindow_);\n+\n \treturn 0;\n }\n \n /**\n  * \\copydoc libcamera::ipa::Algorithm::prepare\n  */\n-void Af::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] rkisp1_params_cfg *params)\n+void Af::prepare([[maybe_unused]] IPAContext &context, rkisp1_params_cfg *params)\n {\n+\tif (updateAfwindow_) {\n+\t\tparams->meas.afc_config.num_afm_win = 1;\n+\t\tparams->meas.afc_config.thres = 128;\n+\t\tparams->meas.afc_config.var_shift = 4;\n+\t\t/* \\todo Allow setting thres and var_shift in tuning file */\n+\n+\t\tparams->meas.afc_config.afm_win[0] = rectangleToIspWindow(currentWindow_);\n+\n+\t\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_AFC;\n+\t\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_AFC;\n+\t\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_AFC;\n+\n+\t\tupdateAfwindow_ = false;\n+\t}\n }\n \n /**\n@@ -55,14 +89,42 @@ void Af::process(IPAContext &context,\n \tcontext.frameContext.af.focus = lensPosition;\n }\n \n-void Af::setMetering([[maybe_unused]] controls::AfMeteringEnum metering)\n+void Af::setMetering(controls::AfMeteringEnum metering)\n {\n-\tLOG(RkISP1Af, Error) << __FUNCTION__ << \" not implemented!\";\n+\tif (metering == meteringMode_)\n+\t\treturn;\n+\n+\tif (metering == controls::AfMeteringWindows) {\n+\t\tupdateCurrentWindow(userWindow_);\n+\t} else {\n+\t\tupdateCurrentWindow(defaultWindow_);\n+\t}\n+\n+\tmeteringMode_ = metering;\n+}\n+\n+void Af::setWindows(Span<const Rectangle> windows)\n+{\n+\tif (windows.size() != 1) {\n+\t\tLOG(RkISP1Af, Error) << \"Only one AF window is supported\";\n+\t\treturn;\n+\t}\n+\n+\t/* \\todo Check if window size is valid for ISP */\n+\n+\tLOG(RkISP1Af, Debug) << \"setWindows: \" << userWindow_;\n+\n+\tuserWindow_ = windows[0];\n+\n+\tif (meteringMode_ == controls::AfMeteringWindows) {\n+\t\tupdateCurrentWindow(userWindow_);\n+\t}\n }\n \n-void Af::setWindows([[maybe_unused]] Span<const Rectangle> windows)\n+void Af::updateCurrentWindow(const Rectangle &window)\n {\n-\tLOG(RkISP1Af, Error) << __FUNCTION__ << \" not implemented!\";\n+\tcurrentWindow_ = window;\n+\tupdateAfwindow_ = true;\n }\n \n REGISTER_IPA_ALGORITHM(Af, \"Af\")\ndiff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h\nindex e9afbb98..eeb806c0 100644\n--- a/src/ipa/rkisp1/algorithms/af.h\n+++ b/src/ipa/rkisp1/algorithms/af.h\n@@ -27,6 +27,15 @@ public:\n \n \tvoid setMetering(controls::AfMeteringEnum metering) override;\n \tvoid setWindows(Span<const Rectangle> windows) override;\n+\n+private:\n+\tvoid updateCurrentWindow(const Rectangle &window);\n+\n+\tcontrols::AfMeteringEnum meteringMode_ = controls::AfMeteringAuto;\n+\tRectangle currentWindow_;\n+\tRectangle defaultWindow_;\n+\tRectangle userWindow_;\n+\tbool updateAfwindow_ = false;\n };\n \n } /* namespace libcamera::ipa::rkisp1::algorithms */\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex 53b53f12..99ac1fb7 100644\n--- a/src/ipa/rkisp1/rkisp1.cpp\n+++ b/src/ipa/rkisp1/rkisp1.cpp\n@@ -319,6 +319,26 @@ void IPARkISP1::queueRequest([[maybe_unused]] const uint32_t frame,\n \t\t\taf->setMode(static_cast<controls::AfModeEnum>(ctrlValue.get<int32_t>()));\n \t\t\tbreak;\n \t\t}\n+\t\tcase controls::AF_METERING: {\n+\t\t\tAf *af = getAlgorithm<Af>();\n+\t\t\tif (!af) {\n+\t\t\t\tLOG(IPARkISP1, Warning) << \"Could not set AF_WINDOWS - no AF algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\taf->setMetering(static_cast<controls::AfMeteringEnum>(ctrlValue.get<int32_t>()));\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase controls::AF_WINDOWS: {\n+\t\t\tAf *af = getAlgorithm<Af>();\n+\t\t\tif (!af) {\n+\t\t\t\tLOG(IPARkISP1, Warning) << \"Could not set AF_WINDOWS - no AF algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\taf->setWindows(ctrlValue.get<Span<const Rectangle>>());\n+\t\t\tbreak;\n+\t\t}\n \t\tcase controls::AF_TRIGGER: {\n \t\t\tAf *af = getAlgorithm<Af>();\n \t\t\tif (!af) {\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 99d66b1d..7ab03057 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -961,6 +961,8 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n \tControlInfoMap::Map ctrls({\n \t\t{ &controls::AeEnable, ControlInfo(false, true) },\n \t\t{ &controls::AfMode, ControlInfo(controls::AfModeValues) },\n+\t\t{ &controls::AfMetering, ControlInfo(controls::AfMeteringValues) },\n+\t\t{ &controls::AfWindows, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) },\n \t\t{ &controls::AfTrigger, ControlInfo(controls::AfTriggerValues) },\n \t\t{ &controls::AfPause, ControlInfo(controls::AfPauseValues) }\n \t});\n","prefixes":["libcamera-devel","v2","08/11"]}