[{"id":34952,"web_url":"https://patchwork.libcamera.org/comment/34952/","msgid":"<khh6rmvozdaawhvvbgt34k4gm7xhjv5im5mthbe6deqvkm76n6@2h7d2i6qsajy>","date":"2025-07-21T04:30:21","subject":"Re: [PATCH] libcamera: software_isp: Remove type casts in statistics\n\tcomputation","submitter":{"id":232,"url":"https://patchwork.libcamera.org/api/people/232/","name":"Umang Jain","email":"uajain@igalia.com"},"content":"On Fri, Jul 18, 2025 at 04:44:44PM +0200, Milan Zamazal wrote:\n> Type casting from unsigned int to int performed in stats computation is\n> unnecessary, window_.width is unsigned and the array index is always\n> non-negative.  Let's simply use unsigned int in all the\n> SwStatsCpu:stats* methods.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Umang Jain <uajain@igalia.com>\n\n> ---\n>  src/libcamera/software_isp/swstats_cpu.cpp | 14 +++++++-------\n>  1 file changed, 7 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n> index c520c806e..4b77b3600 100644\n> --- a/src/libcamera/software_isp/swstats_cpu.cpp\n> +++ b/src/libcamera/software_isp/swstats_cpu.cpp\n> @@ -175,7 +175,7 @@ void SwStatsCpu::statsBGGR8Line0(const uint8_t *src[])\n>  \t\tstd::swap(src0, src1);\n>  \n>  \t/* x += 4 sample every other 2x2 block */\n> -\tfor (int x = 0; x < (int)window_.width; x += 4) {\n> +\tfor (unsigned int x = 0; x < window_.width; x += 4) {\n>  \t\tb = src0[x];\n>  \t\tg = src0[x + 1];\n>  \t\tg2 = src1[x];\n> @@ -200,7 +200,7 @@ void SwStatsCpu::statsBGGR10Line0(const uint8_t *src[])\n>  \t\tstd::swap(src0, src1);\n>  \n>  \t/* x += 4 sample every other 2x2 block */\n> -\tfor (int x = 0; x < (int)window_.width; x += 4) {\n> +\tfor (unsigned int x = 0; x < window_.width; x += 4) {\n>  \t\tb = src0[x];\n>  \t\tg = src0[x + 1];\n>  \t\tg2 = src1[x];\n> @@ -226,7 +226,7 @@ void SwStatsCpu::statsBGGR12Line0(const uint8_t *src[])\n>  \t\tstd::swap(src0, src1);\n>  \n>  \t/* x += 4 sample every other 2x2 block */\n> -\tfor (int x = 0; x < (int)window_.width; x += 4) {\n> +\tfor (unsigned int x = 0; x < window_.width; x += 4) {\n>  \t\tb = src0[x];\n>  \t\tg = src0[x + 1];\n>  \t\tg2 = src1[x];\n> @@ -245,7 +245,7 @@ void SwStatsCpu::statsBGGR10PLine0(const uint8_t *src[])\n>  {\n>  \tconst uint8_t *src0 = src[1] + window_.x * 5 / 4;\n>  \tconst uint8_t *src1 = src[2] + window_.x * 5 / 4;\n> -\tconst int widthInBytes = window_.width * 5 / 4;\n> +\tconst unsigned int widthInBytes = window_.width * 5 / 4;\n>  \n>  \tif (swapLines_)\n>  \t\tstd::swap(src0, src1);\n> @@ -253,7 +253,7 @@ void SwStatsCpu::statsBGGR10PLine0(const uint8_t *src[])\n>  \tSWSTATS_START_LINE_STATS(uint8_t)\n>  \n>  \t/* x += 5 sample every other 2x2 block */\n> -\tfor (int x = 0; x < widthInBytes; x += 5) {\n> +\tfor (unsigned int x = 0; x < widthInBytes; x += 5) {\n>  \t\t/* BGGR */\n>  \t\tb = src0[x];\n>  \t\tg = src0[x + 1];\n> @@ -271,7 +271,7 @@ void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src[])\n>  {\n>  \tconst uint8_t *src0 = src[1] + window_.x * 5 / 4;\n>  \tconst uint8_t *src1 = src[2] + window_.x * 5 / 4;\n> -\tconst int widthInBytes = window_.width * 5 / 4;\n> +\tconst unsigned int widthInBytes = window_.width * 5 / 4;\n>  \n>  \tif (swapLines_)\n>  \t\tstd::swap(src0, src1);\n> @@ -279,7 +279,7 @@ void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src[])\n>  \tSWSTATS_START_LINE_STATS(uint8_t)\n>  \n>  \t/* x += 5 sample every other 2x2 block */\n> -\tfor (int x = 0; x < widthInBytes; x += 5) {\n> +\tfor (unsigned int x = 0; x < widthInBytes; x += 5) {\n>  \t\t/* GBRG */\n>  \t\tg = src0[x];\n>  \t\tb = src0[x + 1];\n> -- \n> 2.50.1\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 1E7E1C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Jul 2025 04:30:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 388BE68FBF;\n\tMon, 21 Jul 2025 06:30:18 +0200 (CEST)","from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E3AAC614F6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jul 2025 06:30:15 +0200 (CEST)","from [49.36.71.87] (helo=uajain) by fanzine2.igalia.com with\n\tesmtpsa \n\t(Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256)\n\t(Exim) id 1udiAI-001YdO-Kt; Mon, 21 Jul 2025 06:30:15 +0200"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=igalia.com header.i=@igalia.com\n\theader.b=\"gOVMIOeR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com;\n\ts=20170329;\n\th=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:\n\tSubject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:\n\tList-Post:List-Owner:List-Archive;\n\tbh=pSl1l6OlvkhgE2MpTbKBpSCeIfF0qSMjJPJAzwvnWeM=;\n\tb=gOVMIOeRFkdPQNHsU7h7NH4Hva\n\tWNMYpMFfAt5cLcIAcC/HTMHFRc35m9Bisrl+c1D3+RQ8zRjJlTXRSw7Ro0oFxD+lTxxALUuvI/WSH\n\tRMxo2k3jOsSry6ngV4gmrz6ZDE9YviTPedTjprVBtmBTtlSUfxqDrTs4NSdJX1jw9tvA69tqH0cSQ\n\tDOsjyk5i+50PnRui8F/HB4wXpoplhXMPSvw7tHdWiUq/GQ8FUfz3LJjvHfY+QidiCzxDiPg98nVL/\n\tN2uZX/0yPdS7dfrtcA1Cg7wPX7V4ktfkmDG6cQ44NjtTOQ0OYTDxRX5PXg+trlufxOGCdpBgFPfj+\n\tURyqaynQ==;","Date":"Mon, 21 Jul 2025 10:00:21 +0530","From":"Umang Jain <uajain@igalia.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] libcamera: software_isp: Remove type casts in statistics\n\tcomputation","Message-ID":"<khh6rmvozdaawhvvbgt34k4gm7xhjv5im5mthbe6deqvkm76n6@2h7d2i6qsajy>","References":"<20250718144444.58573-1-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20250718144444.58573-1-mzamazal@redhat.com>","User-Agent":"NeoMutt/20250510-dirty","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":34967,"web_url":"https://patchwork.libcamera.org/comment/34967/","msgid":"<175309720090.50296.3663571457671931615@ping.linuxembedded.co.uk>","date":"2025-07-21T11:26:40","subject":"Re: [PATCH] libcamera: software_isp: Remove type casts in statistics\n\tcomputation","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Umang Jain (2025-07-21 05:30:21)\n> On Fri, Jul 18, 2025 at 04:44:44PM +0200, Milan Zamazal wrote:\n> > Type casting from unsigned int to int performed in stats computation is\n> > unnecessary, window_.width is unsigned and the array index is always\n> > non-negative.  Let's simply use unsigned int in all the\n> > SwStatsCpu:stats* methods.\n> > \n> > Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> \n> Reviewed-by: Umang Jain <uajain@igalia.com>\n> \n\nhttps://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1473924 is\ngreen, so merging.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n> > ---\n> >  src/libcamera/software_isp/swstats_cpu.cpp | 14 +++++++-------\n> >  1 file changed, 7 insertions(+), 7 deletions(-)\n> > \n> > diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n> > index c520c806e..4b77b3600 100644\n> > --- a/src/libcamera/software_isp/swstats_cpu.cpp\n> > +++ b/src/libcamera/software_isp/swstats_cpu.cpp\n> > @@ -175,7 +175,7 @@ void SwStatsCpu::statsBGGR8Line0(const uint8_t *src[])\n> >               std::swap(src0, src1);\n> >  \n> >       /* x += 4 sample every other 2x2 block */\n> > -     for (int x = 0; x < (int)window_.width; x += 4) {\n> > +     for (unsigned int x = 0; x < window_.width; x += 4) {\n> >               b = src0[x];\n> >               g = src0[x + 1];\n> >               g2 = src1[x];\n> > @@ -200,7 +200,7 @@ void SwStatsCpu::statsBGGR10Line0(const uint8_t *src[])\n> >               std::swap(src0, src1);\n> >  \n> >       /* x += 4 sample every other 2x2 block */\n> > -     for (int x = 0; x < (int)window_.width; x += 4) {\n> > +     for (unsigned int x = 0; x < window_.width; x += 4) {\n> >               b = src0[x];\n> >               g = src0[x + 1];\n> >               g2 = src1[x];\n> > @@ -226,7 +226,7 @@ void SwStatsCpu::statsBGGR12Line0(const uint8_t *src[])\n> >               std::swap(src0, src1);\n> >  \n> >       /* x += 4 sample every other 2x2 block */\n> > -     for (int x = 0; x < (int)window_.width; x += 4) {\n> > +     for (unsigned int x = 0; x < window_.width; x += 4) {\n> >               b = src0[x];\n> >               g = src0[x + 1];\n> >               g2 = src1[x];\n> > @@ -245,7 +245,7 @@ void SwStatsCpu::statsBGGR10PLine0(const uint8_t *src[])\n> >  {\n> >       const uint8_t *src0 = src[1] + window_.x * 5 / 4;\n> >       const uint8_t *src1 = src[2] + window_.x * 5 / 4;\n> > -     const int widthInBytes = window_.width * 5 / 4;\n> > +     const unsigned int widthInBytes = window_.width * 5 / 4;\n> >  \n> >       if (swapLines_)\n> >               std::swap(src0, src1);\n> > @@ -253,7 +253,7 @@ void SwStatsCpu::statsBGGR10PLine0(const uint8_t *src[])\n> >       SWSTATS_START_LINE_STATS(uint8_t)\n> >  \n> >       /* x += 5 sample every other 2x2 block */\n> > -     for (int x = 0; x < widthInBytes; x += 5) {\n> > +     for (unsigned int x = 0; x < widthInBytes; x += 5) {\n> >               /* BGGR */\n> >               b = src0[x];\n> >               g = src0[x + 1];\n> > @@ -271,7 +271,7 @@ void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src[])\n> >  {\n> >       const uint8_t *src0 = src[1] + window_.x * 5 / 4;\n> >       const uint8_t *src1 = src[2] + window_.x * 5 / 4;\n> > -     const int widthInBytes = window_.width * 5 / 4;\n> > +     const unsigned int widthInBytes = window_.width * 5 / 4;\n> >  \n> >       if (swapLines_)\n> >               std::swap(src0, src1);\n> > @@ -279,7 +279,7 @@ void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src[])\n> >       SWSTATS_START_LINE_STATS(uint8_t)\n> >  \n> >       /* x += 5 sample every other 2x2 block */\n> > -     for (int x = 0; x < widthInBytes; x += 5) {\n> > +     for (unsigned int x = 0; x < widthInBytes; x += 5) {\n> >               /* GBRG */\n> >               g = src0[x];\n> >               b = src0[x + 1];\n> > -- \n> > 2.50.1\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 BC19EBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Jul 2025 11:26:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AF5CD68FEA;\n\tMon, 21 Jul 2025 13:26:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BFE5E68FD0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jul 2025 13:26:48 +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 CFC7D111F;\n\tMon, 21 Jul 2025 13:26:07 +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=\"rQ+tZeFC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753097167;\n\tbh=K0snQ2dGXr73p6Rj0iC/Xbm8/E3OQM6JITCVE5xTl3k=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=rQ+tZeFC9rn0gGFzQO8cJMg39F6l0hyvoJyVJuAXlR14sjB8/be2Pkz5B+KC9ZRGQ\n\tKTaLRimbxsImTfDYGX4dmpKXgDwhUCR9tPwPPg0e/y7Mga4WFWMPzHzBU5z8Z8et4p\n\tFAEkwhTR/Ur01+hpt2pGgEcQ/+9rya5htyyDPIo0=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<khh6rmvozdaawhvvbgt34k4gm7xhjv5im5mthbe6deqvkm76n6@2h7d2i6qsajy>","References":"<20250718144444.58573-1-mzamazal@redhat.com>\n\t<khh6rmvozdaawhvvbgt34k4gm7xhjv5im5mthbe6deqvkm76n6@2h7d2i6qsajy>","Subject":"Re: [PATCH] libcamera: software_isp: Remove type casts in statistics\n\tcomputation","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","To":"Milan Zamazal <mzamazal@redhat.com>, Umang Jain <uajain@igalia.com>","Date":"Mon, 21 Jul 2025 12:26:40 +0100","Message-ID":"<175309720090.50296.3663571457671931615@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>"}}]