Show a patch.

GET /api/1.1/patches/18397/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 18397,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/18397/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18397/",
    "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": "<20230314144834.85193-7-dse@thaumatec.com>",
    "date": "2023-03-14T14:48:30",
    "name": "[libcamera-devel,v4,06/10] ipa: rkisp1: Add AF algorithm basing on AfHillClimbing",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "25e5abfebd3944ab9a97546760457c04ace57f49",
    "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/18397/mbox/",
    "series": [
        {
            "id": 3805,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3805/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3805",
            "date": "2023-03-14T14:48:24",
            "name": "ipa: rkisp1: Add autofocus algorithm",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3805/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18397/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18397/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 641CCC329D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Mar 2023 14:50:05 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 77B2E62716;\n\tTue, 14 Mar 2023 15:50:04 +0100 (CET)",
            "from mail-lf1-x132.google.com (mail-lf1-x132.google.com\n\t[IPv6:2a00:1450:4864:20::132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0609062709\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Mar 2023 15:49:54 +0100 (CET)",
            "by mail-lf1-x132.google.com with SMTP id d36so20348501lfv.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Mar 2023 07:49:54 -0700 (PDT)",
            "from localhost.localdomain ([91.90.166.178])\n\tby smtp.gmail.com with ESMTPSA id\n\tq25-20020a2eb4b9000000b00295a35f30e1sm470961ljm.115.2023.03.14.07.49.53\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 14 Mar 2023 07:49:53 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1678805404;\n\tbh=AnuirllEo1Cb2hAfdXm0mYzwNlQEAJgYBUji5i6UfEE=;\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=WV8S8MSSRHivk/s/IBc4lmvIHGXaUZbUChln2e+9uiNxfQkxODDttKXXZnd0MkrLT\n\tdu+oPE5X7n2lt32jh/woxUMtsf4N+9iDmde0vEYY70t+6U0vUZBG/oVW5r2UGXQKkL\n\tvIsfqqh/5dGCO7/NCyc2ox88sTcPIQgXNZkfEYvu1UEHBm/1kl8x8QX+kDAzI2hDLF\n\tQ7UhsQznsM9s1leyPqmna/HYqBDl0SJbf2JPXHKFSOS04ep84cxuoGUZfaM/vzp4Sn\n\tOKudmjQKhekTp2JSfW13JqgFxsriVWSrD9XZFskOcGs/ysZfenDG54CXDqAqfUshgf\n\tBwGeMNaPigeRw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=thaumatec-com.20210112.gappssmtp.com; s=20210112; t=1678805394;\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=P60WbR8KYzaoiKJz8hyfEKZ8GtJHFrfGVTuX5vXZzgo=;\n\tb=H2M0l2PqSgDQG37X+eCJkhdGRNE+4DbUbSwk8GuogOata95czoBv7AxCifm0IWqizV\n\tsdWt/2/sACHEHRj6Y/FHAODqPporu9UPMg1fZGK5gcDA/YEDXrViowVRN3RfqigJlo1+\n\taJtLW7DoeFrWSSnuz2QNCFtBsB/31LJeoz+aT4XoVkUWOuYQJdwrxv/0TMI6Lgpot3tP\n\tBizia1clt/h+ofJpP1R+YCHfAM7u25hocTG/vzZWLVOu5kpaPGBcxA6zXa+4aWx2xfUG\n\t+PWaibssun+cLlT0EnvUoqCB5HgewUhQ5TxI3rLafejwjd74itNqF6sRzYkcfOqeqWfn\n\tRH6w=="
        ],
        "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=\"H2M0l2Pq\"; \n\tdkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1678805394;\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=P60WbR8KYzaoiKJz8hyfEKZ8GtJHFrfGVTuX5vXZzgo=;\n\tb=o/tKRYWB6Pi819XNtbmRd5dUSdnhZ6DftZtCyXEzhWNh/g8IfH7olzRbdP0LCqBkSO\n\tSGJjHFVHHZ7pt+qDr3eywZjXUCnXqPeHKFXBH/iJ5b5ZDQz/CB5X1wwWL73sHGNLt+kx\n\tGsnLIff1rKxK0LPgKY9xKGhZtFHrOoUjpbHycVLZRp+iM1BCqwZf4T9hRucGzUa0whzH\n\tIVXW7WcRfFPgyJfQIJAuXAht5B2boW+yMGzgkaVvVMxG/Cf0LxqziARJ02KOqfhHiks3\n\tDv4IczNQt+Uzliq3vypwT5VC/f6uxCQIHOscSdmBuXkEPKlNixkdXVG52xTCT+DLdUPR\n\tgsvw==",
        "X-Gm-Message-State": "AO0yUKVoGGyRBZNiS9QVlXfxCENve7qPMDRJIhm4eFO5BbRwkU0S0KrP\n\t4I5ypPh3Itk0SHB7F/d6j8WA8R9l4m1vLk6vlw4=",
        "X-Google-Smtp-Source": "AK7set93uzwMz0v9NgBRQrjUyW+Wia5VWSd22o/ZvrtUhoh30GDQv+Mk2oeChvnBXFugA/EEJYytXQ==",
        "X-Received": "by 2002:ac2:514b:0:b0:4d8:8ad1:a05f with SMTP id\n\tq11-20020ac2514b000000b004d88ad1a05fmr913313lfd.48.1678805394128; \n\tTue, 14 Mar 2023 07:49:54 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 14 Mar 2023 15:48:30 +0100",
        "Message-Id": "<20230314144834.85193-7-dse@thaumatec.com>",
        "X-Mailer": "git-send-email 2.39.2",
        "In-Reply-To": "<20230314144834.85193-1-dse@thaumatec.com>",
        "References": "<20230314144834.85193-1-dse@thaumatec.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 06/10] ipa: rkisp1: Add AF algorithm\n\tbasing 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>",
        "Cc": "jacopo.mondi@ideasonboard.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      | 107 ++++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/af.h        |  39 ++++++++++\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, 165 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..abf5d91f\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/af.cpp\n@@ -0,0 +1,107 @@\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::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, basing on the common contrast based\n+ * hill climbing auto focus implementation\n+ * (libcamera::ipa::common::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+\n+LOG_DEFINE_CATEGORY(RkISP1Af)\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+\n+\tLOG(RkISP1Af, Debug) << \"waitFramesLens_: \" << waitFramesLens_;\n+\n+\treturn af.init(tuningData);\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::configure\n+ */\n+int Af::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n+{\n+\tconst auto &lensConfig = context.configuration.lens;\n+\n+\taf.configure(lensConfig.minFocusPosition, lensConfig.maxFocusPosition,\n+\t\t     configInfo.outputSize);\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 = lensConfig.maxFocusPosition + 1;\n+\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.setFramesToSkip(waitFramesLens_);\n+\t}\n+}\n+\n+REGISTER_IPA_ALGORITHM(Af, \"Af\")\n+\n+} /* namespace libcamera::ipa::rkisp1::algorithms */\ndiff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h\nnew file mode 100644\nindex 00000000..85de0a64\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/af.h\n@@ -0,0 +1,39 @@\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::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, const uint32_t frame,\n+\t\t\t  IPAFrameContext &frameContext,\n+\t\t\t  const ControlList &controls) override;\n+\tvoid process(IPAContext &context, const 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::common::algorithms::AfHillClimbing af;\n+\n+\t/* Wait number of frames after changing lens position */\n+\tuint32_t waitFramesLens_;\n+};\n+\n+} /* namespace libcamera::ipa::rkisp1::algorithms */\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 401c098f..5c5f80c7 100644\n--- a/src/ipa/rkisp1/ipa_context.cpp\n+++ b/src/ipa/rkisp1/ipa_context.cpp\n@@ -134,6 +134,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 bfb6e1b7..2c2eec3b 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -58,6 +58,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",
        "v4",
        "06/10"
    ]
}