Show a patch.

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

{
    "id": 18514,
    "url": "https://patchwork.libcamera.org/api/patches/18514/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18514/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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-8-dse@thaumatec.com>",
    "date": "2023-03-31T08:19:27",
    "name": "[libcamera-devel,v6,07/10] ipa: rkisp1: af: Add \"Windows\" Metering mode",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "37f8ac3aec1f9a0d4aa6eac9f8c3ea3306e90ba0",
    "submitter": {
        "id": 126,
        "url": "https://patchwork.libcamera.org/api/people/126/?format=api",
        "name": "Daniel Semkowicz",
        "email": "dse@thaumatec.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/18514/mbox/",
    "series": [
        {
            "id": 3831,
            "url": "https://patchwork.libcamera.org/api/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/18514/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18514/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 C088FC329C\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 819906276E;\n\tFri, 31 Mar 2023 10:19:59 +0200 (CEST)",
            "from mail-lf1-x130.google.com (mail-lf1-x130.google.com\n\t[IPv6:2a00:1450:4864:20::130])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 50CF462756\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Mar 2023 10:19:51 +0200 (CEST)",
            "by mail-lf1-x130.google.com with SMTP id h11so20918204lfu.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Mar 2023 01:19:51 -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.50\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 31 Mar 2023 01:19:50 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680250799;\n\tbh=5I/UFgqh1r9xAS4KT5H61rUndV9Jb7t0H6WnthnATRc=;\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=s8s41oJ9vUBskioX5dwXudBJbPmWKKOmgUDFP90pGP0vbvHNRKM2+9WciJqZhzvKd\n\tglDCzUoMVv0N7CEK7i8XM3uiZih1as094xWomQMgtDzSHMFirdodrqcuBoVC+O8k3m\n\t6hb3XfasEAvM3DQMM9L/V4NkkDhKOMwcuYZ3nvGQ2f5qwURA8eWePhUklsPCLbRIhq\n\tlU3n6jDGAq40CpTQBD5kxfY3/etCYvzdKJNsPVtpRXjEn7zeq09adrg1fv7wTQScxA\n\tC2Gj/iyhURww0totKJCLOufYgF0LsoWSd3Gh3D8ZCcjR4VOwpE2ZhD0CJIgmW5APUs\n\tsSe3JkzL1Zscw==",
            "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=i7HiaDitI9UaV/98RgLZ0YhDRIfpVqYfYoOGSzOSw40=;\n\tb=pMGgcgmwYMfr5vOy/3rcnpQzUqu7FUfOIzLRe+/aq5m9EbXwLvExIp10wd+mkccwke\n\t8vxTLGri/MXTQGMh20dikuQ8t52eyxm+Gi2+KbXFglKddZibFE1O/vL9XecMdbPHz++L\n\t+jqddpLL9ULZNiKMZkb2YaO5iVSZ4Yqu9U3AUqHz30pzqvkV/xs/PFE3RadQTgpl0eY4\n\ta482OHTJi+4hJzzr0LLmqpW7EIWYO7Zh/KnzqapTKoPOD9jR624HUOdFUE0U6ANJrbsH\n\tmiMN6BUe9Mz5sXR+LTH2Y8NGYuUdKmprUfcQYkPxFCsVctZbIEj1P4YGMImQg7ujSihV\n\tTdRw=="
        ],
        "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=\"pMGgcgmw\"; \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=i7HiaDitI9UaV/98RgLZ0YhDRIfpVqYfYoOGSzOSw40=;\n\tb=fKoY66pFRhDGCXAmRDA04k3+j5YW3ersd4xYGgMC7PnDHxD12LAEFQ2YoJo0V7T6QQ\n\tkoGuihIdTUqL/roEcMIso8B5BOt9pZ9eyhVLV9tdGZUDnoS6YVO/6h43QwynHFB92/zP\n\tsK52j9UO88D5b7VtpXklXoISoYHOnR/B/JGtfLjKIBZLrGVauaZmmDO4wwZX0rF8jxHc\n\tsTc9podMvCRNnx1lxSq8fdDgrHavhT6NzEiclwxUt4lNaqvH1Hx0P0RHnRYyrOzCq6BC\n\t48XNwyNhEfOr9wZ00IbZHADh9pBmyt1GzjUNPFA90PYB+wvDEtJJEoaGucbDh2XAOLEb\n\tUB8w==",
        "X-Gm-Message-State": "AAQBX9eukUbwxwOxIAQUaw9zV/aJOb3/BY53uatmCse5aA9JKZSBbuDz\n\tASSqcs3TqayYZOCnnPBMJZLMtot7JH4psQokdB00Ow==",
        "X-Google-Smtp-Source": "AKy350aE9pmcBoveZkTN/KNl4GjPYLmh2+veYU6HM/qnXb1q3G6mFWiqgAEVhUcPSkfAZDORRIOPJg==",
        "X-Received": "by 2002:a19:5502:0:b0:4ea:e262:b94e with SMTP id\n\tn2-20020a195502000000b004eae262b94emr7132028lfe.21.1680250790693; \n\tFri, 31 Mar 2023 01:19:50 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 31 Mar 2023 10:19:27 +0200",
        "Message-Id": "<20230331081930.19289-8-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 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>",
        "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 fde924d4..b6f6eee4 100644\n--- a/src/ipa/rkisp1/algorithms/af.cpp\n+++ b/src/ipa/rkisp1/algorithms/af.cpp\n@@ -32,16 +32,43 @@ 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@@ -54,8 +81,12 @@ int Af::init(IPAContext &context, const YamlObject &tuningData)\n \t}\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(lensConfig->minFocusPosition,\n \t\t       lensConfig->maxFocusPosition, tuningData);\n@@ -89,6 +120,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.skipFrames(1);\n+\t}\n+}\n+\n /**\n  * \\copydoc libcamera::ipa::Algorithm::process\n  */\n@@ -114,6 +171,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",
        "v6",
        "07/10"
    ]
}