Patch Detail
Show a patch.
GET /api/patches/18994/?format=api
{ "id": 18994, "url": "https://patchwork.libcamera.org/api/patches/18994/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18994/", "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": "<20230912102442.169001-6-david.plowman@raspberrypi.com>", "date": "2023-09-12T10:24:42", "name": "[libcamera-devel,v3,5/5] ipa: rpi: agc: Use channel constraints in the AGC algorithm", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "3be57649e2c47c0ed17b7f991de9c98a2b811d74", "submitter": { "id": 42, "url": "https://patchwork.libcamera.org/api/people/42/?format=api", "name": "David Plowman", "email": "david.plowman@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18994/mbox/", "series": [ { "id": 4017, "url": "https://patchwork.libcamera.org/api/series/4017/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4017", "date": "2023-09-12T10:24:37", "name": "Multi-channel AGC", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4017/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18994/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18994/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 6710BBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 12 Sep 2023 10:24:56 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E4D6A62901;\n\tTue, 12 Sep 2023 12:24:55 +0200 (CEST)", "from mail-wr1-x429.google.com (mail-wr1-x429.google.com\n\t[IPv6:2a00:1450:4864:20::429])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BAEDB61DF5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Sep 2023 12:24:53 +0200 (CEST)", "by mail-wr1-x429.google.com with SMTP id\n\tffacd0b85a97d-31fa15f4cc6so2175432f8f.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Sep 2023 03:24:53 -0700 (PDT)", "from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:2bce:64d6:1a5c:49a2])\n\tby smtp.gmail.com with ESMTPSA id\n\tn10-20020a05600c294a00b003fefaf299b6sm12426575wmd.38.2023.09.12.03.24.52\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 12 Sep 2023 03:24:52 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694514296;\n\tbh=XkYIiUSzyhpO+6HqPOq9G2Wc690VG40XrQpEFJ+YpQs=;\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=QvmmkZ6d4vkB8uB9U0qYz7lSNo7umEsxSabsEO+UvJcA77eKrwhgZ34wv9B/IGjzh\n\thd1rVxe2nW6dXS5AUryQ9hj/TOwA8qOvf9EUplivx7Fl8BCcvw3UUcct4PCs3k0xGJ\n\t7Sn8PMxMaTlP4laAghHTBTBjTAwVWsdWrWfvkNUm5G6Kb8E4GN0EpJccxtwyoU9zX6\n\tBnLd90HVWonswUEKrhWylKujGkTOoPp6C3p+Uzs6peDlOIe9g/KZmodiEQzgt5Z+r3\n\tzHIEXk+JyZKvhlPcRq4jNgrhhPnEtntTmrc9FMxgfbhJZRcDywYMHgDfjX8lItvGAk\n\tihJweEO0TsqlQ==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1694514293; x=1695119093;\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=YhoKS/x6aJ1mjwQbp3feKmirRh6yCZCGSuVlhHNlyZU=;\n\tb=t73xC+6Jjv+D3pCkjWmHCSb48Krz9q8zsiqpd58rG+qNHnwoie+pdtGg0qxjZGxBjP\n\tuFWv6xgpXQim8guBWtZAo8UtOyM3loXMbD80dlLY5tSp+eXJO/vGzP90smI3o9mdrCRS\n\t3nBTbm0kbmN+PBUI7YgjgLV4WHMfCIxefEdWupkFG1ALViKOp5Zm+UNw9yzoGOGe5bEz\n\t+Kcm/M5XO3Zso1wJWAnro//RY3er8+nZcJS1lSwDR5IXvvulj40TIL+lYjbwMgmyXSrO\n\txywYP5RV65cYmA69hO+SS9p+UjR+NzrvKyCa6ht71nKuYWr0/y7/cT2HUSJQAxguaYkW\n\t9yPQ==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"t73xC+6J\"; dkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1694514293; x=1695119093;\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=YhoKS/x6aJ1mjwQbp3feKmirRh6yCZCGSuVlhHNlyZU=;\n\tb=qQWoH6dRVawpezL6ZiDKUrIST+lemb0EFnSsXpcGe3j0uy9VmR7+vBzCjATaI3KYCK\n\tmV11fv6azkN31n29+jGtFxkBdVePI9KQEYSjL0lB8hhlK+Ud32OcTnu+Qui82ftCeVc3\n\tvXezmiLzH0VNjY7XPVwEyOSKljhJweC/ydAeTyHr/NS43LPcjb0uK3XozdBbqxn7iEOd\n\tZOxDhUp8J14oZ+/aVgFAEC9SbW1j3dwjr3Cuwc7CXHOv9zWcYxS3/8Q7kHlPvw8HwIvm\n\t53srIuEMwU5vx3idLViOpy9n1hvrZ6eqXCVPl7DUmR8rDEhb5Aw5jYDGcqsBA8+niTgh\n\t5eXg==", "X-Gm-Message-State": "AOJu0YyWhRNuWm35b/51eqQjjWdjAD/BSLHvuuUZMqXVHOL68dJ3IDG8\n\tZtQho5tCYZEprtBdv3ojf4qUUBEKGGNR9qmlMzE=", "X-Google-Smtp-Source": "AGHT+IHG8mDVAYUgA4QygdatRBb5eV6YWKr4LpBUOjnKa+bV+DEbWSDPHj4RB2EaxTqkHsCLDT8ZcA==", "X-Received": "by 2002:a5d:5103:0:b0:319:731f:748c with SMTP id\n\ts3-20020a5d5103000000b00319731f748cmr10049578wrt.34.1694514292927; \n\tTue, 12 Sep 2023 03:24:52 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 12 Sep 2023 11:24:42 +0100", "Message-Id": "<20230912102442.169001-6-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.30.2", "In-Reply-To": "<20230912102442.169001-1-david.plowman@raspberrypi.com>", "References": "<20230912102442.169001-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 5/5] ipa: rpi: agc: Use channel\n\tconstraints in the AGC algorithm", "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": "David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "David Plowman <david.plowman@raspberrypi.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Whenever we run Agc::process(), we store the most recent total\nexposure requested for each channel.\n\nWith these values we can apply the channel constraints after\ntime-filtering the requested total exposure, but before working out\nhow much digital gain is needed.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/rpi/controller/rpi/agc.cpp | 22 ++++++--\n src/ipa/rpi/controller/rpi/agc.h | 1 +\n src/ipa/rpi/controller/rpi/agc_channel.cpp | 58 +++++++++++++++++++---\n src/ipa/rpi/controller/rpi/agc_channel.h | 8 ++-\n 4 files changed, 75 insertions(+), 14 deletions(-)", "diff": "diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp\nindex 58ba8839..170432c9 100644\n--- a/src/ipa/rpi/controller/rpi/agc.cpp\n+++ b/src/ipa/rpi/controller/rpi/agc.cpp\n@@ -40,6 +40,7 @@ int Agc::read(const libcamera::YamlObject ¶ms)\n \t */\n \tif (!params.contains(\"channels\")) {\n \t\tLOG(RPiAgc, Debug) << \"Single channel only\";\n+\t\tchannelTotalExposures_.resize(1, 0s);\n \t\tchannelData_.emplace_back();\n \t\treturn channelData_.back().channel.read(params, getHardwareConfig());\n \t}\n@@ -59,6 +60,8 @@ int Agc::read(const libcamera::YamlObject ¶ms)\n \t\treturn -1;\n \t}\n \n+\tchannelTotalExposures_.resize(channelData_.size(), 0s);\n+\n \treturn 0;\n }\n \n@@ -236,15 +239,21 @@ static void getChannelIndex(Metadata *metadata, const char *message, unsigned in\n \t\tLOG(RPiAgc, Debug) << message;\n }\n \n-static void setChannelIndex(Metadata *metadata, const char *message, unsigned int channelIndex)\n+static libcamera::utils::Duration\n+setChannelIndexGetExposure(Metadata *metadata, const char *message, unsigned int channelIndex)\n {\n \tstd::unique_lock<RPiController::Metadata> lock(*metadata);\n \tAgcStatus *status = metadata->getLocked<AgcStatus>(\"agc.status\");\n-\tif (status)\n+\tlibcamera::utils::Duration dur = 0s;\n+\n+\tif (status) {\n \t\tstatus->channel = channelIndex;\n-\telse\n+\t\tdur = status->totalExposureValue;\n+\t} else\n \t\t/* This does happen at startup, otherwise it would be a Warning or Error. */\n \t\tLOG(RPiAgc, Debug) << message;\n+\n+\treturn dur;\n }\n \n void Agc::prepare(Metadata *imageMetadata)\n@@ -308,8 +317,11 @@ void Agc::process(StatisticsPtr &stats, Metadata *imageMetadata)\n \t\t/* Can also happen when new channels start. */\n \t\tLOG(RPiAgc, Debug) << \"process: channel \" << channelIndex << \" not seen yet\";\n \n-\tchannelData.channel.process(stats, &deviceStatus, imageMetadata);\n-\tsetChannelIndex(imageMetadata, \"process: no AGC status found\", channelIndex);\n+\tchannelData.channel.process(stats, &deviceStatus, imageMetadata, channelTotalExposures_);\n+\tauto dur = setChannelIndexGetExposure(imageMetadata, \"process: no AGC status found\",\n+\t\t\t\t\t channelIndex);\n+\tif (dur)\n+\t\tchannelTotalExposures_[channelIndex] = dur;\n \n \t/* And onto the next channel for the next call. */\n \tindex_ = (index_ + 1) % activeChannels_.size();\ndiff --git a/src/ipa/rpi/controller/rpi/agc.h b/src/ipa/rpi/controller/rpi/agc.h\nindex ee85c693..90890439 100644\n--- a/src/ipa/rpi/controller/rpi/agc.h\n+++ b/src/ipa/rpi/controller/rpi/agc.h\n@@ -55,6 +55,7 @@ private:\n \tstd::vector<AgcChannelData> channelData_;\n \tstd::vector<unsigned int> activeChannels_;\n \tunsigned int index_; /* index into the activeChannels_ */\n+\tAgcChannelTotalExposures channelTotalExposures_;\n };\n \n } /* namespace RPiController */\ndiff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp\nindex 7fce35b0..4669e8da 100644\n--- a/src/ipa/rpi/controller/rpi/agc_channel.cpp\n+++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp\n@@ -493,7 +493,9 @@ void AgcChannel::prepare(Metadata *imageMetadata)\n \t}\n }\n \n-void AgcChannel::process(StatisticsPtr &stats, const DeviceStatus *deviceStatus, Metadata *imageMetadata)\n+void AgcChannel::process(StatisticsPtr &stats, const DeviceStatus *deviceStatus,\n+\t\t\t Metadata *imageMetadata,\n+\t\t\t const AgcChannelTotalExposures &channelTotalExposures)\n {\n \tframeCount_++;\n \t/*\n@@ -512,12 +514,17 @@ void AgcChannel::process(StatisticsPtr &stats, const DeviceStatus *deviceStatus,\n \tcomputeTargetExposure(gain);\n \t/* The results have to be filtered so as not to change too rapidly. */\n \tfilterExposure();\n+\t/*\n+\t * We may be asked to limit the exposure using other channels. If another channel\n+\t * determines our upper bound we may want to know this later.\n+\t */\n+\tbool channelBound = applyChannelConstraints(channelTotalExposures);\n \t/*\n \t * Some of the exposure has to be applied as digital gain, so work out\n-\t * what that is. This function also tells us whether it's decided to\n-\t * \"desaturate\" the image more quickly.\n+\t * what that is. It also tells us whether it's trying to desaturate the image\n+\t * more quickly, which can only happen when another channel is not limiting us.\n \t */\n-\tbool desaturate = applyDigitalGain(gain, targetY);\n+\tbool desaturate = applyDigitalGain(gain, targetY, channelBound);\n \t/*\n \t * The last thing is to divide up the exposure value into a shutter time\n \t * and analogue gain, according to the current exposure mode.\n@@ -796,7 +803,44 @@ void AgcChannel::computeTargetExposure(double gain)\n \tLOG(RPiAgc, Debug) << \"Target totalExposure \" << target_.totalExposure;\n }\n \n-bool AgcChannel::applyDigitalGain(double gain, double targetY)\n+bool AgcChannel::applyChannelConstraints(const AgcChannelTotalExposures &channelTotalExposures)\n+{\n+\tbool channelBound = false;\n+\tLOG(RPiAgc, Debug)\n+\t\t<< \"Total exposure before channel constraints \" << filtered_.totalExposure;\n+\n+\tfor (const auto &constraint : config_.channelConstraints) {\n+\t\tLOG(RPiAgc, Debug)\n+\t\t\t<< \"Check constraint: channel \" << constraint.channel << \" bound \"\n+\t\t\t<< (constraint.bound == AgcChannelConstraint::Bound::UPPER ? \"UPPER\" : \"LOWER\")\n+\t\t\t<< \" factor \" << constraint.factor;\n+\t\tif (constraint.channel >= channelTotalExposures.size() ||\n+\t\t !channelTotalExposures[constraint.channel]) {\n+\t\t\tLOG(RPiAgc, Debug) << \"no such channel or no exposure available- skipped\";\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tlibcamera::utils::Duration limitExposure =\n+\t\t\tchannelTotalExposures[constraint.channel] * constraint.factor;\n+\t\tLOG(RPiAgc, Debug) << \"Limit exposure \" << limitExposure;\n+\t\tif ((constraint.bound == AgcChannelConstraint::Bound::UPPER &&\n+\t\t filtered_.totalExposure > limitExposure) ||\n+\t\t (constraint.bound == AgcChannelConstraint::Bound::LOWER &&\n+\t\t filtered_.totalExposure < limitExposure)) {\n+\t\t\tfiltered_.totalExposure = limitExposure;\n+\t\t\tLOG(RPiAgc, Debug) << \"Constraint applies\";\n+\t\t\tchannelBound = true;\n+\t\t} else\n+\t\t\tLOG(RPiAgc, Debug) << \"Constraint does not apply\";\n+\t}\n+\n+\tLOG(RPiAgc, Debug)\n+\t\t<< \"Total exposure after channel constraints \" << filtered_.totalExposure;\n+\n+\treturn channelBound;\n+}\n+\n+bool AgcChannel::applyDigitalGain(double gain, double targetY, bool channelBound)\n {\n \tdouble minColourGain = std::min({ awb_.gainR, awb_.gainG, awb_.gainB, 1.0 });\n \tASSERT(minColourGain != 0.0);\n@@ -816,8 +860,8 @@ bool AgcChannel::applyDigitalGain(double gain, double targetY)\n \t * quickly (and we then approach the correct value more quickly from\n \t * below).\n \t */\n-\tbool desaturate = targetY > config_.fastReduceThreshold &&\n-\t\t\t gain < sqrt(targetY);\n+\tbool desaturate = !channelBound &&\n+\t\t\t targetY > config_.fastReduceThreshold && gain < sqrt(targetY);\n \tif (desaturate)\n \t\tdg /= config_.fastReduceThreshold;\n \tLOG(RPiAgc, Debug) << \"Digital gain \" << dg << \" desaturate? \" << desaturate;\ndiff --git a/src/ipa/rpi/controller/rpi/agc_channel.h b/src/ipa/rpi/controller/rpi/agc_channel.h\nindex 5d2d8a11..1745f2ef 100644\n--- a/src/ipa/rpi/controller/rpi/agc_channel.h\n+++ b/src/ipa/rpi/controller/rpi/agc_channel.h\n@@ -21,6 +21,8 @@\n \n namespace RPiController {\n \n+using AgcChannelTotalExposures = std::vector<libcamera::utils::Duration>;\n+\n struct AgcMeteringMode {\n \tstd::vector<double> weights;\n \tint read(const libcamera::YamlObject ¶ms);\n@@ -95,7 +97,8 @@ public:\n \tvoid disableAuto();\n \tvoid switchMode(CameraMode const &cameraMode, Metadata *metadata);\n \tvoid prepare(Metadata *imageMetadata);\n-\tvoid process(StatisticsPtr &stats, const DeviceStatus *deviceStatus, Metadata *imageMetadata);\n+\tvoid process(StatisticsPtr &stats, const DeviceStatus *deviceStatus, Metadata *imageMetadata,\n+\t\t const AgcChannelTotalExposures &channelTotalExposures);\n \n private:\n \tbool updateLockStatus(DeviceStatus const &deviceStatus);\n@@ -107,7 +110,8 @@ private:\n \t\t\t double &gain, double &targetY);\n \tvoid computeTargetExposure(double gain);\n \tvoid filterExposure();\n-\tbool applyDigitalGain(double gain, double targetY);\n+\tbool applyChannelConstraints(const AgcChannelTotalExposures &channelTotalExposures);\n+\tbool applyDigitalGain(double gain, double targetY, bool channelBound);\n \tvoid divideUpExposure();\n \tvoid writeAndFinish(Metadata *imageMetadata, bool desaturate);\n \tlibcamera::utils::Duration limitShutter(libcamera::utils::Duration shutter);\n", "prefixes": [ "libcamera-devel", "v3", "5/5" ] }