{"id":18450,"url":"https://patchwork.libcamera.org/api/patches/18450/?format=json","web_url":"https://patchwork.libcamera.org/patch/18450/","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":"<20230324142908.64224-8-dse@thaumatec.com>","date":"2023-03-24T14:29:05","name":"[libcamera-devel,v5,07/10] ipa: rkisp1: af: Add \"Windows\" Metering mode","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6b652c90196642adc509375dd6875ebfdb3f346a","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/18450/mbox/","series":[{"id":3813,"url":"https://patchwork.libcamera.org/api/series/3813/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3813","date":"2023-03-24T14:28:58","name":"ipa: rkisp1: Add autofocus algorithm","version":5,"mbox":"https://patchwork.libcamera.org/series/3813/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18450/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18450/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 2ED08C3260\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Mar 2023 14:29:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 95A4862712;\n\tFri, 24 Mar 2023 15:29:36 +0100 (CET)","from mail-lj1-x236.google.com (mail-lj1-x236.google.com\n\t[IPv6:2a00:1450:4864:20::236])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E7B6626E5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Mar 2023 15:29:28 +0100 (CET)","by mail-lj1-x236.google.com with SMTP id by8so1891267ljb.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Mar 2023 07:29:28 -0700 (PDT)","from localhost.localdomain ([91.90.166.178])\n\tby smtp.gmail.com with ESMTPSA id\n\tj21-20020a2e8515000000b002a10b2ea089sm981714lji.16.2023.03.24.07.29.27\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 24 Mar 2023 07:29:27 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679668176;\n\tbh=ItCp53EbrXJqVrpIw8CXw09ZfGPOxLlLBQIa6SktU/4=;\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:Cc:\n\tFrom;\n\tb=2meKGVau7itneF2Qt9Q1KJ3IyioiJOgfBpIjWuWuR9ZDBU263QnIVQEv49LGku+jW\n\t1pkfc6O7Gec8vDBJ9nen6de1JERlvJnyu6xHc7WjRtTty7tacK+84OAjKAxL5DHoSg\n\tFLZxN9qWu3qWOJzsX3dyanh3ohE4iozJiEsiVwCpvT1BA8GTxevdaR63fULd/D/s/M\n\t2JJPQR/TBJVgn87/t4hdKJWc6ErV9vywt3uzpYWomwDBpIlvW0hS1m8x0Dug2KSLs6\n\tdt5O4ol/S6eoEadbfX5I21tPDyUNFL3fU/sVz5BytivCBrV3JUbby55SeGho4ioVGm\n\tnM5kKTci4yovA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1679668168;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=RW3UZh1I69vi3Jxsfk5UYduKKMBKc8FCToCkGLOtrdE=;\n\tb=4ZNCZXI8cRixZzs+EI5cKK25f9ReTVMBYHCmMy1o3zU42Jxy6HgD45FMrglJGQ0S1O\n\tfoeRmP16OhglVj+iM7lWGL3ZxSVt7uiShs1LxwIayRhrpshAelL3yEUOu2fB9Lr76bIR\n\t9JYL9gMpMUZskpvUsRXTkBcLFJTAm94BFcgGFrbq75tfNUeJVJ2HQr/YbcKXEbRUdAIn\n\tD7N66ic68hwPKrahUhhwcFGwM/YVGEwgQV5cK9Af3dNHh4/+FohgVWWqPc//A0vWYSBC\n\tp2fVr0kcahZmUSpqH+7HUVewVkkQDxxTt6jYe2q1qECFufW7FiK1MD9VdsYPzARFUqS4\n\teeUg=="],"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=\"4ZNCZXI8\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1679668168;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=RW3UZh1I69vi3Jxsfk5UYduKKMBKc8FCToCkGLOtrdE=;\n\tb=BUT5QVhK2gKeLs6qDGlHRwMCUBUqbFCQA55UqeqdAd5tJbXYaEKEL5ddB8EOcI6wI4\n\to1GSSzgBOMMIRhxB9QXttsLB9BB7Q9B/VJn/+9AfNFz+TTAXJW7ubi1cEvaRR+IzqTaN\n\tpr5MXte+DZaIFzyfWZ+ygpE8ZNhQIKcaxTeWHaAbUdRGpE3DwrzREwW4OikpMYFb4Eja\n\tEy0rPYEiK0QRjGEBWNFx+wX71QhU8sUoDMeJkLOkn8FYZ0egzc0uFvwHYqKftpllQQoS\n\t2ZPgGNGnRvmPKET/hb0+JO0D8rglnKh6EcIQ+HLhOl724n8YCplo70FuyIuji/4PdyOy\n\thH4w==","X-Gm-Message-State":"AAQBX9e7I+Q8L01LCGf6tqZ07K+pBfGoSaL7jAvEa05RCzOlUkzSvvmq\n\tCoX69d57eRj+aKM0Hhpz3MwF8NnCIHvrpQn0LBY=","X-Google-Smtp-Source":"AKy350bvbsC2Zc5XP0ne4qsfM49DtDGCvCdoxoPOiYuI79KoZOdXnxljhbb2lBEvz9Cb4QUn7wucCQ==","X-Received":"by 2002:a2e:988b:0:b0:295:a2d0:57ed with SMTP id\n\tb11-20020a2e988b000000b00295a2d057edmr1168320ljj.4.1679668167897; \n\tFri, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 07/10] ipa: rkisp1: af: Add \"Windows\"\n\tMetering mode","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>","Cc":"jacopo.mondi@ideasonboard.com","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add platform related code for configuring auto focus window on the\nrkisp1. Connect to the windowUpdateRequested() signal exposed by the\nAfHillClimbing and configure the window on each signal emission.\nThis enables support of AfMetering and AfWindows controls on the rkisp1\nplatform.\n\nCurrently, only one window is enabled, but ISP allows up to three\nof them.\n\nSigned-off-by: Daniel Semkowicz <dse@thaumatec.com>\n---\n src/ipa/rkisp1/algorithms/af.cpp | 64 +++++++++++++++++++++++++++++++-\n src/ipa/rkisp1/algorithms/af.h   | 13 ++++++-\n 2 files changed, 75 insertions(+), 2 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp\nindex aca127d2..9f7ba72e 100644\n--- a/src/ipa/rkisp1/algorithms/af.cpp\n+++ b/src/ipa/rkisp1/algorithms/af.cpp\n@@ -33,24 +33,55 @@ namespace ipa::rkisp1::algorithms {\n  *   amount of time on each movement. This parameter should be set according\n  *   to the worst case  - the number of frames it takes to move lens between\n  *   limit positions.\n+ * - **isp-threshold:** Threshold used for minimizing the influence of noise.\n+ *   This affects the ISP sharpness calculation.\n+ * - **isp-var-shift:** The number of bits for the shift operation at the end\n+ *   of the calculation chain. This affects the ISP sharpness calculation.\n  * .\n  * \\sa libcamera::ipa::algorithms::AfHillClimbing for additional tuning\n  * parameters.\n  *\n  * \\todo Model the lens delay as number of frames required for the lens position\n  *   to stabilize in the CameraLens class.\n+ * \\todo Check if requested window size is valid. RkISP supports AF window size\n+ *   few pixels smaller than sensor output size.\n+ * \\todo Implement support for all available AF windows. RkISP supports up to 3\n+ *   AF windows.\n  */\n \n LOG_DEFINE_CATEGORY(RkISP1Af)\n \n+namespace {\n+\n+constexpr rkisp1_cif_isp_window rectangleToIspWindow(const Rectangle &rectangle)\n+{\n+\treturn rkisp1_cif_isp_window{\n+\t\t.h_offs = static_cast<uint16_t>(rectangle.x),\n+\t\t.v_offs = static_cast<uint16_t>(rectangle.y),\n+\t\t.h_size = static_cast<uint16_t>(rectangle.width),\n+\t\t.v_size = static_cast<uint16_t>(rectangle.height)\n+\t};\n+}\n+\n+} /* namespace */\n+\n+Af::Af()\n+{\n+\taf.windowUpdateRequested.connect(this, &Af::updateCurrentWindow);\n+}\n+\n /**\n  * \\copydoc libcamera::ipa::Algorithm::init\n  */\n int Af::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)\n {\n \twaitFramesLens_ = tuningData[\"wait-frames-lens\"].get<uint32_t>(1);\n+\tispThreshold_ = tuningData[\"isp-threshold\"].get<uint32_t>(128);\n+\tispVarShift_ = tuningData[\"isp-var-shift\"].get<uint32_t>(4);\n \n-\tLOG(RkISP1Af, Debug) << \"waitFramesLens_: \" << waitFramesLens_;\n+\tLOG(RkISP1Af, Debug) << \"waitFramesLens_: \" << waitFramesLens_\n+\t\t\t     << \", ispThreshold_: \" << ispThreshold_\n+\t\t\t     << \", ispVarShift_: \" << ispVarShift_;\n \n \treturn af.init(tuningData);\n }\n@@ -85,6 +116,32 @@ void Af::queueRequest([[maybe_unused]] IPAContext &context,\n \taf.queueRequest(controls);\n }\n \n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void Af::prepare([[maybe_unused]] IPAContext &context,\n+\t\t [[maybe_unused]] const uint32_t frame,\n+\t\t [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t rkisp1_params_cfg *params)\n+{\n+\tif (updateWindow_) {\n+\t\tparams->meas.afc_config.num_afm_win = 1;\n+\t\tparams->meas.afc_config.thres = ispThreshold_;\n+\t\tparams->meas.afc_config.var_shift = ispVarShift_;\n+\t\tparams->meas.afc_config.afm_win[0] =\n+\t\t\trectangleToIspWindow(*updateWindow_);\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\tupdateWindow_.reset();\n+\n+\t\t/* Wait one frame for the ISP to apply changes. */\n+\t\taf.setFramesToSkip(1);\n+\t}\n+}\n+\n /**\n  * \\copydoc libcamera::ipa::Algorithm::process\n  */\n@@ -110,6 +167,11 @@ void Af::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t}\n }\n \n+void Af::updateCurrentWindow(const Rectangle &window)\n+{\n+\tupdateWindow_ = window;\n+}\n+\n REGISTER_IPA_ALGORITHM(Af, \"Af\")\n \n } /* namespace ipa::rkisp1::algorithms */\ndiff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h\nindex 3ba66d38..6f5adb19 100644\n--- a/src/ipa/rkisp1/algorithms/af.h\n+++ b/src/ipa/rkisp1/algorithms/af.h\n@@ -20,21 +20,32 @@ namespace ipa::rkisp1::algorithms {\n class Af : public Algorithm\n {\n public:\n+\tAf();\n+\n \tint init(IPAContext &context, const YamlObject &tuningData) override;\n \tint configure(IPAContext &context,\n \t\t      const IPACameraSensorInfo &configInfo) override;\n \tvoid queueRequest(IPAContext &context, uint32_t frame,\n \t\t\t  IPAFrameContext &frameContext,\n \t\t\t  const ControlList &controls) override;\n+\tvoid prepare(IPAContext &context, uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     rkisp1_params_cfg *params) override;\n \tvoid process(IPAContext &context, uint32_t frame,\n \t\t     IPAFrameContext &frameContext,\n \t\t     const rkisp1_stat_buffer *stats,\n \t\t     ControlList &metadata) override;\n \n private:\n+\tvoid updateCurrentWindow(const Rectangle &window);\n+\n \tipa::algorithms::AfHillClimbing af;\n \n-\t/* Wait number of frames after changing lens position */\n+\tstd::optional<Rectangle> updateWindow_;\n+\tuint32_t ispThreshold_ = 0;\n+\tuint32_t ispVarShift_ = 0;\n+\n+\t/* Wait number of frames after changing lens position. */\n \tuint32_t waitFramesLens_ = 0;\n };\n \n","prefixes":["libcamera-devel","v5","07/10"]}