Show a patch.

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

{
    "id": 18244,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/18244/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18244/",
    "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": "<20230203091734.22803-6-naush@raspberrypi.com>",
    "date": "2023-02-03T09:17:34",
    "name": "[libcamera-devel,v4,5/5] ipa: raspberrypi: Normalise region sums to 16-bits",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "48667657ca991850c9416e28b178c7a60d052172",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/18244/mbox/",
    "series": [
        {
            "id": 3738,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3738/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3738",
            "date": "2023-02-03T09:17:29",
            "name": "Raspberry Pi: Generalise statistics",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3738/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18244/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18244/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 D21AFC329D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Feb 2023 09:17:46 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8D87D625F3;\n\tFri,  3 Feb 2023 10:17:46 +0100 (CET)",
            "from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com\n\t[IPv6:2a00:1450:4864:20::32b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 07FDE625F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Feb 2023 10:17:43 +0100 (CET)",
            "by mail-wm1-x32b.google.com with SMTP id\n\tq10-20020a1cf30a000000b003db0edfdb74so5272486wmq.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 03 Feb 2023 01:17:43 -0800 (PST)",
            "from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\taz24-20020a05600c601800b003dc4baaedd3sm7468864wmb.37.2023.02.03.01.17.41\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 03 Feb 2023 01:17:42 -0800 (PST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1675415866;\n\tbh=QiXxWahddJBjH0Y2496EO0ohusMMG86k6EqWrbFoh8I=;\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=yql4dOgYcTbWGWvoI7H7vd3tyB3El9mErHGwxPcHSUMtAAcCic674KuvivnuUJRSW\n\tmIsBzaDbdpJuZ3GH2kKbXi8AZND/n6iUtK9GPqS7ja7rLJudGNpQmyJU9+RrDKMCaX\n\t1IF0CjHna0CqazCA9NB5mkbHHMJhzYRxzEw81szrsBYqf3cs6b86XQiWvAsUo78D8T\n\taRMkgD+5ghrFRwHAs1o44Vz10xp4nGuQeQjnkE9uhgJnNQ1haoErYrdyFFdf+YkVf/\n\t5wrKPuN55KnIM7s5xUzrrnktsdjrtn6IHh2RegiOAB3SJaBXKfsXr+guTAQr4LmsGd\n\tiNu3m19XsNsdA==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\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=zPHFslMm2RC6M7HPmlZDZ0wSiz5LyD2fZ96vieBis1Y=;\n\tb=I8SCHb1P9P+Yp+2WXSrGR9BqS5Gfmw7UJ6UlJfDuczA3vqjT0Hk7ixTAkcngzeCT8r\n\tXDhM90IriRnLlB2V/SAbeGET0hVDGQyiA3YxZse+O/0ZaTAdXNUXBu9Cv8HT9NAhkZhM\n\tdlemY/97GeJHDA+PFBn+JxzobKUHkm3XWy+GlNtv1nPWqSgdRRnmXpudxcYpuedOyYAu\n\tRffel6jg16zkxIK/DW4LqGMoIclTGdWKatVNJm3oLobOpYY7v0j3cRSz9WWLPnOkAK+z\n\tXNVgfMLGgBnoGbr5MClCIXte7znPKjPI20Vb5TveyBkQ8JMhla8byVXkRFyBxWbCo308\n\th3lg=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"I8SCHb1P\"; dkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\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=zPHFslMm2RC6M7HPmlZDZ0wSiz5LyD2fZ96vieBis1Y=;\n\tb=OkMZu1UKktiU/KDGQLRh2wwsGGfodZMxZtMjn8+5/a6nh3eq93hHHWk6FkrZZueHuF\n\tJ3R09pmUlcFtZ2GWVRakns9Dsa2r7/Wl5VWEQQIXSzt+lBmbPthmLR6z+4UlbaSdJsN6\n\tmUzfZle5sFuo/I9dJMNoM9aswsU26OawAcepoW1gb3B/82EHfAQN68+R2SSDai+GR2S/\n\tTnxx1o7J5xshiZXL4KuoimYTQ7+iSNgkGKgR2gpeE3g28ddq0JMBpjE/qCaERVmVjLT6\n\tVpPgXuFKpqZkBb033hxXGAEQ/UprdjIDPrCPRNG9YWQfto53x15Lti/gknriy4ycoW0c\n\ttvNQ==",
        "X-Gm-Message-State": "AO0yUKX6jaY2cBYuQWo/piOliLJmtrre/r20+4iKNseYtx8q+d8GuU2Q\n\tE7y9YlvlYREu/M7OZmTdgWwnbnO9JiofYC7B/8OiGA==",
        "X-Google-Smtp-Source": "AK7set/FJWZ9p0v1TEtr5B5AUTKYNEowlB1FKSOO3cNIN6+UZbnG19X0gSeETaznjT2xcaT7ycONdw==",
        "X-Received": "by 2002:a7b:c388:0:b0:3db:2e6e:7826 with SMTP id\n\ts8-20020a7bc388000000b003db2e6e7826mr10717211wmj.5.1675415862272; \n\tFri, 03 Feb 2023 01:17:42 -0800 (PST)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  3 Feb 2023 09:17:34 +0000",
        "Message-Id": "<20230203091734.22803-6-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20230203091734.22803-1-naush@raspberrypi.com>",
        "References": "<20230203091734.22803-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 5/5] ipa: raspberrypi: Normalise region\n\tsums to 16-bits",
        "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": "Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Naushir Patuck <naush@raspberrypi.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The VC4 ISP uses a pipeline bit-depth of 13-bits. The AGC algorithm needs to\nknow this bit-depth when computing the Y value for the image.\n\nInstead of hardcoding the VC4 bit-depth in the AGC source code, normalise all\nregion sums to 16-bits when filling the Statistics structure. AWB and ALSC are\nagnostic about pipeline depth, so do not need changing.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 11 +++++------\n src/ipa/raspberrypi/raspberrypi.cpp        | 18 ++++++++++++------\n 2 files changed, 17 insertions(+), 12 deletions(-)",
    "diff": "diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex 868c30f03d66..ea0c82b5c4c8 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -28,8 +28,6 @@ LOG_DEFINE_CATEGORY(RPiAgc)\n \n #define NAME \"rpi.agc\"\n \n-static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */\n-\n int AgcMeteringMode::read(const libcamera::YamlObject &params)\n {\n \tconst YamlObject &yamlWeights = params[\"weights\"];\n@@ -586,6 +584,7 @@ void Agc::fetchAwbStatus(Metadata *imageMetadata)\n static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,\n \t\t\t      double weights[], double gain)\n {\n+\tconstexpr unsigned int maxVal = 1 << Statistics::NormalisationFactorPow2;\n \t/*\n \t * Note how the calculation below means that equal weights give you\n \t * \"average\" metering (i.e. all pixels equally important).\n@@ -593,9 +592,9 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,\n \tdouble rSum = 0, gSum = 0, bSum = 0, pixelSum = 0;\n \tfor (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) {\n \t\tauto &region = stats->agcRegions.get(i);\n-\t\tdouble rAcc = std::min<double>(region.val.rSum * gain, ((1 << PipelineBits) - 1) * region.counted);\n-\t\tdouble gAcc = std::min<double>(region.val.gSum * gain, ((1 << PipelineBits) - 1) * region.counted);\n-\t\tdouble bAcc = std::min<double>(region.val.bSum * gain, ((1 << PipelineBits) - 1) * region.counted);\n+\t\tdouble rAcc = std::min<double>(region.val.rSum * gain, (maxVal - 1) * region.counted);\n+\t\tdouble gAcc = std::min<double>(region.val.gSum * gain, (maxVal - 1) * region.counted);\n+\t\tdouble bAcc = std::min<double>(region.val.bSum * gain, (maxVal - 1) * region.counted);\n \t\trSum += rAcc * weights[i];\n \t\tgSum += gAcc * weights[i];\n \t\tbSum += bAcc * weights[i];\n@@ -608,7 +607,7 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,\n \tdouble ySum = rSum * awb.gainR * .299 +\n \t\t      gSum * awb.gainG * .587 +\n \t\t      bSum * awb.gainB * .114;\n-\treturn ySum / pixelSum / (1 << PipelineBits);\n+\treturn ySum / pixelSum / maxVal;\n }\n \n /*\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex b8cce51522c0..614b8c6aacdb 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -1377,11 +1377,17 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co\n \t/* RGB histograms are not used, so do not populate them. */\n \tstatistics->yHist = std::move(RPiController::Histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS));\n \n+\t/*\n+\t * All region sums are based on a 13-bit pipeline bit-depth. Normalise\n+\t * this to 16-bits for the AGC/AWB/ALSC algorithms.\n+\t */\n+\tconstexpr unsigned int scale = Statistics::NormalisationFactorPow2 - 13;\n+\n \tstatistics->awbRegions.init({ DEFAULT_AWB_REGIONS_X, DEFAULT_AWB_REGIONS_Y });\n \tfor (i = 0; i < statistics->awbRegions.numRegions(); i++)\n-\t\tstatistics->awbRegions.set(i, { { stats->awb_stats[i].r_sum,\n-\t\t\t\t\t\t  stats->awb_stats[i].g_sum,\n-\t\t\t\t\t\t  stats->awb_stats[i].b_sum },\n+\t\tstatistics->awbRegions.set(i, { { stats->awb_stats[i].r_sum << scale,\n+\t\t\t\t\t\t  stats->awb_stats[i].g_sum << scale,\n+\t\t\t\t\t\t  stats->awb_stats[i].b_sum << scale },\n \t\t\t\t\t\tstats->awb_stats[i].counted,\n \t\t\t\t\t\tstats->awb_stats[i].notcounted });\n \n@@ -1391,9 +1397,9 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co\n \t */\n \tstatistics->agcRegions.init(15);\n \tfor (i = 0; i < statistics->agcRegions.numRegions(); i++)\n-\t\tstatistics->agcRegions.set(i, { { stats->agc_stats[i].r_sum,\n-\t\t\t\t\t\t  stats->agc_stats[i].g_sum,\n-\t\t\t\t\t\t  stats->agc_stats[i].b_sum },\n+\t\tstatistics->agcRegions.set(i, { { stats->agc_stats[i].r_sum << scale,\n+\t\t\t\t\t\t  stats->agc_stats[i].g_sum << scale,\n+\t\t\t\t\t\t  stats->agc_stats[i].b_sum << scale },\n \t\t\t\t\t\tstats->agc_stats[i].counted,\n \t\t\t\t\t\tstats->awb_stats[i].notcounted });\n \n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "5/5"
    ]
}