[{"id":38343,"web_url":"https://patchwork.libcamera.org/comment/38343/","msgid":"<04dab226-2edf-4aa3-ac4d-f4431764bb2c@collabora.com>","date":"2026-03-06T12:45:30","subject":"Re: [PATCH v3 2/3] libcamera: software_isp: Normalize statistics\n\tsums to 8-bit","submitter":{"id":140,"url":"https://patchwork.libcamera.org/api/people/140/","name":"Robert Mader","email":"robert.mader@collabora.com"},"content":"Hi, thanks for the patch!\n\nOn 05.03.26 21:10, Javier Tia wrote:\n> The SWSTATS_ACCUMULATE_LINE_STATS() macro divides the luminance value\n> for the histogram to normalize it to 8-bit range, but does not apply\n> the same normalization to the RGB sums. For 10-bit and 12-bit unpacked\n> Bayer formats this means the sums are accumulated at native bit depth\n> (0-1023 or 0-4095 per pixel) while the AWB algorithm subtracts an\n> 8-bit black level from them, under-correcting by 4x or 16x\n> respectively.\n>\n> This mismatch between the AWB's gain calculation (using incorrectly\n> BLC-subtracted sums) and the debayer's correct normalized BLC\n> subtraction produces a visible color cast. For example, with the\n> OV2740 sensor (10-bit, BLC=16), the under-subtraction skews R/G gain\n> by ~9%.\n>\n> Fix this by right-shifting the RGB sums in finishFrame() to normalize\n> them to 8-bit scale, matching the histogram and the 8-bit black level\n> used by AWB. A per-format sumShift_ value is set in configure():\n> 0 for 8-bit and CSI-2 packed formats (already 8-bit), 2 for 10-bit,\n> and 4 for 12-bit unpacked formats.\n>\n> Signed-off-by: Javier Tia <floss@jetm.me>\n> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>\n> Tested-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>   include/libcamera/internal/software_isp/swstats_cpu.h | 1 +\n>   src/libcamera/software_isp/swstats_cpu.cpp            | 9 +++++++++\n>   2 files changed, 10 insertions(+)\n>\n> diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\n> index 64b3e23f..37bfde53 100644\n> --- a/include/libcamera/internal/software_isp/swstats_cpu.h\n> +++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n> @@ -115,6 +115,7 @@ private:\n>   \n>   \tunsigned int xShift_;\n>   \tunsigned int stride_;\n> +\tunsigned int sumShift_;\n>   \n>   \tSharedMemObject<SwIspStats> sharedStats_;\n>   \tSwIspStats stats_;\n> diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n> index 1cedcfbc..6f834207 100644\n> --- a/src/libcamera/software_isp/swstats_cpu.cpp\n> +++ b/src/libcamera/software_isp/swstats_cpu.cpp\n> @@ -346,6 +346,11 @@ void SwStatsCpu::startFrame(uint32_t frame)\n>   void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId)\n>   {\n>   \tstats_.valid = frame % kStatPerNumFrames == 0;\n> +\tif (stats_.valid && sumShift_) {\n> +\t\tstats_.sum_.r() >>= sumShift_;\n> +\t\tstats_.sum_.g() >>= sumShift_;\n> +\t\tstats_.sum_.b() >>= sumShift_;\n> +\t}\n>   \t*sharedStats_ = stats_;\n>   \tstatsReady.emit(frame, bufferId);\n>   }\n> @@ -405,12 +410,15 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n>   \t\tswitch (bayerFormat.bitDepth) {\n>   \t\tcase 8:\n>   \t\t\tstats0_ = &SwStatsCpu::statsBGGR8Line0;\n> +\t\t\tsumShift_ = 0;\n>   \t\t\treturn 0;\n>   \t\tcase 10:\n>   \t\t\tstats0_ = &SwStatsCpu::statsBGGR10Line0;\n> +\t\t\tsumShift_ = 2;\n>   \t\t\treturn 0;\n>   \t\tcase 12:\n>   \t\t\tstats0_ = &SwStatsCpu::statsBGGR12Line0;\n> +\t\t\tsumShift_ = 4;\n>   \t\t\treturn 0;\n>   \t\t}\n>   \t}\n> @@ -422,6 +430,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n>   \t\t/* Skip every 3th and 4th line, sample every other 2x2 block */\n>   \t\tySkipMask_ = 0x02;\n>   \t\txShift_ = 0;\n> +\t\tsumShift_ = 0;\n\nI quickly tested this series on a Fairphone 5 where this code path is \nused and to me using 0 looks correct with a (guessed) BL value of 4096. \nI'm just slightly confused why that is, given the 10bit format. Do you \nknow / could you very shortly explain what I'm missing here? Or is it \npossible that we actually should use a shift of 2 here?\n\n>   \t\tprocessFrame_ = &SwStatsCpu::processBayerFrame2;\n>   \n>   \t\tswitch (bayerFormat.order) {\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 6CCF5BE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Mar 2026 12:45:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 86F7C620FA;\n\tFri,  6 Mar 2026 13:45:41 +0100 (CET)","from sender4-op-o12.zoho.com (sender4-op-o12.zoho.com\n\t[136.143.188.12])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0295C620FA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2026 13:45:39 +0100 (CET)","by mx.zohomail.com with SMTPS id 1772801132751158.47494181326942; \n\tFri, 6 Mar 2026 04:45:32 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=collabora.com\n\theader.i=robert.mader@collabora.com header.b=\"JE7Nk5r7\"; \n\tdkim-atps=neutral","ARC-Seal":"i=1; a=rsa-sha256; t=1772801135; cv=none; \n\td=zohomail.com; s=zohoarc; \n\tb=Kv/x2eqB68N9ZsKOzB3qett+nsQVRstZ0cx4H4xj1Mr3EY2sWo9rKTFhYOpeqFEAVZ7SISAtEG8g3sPvUmfCtJaW0hwLEWOfskM34a8L5ttWoVb+gVCrjQT9aI0PA767EZ/unsJfudIgRPy4VRmOhJEOA156JNLV/5nwvImG+08=","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; \n\ts=zohoarc; t=1772801135;\n\th=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc;\n\tbh=TUATWAhN+3SgUvoFXPHNBqTWVOOUbVLaWXblyWjERjU=; \n\tb=mbYJWkV70lQIfanvOBxwbJW0NaZBchnvkn0ENQfjy3Bxnz86+aHg+f54Tm6AiP2geJL4OEHou4fskXIf/w0eTwxkxm+DsDjVWKL4omtvXTd08MdRemJiS3vmLVO93ky8E3EDUutHMdc0U/O169NkJkFhjVKqKcTei9hwVNyiW6g=","ARC-Authentication-Results":"i=1; mx.zohomail.com;\n\tdkim=pass  header.i=collabora.com;\n\tspf=pass  smtp.mailfrom=robert.mader@collabora.com;\n\tdmarc=pass header.from=<robert.mader@collabora.com>","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1772801135;\n\ts=zohomail; d=collabora.com; i=robert.mader@collabora.com;\n\th=Message-ID:Date:Date:MIME-Version:Subject:Subject:To:To:References:From:From:In-Reply-To:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To:Cc;\n\tbh=TUATWAhN+3SgUvoFXPHNBqTWVOOUbVLaWXblyWjERjU=;\n\tb=JE7Nk5r7W4clj1Kxjnz9KtzDY2C7J2Jkfad0LqbFZeBvE/j4e+LnxljvYkFm5MP2\n\tT+R2ohPXy1AQG2+v5R7S7MOxxtl2ZrRMANUx32J06TQVPd9fd9qSceWfO38TEZSD3Iz\n\tm9avcnd106VMdekXdejvZUHdAaujE9Tok+0VQF70=","Message-ID":"<04dab226-2edf-4aa3-ac4d-f4431764bb2c@collabora.com>","Date":"Fri, 6 Mar 2026 13:45:30 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 2/3] libcamera: software_isp: Normalize statistics\n\tsums to 8-bit","To":"libcamera-devel@lists.libcamera.org","References":"<20260305-agc-proportional-v3-0-25abc1bfacca@jetm.me>\n\t<20260305-agc-proportional-v3-2-25abc1bfacca@jetm.me>","Content-Language":"en-US, de-DE","From":"Robert Mader <robert.mader@collabora.com>","In-Reply-To":"<20260305-agc-proportional-v3-2-25abc1bfacca@jetm.me>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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":38344,"web_url":"https://patchwork.libcamera.org/comment/38344/","msgid":"<7d1710b2-5829-45c5-be33-2322b0371b09@ideasonboard.com>","date":"2026-03-06T12:49:46","subject":"Re: [PATCH v3 2/3] libcamera: software_isp: Normalize statistics\n\tsums to 8-bit","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2026. 03. 06. 13:45 keltezéssel, Robert Mader írta:\n> Hi, thanks for the patch!\n> \n> On 05.03.26 21:10, Javier Tia wrote:\n>> The SWSTATS_ACCUMULATE_LINE_STATS() macro divides the luminance value\n>> for the histogram to normalize it to 8-bit range, but does not apply\n>> the same normalization to the RGB sums. For 10-bit and 12-bit unpacked\n>> Bayer formats this means the sums are accumulated at native bit depth\n>> (0-1023 or 0-4095 per pixel) while the AWB algorithm subtracts an\n>> 8-bit black level from them, under-correcting by 4x or 16x\n>> respectively.\n>>\n>> This mismatch between the AWB's gain calculation (using incorrectly\n>> BLC-subtracted sums) and the debayer's correct normalized BLC\n>> subtraction produces a visible color cast. For example, with the\n>> OV2740 sensor (10-bit, BLC=16), the under-subtraction skews R/G gain\n>> by ~9%.\n>>\n>> Fix this by right-shifting the RGB sums in finishFrame() to normalize\n>> them to 8-bit scale, matching the histogram and the 8-bit black level\n>> used by AWB. A per-format sumShift_ value is set in configure():\n>> 0 for 8-bit and CSI-2 packed formats (already 8-bit), 2 for 10-bit,\n>> and 4 for 12-bit unpacked formats.\n>>\n>> Signed-off-by: Javier Tia <floss@jetm.me>\n>> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>\n>> Tested-by: Milan Zamazal <mzamazal@redhat.com>\n>> ---\n>>   include/libcamera/internal/software_isp/swstats_cpu.h | 1 +\n>>   src/libcamera/software_isp/swstats_cpu.cpp            | 9 +++++++++\n>>   2 files changed, 10 insertions(+)\n>>\n>> diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\n>> index 64b3e23f..37bfde53 100644\n>> --- a/include/libcamera/internal/software_isp/swstats_cpu.h\n>> +++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n>> @@ -115,6 +115,7 @@ private:\n>>       unsigned int xShift_;\n>>       unsigned int stride_;\n>> +    unsigned int sumShift_;\n>>       SharedMemObject<SwIspStats> sharedStats_;\n>>       SwIspStats stats_;\n>> diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n>> index 1cedcfbc..6f834207 100644\n>> --- a/src/libcamera/software_isp/swstats_cpu.cpp\n>> +++ b/src/libcamera/software_isp/swstats_cpu.cpp\n>> @@ -346,6 +346,11 @@ void SwStatsCpu::startFrame(uint32_t frame)\n>>   void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId)\n>>   {\n>>       stats_.valid = frame % kStatPerNumFrames == 0;\n>> +    if (stats_.valid && sumShift_) {\n>> +        stats_.sum_.r() >>= sumShift_;\n>> +        stats_.sum_.g() >>= sumShift_;\n>> +        stats_.sum_.b() >>= sumShift_;\n>> +    }\n>>       *sharedStats_ = stats_;\n>>       statsReady.emit(frame, bufferId);\n>>   }\n>> @@ -405,12 +410,15 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n>>           switch (bayerFormat.bitDepth) {\n>>           case 8:\n>>               stats0_ = &SwStatsCpu::statsBGGR8Line0;\n>> +            sumShift_ = 0;\n>>               return 0;\n>>           case 10:\n>>               stats0_ = &SwStatsCpu::statsBGGR10Line0;\n>> +            sumShift_ = 2;\n>>               return 0;\n>>           case 12:\n>>               stats0_ = &SwStatsCpu::statsBGGR12Line0;\n>> +            sumShift_ = 4;\n>>               return 0;\n>>           }\n>>       }\n>> @@ -422,6 +430,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n>>           /* Skip every 3th and 4th line, sample every other 2x2 block */\n>>           ySkipMask_ = 0x02;\n>>           xShift_ = 0;\n>> +        sumShift_ = 0;\n> \n> I quickly tested this series on a Fairphone 5 where this code path is used and to me using 0 looks correct with a (guessed) BL value of 4096. I'm just slightly confused why that is, given the 10bit format. Do you know / could you very shortly explain what I'm missing here? Or is it possible that we actually should use a shift of 2 here?\n\nI think that's because when processing CSI2 packed data, the 2\nleast significant bits are dropped, so it is essentially 8-bit.\n\n\nRegards,\nBarnabás Pőcze\n\n> \n>>           processFrame_ = &SwStatsCpu::processBayerFrame2;\n>>           switch (bayerFormat.order) {\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 932BBBE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Mar 2026 12:49:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6869D625FC;\n\tFri,  6 Mar 2026 13:49:51 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4DB5D620FA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2026 13:49:50 +0100 (CET)","from [192.168.33.103] (185.182.214.224.nat.pool.zt.hu\n\t[185.182.214.224])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 240F2591;\n\tFri,  6 Mar 2026 13:48:46 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"J7UmCzsF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1772801326;\n\tbh=zvC0mYiArW2gkq5QgW37xPNfWqQL12fHM/EvwTWS60Y=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=J7UmCzsFeUAs0MoS9N9poaPiwx0FGaq4xLYnS8VJtIgvx72Uul6euQBelpb3Ob4a3\n\tOFOeR+cuvS9IsZixRhkWtKlGOvCfVXWFs26Z+lTk1EI0rywsFDHoS3pA3BGmZOB+8b\n\tE4WgHmnrkYwWjn9wyh0BDzZ3HqFTqfo1WjUY7kBY=","Message-ID":"<7d1710b2-5829-45c5-be33-2322b0371b09@ideasonboard.com>","Date":"Fri, 6 Mar 2026 13:49:46 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 2/3] libcamera: software_isp: Normalize statistics\n\tsums to 8-bit","To":"Robert Mader <robert.mader@collabora.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20260305-agc-proportional-v3-0-25abc1bfacca@jetm.me>\n\t<20260305-agc-proportional-v3-2-25abc1bfacca@jetm.me>\n\t<04dab226-2edf-4aa3-ac4d-f4431764bb2c@collabora.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<04dab226-2edf-4aa3-ac4d-f4431764bb2c@collabora.com>","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":38347,"web_url":"https://patchwork.libcamera.org/comment/38347/","msgid":"<9f91f55e-7af0-4e97-8ef9-1b86cd4260f4@ideasonboard.com>","date":"2026-03-06T15:23:19","subject":"Re: [PATCH v3 2/3] libcamera: software_isp: Normalize statistics\n\tsums to 8-bit","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2026. 03. 05. 21:10 keltezéssel, Javier Tia írta:\n> The SWSTATS_ACCUMULATE_LINE_STATS() macro divides the luminance value\n> for the histogram to normalize it to 8-bit range, but does not apply\n> the same normalization to the RGB sums. For 10-bit and 12-bit unpacked\n> Bayer formats this means the sums are accumulated at native bit depth\n> (0-1023 or 0-4095 per pixel) while the AWB algorithm subtracts an\n> 8-bit black level from them, under-correcting by 4x or 16x\n> respectively.\n> \n> This mismatch between the AWB's gain calculation (using incorrectly\n> BLC-subtracted sums) and the debayer's correct normalized BLC\n> subtraction produces a visible color cast. For example, with the\n> OV2740 sensor (10-bit, BLC=16), the under-subtraction skews R/G gain\n> by ~9%.\n> \n> Fix this by right-shifting the RGB sums in finishFrame() to normalize\n> them to 8-bit scale, matching the histogram and the 8-bit black level\n> used by AWB. A per-format sumShift_ value is set in configure():\n> 0 for 8-bit and CSI-2 packed formats (already 8-bit), 2 for 10-bit,\n> and 4 for 12-bit unpacked formats.\n> \n> Signed-off-by: Javier Tia <floss@jetm.me>\n> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>\n> Tested-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>   include/libcamera/internal/software_isp/swstats_cpu.h | 1 +\n>   src/libcamera/software_isp/swstats_cpu.cpp            | 9 +++++++++\n>   2 files changed, 10 insertions(+)\n> \n> diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\n> index 64b3e23f..37bfde53 100644\n> --- a/include/libcamera/internal/software_isp/swstats_cpu.h\n> +++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n> @@ -115,6 +115,7 @@ private:\n>   \n>   \tunsigned int xShift_;\n>   \tunsigned int stride_;\n> +\tunsigned int sumShift_;\n>   \n>   \tSharedMemObject<SwIspStats> sharedStats_;\n>   \tSwIspStats stats_;\n> diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n> index 1cedcfbc..6f834207 100644\n> --- a/src/libcamera/software_isp/swstats_cpu.cpp\n> +++ b/src/libcamera/software_isp/swstats_cpu.cpp\n> @@ -346,6 +346,11 @@ void SwStatsCpu::startFrame(uint32_t frame)\n>   void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId)\n>   {\n>   \tstats_.valid = frame % kStatPerNumFrames == 0;\n> +\tif (stats_.valid && sumShift_) {\n> +\t\tstats_.sum_.r() >>= sumShift_;\n> +\t\tstats_.sum_.g() >>= sumShift_;\n> +\t\tstats_.sum_.b() >>= sumShift_;\n> +\t}\n>   \t*sharedStats_ = stats_;\n>   \tstatsReady.emit(frame, bufferId);\n>   }\n> @@ -405,12 +410,15 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n>   \t\tswitch (bayerFormat.bitDepth) {\n>   \t\tcase 8:\n>   \t\t\tstats0_ = &SwStatsCpu::statsBGGR8Line0;\n> +\t\t\tsumShift_ = 0;\n>   \t\t\treturn 0;\n>   \t\tcase 10:\n>   \t\t\tstats0_ = &SwStatsCpu::statsBGGR10Line0;\n> +\t\t\tsumShift_ = 2;\n>   \t\t\treturn 0;\n>   \t\tcase 12:\n>   \t\t\tstats0_ = &SwStatsCpu::statsBGGR12Line0;\n> +\t\t\tsumShift_ = 4;\n>   \t\t\treturn 0;\n>   \t\t}\n\nThe above could probably just be `sumShift_ = bayerFormat.bitDepth - 8`, no?\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nTested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> # ThinkPad X1 Yoga Gen 7 + ov2740\n\n\n>   \t}\n> @@ -422,6 +430,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n>   \t\t/* Skip every 3th and 4th line, sample every other 2x2 block */\n>   \t\tySkipMask_ = 0x02;\n>   \t\txShift_ = 0;\n> +\t\tsumShift_ = 0;\n>   \t\tprocessFrame_ = &SwStatsCpu::processBayerFrame2;\n>   \n>   \t\tswitch (bayerFormat.order) {\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 1CCA7BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Mar 2026 15:23:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4DD8D6261B;\n\tFri,  6 Mar 2026 16:23:24 +0100 (CET)","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 4D87A6260B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2026 16:23:22 +0100 (CET)","from [192.168.33.103] (185.182.214.224.nat.pool.zt.hu\n\t[185.182.214.224])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 39172874;\n\tFri,  6 Mar 2026 16:22:18 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"VSqpPtOZ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1772810538;\n\tbh=bOby3CqKBa3VDz0er+N96GxzyGM8MmDwkHLlMkptad0=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=VSqpPtOZs1LJB3OwcSNsM5TbdYMuxgkFiMglvDUpjSPZCFkpWldUPurWEkT4cXGzN\n\tpfg2Gf6dGpTB5lJ7QtX0v5h8CxgY3gQd7dOw/jV3rxtYizc0RmOSe3DYb7j4PUaCu7\n\tarKna0pGi4N0xtvItIHYtx18UOSrusilTxbe+Xms=","Message-ID":"<9f91f55e-7af0-4e97-8ef9-1b86cd4260f4@ideasonboard.com>","Date":"Fri, 6 Mar 2026 16:23:19 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 2/3] libcamera: software_isp: Normalize statistics\n\tsums to 8-bit","To":"Javier Tia <floss@jetm.me>, libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>","References":"<20260305-agc-proportional-v3-0-25abc1bfacca@jetm.me>\n\t<20260305-agc-proportional-v3-2-25abc1bfacca@jetm.me>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20260305-agc-proportional-v3-2-25abc1bfacca@jetm.me>","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>"}}]