Patch Detail
Show a patch.
GET /api/1.1/patches/18513/?format=api
{ "id": 18513, "url": "https://patchwork.libcamera.org/api/1.1/patches/18513/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18513/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230331081930.19289-7-dse@thaumatec.com>", "date": "2023-03-31T08:19:26", "name": "[libcamera-devel,v6,06/10] ipa: rkisp1: Add AF algorithm based on AfHillClimbing", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "bb876a2356693ac3f12502d01ef10239b6d8dea3", "submitter": { "id": 126, "url": "https://patchwork.libcamera.org/api/1.1/people/126/?format=api", "name": "Daniel Semkowicz", "email": "dse@thaumatec.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18513/mbox/", "series": [ { "id": 3831, "url": "https://patchwork.libcamera.org/api/1.1/series/3831/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3831", "date": "2023-03-31T08:19:21", "name": "ipa: rkisp1: Add autofocus algorithm", "version": 6, "mbox": "https://patchwork.libcamera.org/series/3831/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18513/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18513/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 2C096C32A0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Mar 2023 08:19:59 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B942462750;\n\tFri, 31 Mar 2023 10:19:58 +0200 (CEST)", "from mail-lf1-x129.google.com (mail-lf1-x129.google.com\n\t[IPv6:2a00:1450:4864:20::129])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DC9BA62756\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Mar 2023 10:19:50 +0200 (CEST)", "by mail-lf1-x129.google.com with SMTP id g17so27898114lfv.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Mar 2023 01:19:50 -0700 (PDT)", "from localhost.localdomain ([91.90.166.178])\n\tby smtp.gmail.com with ESMTPSA id\n\tt1-20020ac24c01000000b004e84a8c3d86sm281459lfq.42.2023.03.31.01.19.49\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 31 Mar 2023 01:19:49 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680250798;\n\tbh=cvm0p2xzbPrL3WWPGL+Zj+DNBa64YRXSKp2GZkL4TUQ=;\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=zGmoralrNUqXJFr7hZ4h0Xasbc2cGUH5Xj/30qu5AZtldwcOU1JtN+nPyOfPfrJF7\n\thNqh/lCL0rlweKXtRe3ockl4F7ca1wX4zsNdg+TvdOl6Tven7sv901A46VasjEYoAe\n\tK1EQwITosVKPzuWSRxj7NHbRyUzCkTNXMUbI+S59jWRM1CHRGIAcV08Jf9bC2rJXOH\n\t2WLhQ1zljdMr1o3gbWQVlCGd2jRumW34VKUNiqExX+zRO8B6LHFk1RTVIqebsMjLxn\n\tlAAO84mmHiAX6aF9kgzPOTMZ9ZcuYhdxkHz62mnPNH8i/2f931WhJYfNTdwWYmzx3a\n\th7/sNEGIU1aAw==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1680250790;\n\tx=1682842790; \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=KuEVT9yr3uileFamXcqJ52XI9cacPgm5UgjSltD6O0I=;\n\tb=vmRApNIrNh7EjBdIfPm3URfxDuWXBNkpn/4xjM34Maa7FNeJVU9//mzTX8IvaEbssc\n\ttaSchExq/1Z6DR9QjnV8Aw/klwdAeuJCugdqjx5tFYVB5sCStU5ZOvLIG8+HcKLe4RuT\n\t/U29xYtACWRYPPq+Rj2rCWorTfhIwNNHS5reseEcQfuuGlscfVLDVixIqnW9c7qrTx6v\n\tNLD+O2Ssnrhkt/eHBNFRxBPq07nf99vTC5htu9lkEDUbC1oppsoOq0+ERueDgdJx9fxq\n\thOWpP10ffKkBsq/AFaqUBgR+BCuS4VrKqwsrJEYTVITS/6Skw1K56mIDSgi78RVi9RZ/\n\tHFGg==" ], "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=\"vmRApNIr\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1680250790; x=1682842790;\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=KuEVT9yr3uileFamXcqJ52XI9cacPgm5UgjSltD6O0I=;\n\tb=7Qe6cHOP66fp0B2NbsLemf0vl9fmz0liZyKjwrWoBrouNnOarizBqYvXQ6vxVk70Vh\n\t1CJ7OIRWvZhb2eIktUQD+9yp5s6z/y9st+wctP8wxvCkyf2zPj/3m3Q/dlACffALl682\n\t/DRw8NfTzAPxFisD9/5iQj+/uRchQl2nOPFEFN1G+3DmorGZiDQGoVRSxZqAKrdWPK0H\n\tuZLmuSYZ/udBxpadbRwsCciB3h1iURA++uubkj8j3SBFslMFSnjTmTPvDLikXpETtWKJ\n\tFO2Sq7UA8leIGHokhErYwk2v7+COdTitnqauJTgA7NWSfCCuntbcLYdC/UXXQ7k+XAdH\n\tckFA==", "X-Gm-Message-State": "AAQBX9c5gg47tzzkf/ZUwwMPxyo6perGJy6d2sF1d2aFDVE0/HnLhWda\n\temhGxGGKem37ln0Zc9R/rkhsgvwLEpWtYcyipa5nNQ==", "X-Google-Smtp-Source": "AKy350Zl/hVLFcg7uKKOC7EiEHmz2EfBLTeaJVNhAge0Jqgf54mhaU0urN1dtW/4XNvOR0P4POrLIw==", "X-Received": "by 2002:a19:ad47:0:b0:4ea:c730:aac3 with SMTP id\n\ts7-20020a19ad47000000b004eac730aac3mr2335520lfd.3.1680250790194; \n\tFri, 31 Mar 2023 01:19:50 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 31 Mar 2023 10:19:26 +0200", "Message-Id": "<20230331081930.19289-7-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", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v6 06/10] ipa: rkisp1: Add AF algorithm\n\tbased on AfHillClimbing", "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": "Add contrast based auto focus implementation for rkisp1 platform using\nthe common AfHillClimbing algorithm.\n\nRockchip ISP AF block allows calculation of sharpness and luminance\nin up to three user defined windows. If no windows are set, there are\nsome default settings applied for the first window and exposed through\nthe driver. For each frame, use the sharpness value calculated for this\ndefault window and feed the hill climbing algorithm with them. Then set\nthe lens position to value calculated by the algorithm.\n\nSigned-off-by: Daniel Semkowicz <dse@thaumatec.com>\n---\n src/ipa/rkisp1/algorithms/af.cpp | 121 ++++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/af.h | 43 +++++++++\n src/ipa/rkisp1/algorithms/meson.build | 1 +\n src/ipa/rkisp1/ipa_context.cpp | 13 +++\n src/ipa/rkisp1/ipa_context.h | 5 ++\n 5 files changed, 183 insertions(+)\n create mode 100644 src/ipa/rkisp1/algorithms/af.cpp\n create mode 100644 src/ipa/rkisp1/algorithms/af.h", "diff": "diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp\nnew file mode 100644\nindex 00000000..fde924d4\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/af.cpp\n@@ -0,0 +1,121 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2023, Theobroma Systems\n+ *\n+ * af.cpp - RkISP1 AF hill climbing based control algorithm\n+ */\n+\n+#include \"af.h\"\n+\n+/**\n+ * \\file af.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+/**\n+ * \\class Af\n+ * \\brief AF contrast based hill climbing control algorithm for RkISP platforms\n+ *\n+ * Auto focus algorithm for RkISP platforms, based on the common hill climbing\n+ * auto focus implementation (libcamera::ipa::algorithms::AfHillClimbing).\n+ *\n+ * This is the platform layer of the algorithm.\n+ *\n+ * Tuning file parameters:\n+ * - **wait-frames-lens:** Number of frames that should be skipped when lens\n+ * position is changed. Lens movement takes some time and statistics measured\n+ * during the lens movement are unstable. Currently there is no way to know\n+ * when lens movement finished and this is a workaround for this. Wait a fixed\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+ * .\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+ */\n+\n+LOG_DEFINE_CATEGORY(RkISP1Af)\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::init\n+ */\n+int Af::init(IPAContext &context, const YamlObject &tuningData)\n+{\n+\tconst auto &lensConfig = context.configuration.lens;\n+\tif (!lensConfig) {\n+\t\tLOG(RkISP1Af, Error) << \"Lens not found\";\n+\t\treturn 1;\n+\t}\n+\n+\twaitFramesLens_ = tuningData[\"wait-frames-lens\"].get<uint32_t>(1);\n+\n+\tLOG(RkISP1Af, Debug) << \"waitFramesLens_: \" << waitFramesLens_;\n+\n+\treturn af.init(lensConfig->minFocusPosition,\n+\t\t lensConfig->maxFocusPosition, tuningData);\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::configure\n+ */\n+int Af::configure(IPAContext &context,\n+\t\t const IPACameraSensorInfo &configInfo)\n+{\n+\t/*\n+\t * Lens position is unknown at the startup, so initialize\n+\t * the current position to something out of range.\n+\t */\n+\tcontext.activeState.af.lensPosition =\n+\t\tcontext.configuration.lens->maxFocusPosition + 1;\n+\n+\taf.configure(configInfo.outputSize);\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::queueRequest\n+ */\n+void Af::queueRequest([[maybe_unused]] IPAContext &context,\n+\t\t [[maybe_unused]] const uint32_t frame,\n+\t\t [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t const ControlList &controls)\n+{\n+\taf.queueRequest(controls);\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::process\n+ */\n+void Af::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n+\t\t [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t const rkisp1_stat_buffer *stats,\n+\t\t [[maybe_unused]] ControlList &metadata)\n+{\n+\tuint32_t sharpness = stats->params.af.window[0].sum;\n+\tuint32_t luminance = stats->params.af.window[0].lum;\n+\n+\tLOG(RkISP1Af, Debug)\n+\t\t<< \"lensPosition: \" << context.activeState.af.lensPosition\n+\t\t<< \", Sharpness: \" << sharpness\n+\t\t<< \", Luminance: \" << luminance;\n+\n+\tint32_t newLensPosition = af.process(sharpness);\n+\n+\tif (newLensPosition != context.activeState.af.lensPosition) {\n+\t\tcontext.activeState.af.lensPosition = newLensPosition;\n+\t\tcontext.activeState.af.applyLensCtrls = true;\n+\t\taf.skipFrames(waitFramesLens_);\n+\t}\n+}\n+\n+REGISTER_IPA_ALGORITHM(Af, \"Af\")\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h\nnew file mode 100644\nindex 00000000..3ba66d38\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/af.h\n@@ -0,0 +1,43 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2023, Theobroma Systems\n+ *\n+ * af.h - RkISP1 AF hill climbing based control algorithm\n+ */\n+\n+#pragma once\n+\n+#include <linux/rkisp1-config.h>\n+\n+#include \"libipa/algorithms/af_hill_climbing.h\"\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+class Af : public Algorithm\n+{\n+public:\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 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+\tipa::algorithms::AfHillClimbing af;\n+\n+\t/* Wait number of frames after changing lens position */\n+\tuint32_t waitFramesLens_ = 0;\n+};\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\nindex 93a48329..ab7e44f3 100644\n--- a/src/ipa/rkisp1/algorithms/meson.build\n+++ b/src/ipa/rkisp1/algorithms/meson.build\n@@ -1,6 +1,7 @@\n # SPDX-License-Identifier: CC0-1.0\n \n rkisp1_ipa_algorithms = files([\n+ 'af.cpp',\n 'agc.cpp',\n 'awb.cpp',\n 'blc.cpp',\ndiff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp\nindex aea99299..d80a7b1b 100644\n--- a/src/ipa/rkisp1/ipa_context.cpp\n+++ b/src/ipa/rkisp1/ipa_context.cpp\n@@ -139,6 +139,19 @@ namespace libcamera::ipa::rkisp1 {\n * member may be read by any algorithm, but shall only be written by its owner.\n */\n \n+/**\n+ * \\var IPAActiveState::af\n+ * \\brief State for the Automatic Focus Control algorithm\n+ *\n+ * \\var IPAActiveState::af.lensPosition\n+ * \\brief Lens position calculated by the AF algorithm\n+ *\n+ * \\var IPAActiveState::af.applyLensCtrls\n+ * \\brief Whether the lens position should be applied\n+ *\n+ * If true, IPA should send new controls to the PH to set new lens position.\n+ */\n+\n /**\n * \\var IPAActiveState::agc\n * \\brief State for the Automatic Gain Control algorithm\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 65b3fbfe..3dcc5aa0 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -62,6 +62,11 @@ struct IPASessionConfiguration {\n };\n \n struct IPAActiveState {\n+\tstruct {\n+\t\tint32_t lensPosition;\n+\t\tbool applyLensCtrls;\n+\t} af;\n+\n \tstruct {\n \t\tstruct {\n \t\t\tuint32_t exposure;\n", "prefixes": [ "libcamera-devel", "v6", "06/10" ] }