{"id":20135,"url":"https://patchwork.libcamera.org/api/patches/20135/?format=json","web_url":"https://patchwork.libcamera.org/patch/20135/","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":"<20240529193322.835594-1-paul.elder@ideasonboard.com>","date":"2024-05-29T19:33:22","name":"[v2] ipa: libipa: Change constraint Y target to piecewise linear function","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"696a429e348563b0e1ec3aa9acf6e93f81dec909","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/20135/mbox/","series":[{"id":4337,"url":"https://patchwork.libcamera.org/api/series/4337/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4337","date":"2024-05-29T19:33:22","name":"[v2] ipa: libipa: Change constraint Y target to piecewise linear function","version":2,"mbox":"https://patchwork.libcamera.org/series/4337/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20135/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20135/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 9453DBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 29 May 2024 19:33:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 46E0A634BE;\n\tWed, 29 May 2024 21:33:46 +0200 (CEST)","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 56BCF634B0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 May 2024 21:33:44 +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 C1B23149B;\n\tWed, 29 May 2024 21:33:39 +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=\"Rj6mwSjm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1717011220;\n\tbh=aQaOiI389V5z7l/blCk2lPTlsSOCVQWESFUi2eMkRig=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=Rj6mwSjmsd8Twtz/FyP5gvK4W/DW+thHJbmESapi1uY5WYBRxvcdCLB+9vo3pxedw\n\t3aaXh5bI0nS98wH74Ehtl25Gyg4PSayz+dJl6rWSLympL/PfFHHWws9dRYmTgFhs2K\n\tIohHNEx88NEYDfW3KuF/CL2mlRL4/M5EAZSQuLv4=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Paul Elder <paul.elder@ideasonboard.com>","Subject":"[PATCH v2] ipa: libipa: Change constraint Y target to piecewise\n\tlinear function","Date":"Thu, 30 May 2024 04:33:22 +0900","Message-Id":"<20240529193322.835594-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---\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 5b79d5d59..5eaa86c82 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({ PointF(0, 0.5), 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({ PointF(0, 0.5), 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":["v2"]}