Patch Detail
Show a patch.
GET /api/patches/27590/?format=api
{ "id": 27590, "url": "https://patchwork.libcamera.org/api/patches/27590/?format=api", "web_url": "https://patchwork.libcamera.org/patch/27590/", "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": "<20260803131435.153927-43-barnabas.pocze@ideasonboard.com>", "date": "2026-08-03T13:14:27", "name": "[RFC,v3,42/50] ipa: libipa: agc_msv: Ensure limits are always respected", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "1ddd19ac00602e268257ae9374f4c2381e7a67fa", "submitter": { "id": 216, "url": "https://patchwork.libcamera.org/api/people/216/?format=api", "name": "Barnabás Pőcze", "email": "barnabas.pocze@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/27590/mbox/", "series": [ { "id": 6103, "url": "https://patchwork.libcamera.org/api/series/6103/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6103", "date": "2026-08-03T13:13:45", "name": "ipa: libipa: agc rework", "version": 3, "mbox": "https://patchwork.libcamera.org/series/6103/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/27590/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/27590/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 CA628C3349\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 3 Aug 2026 13:15:23 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D737A6810C;\n\tMon, 3 Aug 2026 15:15:20 +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 522B0680BB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 3 Aug 2026 15:14:48 +0200 (CEST)", "from pb-laptop.local (185.221.141.208.nat.pool.zt.hu\n\t[185.221.141.208])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6BC585B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 3 Aug 2026 15:13: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=\"izXHkm7m\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1785762819;\n\tbh=tqxwRekX1pe5lTqv8KeMnWE5PYwZfpJxr4s+icm4tOo=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=izXHkm7m6h5h9/vDIvRW6KkJPEPZ9I+FUDxg8OH2QA9vrYJRHiwY5LC1c21OaHTjs\n\t5He43n61mj+vCYOLyF51r+f5kuhRTEaH9MhYzG2XpUWYLf1AbLkCytydb5ssivWKVT\n\tXwpWQZW6mIiEeX6QBmLr3oevC7ptE6oEVTkupDP4=", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[RFC PATCH v3 42/50] ipa: libipa: agc_msv: Ensure limits are always\n\trespected", "Date": "Mon, 3 Aug 2026 15:14:27 +0200", "Message-ID": "<20260803131435.153927-43-barnabas.pocze@ideasonboard.com>", "X-Mailer": "git-send-email 2.55.0", "In-Reply-To": "<20260803131435.153927-1-barnabas.pocze@ideasonboard.com>", "References": "<20260803131435.153927-1-barnabas.pocze@ideasonboard.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "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": "Make sure that even in the presence of continous limit changes, the\nreturned exposure and gain values are always within bounds. This is\nneeded for integration into `AgcAlgorithm`, which might vary the limits\nfor every invocation.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n src/ipa/libipa/agc_msv.cpp | 84 ++++++++++++++++++++------------------\n 1 file changed, 45 insertions(+), 39 deletions(-)", "diff": "diff --git a/src/ipa/libipa/agc_msv.cpp b/src/ipa/libipa/agc_msv.cpp\nindex 63580a0055..956551685c 100644\n--- a/src/ipa/libipa/agc_msv.cpp\n+++ b/src/ipa/libipa/agc_msv.cpp\n@@ -157,59 +157,65 @@ void AgcMSV::setLimits(const Limits &limits)\n */\n AgcMSV::Result AgcMSV::calculateNewEv(const Params ¶ms)\n {\n-\tauto exposureMSV = calculateMSV(params.yHist);\n-\tif (!exposureMSV) {\n+\tAgcMSV::Result result = { params.exposure, params.gain };\n+\n+\tif (auto exposureMSV = calculateMSV(params.yHist)) {\n+\t\tresult = updateExposure(params.exposure, params.gain, *exposureMSV);\n+\t} else {\n \t\tLOG(AgcMSV, Debug)\n \t\t\t<< \"Not adjusting exposure due to insufficient histogram data\";\n-\t\treturn { params.exposure, params.gain };\n \t}\n \n-\treturn updateExposure(params.exposure, params.gain, *exposureMSV);\n+\tresult.exposure = std::clamp(result.exposure, limits_.exposure[0], limits_.exposure[1]);\n+\tresult.analogueGain = std::clamp(result.analogueGain, limits_.gain[0], limits_.gain[1]);\n+\n+\tLOG(AgcMSV, Debug)\n+\t\t<< \"exposure:\" << result.exposure\n+\t\t<< \" analogue-gain:\" << result.analogueGain;\n+\n+\treturn result;\n }\n \n AgcMSV::Result AgcMSV::updateExposure(uint32_t exposure, double again, float exposureMSV)\n {\n \tfloat error = kExposureOptimal - exposureMSV;\n-\tif (std::abs(error) <= kExposureSatisfactory)\n-\t\treturn { exposure, again };\n \n-\t/*\n-\t * Compute a proportional correction factor. The sign of the error\n-\t * determines the direction: positive error means too dark (increase),\n-\t * negative means too bright (decrease).\n-\t */\n-\tfloat step = std::clamp(error * kExpProportionalGain,\n-\t\t\t\t-kExpMaxStep, kExpMaxStep);\n-\tfloat factor = 1.0f + step;\n-\n-\tif (factor > 1.0f) {\n-\t\t/* Scene too dark: increase exposure first, then gain. */\n-\t\tif (exposure < limits_.exposure[1]) {\n-\t\t\tuint32_t next = exposure * factor;\n-\t\t\texposure = std::max(next, exposure + 1);\n-\t\t} else {\n-\t\t\tdouble next = again * factor;\n-\t\t\tagain = std::max(next, again + limits_.gainMinStep);\n-\t\t}\n-\t} else {\n-\t\t/* Scene too bright: decrease gain first, then exposure. */\n-\t\tif (again > limits_.gain1) {\n-\t\t\tdouble next = again * factor;\n-\t\t\tagain = std::min(next, again - limits_.gainMinStep);\n+\tLOG(AgcMSV, Debug)\n+\t\t<< \"exposureMSV:\" << exposureMSV << \" error:\" << error;\n+\n+\tif (std::abs(error) > kExposureSatisfactory) {\n+\t\t/*\n+\t\t * Compute a proportional correction factor. The sign of the error\n+\t\t * determines the direction: positive error means too dark (increase),\n+\t\t * negative means too bright (decrease).\n+\t\t */\n+\t\tfloat step = std::clamp(error * kExpProportionalGain,\n+\t\t\t\t\t-kExpMaxStep, kExpMaxStep);\n+\t\tfloat factor = 1.0f + step;\n+\n+\t\tLOG(AgcMSV, Debug) << \"factor:\" << factor;\n+\n+\t\tif (factor > 1.0f) {\n+\t\t\t/* Scene too dark: increase exposure first, then gain. */\n+\t\t\tif (exposure < limits_.exposure[1]) {\n+\t\t\t\tuint32_t next = exposure * factor;\n+\t\t\t\texposure = std::max(next, exposure + 1);\n+\t\t\t} else {\n+\t\t\t\tdouble next = again * factor;\n+\t\t\t\tagain = std::max(next, again + limits_.gainMinStep);\n+\t\t\t}\n \t\t} else {\n-\t\t\tuint32_t next = exposure * factor;\n-\t\t\texposure = std::min(next, exposure - 1);\n+\t\t\t/* Scene too bright: decrease gain first, then exposure. */\n+\t\t\tif (again > limits_.gain1) {\n+\t\t\t\tdouble next = again * factor;\n+\t\t\t\tagain = std::min(next, again - limits_.gainMinStep);\n+\t\t\t} else {\n+\t\t\t\tuint32_t next = exposure * factor;\n+\t\t\t\texposure = std::min(next, exposure - 1);\n+\t\t\t}\n \t\t}\n \t}\n \n-\texposure = std::clamp(exposure, limits_.exposure[0], limits_.exposure[1]);\n-\tagain = std::clamp(again, limits_.gain[0], limits_.gain[1]);\n-\n-\tLOG(AgcMSV, Debug)\n-\t\t<< \"exposureMSV:\" << exposureMSV\n-\t\t<< \" error:\" << error << \" factor:\" << factor\n-\t\t<< \" exposure:\" << exposure << \" analogue-gain:\" << again;\n-\n \treturn { exposure, again };\n }\n \n", "prefixes": [ "RFC", "v3", "42/50" ] }