[{"id":36041,"web_url":"https://patchwork.libcamera.org/comment/36041/","msgid":"<42a0f93f-2654-4c81-aead-b59d84f82101@ideasonboard.com>","date":"2025-09-29T15:52:01","subject":"Re: [PATCH] ipa: simple: blc: Use 16 as starting blacklevel when\n\tthere is no sensor-info","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 09. 29. 15:13 keltezéssel, Hans de Goede írta:\n> At the moment the blc code uses 255 as starting blacklevel for sensors\n> where there is no blacklevel info in the sensor-helper.\n> \n> There are a number of issues with this:\n> \n> 1. When the first frame is bad (e.g. mostly white) which happens sometimes\n> the initial blacklevel will be kept leading to a divide by zero problem\n> in the AGC code (this divide by 0 problem is avoided in the AGC code by\n> not running the AGC algorithm).\n\nThe note in parentheses only applies after https://patchwork.libcamera.org/patch/24461/ right?\n\n\n> \n> 2. Not runnning the AGC algorithm means that the gain/exposure do not\n> change, which causes the BLC algorithm to not run on the next frames,\n> so we keep the bad 255 blacklevel which stops AGC from running which\n> stops BLC from running. Leaving things stuck at a 255 blacklevel\n> resulting in an unusuable image.\n> \n> 3. Sometimes the auto-blc code leads to an unrealistic high\n> blacklevel detection which results in lower image quality.\n> \n> To fix this start with a blacklevel of 16, which is the highest\n> (4096 / 256) blacklevel used for any sensor listing a blackLevel_\n> value in the sensor-helper class.\n\nAs far as I can see the black level is only ever decreased by the algorithm.\nSo this changes the initial value from the \"theoretical maximum\" to a\n\"heuristic maximum\", correct?\n\n\nRegards,\nBarnabás Pőcze\n\n\n> \n> Note 2. could alternatively be fixed by disabling the check for\n> exposure/gain changes when the blacklevel is unrealistic high,\n> but that still leaves the other problems.\n> \n> Signed-off-by: Hans de Goede <hansg@kernel.org>\n> ---\n>   src/ipa/simple/algorithms/blc.cpp | 2 +-\n>   1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp\n> index ec71e154e..370385afc 100644\n> --- a/src/ipa/simple/algorithms/blc.cpp\n> +++ b/src/ipa/simple/algorithms/blc.cpp\n> @@ -43,7 +43,7 @@ int BlackLevel::configure(IPAContext &context,\n>   \tif (definedLevel_.has_value())\n>   \t\tcontext.configuration.black.level = definedLevel_;\n>   \tcontext.activeState.blc.level =\n> -\t\tcontext.configuration.black.level.value_or(255);\n> +\t\tcontext.configuration.black.level.value_or(16);\n>   \treturn 0;\n>   }\n>","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 A0A67C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Sep 2025 15:52:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 82D1C6B5F3;\n\tMon, 29 Sep 2025 17:52:06 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BEC486B599\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Sep 2025 17:52:04 +0200 (CEST)","from [192.168.33.13] (185.221.142.146.nat.pool.zt.hu\n\t[185.221.142.146])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F3AE26A8;\n\tMon, 29 Sep 2025 17:50:36 +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=\"tD++x+lk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1759161037;\n\tbh=48Lf3GskRIaL4WsSalcYPRELIWdTqRGI0+JrEJ/Xui8=;\n\th=Date:Subject:To:References:From:Cc:In-Reply-To:From;\n\tb=tD++x+lkTaoouBC7ojxSX5lIkTStrJbpDOe/1qXCQSm5RG8ri8At0q2d8CRfF5pGY\n\tR1mtQnk3WkIqkwYqnqD97tv8qGFMTkc4GbKin4aUA3HBMInmhQGmJgjovP66ovFs+t\n\tZGluedmmYs73hC/6knjM2Wix910d1/73rxyZcFBc=","Message-ID":"<42a0f93f-2654-4c81-aead-b59d84f82101@ideasonboard.com>","Date":"Mon, 29 Sep 2025 17:52:01 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] ipa: simple: blc: Use 16 as starting blacklevel when\n\tthere is no sensor-info","To":"Hans de Goede <hansg@kernel.org>","References":"<20250929131355.25897-1-hansg@kernel.org>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","Cc":"libcamera-devel@lists.libcamera.org","In-Reply-To":"<20250929131355.25897-1-hansg@kernel.org>","Content-Type":"text/plain; charset=UTF-8; format=flowed","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>"}},{"id":36042,"web_url":"https://patchwork.libcamera.org/comment/36042/","msgid":"<85plb9p7g5.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-09-29T16:08:42","subject":"Re: [PATCH] ipa: simple: blc: Use 16 as starting blacklevel when\n\tthere is no sensor-info","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Hans,\n\nthank you for the patch.\n\nHans de Goede <hansg@kernel.org> writes:\n\n> At the moment the blc code uses 255 as starting blacklevel for sensors\n> where there is no blacklevel info in the sensor-helper.\n>\n> There are a number of issues with this:\n>\n> 1. When the first frame is bad (e.g. mostly white) which happens sometimes\n> the initial blacklevel will be kept leading to a divide by zero problem\n> in the AGC code (this divide by 0 problem is avoided in the AGC code by\n> not running the AGC algorithm).\n>\n> 2. Not runnning the AGC algorithm means that the gain/exposure do not\n> change, which causes the BLC algorithm to not run on the next frames,\n> so we keep the bad 255 blacklevel which stops AGC from running which\n> stops BLC from running. Leaving things stuck at a 255 blacklevel\n> resulting in an unusuable image.\n>\n> 3. Sometimes the auto-blc code leads to an unrealistic high\n> blacklevel detection which results in lower image quality.\n>\n> To fix this start with a blacklevel of 16, which is the highest\n> (4096 / 256) blacklevel used for any sensor listing a blackLevel_\n> value in the sensor-helper class.\n>\n> Note 2. could alternatively be fixed by disabling the check for\n> exposure/gain changes when the blacklevel is unrealistic high,\n> but that still leaves the other problems.\n>\n> Signed-off-by: Hans de Goede <hansg@kernel.org>\n\nMakes sense.\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/ipa/simple/algorithms/blc.cpp | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp\n> index ec71e154e..370385afc 100644\n> --- a/src/ipa/simple/algorithms/blc.cpp\n> +++ b/src/ipa/simple/algorithms/blc.cpp\n> @@ -43,7 +43,7 @@ int BlackLevel::configure(IPAContext &context,\n>  \tif (definedLevel_.has_value())\n>  \t\tcontext.configuration.black.level = definedLevel_;\n>  \tcontext.activeState.blc.level =\n> -\t\tcontext.configuration.black.level.value_or(255);\n> +\t\tcontext.configuration.black.level.value_or(16);\n>  \treturn 0;\n>  }","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 055E5C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Sep 2025 16:08:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 92E8E6B5F8;\n\tMon, 29 Sep 2025 18:08:53 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EC186B599\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Sep 2025 18:08:49 +0200 (CEST)","from mail-wm1-f69.google.com (mail-wm1-f69.google.com\n\t[209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-230-NBFbrzYsMMi3zEak9jWSZw-1; Mon, 29 Sep 2025 12:08:46 -0400","by mail-wm1-f69.google.com with SMTP id\n\t5b1f17b1804b1-46e31191379so31006215e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Sep 2025 09:08:46 -0700 (PDT)","from mzamazal-thinkpadp1gen7.tpbc.csb\n\t(ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-46e59b3c755sm569415e9.8.2025.09.29.09.08.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 29 Sep 2025 09:08:44 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"EGVWC5p/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1759162128;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=mo+Di0PAK8j7tgMW5xfDbguVxZ5d6KhqQlbG0oTxOrQ=;\n\tb=EGVWC5p/9R2dlLlk0eHZ0VdCExKYYM0cv5EYBDeq6aJ1/vjdKBoREVPgcswk3nVfcnY+BW\n\taf1KbA8GJ3Wu9TciIpTxRrdwnYE4CSqkoGt0V/DTYpG3imY/B5U81tc0oCLtZLwPVxgQTw\n\tq9OWXYQ6t9TYYLk4jhJ/4m7r6dYa+wI=","X-MC-Unique":"NBFbrzYsMMi3zEak9jWSZw-1","X-Mimecast-MFC-AGG-ID":"NBFbrzYsMMi3zEak9jWSZw_1759162126","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1759162125; x=1759766925;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=mo+Di0PAK8j7tgMW5xfDbguVxZ5d6KhqQlbG0oTxOrQ=;\n\tb=gOf+cCRMTsUuwVr2TJ9IAE2rE8H2CS6ziAcv9gq/PmuK2g2UIq4Mc+CO9gHPRjp9SW\n\tIzHjfssLlXcnWBbXAJT77Pe/gwypQbFUVbasE5cWkLU4EpegI8M87WkeuXdFfKLlONb6\n\tTe1YgeLVJhVPxBWlFFj6/UrEt3cFaDZBSpei7aS6/XZs1+EPPDNSVr+pGTlPkwf490gl\n\tiR9X9moBdcgfKJcheJOAT/PKHae16JZVh7hGvlbQTLU0mPaaMMwVqFhgORDN+ZlUXOh2\n\tzVqylnqtwvqtkcDXd9Fhz6q6zYE118ysTutAupSNhGsGXqzZaB3nphrbvlcNiv1ODolo\n\tzv1w==","X-Gm-Message-State":"AOJu0YyIyJoLn/sfRcQwQJKb/q1WLrzp+98aAVoLYGGSi/bzuKiOBMaE\n\twqnVmZ1QEUrOHQ9TBLAz8Yk4AdKbpE3YufQ8R3eSnRJHRsUapc+IxcS2Jd3pf5JI7D0OD7q1SJd\n\tO3oiqm+gl2fbspP494vR2FUaT2f+yEbVFb5d6x82eBkHgNm9nfnP9cDBAxrpuwO2hPjtqUy3cry\n\tGVcjDTQQO+W7Y0SbpLOtTQU3lBYV6rrodIIx+udUOMIZRgb9L+S27JX+JOnH0=","X-Gm-Gg":"ASbGncvMiXsBmE5juLM0ZIiIh5BHNMhKptVakSpvCHIa5Si6Lz1EgsdbJdmqhvZt2MI\n\tjvK5oKQTo3raxFgixGcnpr8WbRx0u9jOiUIF+8Vg3mN1i+fSpWkWKwmAqoztASF8X1Utbz+gOpM\n\toGPkBifMSVosT5D8NQ3aw4/FwSjKVXfQGqYx6UHyQb6DJ/tZH4xpkQaZgV8s9m63nEpgTQQeo+0\n\tGLOudhG+N7IKfMyQL6TXwsEKX9pDnzZMoLsLzplaVZNlKttwFqXnSxrPfPAiLJAsRVlPnqXmBi5\n\tmFzp2wz4OuUxswtZJ4gKRvRcCUW3DIEKR6ozL9Cfq1dnKzM5x4xBt0faO4Om3Gh/V/Q2D9r9OIo\n\tn64UkE1Rg8J1J4zbl2w==","X-Received":["by 2002:a05:600c:870b:b0:46e:4937:dd1b with SMTP id\n\t5b1f17b1804b1-46e4937df7dmr74346155e9.17.1759162125035; \n\tMon, 29 Sep 2025 09:08:45 -0700 (PDT)","by 2002:a05:600c:870b:b0:46e:4937:dd1b with SMTP id\n\t5b1f17b1804b1-46e4937df7dmr74345855e9.17.1759162124575; \n\tMon, 29 Sep 2025 09:08:44 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IHojiuxJc93kgf/t4BzqYcntTcR+zJFyuMEtIwroERr2GzgNwO3SCSa9UmwgCyr5yexxuTrHA==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Hans de Goede <hansg@kernel.org>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] ipa: simple: blc: Use 16 as starting blacklevel when\n\tthere is no sensor-info","In-Reply-To":"<20250929131355.25897-1-hansg@kernel.org> (Hans de Goede's\n\tmessage of \"Mon, 29 Sep 2025 15:13:55 +0200\")","References":"<20250929131355.25897-1-hansg@kernel.org>","Date":"Mon, 29 Sep 2025 18:08:42 +0200","Message-ID":"<85plb9p7g5.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"yuA6ISJpSPSSehwTglKrkCgZ1diiHWYo8z6L_Rrede0_1759162126","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}},{"id":36043,"web_url":"https://patchwork.libcamera.org/comment/36043/","msgid":"<320384f7-c565-41a0-8250-1b0a9e1e8d28@kernel.org>","date":"2025-09-29T16:14:51","subject":"Re: [PATCH] ipa: simple: blc: Use 16 as starting blacklevel when\n\tthere is no sensor-info","submitter":{"id":239,"url":"https://patchwork.libcamera.org/api/people/239/","name":"Hans de Goede","email":"hansg@kernel.org"},"content":"Hi,\n\nOn 29-Sep-25 5:52 PM, Barnabás Pőcze wrote:\n> Hi\n> \n> 2025. 09. 29. 15:13 keltezéssel, Hans de Goede írta:\n>> At the moment the blc code uses 255 as starting blacklevel for sensors\n>> where there is no blacklevel info in the sensor-helper.\n>>\n>> There are a number of issues with this:\n>>\n>> 1. When the first frame is bad (e.g. mostly white) which happens sometimes\n>> the initial blacklevel will be kept leading to a divide by zero problem\n>> in the AGC code (this divide by 0 problem is avoided in the AGC code by\n>> not running the AGC algorithm).\n> \n> The note in parentheses only applies after https://patchwork.libcamera.org/patch/24461/ right?\n\nRight.\n\n>> 2. Not runnning the AGC algorithm means that the gain/exposure do not\n>> change, which causes the BLC algorithm to not run on the next frames,\n>> so we keep the bad 255 blacklevel which stops AGC from running which\n>> stops BLC from running. Leaving things stuck at a 255 blacklevel\n>> resulting in an unusuable image.\n>>\n>> 3. Sometimes the auto-blc code leads to an unrealistic high\n>> blacklevel detection which results in lower image quality.\n>>\n>> To fix this start with a blacklevel of 16, which is the highest\n>> (4096 / 256) blacklevel used for any sensor listing a blackLevel_\n>> value in the sensor-helper class.\n> \n> As far as I can see the black level is only ever decreased by the algorithm.\n> So this changes the initial value from the \"theoretical maximum\" to a\n> \"heuristic maximum\", correct?\n\nCorrect.\n\nRegards,\n\nHans\n\n\n\n\n>> Note 2. could alternatively be fixed by disabling the check for\n>> exposure/gain changes when the blacklevel is unrealistic high,\n>> but that still leaves the other problems.\n>>\n>> Signed-off-by: Hans de Goede <hansg@kernel.org>\n>> ---\n>>   src/ipa/simple/algorithms/blc.cpp | 2 +-\n>>   1 file changed, 1 insertion(+), 1 deletion(-)\n>>\n>> diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp\n>> index ec71e154e..370385afc 100644\n>> --- a/src/ipa/simple/algorithms/blc.cpp\n>> +++ b/src/ipa/simple/algorithms/blc.cpp\n>> @@ -43,7 +43,7 @@ int BlackLevel::configure(IPAContext &context,\n>>       if (definedLevel_.has_value())\n>>           context.configuration.black.level = definedLevel_;\n>>       context.activeState.blc.level =\n>> -        context.configuration.black.level.value_or(255);\n>> +        context.configuration.black.level.value_or(16);\n>>       return 0;\n>>   }\n>>   \n>","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 18D94C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Sep 2025 16:14:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2E0B26B5FB;\n\tMon, 29 Sep 2025 18:14:58 +0200 (CEST)","from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C4106B599\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Sep 2025 18:14:55 +0200 (CEST)","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby tor.source.kernel.org (Postfix) with ESMTP id F35CC625F2;\n\tMon, 29 Sep 2025 16:14:53 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 2F703C4CEF4;\n\tMon, 29 Sep 2025 16:14:53 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=kernel.org header.i=@kernel.org\n\theader.b=\"rFJiASir\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1759162493;\n\tbh=OpvmfrVGh5ZEx5w9di/HtthWc0/h1Ko+8KrMM9q1KCE=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=rFJiASirCh4qWFXLasp1OITlnfS2Y6EBI0powjaLt6NbhsGxW4ni6S21UFggkcgbf\n\tw/NYCWhTEdp6nbCTnjm1604Orxs2nkpY9tvTImYDoNMBxvW2Np5N2/hKW/VRxQ70bQ\n\ttJRARxA6tMeVE0NXjE260sZ68Og4YZEiejguS4QUrbpJi5uccTAJAil91FYy1jLkQ7\n\td5lvFn7SIDJiLndj8cHVFmRrRhrI+pc37HRQ57DKwrMY8fGC71ehjwTO4rndSwEQCI\n\tg0GWzxW+xx8MMN+Id4Q2Oa39FUw1KNVuhvp/Rs8Fjur5lsoi1gAdXjY6Lgm4JTkFV+\n\tf/b+ClfI2WBnA==","Message-ID":"<320384f7-c565-41a0-8250-1b0a9e1e8d28@kernel.org>","Date":"Mon, 29 Sep 2025 18:14:51 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] ipa: simple: blc: Use 16 as starting blacklevel when\n\tthere is no sensor-info","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","References":"<20250929131355.25897-1-hansg@kernel.org>\n\t<42a0f93f-2654-4c81-aead-b59d84f82101@ideasonboard.com>","From":"Hans de Goede <hansg@kernel.org>","Content-Language":"en-US, nl","In-Reply-To":"<42a0f93f-2654-4c81-aead-b59d84f82101@ideasonboard.com>","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>"}},{"id":36067,"web_url":"https://patchwork.libcamera.org/comment/36067/","msgid":"<175933412997.756374.14185752896261175297@ping.linuxembedded.co.uk>","date":"2025-10-01T15:55:29","subject":"Re: [PATCH] ipa: simple: blc: Use 16 as starting blacklevel when\n\tthere is no sensor-info","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Hans de Goede (2025-09-29 17:14:51)\n> Hi,\n> \n> On 29-Sep-25 5:52 PM, Barnabás Pőcze wrote:\n> > Hi\n> > \n> > 2025. 09. 29. 15:13 keltezéssel, Hans de Goede írta:\n> >> At the moment the blc code uses 255 as starting blacklevel for sensors\n> >> where there is no blacklevel info in the sensor-helper.\n> >>\n> >> There are a number of issues with this:\n> >>\n> >> 1. When the first frame is bad (e.g. mostly white) which happens sometimes\n> >> the initial blacklevel will be kept leading to a divide by zero problem\n> >> in the AGC code (this divide by 0 problem is avoided in the AGC code by\n> >> not running the AGC algorithm).\n> > \n> > The note in parentheses only applies after https://patchwork.libcamera.org/patch/24461/ right?\n> \n> Right.\n> \n> >> 2. Not runnning the AGC algorithm means that the gain/exposure do not\n> >> change, which causes the BLC algorithm to not run on the next frames,\n> >> so we keep the bad 255 blacklevel which stops AGC from running which\n> >> stops BLC from running. Leaving things stuck at a 255 blacklevel\n> >> resulting in an unusuable image.\n> >>\n> >> 3. Sometimes the auto-blc code leads to an unrealistic high\n> >> blacklevel detection which results in lower image quality.\n> >>\n> >> To fix this start with a blacklevel of 16, which is the highest\n> >> (4096 / 256) blacklevel used for any sensor listing a blackLevel_\n> >> value in the sensor-helper class.\n> > \n> > As far as I can see the black level is only ever decreased by the algorithm.\n> > So this changes the initial value from the \"theoretical maximum\" to a\n> > \"heuristic maximum\", correct?\n> \n> Correct.\n\nIt's a bit arbitrary - but 16 is a better default black level than 255 by a long\nshot ;-)\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n> \n> Regards,\n> \n> Hans\n> \n> \n> \n> \n> >> Note 2. could alternatively be fixed by disabling the check for\n> >> exposure/gain changes when the blacklevel is unrealistic high,\n> >> but that still leaves the other problems.\n> >>\n> >> Signed-off-by: Hans de Goede <hansg@kernel.org>\n> >> ---\n> >>   src/ipa/simple/algorithms/blc.cpp | 2 +-\n> >>   1 file changed, 1 insertion(+), 1 deletion(-)\n> >>\n> >> diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp\n> >> index ec71e154e..370385afc 100644\n> >> --- a/src/ipa/simple/algorithms/blc.cpp\n> >> +++ b/src/ipa/simple/algorithms/blc.cpp\n> >> @@ -43,7 +43,7 @@ int BlackLevel::configure(IPAContext &context,\n> >>       if (definedLevel_.has_value())\n> >>           context.configuration.black.level = definedLevel_;\n> >>       context.activeState.blc.level =\n> >> -        context.configuration.black.level.value_or(255);\n> >> +        context.configuration.black.level.value_or(16);\n> >>       return 0;\n> >>   }\n> >>   \n> > \n>","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 63247C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  1 Oct 2025 15:55:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6833B6B58E;\n\tWed,  1 Oct 2025 17:55:34 +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 43D696B58E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Oct 2025 17:55:33 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DA54C4C7;\n\tWed,  1 Oct 2025 17:54:03 +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=\"kmqaKI3r\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1759334043;\n\tbh=6tqUgbI1ToaVpyCG7LgBGctpM5RIyiAfvktd9+pRCNQ=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=kmqaKI3rIVzEuk1YhmtnolYessytx2CMwHGZMqAxkWv9aPm+YZOnesT9CODYer2o9\n\tCF+dsP+TC6rs9YmyLR6eUlndbX8iGy72drgtRWmT3+TapUBwSIjeZbnxhgX0E8GUhu\n\tMcztliIB2Sv9UMsb9Axhmyc0xwMjHqzZiHBbi+lk=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<320384f7-c565-41a0-8250-1b0a9e1e8d28@kernel.org>","References":"<20250929131355.25897-1-hansg@kernel.org>\n\t<42a0f93f-2654-4c81-aead-b59d84f82101@ideasonboard.com>\n\t<320384f7-c565-41a0-8250-1b0a9e1e8d28@kernel.org>","Subject":"Re: [PATCH] ipa: simple: blc: Use 16 as starting blacklevel when\n\tthere is no sensor-info","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tHans de Goede <hansg@kernel.org>","Date":"Wed, 01 Oct 2025 16:55:29 +0100","Message-ID":"<175933412997.756374.14185752896261175297@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]