Show a patch.

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

{
    "id": 20510,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20510/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20510/",
    "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": "<20240703135000.242227-4-stefan.klug@ideasonboard.com>",
    "date": "2024-07-03T13:49:51",
    "name": "[v3,3/6] ipa: rkisp1: blc: Query black levels from camera sensor helper",
    "commit_ref": "50c28e1351000b879ff38eca8b36751b4ac7c0c9",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "86e10cfa814201695578a2a4fa825755046e81d5",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20510/mbox/",
    "series": [
        {
            "id": 4436,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4436/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4436",
            "date": "2024-07-03T13:49:48",
            "name": "ipa: Add black level to camera sensor helpers",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/4436/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20510/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20510/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 014E1BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 13:50:19 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AB46963339;\n\tWed,  3 Jul 2024 15:50:18 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ED11962E25\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Jul 2024 15:50:14 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:9263:c199:9587:576])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BFFA43D6;\n\tWed,  3 Jul 2024 15:49:46 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"F90E28fe\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720014586;\n\tbh=14LbDAN6T5tIXqacl03ylzHMz+akW+S3DqGC85tHzXQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=F90E28fe1/nM8RDu++sENsY3aIBKrIyD0cMe0NRP2RqOKD5FfuF4busGnNkNGRDO0\n\tNfGYiaNq5dLF+ox0NFTdFjVcsSdiYSFwGB1SY5AVO3Cqa5HU45RP+qinCCW2pk0VK1\n\tDw2/XVX/TlEY/UEkYTxpk7La9x4tP16XAWzfr62I=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Subject": "[PATCH v3 3/6] ipa: rkisp1: blc: Query black levels from camera\n\tsensor helper",
        "Date": "Wed,  3 Jul 2024 15:49:51 +0200",
        "Message-ID": "<20240703135000.242227-4-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20240703135000.242227-1-stefan.klug@ideasonboard.com>",
        "References": "<20240703135000.242227-1-stefan.klug@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "As the camera sensor helper now has the ability to provide the black\nlevel, use it. Black levels can still be overwritten by the tuning\nfile, but the direction is to remove them from the tuning files and move\nthem into the sensor helpers.\n\nAdditionally interpret all values based on 16bits. The conversion to the\nscale required by the hardware is done in process(). It ensures all the\nvalues inside libcamera are the same scale and is in preparation for the\ni.MX8MP where black levels are based on a 20bit scale. Note that this\nbreaks existing tuning files. The tuning files distributed with\nlibcamera will be fixed in a later patch.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/blc.cpp | 54 ++++++++++++++++++++++++++-----\n 1 file changed, 46 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp\nindex d2e743541c99..b17b549c55df 100644\n--- a/src/ipa/rkisp1/algorithms/blc.cpp\n+++ b/src/ipa/rkisp1/algorithms/blc.cpp\n@@ -46,10 +46,47 @@ BlackLevelCorrection::BlackLevelCorrection()\n int BlackLevelCorrection::init([[maybe_unused]] IPAContext &context,\n \t\t\t       const YamlObject &tuningData)\n {\n-\tblackLevelRed_ = tuningData[\"R\"].get<int16_t>(256);\n-\tblackLevelGreenR_ = tuningData[\"Gr\"].get<int16_t>(256);\n-\tblackLevelGreenB_ = tuningData[\"Gb\"].get<int16_t>(256);\n-\tblackLevelBlue_ = tuningData[\"B\"].get<int16_t>(256);\n+\tstd::optional<int16_t> levelRed = tuningData[\"R\"].get<int16_t>();\n+\tstd::optional<int16_t> levelGreenR = tuningData[\"Gr\"].get<int16_t>();\n+\tstd::optional<int16_t> levelGreenB = tuningData[\"Gb\"].get<int16_t>();\n+\tstd::optional<int16_t> levelBlue = tuningData[\"B\"].get<int16_t>();\n+\tbool tuningHasLevels = levelRed && levelGreenR && levelGreenB && levelBlue;\n+\n+\tauto blackLevel = context.camHelper->blackLevel();\n+\tif (!blackLevel) {\n+\t\t/*\n+\t\t * Not all camera sensor helpers have been updated with black\n+\t\t * levels. Print a warning and fall back to the levels from the\n+\t\t * tuning data to preserve backward compatibility. This should\n+\t\t * be removed once all helpers provide the data.\n+\t\t */\n+\t\tLOG(RkISP1Blc, Warning)\n+\t\t\t<< \"No black levels provided by camera sensor helper\"\n+\t\t\t<< \", please fix\";\n+\n+\t\tblackLevelRed_ = levelRed.value_or(4096);\n+\t\tblackLevelGreenR_ = levelGreenR.value_or(4096);\n+\t\tblackLevelGreenB_ = levelGreenB.value_or(4096);\n+\t\tblackLevelBlue_ = levelBlue.value_or(4096);\n+\t} else if (tuningHasLevels) {\n+\t\t/*\n+\t\t * If black levels are provided in the tuning file, use them to\n+\t\t * avoid breaking existing camera tuning. This is deprecated and\n+\t\t * will be removed.\n+\t\t */\n+\t\tLOG(RkISP1Blc, Warning)\n+\t\t\t<< \"Deprecated: black levels overwritten by tuning file\";\n+\n+\t\tblackLevelRed_ = *levelRed;\n+\t\tblackLevelGreenR_ = *levelGreenR;\n+\t\tblackLevelGreenB_ = *levelGreenB;\n+\t\tblackLevelBlue_ = *levelBlue;\n+\t} else {\n+\t\tblackLevelRed_ = *blackLevel;\n+\t\tblackLevelGreenR_ = *blackLevel;\n+\t\tblackLevelGreenB_ = *blackLevel;\n+\t\tblackLevelBlue_ = *blackLevel;\n+\t}\n \n \ttuningParameters_ = true;\n \n@@ -77,10 +114,11 @@ void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,\n \t\treturn;\n \n \tparams->others.bls_config.enable_auto = 0;\n-\tparams->others.bls_config.fixed_val.r = blackLevelRed_;\n-\tparams->others.bls_config.fixed_val.gr = blackLevelGreenR_;\n-\tparams->others.bls_config.fixed_val.gb = blackLevelGreenB_;\n-\tparams->others.bls_config.fixed_val.b = blackLevelBlue_;\n+\t/* The rkisp1 uses 12bit based black levels. Scale down accordingly. */\n+\tparams->others.bls_config.fixed_val.r = blackLevelRed_ >> 4;\n+\tparams->others.bls_config.fixed_val.gr = blackLevelGreenR_ >> 4;\n+\tparams->others.bls_config.fixed_val.gb = blackLevelGreenB_ >> 4;\n+\tparams->others.bls_config.fixed_val.b = blackLevelBlue_ >> 4;\n \n \tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_BLS;\n \tparams->module_ens |= RKISP1_CIF_ISP_MODULE_BLS;\n",
    "prefixes": [
        "v3",
        "3/6"
    ]
}