[{"id":34073,"web_url":"https://patchwork.libcamera.org/comment/34073/","msgid":"<CAEmqJPo6co5yL5R59xUL0d5f+NCfb1RfRGDbLKtbJJRhoHQmrQ@mail.gmail.com>","date":"2025-04-28T13:20:26","subject":"Re: [PATCH 1/2] utils: raspberrypi: ctt: Fix NaNs in lens shading\n\ttables","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\nOn Mon, 28 Apr 2025 at 11:36, David Plowman\n<david.plowman@raspberrypi.com> wrote:\n>\n> The problem occurs when the calculation could lead to a final row (or\n> column) of grid squares with no pixels in them (and hence, NaNs).\n>\n> One specific case is a Pi 5 with an image width (or height) of 1364,\n> so that's 682 Bayer quads. To give 32 grid squares it was calculating\n> 22 quads per cell. However, 31 * 22 = 682 leaving nothing in the final\n> column.\n>\n> The fix is to do a rounding-down division by the number of cells minus\n> one, rather than a rounding-up division by the number of cells. This\n> turns the corner case from one where the final row/column has no\n> pixels to one where we don't quite cover the full image, which is how\n> we have to handle these cases.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n> ---\n>  utils/raspberrypi/ctt/ctt_alsc.py | 7 ++++---\n>  1 file changed, 4 insertions(+), 3 deletions(-)\n>\n> diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py\n> index 1d94dfa5..f4fd09e3 100644\n> --- a/utils/raspberrypi/ctt/ctt_alsc.py\n> +++ b/utils/raspberrypi/ctt/ctt_alsc.py\n> @@ -127,11 +127,12 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12), max_gain=8.0)\n>      channels = [Img.channels[i] for i in Img.order]\n>      \"\"\"\n>      calculate size of single rectangle.\n> -    -(-(w-1)//32) is a ceiling division. w-1 is to deal robustly with the case\n> -    where w is a multiple of 32.\n> +    The divisions here must ensure the final row/column of cells has a non-zero number of\n> +    pixels.\n>      \"\"\"\n>      w, h = Img.w/2, Img.h/2\n> -    dx, dy = int(-(-(w-1)//grid_w)), int(-(-(h-1)//grid_h))\n> +    dx, dy = (w - 1) // (grid_w - 1), (h - 1) // (grid_h - 1)\n> +\n>      \"\"\"\n>      average the green channels into one\n>      \"\"\"\n> --\n> 2.34.1\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":["parsemail@patchwork.libcamera.org","kbingham@ideasonboard.com"],"Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C40CABE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Apr 2025 15:09:57 +0000 (UTC)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net\n\t[86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D5CF7AF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Apr 2025 17:09:51 +0200 (CEST)","from perceval.ideasonboard.com\n\tby perceval.ideasonboard.com with LMTP id Y3MuIrmAD2jKkDMA4E0KoQ\n\t(envelope-from <libcamera-devel-bounces@lists.libcamera.org>)\n\tfor <kbingham@ideasonboard.com>; Mon, 28 Apr 2025 15:20:57 +0200","from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\tby perceval.ideasonboard.com (Postfix) with ESMTPS\n\tid 56CC41E3;\tMon, 28 Apr 2025 15:20:57 +0200 (CEST)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2FE0068AD8;\n\tMon, 28 Apr 2025 15:21:01 +0200 (CEST)","from mail-ua1-x932.google.com (mail-ua1-x932.google.com\n\t[IPv6:2607:f8b0:4864:20::932])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EB5668AD0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Apr 2025 15:20:59 +0200 (CEST)","by mail-ua1-x932.google.com with SMTP id\n\ta1e0cc1a2514c-86cd8bcd8dfso142976241.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Apr 2025 06:20:59 -0700 (PDT)"],"Authentication-Results":["perceval.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.a=rsa-sha256 header.s=google header.b=jheSIDV7; \n\tdkim-atps=neutral","lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"jheSIDV7\";\tdkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1745846458; x=1746451258;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=MU60HGfd1JsKNCRCH3FGwUjtdd/q+BGfpyo99zNljTc=;\n\tb=jheSIDV7Avs1hA4aVgkqpEoSRkwRA/KQSfWKDwFXO1xR49X9xhFQzj6gYsiNhDk9bj\n\thd1/crO6MhmR9pH7cgfgSQZvDEt+Un7tWg5vPl5+KnzQmnsMD4qNGYeRMl9kxsPs8PNj\n\t35jEflL/Cp610QNLDJboS5sPt7uCUYA8gB2eg2fbSTEk0zMI113OZKA2zd8ByQLAJfcQ\n\tY6c2JJ0jlxitvNpNjSIK0dHj2VI2J1rj3tQQj7z9YRWo+5t+IQ4m9+oKiEYd9YrTd0Pq\n\tkBsBg1jI91D7JdsoXXRxqwK6IWAv95LmVfo8B1HxBZ/xuRJSElJa+nqEduEg6VewVF7P\n\t63yA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1745846458; x=1746451258;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=MU60HGfd1JsKNCRCH3FGwUjtdd/q+BGfpyo99zNljTc=;\n\tb=nvF2ze8PzxgNlBX+vg8sWGRelNoliH8FXmeyW1PL7J9O/zyC8IKJawiiiKoROmrtNH\n\tXKbuzUS25JHiiY5XHQ3Jkqt+NZz97Zco3d+/31P8CRsMlO9HWpXnvFa/gTlclbI7XEwZ\n\tABMgNztGHJafubuhCtxL2f/hZWoS9YtCsjbJLfJz5Dq/9u8fAxASLolkWahRHbUonZZj\n\tk6h8ZOR5Oynweu5yvLgeGMiocBwmKSyUqR0RGfnR6Uvmxw/M3z1R5wUfZ1bCOgay4IR1\n\tX1qZ0hNlXvro8swZoj2M+btMPXAUYVosSUa9h0lATJ8dhOJ91/er1NM+JluHTa6omT+H\n\t/k/g==","X-Gm-Message-State":"AOJu0YxRN6X2R6+j7CDjdnMEo9PF1mZGxc4V0I9Faur9+K0A7c6dUFz0\n\texKeiVqeYWfs7i6gAi8o+zwD9MOnhhuNU9isf3MC07K4koW6sZ4wVakv7mp30G0OacgSe4G5NAf\n\tKilmfYb8HRENnejBuugI0OLuUQpH/gdAwcq/OKg==","X-Gm-Gg":"ASbGncuvl49btTENfoNB2etagvYhQC28oJGhOYsSX31hk7ijUm3vdn81QfQueb4La4A\n\tHoAZ6gC5HUWUHz+1iZtcHq6lDRFH0Tp6goBpgqn3eeIl2SYn2QKEkiHGvVk5JVv8wrDKXgmHJoY\n\t+42ns0GWvWyPY5EjNZpWrg01prgIJZDGKV2BnkMvrhScg1UxbxOZM+2w==","X-Google-Smtp-Source":"=?utf-8?q?AGHT+IH0lDBlZErjArIUw4uqgdDK73CW6SNW2nchx?=\n\t=?utf-8?q?NoJxZfplxu289hj5pdjNOSro96xiKI1G5QdRs5eiWZYM1NT9ao=3D?=","X-Received":"by 2002:a05:6122:3410:b0:520:4f41:b41a with SMTP id\n\t71dfb90a1353d-52a89eff256mr2837954e0c.3.1745846458122;\n\tMon, 28 Apr 2025 06:20:58 -0700 (PDT)","MIME-Version":"1.0","References":"<20250428103604.151551-1-david.plowman@raspberrypi.com>\n\t<20250428103604.151551-2-david.plowman@raspberrypi.com>","In-Reply-To":"<20250428103604.151551-2-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Mon, 28 Apr 2025 14:20:26 +0100","X-Gm-Features":"ATxdqUEqa3q-ujMraaz3pILETAj1B3w7EDDktA8OTvRlja8LSZ6nhcH4Ja7dUDs","Message-ID":"<CAEmqJPo6co5yL5R59xUL0d5f+NCfb1RfRGDbLKtbJJRhoHQmrQ@mail.gmail.com>","Subject":"Re: [PATCH 1/2] utils: raspberrypi: ctt: Fix NaNs in lens shading\n\ttables","To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","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>","X-TUID":"q0JrCBGMvrj9","Resent-From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Resent-To":"parsemail@patchwork.libcamera.org"}},{"id":34074,"web_url":"https://patchwork.libcamera.org/comment/34074/","msgid":"<174584803495.1586992.5613726939290226228@ping.linuxembedded.co.uk>","date":"2025-04-28T13:47:14","subject":"Re: [PATCH 1/2] utils: raspberrypi: ctt: Fix NaNs in lens shading\n\ttables","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2025-04-28 14:20:26)\n> Hi David,\n> \n> On Mon, 28 Apr 2025 at 11:36, David Plowman\n> <david.plowman@raspberrypi.com> wrote:\n> >\n> > The problem occurs when the calculation could lead to a final row (or\n> > column) of grid squares with no pixels in them (and hence, NaNs).\n> >\n> > One specific case is a Pi 5 with an image width (or height) of 1364,\n> > so that's 682 Bayer quads. To give 32 grid squares it was calculating\n> > 22 quads per cell. However, 31 * 22 = 682 leaving nothing in the final\n> > column.\n> >\n> > The fix is to do a rounding-down division by the number of cells minus\n> > one, rather than a rounding-up division by the number of cells. This\n> > turns the corner case from one where the final row/column has no\n> > pixels to one where we don't quite cover the full image, which is how\n> > we have to handle these cases.\n> >\n> > Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> \n> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n\nAcked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nWill merge these two.\n\nWould you like to add any Bug/Fixes reference so it appears in the\nlibcamera release notes ?\n\n--\nKieran\n\n\n\n> \n> > ---\n> >  utils/raspberrypi/ctt/ctt_alsc.py | 7 ++++---\n> >  1 file changed, 4 insertions(+), 3 deletions(-)\n> >\n> > diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py\n> > index 1d94dfa5..f4fd09e3 100644\n> > --- a/utils/raspberrypi/ctt/ctt_alsc.py\n> > +++ b/utils/raspberrypi/ctt/ctt_alsc.py\n> > @@ -127,11 +127,12 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12), max_gain=8.0)\n> >      channels = [Img.channels[i] for i in Img.order]\n> >      \"\"\"\n> >      calculate size of single rectangle.\n> > -    -(-(w-1)//32) is a ceiling division. w-1 is to deal robustly with the case\n> > -    where w is a multiple of 32.\n> > +    The divisions here must ensure the final row/column of cells has a non-zero number of\n> > +    pixels.\n> >      \"\"\"\n> >      w, h = Img.w/2, Img.h/2\n> > -    dx, dy = int(-(-(w-1)//grid_w)), int(-(-(h-1)//grid_h))\n> > +    dx, dy = (w - 1) // (grid_w - 1), (h - 1) // (grid_h - 1)\n> > +\n> >      \"\"\"\n> >      average the green channels into one\n> >      \"\"\"\n> > --\n> > 2.34.1\n> >","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 39314BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Apr 2025 15:10:12 +0000 (UTC)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net\n\t[86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8128B669\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Apr 2025 17:10:06 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1745939406;\n\tbh=FyyTuKuQ4My/v9H9nbTOhludWH4n+0zQVJG2CjZ3nfg=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:Resent-From:\n\tResent-To:From;\n\tb=oKUrHMl/6dSmaJaMCtNDnRkNa6sV7PQsCWSGNpnMFrNdj6lBAoL5fBoNWcpI4fJpT\n\tmCuTgUK8W/S0nP+edsBeqHISm3D0cMUZOIypUGjr70fJpDFZXHmXDewCe7aZr9/1bB\n\ty2EGEoTtrZoNmF3tDzJMq2AsrFDeKKy1TCpr6u1A=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<CAEmqJPo6co5yL5R59xUL0d5f+NCfb1RfRGDbLKtbJJRhoHQmrQ@mail.gmail.com>","References":"<20250428103604.151551-1-david.plowman@raspberrypi.com>\n\t<20250428103604.151551-2-david.plowman@raspberrypi.com>\n\t<CAEmqJPo6co5yL5R59xUL0d5f+NCfb1RfRGDbLKtbJJRhoHQmrQ@mail.gmail.com>","Subject":"Re: [PATCH 1/2] utils: raspberrypi: ctt: Fix NaNs in lens shading\n\ttables","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","To":"David Plowman <david.plowman@raspberrypi.com>,\n\tNaushir Patuck <naush@raspberrypi.com>","Date":"Mon, 28 Apr 2025 14:47:14 +0100","Message-ID":"<174584803495.1586992.5613726939290226228@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","Resent-From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Resent-To":"parsemail@patchwork.libcamera.org"}}]