Patch Detail
Show a patch.
GET /api/patches/21975/?format=api
{ "id": 21975, "url": "https://patchwork.libcamera.org/api/patches/21975/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21975/", "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": "<20241118221618.13953-16-laurent.pinchart@ideasonboard.com>", "date": "2024-11-18T22:16:16", "name": "[v3,15/17] ipa: rkisp1: awb: Use RGB class to store colour gains", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "c372820e666e0cd947235806fe2cb126cfbcf94a", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21975/mbox/", "series": [ { "id": 4798, "url": "https://patchwork.libcamera.org/api/series/4798/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4798", "date": "2024-11-18T22:16:01", "name": "Improve linear algebra helpers in libipa", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4798/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21975/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21975/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 3D6DDC32F0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Nov 2024 22:17:04 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 95C5265EE4;\n\tMon, 18 Nov 2024 23:17:03 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A813B65ED5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 23:16:48 +0100 (CET)", "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A7F56DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 23:16:31 +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=\"wbIJQNW2\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1731968191;\n\tbh=kCGkI5awc1sOrdtp9sDY95oyT1K6jXBY+I7HgQyzjhw=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=wbIJQNW2QiE4CQqkHu7odgt7K/4LOLbTR1n2+LxO2kVBhfSfHb3vdowLN9dL9cwMj\n\tv+g9wt7WDkI6NCDVJgksE20cwTYRgZEYWpls4kidy5BGyOC+UMCV8NQxa3msafzQmb\n\tiIoRQ5oToFsEkdodDPzXkBceyiiO9qD0+twEW1CY=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[PATCH v3 15/17] ipa: rkisp1: awb: Use RGB class to store colour\n\tgains", "Date": "Tue, 19 Nov 2024 00:16:16 +0200", "Message-ID": "<20241118221618.13953-16-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.45.2", "In-Reply-To": "<20241118221618.13953-1-laurent.pinchart@ideasonboard.com>", "References": "<20241118221618.13953-1-laurent.pinchart@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": "Replace the manual storage of gains in the IPA active state and frame\ncontext with usage of the RGB class. This simplifies the code thanks to\nusage of the arithmetic functions provided by the RGB class.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/awb.cpp | 71 +++++++++++--------------------\n src/ipa/rkisp1/ipa_context.cpp | 31 +-------------\n src/ipa/rkisp1/ipa_context.h | 20 ++-------\n 3 files changed, 32 insertions(+), 90 deletions(-)", "diff": "diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\nindex dbeaf81565ff..c330feff9f5d 100644\n--- a/src/ipa/rkisp1/algorithms/awb.cpp\n+++ b/src/ipa/rkisp1/algorithms/awb.cpp\n@@ -47,12 +47,8 @@ Awb::Awb()\n int Awb::configure(IPAContext &context,\n \t\t const IPACameraSensorInfo &configInfo)\n {\n-\tcontext.activeState.awb.gains.manual.red = 1.0;\n-\tcontext.activeState.awb.gains.manual.blue = 1.0;\n-\tcontext.activeState.awb.gains.manual.green = 1.0;\n-\tcontext.activeState.awb.gains.automatic.red = 1.0;\n-\tcontext.activeState.awb.gains.automatic.blue = 1.0;\n-\tcontext.activeState.awb.gains.automatic.green = 1.0;\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 \n \t/*\n@@ -89,21 +85,17 @@ void Awb::queueRequest(IPAContext &context,\n \n \tconst auto &colourGains = controls.get(controls::ColourGains);\n \tif (colourGains && !awb.autoEnabled) {\n-\t\tawb.gains.manual.red = (*colourGains)[0];\n-\t\tawb.gains.manual.blue = (*colourGains)[1];\n+\t\tawb.gains.manual.r() = (*colourGains)[0];\n+\t\tawb.gains.manual.b() = (*colourGains)[1];\n \n \t\tLOG(RkISP1Awb, Debug)\n-\t\t\t<< \"Set colour gains to red: \" << awb.gains.manual.red\n-\t\t\t<< \", blue: \" << awb.gains.manual.blue;\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.red = awb.gains.manual.red;\n-\t\tframeContext.awb.gains.green = 1.0;\n-\t\tframeContext.awb.gains.blue = awb.gains.manual.blue;\n-\t}\n+\tif (!awb.autoEnabled)\n+\t\tframeContext.awb.gains = awb.gains.manual;\n }\n \n /**\n@@ -116,19 +108,16 @@ 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-\t\tframeContext.awb.gains.red = context.activeState.awb.gains.automatic.red;\n-\t\tframeContext.awb.gains.green = context.activeState.awb.gains.automatic.green;\n-\t\tframeContext.awb.gains.blue = context.activeState.awb.gains.automatic.blue;\n-\t}\n+\tif (frameContext.awb.autoEnabled)\n+\t\tframeContext.awb.gains = context.activeState.awb.gains.automatic;\n \n \tauto gainConfig = params->block<BlockType::AwbGain>();\n \tgainConfig.setEnabled(true);\n \n-\tgainConfig->gain_green_b = std::clamp<int>(256 * frameContext.awb.gains.green, 0, 0x3ff);\n-\tgainConfig->gain_blue = std::clamp<int>(256 * frameContext.awb.gains.blue, 0, 0x3ff);\n-\tgainConfig->gain_red = std::clamp<int>(256 * frameContext.awb.gains.red, 0, 0x3ff);\n-\tgainConfig->gain_green_r = std::clamp<int>(256 * frameContext.awb.gains.green, 0, 0x3ff);\n+\tgainConfig->gain_green_b = std::clamp<int>(256 * frameContext.awb.gains.g(), 0, 0x3ff);\n+\tgainConfig->gain_blue = std::clamp<int>(256 * frameContext.awb.gains.b(), 0, 0x3ff);\n+\tgainConfig->gain_red = std::clamp<int>(256 * frameContext.awb.gains.r(), 0, 0x3ff);\n+\tgainConfig->gain_green_r = std::clamp<int>(256 * frameContext.awb.gains.g(), 0, 0x3ff);\n \n \t/* If we have already set the AWB measurement parameters, return. */\n \tif (frame > 0)\n@@ -196,8 +185,8 @@ void Awb::process(IPAContext &context,\n \n \tmetadata.set(controls::AwbEnable, frameContext.awb.autoEnabled);\n \tmetadata.set(controls::ColourGains, {\n-\t\t\tstatic_cast<float>(frameContext.awb.gains.red),\n-\t\t\tstatic_cast<float>(frameContext.awb.gains.blue)\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 \n@@ -253,12 +242,7 @@ void Awb::process(IPAContext &context,\n \t * divide by the gains that were used to get the raw means from the\n \t * sensor.\n \t */\n-\tRGB<double> gains{{\n-\t\tframeContext.awb.gains.red,\n-\t\tframeContext.awb.gains.green,\n-\t\tframeContext.awb.gains.blue\n-\t}};\n-\trgbMeans /= gains;\n+\trgbMeans /= frameContext.awb.gains;\n \n \t/*\n \t * If the means are too small we don't have enough information to\n@@ -278,8 +262,11 @@ void Awb::process(IPAContext &context,\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-\tdouble redGain = rgbMeans.g() / std::max(rgbMeans.r(), 1.0);\n-\tdouble blueGain = rgbMeans.g() / std::max(rgbMeans.b(), 1.0);\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@@ -287,24 +274,18 @@ void Awb::process(IPAContext &context,\n \t * divisions by zero when computing the raw means in subsequent\n \t * iterations.\n \t */\n-\tredGain = std::clamp(redGain, 1.0 / 256, 1023.0 / 256);\n-\tblueGain = std::clamp(blueGain, 1.0 / 256, 1023.0 / 256);\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-\tredGain = speed * redGain + (1 - speed) * activeState.awb.gains.automatic.red;\n-\tblueGain = speed * blueGain + (1 - speed) * activeState.awb.gains.automatic.blue;\n+\tgains = gains * speed + activeState.awb.gains.automatic * (1 - speed);\n \n-\tactiveState.awb.gains.automatic.red = redGain;\n-\tactiveState.awb.gains.automatic.blue = blueGain;\n-\tactiveState.awb.gains.automatic.green = 1.0;\n+\tactiveState.awb.gains.automatic = gains;\n \n \tLOG(RkISP1Awb, Debug)\n \t\t<< std::showpoint\n-\t\t<< \"Means \" << rgbMeans\n-\t\t<< \", gains [\" << activeState.awb.gains.automatic.red << \", \"\n-\t\t<< activeState.awb.gains.automatic.green << \", \"\n-\t\t<< activeState.awb.gains.automatic.blue << \"], temp \"\n+\t\t<< \"Means \" << rgbMeans << \", gains \"\n+\t\t<< activeState.awb.gains.automatic << \", temp \"\n \t\t<< activeState.awb.temperatureK << \"K\";\n }\n \ndiff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp\nindex 14d0c02a2b32..8f545cd76d52 100644\n--- a/src/ipa/rkisp1/ipa_context.cpp\n+++ b/src/ipa/rkisp1/ipa_context.cpp\n@@ -188,30 +188,12 @@ namespace libcamera::ipa::rkisp1 {\n * \\struct IPAActiveState::awb.gains\n * \\brief White balance gains\n *\n- * \\struct IPAActiveState::awb.gains.manual\n+ * \\var IPAActiveState::awb.gains.manual\n * \\brief Manual white balance gains (set through requests)\n *\n- * \\var IPAActiveState::awb.gains.manual.red\n- * \\brief Manual white balance gain for R channel\n- *\n- * \\var IPAActiveState::awb.gains.manual.green\n- * \\brief Manual white balance gain for G channel\n- *\n- * \\var IPAActiveState::awb.gains.manual.blue\n- * \\brief Manual white balance gain for B channel\n- *\n- * \\struct IPAActiveState::awb.gains.automatic\n+ * \\var IPAActiveState::awb.gains.automatic\n * \\brief Automatic white balance gains (computed by the algorithm)\n *\n- * \\var IPAActiveState::awb.gains.automatic.red\n- * \\brief Automatic white balance gain for R channel\n- *\n- * \\var IPAActiveState::awb.gains.automatic.green\n- * \\brief Automatic white balance gain for G channel\n- *\n- * \\var IPAActiveState::awb.gains.automatic.blue\n- * \\brief Automatic white balance gain for B channel\n- *\n * \\var IPAActiveState::awb.temperatureK\n * \\brief Estimated color temperature\n *\n@@ -333,15 +315,6 @@ namespace libcamera::ipa::rkisp1 {\n * \\struct IPAFrameContext::awb.gains\n * \\brief White balance gains\n *\n- * \\var IPAFrameContext::awb.gains.red\n- * \\brief White balance gain for R channel\n- *\n- * \\var IPAFrameContext::awb.gains.green\n- * \\brief White balance gain for G channel\n- *\n- * \\var IPAFrameContext::awb.gains.blue\n- * \\brief White balance gain for B channel\n- *\n * \\var IPAFrameContext::awb.temperatureK\n * \\brief Estimated color temperature\n *\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 7b93a9e9461d..b4dec0c3288d 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -25,6 +25,7 @@\n #include <libipa/camera_sensor_helper.h>\n #include <libipa/fc_queue.h>\n #include <libipa/matrix.h>\n+#include <libipa/vector.h>\n \n namespace libcamera {\n \n@@ -87,16 +88,8 @@ struct IPAActiveState {\n \n \tstruct {\n \t\tstruct {\n-\t\t\tstruct {\n-\t\t\t\tdouble red;\n-\t\t\t\tdouble green;\n-\t\t\t\tdouble blue;\n-\t\t\t} manual;\n-\t\t\tstruct {\n-\t\t\t\tdouble red;\n-\t\t\t\tdouble green;\n-\t\t\t\tdouble blue;\n-\t\t\t} automatic;\n+\t\t\tRGB<double> manual;\n+\t\t\tRGB<double> automatic;\n \t\t} gains;\n \n \t\tunsigned int temperatureK;\n@@ -140,12 +133,7 @@ struct IPAFrameContext : public FrameContext {\n \t} agc;\n \n \tstruct {\n-\t\tstruct {\n-\t\t\tdouble red;\n-\t\t\tdouble green;\n-\t\t\tdouble blue;\n-\t\t} gains;\n-\n+\t\tRGB<double> gains;\n \t\tbool autoEnabled;\n \t} awb;\n \n", "prefixes": [ "v3", "15/17" ] }