Patch Detail
Show a patch.
GET /api/patches/19162/?format=api
{ "id": 19162, "url": "https://patchwork.libcamera.org/api/patches/19162/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19162/", "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": "<20231020084002.30665-2-naush@raspberrypi.com>", "date": "2023-10-20T08:39:57", "name": "[libcamera-devel,v1,1/6] ipa: rpi: hdr: Add the ability to alter the LSC table", "commit_ref": "5f2ef63e7a4ad1d6326619f44e469558cfed6390", "pull_url": null, "state": "accepted", "archived": false, "hash": "95272623116cda1ac3b43d7f2e2f6d71ba8e60f5", "submitter": { "id": 34, "url": "https://patchwork.libcamera.org/api/people/34/?format=api", "name": "Naushir Patuck", "email": "naush@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19162/mbox/", "series": [ { "id": 4054, "url": "https://patchwork.libcamera.org/api/series/4054/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4054", "date": "2023-10-20T08:39:56", "name": "Raspberry Pi: Preliminary PiSP support (round 2)", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4054/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19162/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19162/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 45A4FC3275\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Oct 2023 08:40:32 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7405F62988;\n\tFri, 20 Oct 2023 10:40:31 +0200 (CEST)", "from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9875661DCF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Oct 2023 10:40:28 +0200 (CEST)", "by mail-wr1-x433.google.com with SMTP id\n\tffacd0b85a97d-32d9d8284abso388544f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Oct 2023 01:40:28 -0700 (PDT)", "from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tr3-20020adff103000000b0032d9337e7d1sm1213356wro.11.2023.10.20.01.40.27\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 20 Oct 2023 01:40:27 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1697791231;\n\tbh=jPOOtFeFO691t5CANdGRuf0v9dP+awElgPtevT6dTLs=;\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=XEuOy5Og5dXhYH+P5lLiu6UBtLcxx547vuVL0/AvvPFHxd5RuwR/vV9p/jXqHeA8J\n\tewiaBazvujVAO/rRmJ/op4CLW1Jv0cPLQJ/hLhBmYfRHN0lehmzGBjPxggBCKz2UHO\n\tNKCglhgwOADt9ONJzJzq0HkZpA4kuC9WKJpQzpTwTlKQMV44rPA3sSRbugBdPACbC8\n\tFe9/RIH/QR71KNW4Ik+0c3eRyWHPvWGE9NCemwTEDFQ25XP0ZwS4mlDOxXcGTlctjG\n\tDUqDivKR+wBskr/SkrjOxdopZuYRKaqv9/TcbofYoFmP+Y1xDL7KvnwgpH/Dd4bT+P\n\tToon8RQVVG18g==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1697791228; x=1698396028;\n\tdarn=lists.libcamera.org; \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=JXyzeKU2fDyJlg0dlNuph+ANleEJ18H6lcHHs7yn1j4=;\n\tb=V+ysmBJ1DOTZZhp+2gLJN+mADKl970Ct4HKhvmv+DhkPX+xBOStf50vh/t49SivyJk\n\t1GFa1M0Y0oijaA4oDQMMUE3hCixlZMVu3XtcH+mu8rqE55rxC0mX0KDZl7VNmARwEQf2\n\tkRsy2hTJTtNaKplLQCRFco/x8WHy/LkxvVOpzqE2CYuWaAjTlL/uhHVJ9yoFp0+GgIcI\n\t6SE4dSG7M49+xFn1ZIVkHjd2WxIHTCsyTQAWUtJ64vF39TQqa4KvtRRmQ6+ebtZmXI2p\n\tL4UdDzm6QxkUSNNINGWaXthSLV4GxqmPdRDM+zpYH8Ka1HAKRfr8g15ug1+nDm3Xyy7W\n\tzwSQ==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"V+ysmBJ1\"; dkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1697791228; x=1698396028;\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=JXyzeKU2fDyJlg0dlNuph+ANleEJ18H6lcHHs7yn1j4=;\n\tb=GClJ30D0ErRzs34JRJ/ux34JgNmxCtv58G2PmyIBjM4MAyuma7mXjKkeC40SYAL6I8\n\tiYHj3Fg/A48n+/IQN0dm79tg61gcW4+ifdPq88EAYXI9JT0p7EmjiVdptnjVzUP77KlC\n\tuypif38MF4DFuchG1dCQxrNei4etrc6/HkQOSh3y+3jLb+jeI/hBCz8OgkxgEgeLDBuY\n\tKeyrJfr8rTrVM4nJQJtfkZGQLKYM9uQ/hwP/J5a6upW9lcsw4/XoZ3tWq5Fsi0O8cazm\n\tiMXUGL+T4lhxQ+BpEtnYoL58WDge5nJeP+og6AXoVG32lNZ2j2RKEkYzg1SLcgmMPHR9\n\tkXEQ==", "X-Gm-Message-State": "AOJu0YzleJL6/jK+OTfFKnTSNfyrnMorP03bfQWbzOJAKb7watx3JIIq\n\tSAVuM9urKimLX6Ud7HHe6gvvA+nv0pozgCZuWyYp5g==", "X-Google-Smtp-Source": "AGHT+IHCAVP+v9NPOR4auDwEdNZYhAFWUASh4PYV5WxciGJ7mCE7WU10CwGYv4X+Q2loYZaLCJCUQg==", "X-Received": "by 2002:a5d:5267:0:b0:31f:f65f:74ac with SMTP id\n\tl7-20020a5d5267000000b0031ff65f74acmr953790wrc.70.1697791227858; \n\tFri, 20 Oct 2023 01:40:27 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 20 Oct 2023 09:39:57 +0100", "Message-Id": "<20231020084002.30665-2-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20231020084002.30665-1-naush@raspberrypi.com>", "References": "<20231020084002.30665-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v1 1/6] ipa: rpi: hdr: Add the ability to\n\talter the LSC table", "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": "From: David Plowman <david.plowman@raspberrypi.com>\n\nWe can perform some of the local contrast adjustment using global\ngains in the LSC table. We can vary the amount of gain according to\nthe measured brightness of that image region.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/rpi/controller/rpi/hdr.cpp | 183 ++++++++++++++++++++---------\n src/ipa/rpi/controller/rpi/hdr.h | 18 +--\n 2 files changed, 136 insertions(+), 65 deletions(-)", "diff": "diff --git a/src/ipa/rpi/controller/rpi/hdr.cpp b/src/ipa/rpi/controller/rpi/hdr.cpp\nindex 295e4c5f1c0a..fb580548d068 100644\n--- a/src/ipa/rpi/controller/rpi/hdr.cpp\n+++ b/src/ipa/rpi/controller/rpi/hdr.cpp\n@@ -10,6 +10,7 @@\n #include <libcamera/base/log.h>\n \n #include \"../agc_status.h\"\n+#include \"../alsc_status.h\"\n #include \"../stitch_status.h\"\n #include \"../tonemap_status.h\"\n \n@@ -37,29 +38,26 @@ void HdrConfig::read(const libcamera::YamlObject ¶ms, const std::string &mod\n \tfor (const auto &[k, v] : params[\"channel_map\"].asDict())\n \t\tchannelMap[v.get<unsigned int>().value()] = k;\n \n+\t/* Lens shading related parameters. */\n+\tif (params.contains(\"spatial_gain\")) {\n+\t\tspatialGain.read(params[\"spatial_gain\"]);\n+\t\tdiffusion = params[\"diffusion\"].get<unsigned int>(3);\n+\t\t/* Clip to an arbitrary limit just to stop typos from killing the system! */\n+\t\tconst unsigned int MAX_DIFFUSION = 15;\n+\t\tif (diffusion > MAX_DIFFUSION) {\n+\t\t\tdiffusion = MAX_DIFFUSION;\n+\t\t\tLOG(RPiHdr, Warning) << \"Diffusion value clipped to \" << MAX_DIFFUSION;\n+\t\t}\n+\t}\n+\n \t/* Read any tonemap parameters. */\n \ttonemapEnable = params[\"tonemap_enable\"].get<int>(0);\n \tdetailConstant = params[\"detail_constant\"].get<uint16_t>(50);\n \tdetailSlope = params[\"detail_slope\"].get<double>(8.0);\n \tiirStrength = params[\"iir_strength\"].get<double>(8.0);\n \tstrength = params[\"strength\"].get<double>(1.5);\n-\n-\tif (tonemapEnable) {\n-\t\t/* We need either an explicit tonemap, or the information to build them dynamically. */\n-\t\tif (params.contains(\"tonemap\")) {\n-\t\t\tif (tonemap.read(params[\"tonemap\"]))\n-\t\t\t\tLOG(RPiHdr, Fatal) << \"Failed to read tonemap in HDR mode \" << name;\n-\t\t} else {\n-\t\t\tif (target.read(params[\"target\"]))\n-\t\t\t\tLOG(RPiHdr, Fatal) << \"Failed to read target in HDR mode \" << name;\n-\t\t\tif (maxSlope.read(params[\"max_slope\"]))\n-\t\t\t\tLOG(RPiHdr, Fatal) << \"Failed to read max_slope in HDR mode \" << name;\n-\t\t\tminSlope = params[\"min_slope\"].get<double>(1.0);\n-\t\t\tmaxGain = params[\"max_gain\"].get<double>(64.0);\n-\t\t\tstep = params[\"step\"].get<double>(0.05);\n-\t\t\tspeed = params[\"speed\"].get<double>(0.5);\n-\t\t}\n-\t}\n+\tif (tonemapEnable)\n+\t\ttonemap.read(params[\"tonemap\"]);\n \n \t/* Read any stitch parameters. */\n \tstitchEnable = params[\"stitch_enable\"].get<int>(0);\n@@ -73,6 +71,10 @@ void HdrConfig::read(const libcamera::YamlObject ¶ms, const std::string &mod\n Hdr::Hdr(Controller *controller)\n \t: HdrAlgorithm(controller)\n {\n+\tregions_ = controller->getHardwareConfig().awbRegions;\n+\tnumRegions_ = regions_.width * regions_.height;\n+\tgains_[0].resize(numRegions_, 1.0);\n+\tgains_[1].resize(numRegions_, 1.0);\n }\n \n char const *Hdr::name() const\n@@ -143,7 +145,40 @@ void Hdr::switchMode([[maybe_unused]] CameraMode const &cameraMode, Metadata *me\n \tdelayedStatus_ = status_;\n }\n \n-bool Hdr::updateTonemap(StatisticsPtr &stats, HdrConfig &config)\n+void Hdr::prepare(Metadata *imageMetadata)\n+{\n+\tAgcStatus agcStatus;\n+\tif (!imageMetadata->get<AgcStatus>(\"agc.delayed_status\", agcStatus))\n+\t\tdelayedStatus_ = agcStatus.hdr;\n+\n+\tauto it = config_.find(delayedStatus_.mode);\n+\tif (it == config_.end()) {\n+\t\t/* Shouldn't be possible. There would be nothing we could do. */\n+\t\tLOG(RPiHdr, Warning) << \"Unexpected HDR mode \" << delayedStatus_.mode;\n+\t\treturn;\n+\t}\n+\n+\tHdrConfig &config = it->second;\n+\tif (config.spatialGain.empty())\n+\t\treturn;\n+\n+\tAlscStatus alscStatus{}; /* some compilers seem to require the braces */\n+\tif (imageMetadata->get<AlscStatus>(\"alsc.status\", alscStatus)) {\n+\t\tLOG(RPiHdr, Warning) << \"No ALSC status\";\n+\t\treturn;\n+\t}\n+\n+\t/* The final gains ended up in the odd or even array, according to diffusion. */\n+\tstd::vector<double> &gains = gains_[config.diffusion & 1];\n+\tfor (unsigned int i = 0; i < numRegions_; i++) {\n+\t\talscStatus.r[i] *= gains[i];\n+\t\talscStatus.g[i] *= gains[i];\n+\t\talscStatus.b[i] *= gains[i];\n+\t}\n+\timageMetadata->set(\"alsc.status\", alscStatus);\n+}\n+\n+bool Hdr::updateTonemap([[maybe_unused]] StatisticsPtr &stats, HdrConfig &config)\n {\n \t/* When there's a change of HDR mode we start over with a new tonemap curve. */\n \tif (delayedStatus_.mode != previousMode_) {\n@@ -162,56 +197,85 @@ bool Hdr::updateTonemap(StatisticsPtr &stats, HdrConfig &config)\n \t}\n \n \t/*\n-\t * We only update the tonemap on short frames when in multi-exposure mode. But\n+\t * We wouldn't update the tonemap on short frames when in multi-exposure mode. But\n \t * we still need to output the most recent tonemap. Possibly we should make the\n \t * config indicate the channels for which we should update the tonemap?\n \t */\n \tif (delayedStatus_.mode == \"MultiExposure\" && delayedStatus_.channel != \"short\")\n \t\treturn true;\n \n-\t/* Build the tonemap dynamically using the image histogram. */\n-\tPwl tonemap;\n-\ttonemap.append(0, 0);\n-\n-\tdouble prev_input_val = 0;\n-\tdouble prev_output_val = 0;\n-\tconst double step2 = config.step / 2;\n-\tfor (double q = config.step; q < 1.0 - step2; q += config.step) {\n-\t\tdouble q_lo = std::max(0.0, q - step2);\n-\t\tdouble q_hi = std::min(1.0, q + step2);\n-\t\tdouble iqm = stats->yHist.interQuantileMean(q_lo, q_hi);\n-\t\tdouble input_val = std::min(iqm * 64, 65535.0);\n-\n-\t\tif (input_val > prev_input_val + 1) {\n-\t\t\t/* We're going to calcualte a Pwl to map input_val to this output_val. */\n-\t\t\tdouble want_output_val = config.target.eval(q) * 65535;\n-\t\t\t/* But we must ensure we aren't applying too small or too great a local gain. */\n-\t\t\tdouble want_slope = (want_output_val - prev_output_val) / (input_val - prev_input_val);\n-\t\t\tdouble slope = std::clamp(want_slope, config.minSlope,\n-\t\t\t\t\t\t config.maxSlope.eval(q));\n-\t\t\tdouble output_val = prev_output_val + slope * (input_val - prev_input_val);\n-\t\t\toutput_val = std::min(output_val, config.maxGain * input_val);\n-\t\t\toutput_val = std::clamp(output_val, 0.0, 65535.0);\n-\t\t\t/* Let the tonemap adapte slightly more gently from frame to frame. */\n-\t\t\tif (!tonemap_.empty()) {\n-\t\t\t\tdouble old_output_val = tonemap_.eval(input_val);\n-\t\t\t\toutput_val = config.speed * output_val +\n-\t\t\t\t\t (1 - config.speed) * old_output_val;\n-\t\t\t}\n-\t\t\tLOG(RPiHdr, Debug) << \"q \" << q << \" input \" << input_val\n-\t\t\t\t\t << \" output \" << want_output_val << \" slope \" << want_slope\n-\t\t\t\t\t << \" slope \" << slope << \" output \" << output_val;\n-\t\t\ttonemap.append(input_val, output_val);\n-\t\t\tprev_input_val = input_val;\n-\t\t\tprev_output_val = output_val;\n+\t/*\n+\t * If we wanted to build or adjust tonemaps dynamically, this would be the place\n+\t * to do it. But for now we seem to be getting by without.\n+\t */\n+\n+\treturn true;\n+}\n+\n+static void averageGains(std::vector<double> &src, std::vector<double> &dst, const Size &size)\n+{\n+#define IDX(y, x) ((y)*size.width + (x))\n+\tunsigned int lastCol = size.width - 1; /* index of last column */\n+\tunsigned int preLastCol = lastCol - 1; /* and the column before that */\n+\tunsigned int lastRow = size.height - 1; /* index of last row */\n+\tunsigned int preLastRow = lastRow - 1; /* and the row before that */\n+\n+\t/* Corners first. */\n+\tdst[IDX(0, 0)] = (src[IDX(0, 0)] + src[IDX(0, 1)] + src[IDX(1, 0)]) / 3;\n+\tdst[IDX(0, lastCol)] = (src[IDX(0, lastCol)] + src[IDX(0, preLastCol)] + src[IDX(1, lastCol)]) / 3;\n+\tdst[IDX(lastRow, 0)] = (src[IDX(lastRow, 0)] + src[IDX(lastRow, 1)] + src[IDX(preLastRow, 0)]) / 3;\n+\tdst[IDX(lastRow, lastCol)] = (src[IDX(lastRow, lastCol)] + src[IDX(lastRow, preLastCol)] +\n+\t\t\t\t src[IDX(preLastRow, lastCol)]) /\n+\t\t\t\t 3;\n+\n+\t/* Now the edges. */\n+\tfor (unsigned int i = 1; i < lastCol; i++) {\n+\t\tdst[IDX(0, i)] = (src[IDX(0, i - 1)] + src[IDX(0, i)] + src[IDX(0, i + 1)] + src[IDX(1, i)]) / 4;\n+\t\tdst[IDX(lastRow, i)] = (src[IDX(lastRow, i - 1)] + src[IDX(lastRow, i)] +\n+\t\t\t\t\tsrc[IDX(lastRow, i + 1)] + src[IDX(preLastRow, i)]) /\n+\t\t\t\t 4;\n+\t}\n+\n+\tfor (unsigned int i = 1; i < lastRow; i++) {\n+\t\tdst[IDX(i, 0)] = (src[IDX(i - 1, 0)] + src[IDX(i, 0)] + src[IDX(i + 1, 0)] + src[IDX(i, 1)]) / 4;\n+\t\tdst[IDX(i, 31)] = (src[IDX(i - 1, lastCol)] + src[IDX(i, lastCol)] +\n+\t\t\t\t src[IDX(i + 1, lastCol)] + src[IDX(i, preLastCol)]) /\n+\t\t\t\t 4;\n+\t}\n+\n+\t/* Finally the interior. */\n+\tfor (unsigned int j = 1; j < lastRow; j++) {\n+\t\tfor (unsigned int i = 1; i < lastCol; i++) {\n+\t\t\tdst[IDX(j, i)] = (src[IDX(j - 1, i)] + src[IDX(j, i - 1)] + src[IDX(j, i)] +\n+\t\t\t\t\t src[IDX(j, i + 1)] + src[IDX(j + 1, i)]) /\n+\t\t\t\t\t 5;\n \t\t}\n \t}\n+}\n \n-\ttonemap.append(65535, 65535);\n-\t/* tonemap.debug(); */\n-\ttonemap_ = tonemap;\n+void Hdr::updateGains(StatisticsPtr &stats, HdrConfig &config)\n+{\n+\tif (config.spatialGain.empty())\n+\t\treturn;\n \n-\treturn true;\n+\t/* When alternating exposures, only compute these gains for the short frame. */\n+\tif (delayedStatus_.mode == \"MultiExposure\" && delayedStatus_.channel != \"short\")\n+\t\treturn;\n+\n+\tfor (unsigned int i = 0; i < numRegions_; i++) {\n+\t\tauto ®ion = stats->awbRegions.get(i);\n+\t\tunsigned int counted = region.counted;\n+\t\tcounted += (counted == 0); /* avoid div by zero */\n+\t\tdouble r = region.val.rSum / counted;\n+\t\tdouble g = region.val.gSum / counted;\n+\t\tdouble b = region.val.bSum / counted;\n+\t\tdouble brightness = std::max({ r, g, b }) / 65535;\n+\t\tgains_[0][i] = config.spatialGain.eval(brightness);\n+\t}\n+\n+\t/* Ping-pong between the two gains_ buffers. */\n+\tfor (unsigned int i = 0; i < config.diffusion; i++)\n+\t\taverageGains(gains_[i & 1], gains_[(i & 1) ^ 1], regions_);\n }\n \n void Hdr::process(StatisticsPtr &stats, Metadata *imageMetadata)\n@@ -237,6 +301,9 @@ void Hdr::process(StatisticsPtr &stats, Metadata *imageMetadata)\n \n \tHdrConfig &config = it->second;\n \n+\t/* Update the spatially varying gains. They get written in prepare(). */\n+\tupdateGains(stats, config);\n+\n \tif (updateTonemap(stats, config)) {\n \t\t/* Add tonemap.status metadata. */\n \t\tTonemapStatus tonemapStatus;\ndiff --git a/src/ipa/rpi/controller/rpi/hdr.h b/src/ipa/rpi/controller/rpi/hdr.h\nindex 01ba45f1d3dc..980aa3d1850d 100644\n--- a/src/ipa/rpi/controller/rpi/hdr.h\n+++ b/src/ipa/rpi/controller/rpi/hdr.h\n@@ -10,6 +10,8 @@\n #include <string>\n #include <vector>\n \n+#include <libcamera/geometry.h>\n+\n #include \"../hdr_algorithm.h\"\n #include \"../hdr_status.h\"\n #include \"../pwl.h\"\n@@ -23,20 +25,17 @@ struct HdrConfig {\n \tstd::vector<unsigned int> cadence;\n \tstd::map<unsigned int, std::string> channelMap;\n \n+\t/* Lens shading related parameters. */\n+\tPwl spatialGain; /* Brightness to gain curve for different image regions. */\n+\tunsigned int diffusion; /* How much to diffuse the gain spatially. */\n+\n \t/* Tonemap related parameters. */\n \tbool tonemapEnable;\n \tuint16_t detailConstant;\n \tdouble detailSlope;\n \tdouble iirStrength;\n \tdouble strength;\n-\t/* We must have either an explicit tonemap curve, or the other parameters. */\n \tPwl tonemap;\n-\tPwl target; /* maps histogram quatile to desired target output value */\n-\tPwl maxSlope; /* the maximum slope allowed at each point in the mapping */\n-\tdouble minSlope; /* the minimum allowed slope */\n-\tdouble maxGain; /* limit to the max absolute gain */\n-\tdouble step; /* the histogram granularity for building the mapping */\n-\tdouble speed; /* rate at which tonemap is updated */\n \n \t/* Stitch related parameters. */\n \tbool stitchEnable;\n@@ -54,12 +53,14 @@ public:\n \tchar const *name() const override;\n \tvoid switchMode(CameraMode const &cameraMode, Metadata *metadata) override;\n \tint read(const libcamera::YamlObject ¶ms) override;\n+\tvoid prepare(Metadata *imageMetadata) override;\n \tvoid process(StatisticsPtr &stats, Metadata *imageMetadata) override;\n \tint setMode(std::string const &mode) override;\n \tstd::vector<unsigned int> getChannels() const override;\n \n private:\n \tvoid updateAgcStatus(Metadata *metadata);\n+\tvoid updateGains(StatisticsPtr &stats, HdrConfig &config);\n \tbool updateTonemap(StatisticsPtr &stats, HdrConfig &config);\n \n \tstd::map<std::string, HdrConfig> config_;\n@@ -67,6 +68,9 @@ private:\n \tHdrStatus delayedStatus_; /* track the delayed HDR mode and channel */\n \tstd::string previousMode_;\n \tPwl tonemap_;\n+\tlibcamera::Size regions_; /* stats regions */\n+\tunsigned int numRegions_; /* total number of stats regions */\n+\tstd::vector<double> gains_[2];\n };\n \n } /* namespace RPiController */\n", "prefixes": [ "libcamera-devel", "v1", "1/6" ] }