{"id":20228,"url":"https://patchwork.libcamera.org/api/patches/20228/?format=json","web_url":"https://patchwork.libcamera.org/patch/20228/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240607075914.2655019-1-paul.elder@ideasonboard.com>","date":"2024-06-07T07:59:14","name":"[v3] ipa: libipa: Change constraint Y target to piecewise linear function","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"3f8ba771d3d667da677dd68972a7f53b83cdaf0d","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20228/mbox/","series":[{"id":4371,"url":"https://patchwork.libcamera.org/api/series/4371/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4371","date":"2024-06-07T07:59:14","name":"[v3] ipa: libipa: Change constraint Y target to piecewise linear function","version":3,"mbox":"https://patchwork.libcamera.org/series/4371/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20228/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20228/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 A80C6BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  7 Jun 2024 07:59:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5A2256545A;\n\tFri,  7 Jun 2024 09:59:24 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 476FA633DD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  7 Jun 2024 09:59:23 +0200 (CEST)","from neptunite.hamster-moth.ts.net\n\t(h175-177-049-156.catv02.itscom.jp [175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B3D70C67;\n\tFri,  7 Jun 2024 09:59:12 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jWepHlG1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1717747153;\n\tbh=xHCSuh8UP54e7dYCC0ly154u8tT7c3ko6QciQc3a6LY=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=jWepHlG1p2AFyyPaRRfg3/FSGeRCb4P5rVrAons9V93ZD38qaZCCzS4SdiQ0KDbRJ\n\tILv03sm4exEBaqYS/9NJxGltSzr4YP+ZZCRAD1jh5COxHl7xhDWQoq/m+PVEhSES19\n\tchtKOzjYpfjJMzvKEs5NrvipqbOowmTk55wN+UcU=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Paul Elder <paul.elder@ideasonboard.com>","Subject":"[PATCH v3] ipa: libipa: Change constraint Y target to piecewise\n\tlinear function","Date":"Fri,  7 Jun 2024 16:59:14 +0900","Message-Id":"<20240607075914.2655019-1-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.39.2","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":"Change the constraint luminance target from a scalar value to a\npiecewise linear function that needs to be sampled by the estimated lux\nvalue.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nThis patch depends on v5 of \"ipa:: Move Pwl from Raspberry Pi\"\n\nChanges in v3:\n- use new PointF that's a typedef of Vector\n\nChanges in v2:\n- s/FPoint/PointF/\n- construct default Pwl with *two* points so that it actually constructs\n  properly\n---\n src/ipa/libipa/agc_mean_luminance.cpp | 15 +++++++++------\n src/ipa/libipa/agc_mean_luminance.h   |  4 ++--\n 2 files changed, 11 insertions(+), 8 deletions(-)","diff":"diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex 10c16850d..575143610 100644\n--- a/src/ipa/libipa/agc_mean_luminance.cpp\n+++ b/src/ipa/libipa/agc_mean_luminance.cpp\n@@ -168,8 +168,10 @@ void AgcMeanLuminance::parseConstraint(const YamlObject &modeDict, int32_t id)\n \t\tAgcConstraint::Bound bound = static_cast<AgcConstraint::Bound>(idx);\n \t\tdouble qLo = content[\"qLo\"].get<double>().value_or(0.98);\n \t\tdouble qHi = content[\"qHi\"].get<double>().value_or(1.0);\n-\t\tdouble yTarget =\n-\t\t\tcontent[\"yTarget\"].getList<double>().value_or(std::vector<double>{ 0.5 }).at(0);\n+\t\tPwl yTarget;\n+\t\tint ret = yTarget.readYaml(content[\"yTarget\"]);\n+\t\tif (ret < 0)\n+\t\t\tyTarget = Pwl({ Pwl::PointF({ 0, 0.5 }), Pwl::PointF({ 1000, 0.5 }) });\n \n \t\tAgcConstraint constraint = { bound, qLo, qHi, yTarget };\n \n@@ -221,7 +223,7 @@ int AgcMeanLuminance::parseConstraintModes(const YamlObject &tuningData)\n \t\t\tAgcConstraint::Bound::lower,\n \t\t\t0.98,\n \t\t\t1.0,\n-\t\t\t0.5\n+\t\t\tPwl({ Pwl::PointF({ 0, 0.5 }), Pwl::PointF({ 1000, 0.5 }) })\n \t\t};\n \n \t\tconstraintModes_[controls::ConstraintNormal].insert(\n@@ -471,16 +473,17 @@ double AgcMeanLuminance::estimateInitialGain(double lux) const\n  * \\param[in] constraintModeIndex The index of the constraint to adhere to\n  * \\param[in] hist A histogram over which to calculate inter-quantile means\n  * \\param[in] gain The gain to clamp\n+ * \\param[in] lux The lux value at which to sample the constraint luminance target pwl\n  *\n  * \\return The gain clamped within the constraint bounds\n  */\n double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n \t\t\t\t\t     const Histogram &hist,\n-\t\t\t\t\t     double gain)\n+\t\t\t\t\t     double gain, double lux)\n {\n \tstd::vector<AgcConstraint> &constraints = constraintModes_[constraintModeIndex];\n \tfor (const AgcConstraint &constraint : constraints) {\n-\t\tdouble newGain = constraint.yTarget * hist.bins() /\n+\t\tdouble newGain = constraint.yTarget.eval(constraint.yTarget.domain().clamp(lux)) * hist.bins() /\n \t\t\t\t hist.interQuantileMean(constraint.qLo, constraint.qHi);\n \n \t\tif (constraint.bound == AgcConstraint::Bound::lower &&\n@@ -559,7 +562,7 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex,\n \t\texposureModeHelpers_.at(exposureModeIndex);\n \n \tdouble gain = estimateInitialGain(lux);\n-\tgain = constraintClampGain(constraintModeIndex, yHist, gain);\n+\tgain = constraintClampGain(constraintModeIndex, yHist, gain, lux);\n \n \t/*\n \t * We don't check whether we're already close to the target, because\ndiff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\nindex 6ec2a0dc9..d43f673dd 100644\n--- a/src/ipa/libipa/agc_mean_luminance.h\n+++ b/src/ipa/libipa/agc_mean_luminance.h\n@@ -38,7 +38,7 @@ public:\n \t\tBound bound;\n \t\tdouble qLo;\n \t\tdouble qHi;\n-\t\tdouble yTarget;\n+\t\tPwl yTarget;\n \t};\n \n \tint parseTuningData(const YamlObject &tuningData);\n@@ -80,7 +80,7 @@ private:\n \tdouble estimateInitialGain(double lux) const;\n \tdouble constraintClampGain(uint32_t constraintModeIndex,\n \t\t\t\t   const Histogram &hist,\n-\t\t\t\t   double gain);\n+\t\t\t\t   double gain, double lux);\n \tutils::Duration filterExposure(utils::Duration exposureValue);\n \n \tuint64_t frameCount_;\n","prefixes":["v3"]}