Show a patch.

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

{
    "id": 22621,
    "url": "https://patchwork.libcamera.org/api/patches/22621/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22621/",
    "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": "<20250123114204.79321-7-stefan.klug@ideasonboard.com>",
    "date": "2025-01-23T11:40:56",
    "name": "[v2,06/17] ipa: rkisp1: Move calculation of RGB means into own function",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "cbe13f7417d76b3f036bdbd956bb5f2f7f01a529",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22621/mbox/",
    "series": [
        {
            "id": 4966,
            "url": "https://patchwork.libcamera.org/api/series/4966/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4966",
            "date": "2025-01-23T11:40:50",
            "name": "Add Bayesian AWB algorithm to libipa and rkisp1",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4966/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22621/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22621/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 272FDC3317\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jan 2025 11:42:32 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AFF2068567;\n\tThu, 23 Jan 2025 12:42:31 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E68FD6856B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jan 2025 12:42:28 +0100 (CET)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:c0a:33cd:b453:5d3f])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7051089A;\n\tThu, 23 Jan 2025 12:41:25 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"BgPgLt94\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1737632485;\n\tbh=lvAi5F/HQLssBVL066+WyjXqD/F8Xots7NktGu5TKuA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=BgPgLt94ivZIRlOmkvTFrUzHBLEvSoa4Sf4wZdf7ijx4bnVBk27Y3wHOSsKTR7esa\n\t/RGDzhINSvOBbvXZtQi5yrFDdIB1eTjzomOaWmnQPpbQ1hpFakxYuHYPuEvTTMjtvG\n\tYna7no28mrvAtUIo0WikNGsEt5tDemaKq1QY2Gdc=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>",
        "Subject": "[PATCH v2 06/17] ipa: rkisp1: Move calculation of RGB means into own\n\tfunction",
        "Date": "Thu, 23 Jan 2025 12:40:56 +0100",
        "Message-ID": "<20250123114204.79321-7-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20250123114204.79321-1-stefan.klug@ideasonboard.com>",
        "References": "<20250123114204.79321-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": "Move the calculation of the RGB means into an own function for better\ncode clarity. This commit doesn't contain any functional changes.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n---\n\nChanges in v2:\n- Collected tags\n---\n src/ipa/rkisp1/algorithms/awb.cpp | 90 +++++++++++++++++--------------\n src/ipa/rkisp1/algorithms/awb.h   |  3 ++\n 2 files changed, 52 insertions(+), 41 deletions(-)",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\nindex cffaa06a22c1..f6449565834b 100644\n--- a/src/ipa/rkisp1/algorithms/awb.cpp\n+++ b/src/ipa/rkisp1/algorithms/awb.cpp\n@@ -229,7 +229,7 @@ void Awb::process(IPAContext &context,\n \tconst rkisp1_cif_isp_stat *params = &stats->params;\n \tconst rkisp1_cif_isp_awb_stat *awb = &params->awb;\n \tIPAActiveState &activeState = context.activeState;\n-\tRGB<double> rgbMeans;\n+\tRGB<double> rgbMeans = calculateRgbMeans(frameContext, awb);\n \n \tmetadata.set(controls::AwbEnable, frameContext.awb.autoEnabled);\n \tmetadata.set(controls::ColourGains, {\n@@ -243,6 +243,53 @@ void Awb::process(IPAContext &context,\n \t\treturn;\n \t}\n \n+\t/*\n+\t * If the means are too small we don't have enough information to\n+\t * meaningfully calculate gains. Freeze the algorithm in that case.\n+\t */\n+\tif (rgbMeans.r() < kMeanMinThreshold && rgbMeans.g() < kMeanMinThreshold &&\n+\t    rgbMeans.b() < kMeanMinThreshold)\n+\t\treturn;\n+\n+\tactiveState.awb.temperatureK = estimateCCT(rgbMeans);\n+\n+\t/* Metadata shall contain the up to date measurement */\n+\tmetadata.set(controls::ColourTemperature, activeState.awb.temperatureK);\n+\n+\t/*\n+\t * Estimate the red and blue gains to apply in a grey world. The green\n+\t * gain is hardcoded to 1.0. Avoid divisions by zero by clamping the\n+\t * divisor to a minimum value of 1.0.\n+\t */\n+\tRGB<double> gains({ rgbMeans.g() / std::max(rgbMeans.r(), 1.0),\n+\t\t\t    1.0,\n+\t\t\t    rgbMeans.g() / std::max(rgbMeans.b(), 1.0) });\n+\n+\t/*\n+\t * Clamp the gain values to the hardware, which expresses gains as Q2.8\n+\t * unsigned integer values. Set the minimum just above zero to avoid\n+\t * divisions by zero when computing the raw means in subsequent\n+\t * iterations.\n+\t */\n+\tgains = gains.max(1.0 / 256).min(1023.0 / 256);\n+\n+\t/* Filter the values to avoid oscillations. */\n+\tdouble speed = 0.2;\n+\tgains = gains * speed + activeState.awb.gains.automatic * (1 - speed);\n+\n+\tactiveState.awb.gains.automatic = gains;\n+\n+\tLOG(RkISP1Awb, Debug)\n+\t\t<< std::showpoint\n+\t\t<< \"Means \" << rgbMeans << \", gains \"\n+\t\t<< activeState.awb.gains.automatic << \", temp \"\n+\t\t<< activeState.awb.temperatureK << \"K\";\n+}\n+\n+RGB<double> Awb::calculateRgbMeans(const IPAFrameContext &frameContext, const rkisp1_cif_isp_awb_stat *awb) const\n+{\n+\tVector<double, 3> rgbMeans;\n+\n \tif (rgbMode_) {\n \t\trgbMeans = {{\n \t\t\tstatic_cast<double>(awb->awb_mean[0].mean_y_or_g),\n@@ -301,46 +348,7 @@ void Awb::process(IPAContext &context,\n \t */\n \trgbMeans /= frameContext.awb.gains;\n \n-\t/*\n-\t * If the means are too small we don't have enough information to\n-\t * meaningfully calculate gains. Freeze the algorithm in that case.\n-\t */\n-\tif (rgbMeans.r() < kMeanMinThreshold && rgbMeans.g() < kMeanMinThreshold &&\n-\t    rgbMeans.b() < kMeanMinThreshold)\n-\t\treturn;\n-\n-\tactiveState.awb.temperatureK = estimateCCT(rgbMeans);\n-\n-\t/*\n-\t * Estimate the red and blue gains to apply in a grey world. The green\n-\t * gain is hardcoded to 1.0. Avoid divisions by zero by clamping the\n-\t * divisor to a minimum value of 1.0.\n-\t */\n-\tRGB<double> gains({\n-\t\trgbMeans.g() / std::max(rgbMeans.r(), 1.0),\n-\t\t1.0,\n-\t\trgbMeans.g() / std::max(rgbMeans.b(), 1.0)\n-\t});\n-\n-\t/*\n-\t * Clamp the gain values to the hardware, which expresses gains as Q2.8\n-\t * unsigned integer values. Set the minimum just above zero to avoid\n-\t * divisions by zero when computing the raw means in subsequent\n-\t * iterations.\n-\t */\n-\tgains = gains.max(1.0 / 256).min(1023.0 / 256);\n-\n-\t/* Filter the values to avoid oscillations. */\n-\tdouble speed = 0.2;\n-\tgains = gains * speed + activeState.awb.gains.automatic * (1 - speed);\n-\n-\tactiveState.awb.gains.automatic = gains;\n-\n-\tLOG(RkISP1Awb, Debug)\n-\t\t<< std::showpoint\n-\t\t<< \"Means \" << rgbMeans << \", gains \"\n-\t\t<< activeState.awb.gains.automatic << \", temp \"\n-\t\t<< activeState.awb.temperatureK << \"K\";\n+\treturn rgbMeans;\n }\n \n REGISTER_IPA_ALGORITHM(Awb, \"Awb\")\ndiff --git a/src/ipa/rkisp1/algorithms/awb.h b/src/ipa/rkisp1/algorithms/awb.h\nindex e424804861a6..2a64cb60d5f4 100644\n--- a/src/ipa/rkisp1/algorithms/awb.h\n+++ b/src/ipa/rkisp1/algorithms/awb.h\n@@ -38,6 +38,9 @@ public:\n \t\t     ControlList &metadata) override;\n \n private:\n+\tRGB<double> calculateRgbMeans(const IPAFrameContext &frameContext,\n+\t\t\t\t      const rkisp1_cif_isp_awb_stat *awb) const;\n+\n \tstd::optional<Interpolator<Vector<double, 2>>> colourGainCurve_;\n \tbool rgbMode_;\n };\n",
    "prefixes": [
        "v2",
        "06/17"
    ]
}