Patch Detail
Show a patch.
GET /api/patches/22411/?format=api
{ "id": 22411, "url": "https://patchwork.libcamera.org/api/patches/22411/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22411/", "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": "<20241219175729.293782-4-stefan.klug@ideasonboard.com>", "date": "2024-12-19T17:57:20", "name": "[v6,3/9] ipa: rkisp1: awb: Implement ColourTemperature control", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "5cd177b6f41b75613c36e55faaed000183e137a8", "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/22411/mbox/", "series": [ { "id": 4919, "url": "https://patchwork.libcamera.org/api/series/4919/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4919", "date": "2024-12-19T17:57:17", "name": "rkisp1: Add manual colour temperature control", "version": 6, "mbox": "https://patchwork.libcamera.org/series/4919/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22411/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22411/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 07F65C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Dec 2024 17:57:48 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 67D1E68486;\n\tThu, 19 Dec 2024 18:57:47 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 21BBE68481\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Dec 2024 18:57:42 +0100 (CET)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:783:85f9:c998:cb11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4C63EAD8;\n\tThu, 19 Dec 2024 18:57:03 +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=\"AijzNkXE\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734631023;\n\tbh=EFIMPL9bJiAOcv8nKEqT0wrUgTgwwYUg41VwflN086s=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=AijzNkXEhYSvLD4nd/hT7g9FCN3k5Y71lDan2a7NSu5iZoyhKatnFVpp1L06bZBBy\n\tVh/QxoUo26u7BFh/OYdjAS+fMmwLIBIHO2EdMMTnNS/vYKFKUrgtNbeWu0YBZ+BPmY\n\t9QjvhcZNYZKm9mzfiYmjS+mMnntmBJdWsKlDj1Pk=", "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\tKieran Bingham <kieran.bingham@ideasonboard.com>", "Subject": "[PATCH v6 3/9] ipa: rkisp1: awb: Implement ColourTemperature control", "Date": "Thu, 19 Dec 2024 18:57:20 +0100", "Message-ID": "<20241219175729.293782-4-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20241219175729.293782-1-stefan.klug@ideasonboard.com>", "References": "<20241219175729.293782-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": "There are many use-cases (tuning-validation, working in static\nenvironments) where a manual ColourTemperature control is helpful.\nImplement that by interpolating and applying the white balance gains\nfrom the tuning file according to the requested colour temperature. If\ncolour gains are provided on the same request, they take precedence.\nStore the colour temperature used for a given frame in the frame context\nand report that in metadata.\n\nNote that in the automatic case, the colour gains are still based on the\ngray world model and the CT curve from the tuning file get ignored.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\n\nChanges in v6:\n- Updated commit message\n- Moved retrieval of controls to the place where needed\n- Output the colour temperature applied to a frame in metadata\n---\n src/ipa/rkisp1/algorithms/awb.cpp | 51 +++++++++++++++++++++++--------\n src/ipa/rkisp1/ipa_context.h | 1 +\n 2 files changed, 40 insertions(+), 12 deletions(-)", "diff": "diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\nindex e23f67a96edf..cffaa06a22c1 100644\n--- a/src/ipa/rkisp1/algorithms/awb.cpp\n+++ b/src/ipa/rkisp1/algorithms/awb.cpp\n@@ -33,6 +33,10 @@ namespace ipa::rkisp1::algorithms {\n \n LOG_DEFINE_CATEGORY(RkISP1Awb)\n \n+constexpr int32_t kMinColourTemperature = 2500;\n+constexpr int32_t kMaxColourTemperature = 10000;\n+constexpr int32_t kDefaultColourTemperature = 5000;\n+\n /* Minimum mean value below which AWB can't operate. */\n constexpr double kMeanMinThreshold = 2.0;\n \n@@ -44,8 +48,13 @@ Awb::Awb()\n /**\n * \\copydoc libcamera::ipa::Algorithm::init\n */\n-int Awb::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)\n+int Awb::init(IPAContext &context, const YamlObject &tuningData)\n {\n+\tauto &cmap = context.ctrlMap;\n+\tcmap[&controls::ColourTemperature] = ControlInfo(kMinColourTemperature,\n+\t\t\t\t\t\t\t kMaxColourTemperature,\n+\t\t\t\t\t\t\t kDefaultColourTemperature);\n+\n \tInterpolator<Vector<double, 2>> gainCurve;\n \tint ret = gainCurve.readYaml(tuningData[\"colourGains\"], \"ct\", \"gains\");\n \tif (ret < 0)\n@@ -68,6 +77,7 @@ int Awb::configure(IPAContext &context,\n \tcontext.activeState.awb.gains.manual = RGB<double>{ 1.0 };\n \tcontext.activeState.awb.gains.automatic = RGB<double>{ 1.0 };\n \tcontext.activeState.awb.autoEnabled = true;\n+\tcontext.activeState.awb.temperatureK = kDefaultColourTemperature;\n \n \t/*\n \t * Define the measurement window for AWB as a centered rectangle\n@@ -101,19 +111,37 @@ void Awb::queueRequest(IPAContext &context,\n \t\t\t<< (*awbEnable ? \"Enabling\" : \"Disabling\") << \" AWB\";\n \t}\n \n+\tframeContext.awb.autoEnabled = awb.autoEnabled;\n+\n+\tif (awb.autoEnabled)\n+\t\treturn;\n+\n \tconst auto &colourGains = controls.get(controls::ColourGains);\n-\tif (colourGains && !awb.autoEnabled) {\n+\tconst auto &colourTemperature = controls.get(controls::ColourTemperature);\n+\tbool update = false;\n+\tif (colourGains) {\n \t\tawb.gains.manual.r() = (*colourGains)[0];\n \t\tawb.gains.manual.b() = (*colourGains)[1];\n+\t\t/*\n+\t\t * \\todo: Colour temperature reported in metadata is now\n+\t\t * incorrect, as we can't deduce the temperature from the gains.\n+\t\t * This will be fixed with the bayes AWB algorithm.\n+\t\t */\n+\t\tupdate = true;\n+\t} else if (colourTemperature && colourGainCurve_) {\n+\t\tconst auto &gains = colourGainCurve_->getInterpolated(*colourTemperature);\n+\t\tawb.gains.manual.r() = gains[0];\n+\t\tawb.gains.manual.b() = gains[1];\n+\t\tawb.temperatureK = *colourTemperature;\n+\t\tupdate = true;\n+\t}\n \n+\tif (update)\n \t\tLOG(RkISP1Awb, Debug)\n \t\t\t<< \"Set colour gains to \" << awb.gains.manual;\n-\t}\n \n-\tframeContext.awb.autoEnabled = awb.autoEnabled;\n-\n-\tif (!awb.autoEnabled)\n-\t\tframeContext.awb.gains = awb.gains.manual;\n+\tframeContext.awb.gains = awb.gains.manual;\n+\tframeContext.awb.temperatureK = awb.temperatureK;\n }\n \n /**\n@@ -126,8 +154,10 @@ void Awb::prepare(IPAContext &context, const uint32_t frame,\n \t * This is the latest time we can read the active state. This is the\n \t * most up-to-date automatic values we can read.\n \t */\n-\tif (frameContext.awb.autoEnabled)\n+\tif (frameContext.awb.autoEnabled) {\n \t\tframeContext.awb.gains = context.activeState.awb.gains.automatic;\n+\t\tframeContext.awb.temperatureK = context.activeState.awb.temperatureK;\n+\t}\n \n \tauto gainConfig = params->block<BlockType::AwbGain>();\n \tgainConfig.setEnabled(true);\n@@ -206,7 +236,7 @@ void Awb::process(IPAContext &context,\n \t\t\tstatic_cast<float>(frameContext.awb.gains.r()),\n \t\t\tstatic_cast<float>(frameContext.awb.gains.b())\n \t\t});\n-\tmetadata.set(controls::ColourTemperature, activeState.awb.temperatureK);\n+\tmetadata.set(controls::ColourTemperature, frameContext.awb.temperatureK);\n \n \tif (!stats || !(stats->meas_type & RKISP1_CIF_ISP_STAT_AWB)) {\n \t\tLOG(RkISP1Awb, Error) << \"AWB data is missing in statistics\";\n@@ -281,9 +311,6 @@ void Awb::process(IPAContext &context,\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\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex deb8c196f1b8..4b50015beee8 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -135,6 +135,7 @@ struct IPAFrameContext : public FrameContext {\n \tstruct {\n \t\tRGB<double> gains;\n \t\tbool autoEnabled;\n+\t\tunsigned int temperatureK;\n \t} awb;\n \n \tstruct {\n", "prefixes": [ "v6", "3/9" ] }