Show a patch.

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

{
    "id": 16490,
    "url": "https://patchwork.libcamera.org/api/patches/16490/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16490/",
    "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": "<20220630143543.39599-9-dse@thaumatec.com>",
    "date": "2022-06-30T14:35:43",
    "name": "[libcamera-devel,8/8] 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=api",
        "name": "Daniel Semkowicz",
        "email": "dse@thaumatec.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16490/mbox/",
    "series": [
        {
            "id": 3239,
            "url": "https://patchwork.libcamera.org/api/series/3239/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3239",
            "date": "2022-06-30T14:35:35",
            "name": "ipa: rkisp1: Add autofocus algorithm",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3239/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16490/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16490/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 24A82BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Jun 2022 14:36:08 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D7DB96564C;\n\tThu, 30 Jun 2022 16:36:07 +0200 (CEST)",
            "from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com\n\t[IPv6:2a00:1450:4864:20::32e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 136DD6564C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Jun 2022 16:36:05 +0200 (CEST)",
            "by mail-wm1-x32e.google.com with SMTP id\n\to19-20020a05600c4fd300b003a0489f414cso1796450wmq.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Jun 2022 07:36:05 -0700 (PDT)",
            "from localhost.localdomain (ip092042140082.rev.nessus.at.\n\t[92.42.140.82]) by smtp.gmail.com with ESMTPSA id\n\tr5-20020a05600c320500b0039db500714fsm6405945wmp.6.2022.06.30.07.36.03\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 30 Jun 2022 07:36:04 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656599767;\n\tbh=n4X3SEbhaRTmUqd2WK/p86Vgax6EYiFiLNeERaiLxkQ=;\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=N3xe4j3nfbcIAy+gtRt84z9oYYcf4Qfseijrf4cDslif704V0w3X3AAq444sqMe02\n\to2z2FwOK94kb4nUd2kZxMMCtWkv5dgAXP4wRcO63jixjwoqfJorVQIh7rO2lguLm6e\n\t4+g303+v4s9QRnF5UogCSy/7ZgXJaEtZ5dl/c1jLBQVsnBFwI+MfSCa/P76oxEDD8d\n\t1C/s4Tesctjx3mSNJF9WiXuCnjui2J0I/CMEKkQHielmn09OSCVYha16V5Yd5jtSNp\n\tlqOzWaTeZVDU+TklGXIbDu6wtRSemhH9xmLpqQREr8c1bFxN0EodyLllqkHJPKVNmV\n\tJ8vVSKIoAuoTQ==",
            "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=nyiOgrJW6e4HOWfmcUP3xJpxFA0ukWTwpc62dxzTC18=;\n\tb=Gd0TpMAG2rviMugW24pCgYzVZC+2IaMnqo2hgfzvQmtVRvDDomCW9b/Gr2R/5HQ9Fv\n\tbz9LCpR7J+IVpp/l6V0mjtmLwSI1aZhJFzF6c4cdrO+zsLjBnq6Loxo9K0F7lzJ/q5e4\n\tNUZ6kBI8wu5zd9GbLNmw8GlPW9zwdJovJG9Y9+Z1uGkzOle9bQ/0gZ8nJXmTQ8eVNfuP\n\tPRSr+iJWrecOcPZgLgRBXDdQnhKUWfbP5uKFPDolGG4TGP+urduh/kVs4bHQV+SBwLGr\n\tZxDvVkKKD29/hWhLIVNgypQhM2rmEUpgfqukEo2D3ZhxXg/fBL7MtUWMEhc3FDN7SdnE\n\tk+nA=="
        ],
        "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=\"Gd0TpMAG\"; \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=nyiOgrJW6e4HOWfmcUP3xJpxFA0ukWTwpc62dxzTC18=;\n\tb=BeuOn8OFUk4Ih5zfiZhyYPBp0XBewcMZviS9YSdwfjNFDWE1nMYLmhtfFeXaFVw38L\n\tURpudvTnLIFqsNYoyIrNxD59bUrXdLtFgbDk5pcTA1IxExWCkB4i2yWRAMXOUs7EGK7K\n\tfb6aU56nl4vyI75lVMrlzMsZUzCbxrW9v4IGF9iwy1PCIqXyt1Z7whXt/CZQsoJeGz4V\n\thzkfF4+sgWW4/50M8ejie7S86PjTEzFY5fauqOpl718A3WhJrcsZsf0yxYV3B8rCv+iU\n\tizevuHc4BXHR7nA124C/hGBnvyRpLrP0HG05L15icizbPCJ6Kp8LAIhc+idGuUT9n46G\n\tzDfA==",
        "X-Gm-Message-State": "AJIora9jXF12ixdX+jIlQijoJbZPFRZfwPdVJM0PGfr2HXntfvsAK1n1\n\tDYy54gRX2Io9HwpFC85+GS0tYUiJYz6YGg==",
        "X-Google-Smtp-Source": "AGRyM1vbLeWdjZ4sSz8HQeAgDofLfyaV0jJ/lCVaagsOmxUxgNF+1JIkgo5QRFXI7x9qAjMBIO/Ztg==",
        "X-Received": "by 2002:a1c:7c18:0:b0:3a0:39b1:3403 with SMTP id\n\tx24-20020a1c7c18000000b003a039b13403mr13072413wmc.84.1656599764584; \n\tThu, 30 Jun 2022 07:36:04 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 30 Jun 2022 16:35:43 +0200",
        "Message-Id": "<20220630143543.39599-9-dse@thaumatec.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220630143543.39599-1-dse@thaumatec.com>",
        "References": "<20220630143543.39599-1-dse@thaumatec.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 8/8] ipa: rkisp1: Add \"Windows\" Metering\n\tmode 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 8da970e3..22507918 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 c470c9b2..c709ee98 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",
        "8/8"
    ]
}