From patchwork Mon Apr 28 10:36:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 23293 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A1E8AC32A2 for ; Mon, 28 Apr 2025 10:36:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 81FE268AD3; Mon, 28 Apr 2025 12:36:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Koxsizam"; dkim-atps=neutral Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B028A617E0 for ; Mon, 28 Apr 2025 12:36:08 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-43cf257158fso26079645e9.2 for ; Mon, 28 Apr 2025 03:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1745836568; x=1746441368; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qoRCr89TXl/i3hjgdLgcG0kkBisf6Z3KiLiAat5s6SY=; b=KoxsizamAacy6EB5kZm8sH9fsrK/EL/5/SsgSD4Uhf1Hlah0vgCOgm7/rlA1l/NoyB 3Le2xBAvSkm/o5iHcHnIs5ctWMzyKNgXril7wCMD/pVdZXvSskEuHkBgX8IkY+naZosg 287grTAQbLutlY9r2K+nvuemNnkvZ0hZGeX4N/1PEYMGo+9hRpz2md/lvLrK+pwJJXnP c/tCUOPoIXxZc9G+e8Rj1s7B6DQD9zewWhBM9V78crXBEej2+SedknvWca0tyWdOKogU If8FKxzhJy7O9Ijp4Edw6EXADx0PxDUwleeIRtCW7gIq7jBsIQdAeQqFMiXRMcFG5urv GmhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745836568; x=1746441368; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qoRCr89TXl/i3hjgdLgcG0kkBisf6Z3KiLiAat5s6SY=; b=QTt/VJi6WuUD7b1CanoVlzOo5Xu6Hd7agdyYEW0fgYJnlgJb53C5Vk+XJaCOR4xpWL fiUevx59ru5uzuMBE0hPrZLO+/ae3x0sEAM/TtM4HgfzAPKmZwhvmqhNSf2+MVM5i3ho C2VIKxK1wi1rkJ5Uu+i9PNGDoe4aUu2OukF7G9oD6Aq2EaL8exrNFW5cTNgE0n66Hmi6 aJShMH6H3s5U/o0G9VHKN6dc6kvYEU8ge1w5tpRwEmT2+3yDQArL0dKyJONnKZiJlMsi nNyjMlaVe71dNCW6I4tMixtyhKBMuIC/+816lKptrh9LWwEj/aNMXs8vPG+GhBKO+Y0t YXbw== X-Gm-Message-State: AOJu0YzrWVgVrAJUHBUH3TNrMM0IEzuXeldsiJUSyxCqYyMsxNdGVibJ jXnQ/XC1I3DGW5yKWd/SkD/Z4YuLLbuXeuaZuAnzsPwkWkvlCvNZW7w49cxQQ+OgeR94RPajy2s J X-Gm-Gg: ASbGncsMfJ/SLtxqSg/dZqNvBfxxQwvKqQA5/icovVM5Iq30oUcbNHDcVuQqQXot0kl dSv3bRbmkApAeRkZXVrb6Xv3defMmfoFp0Xu8A6Bic0j/UAsiYFSs6YcbFSKUU+zs9razKwlKrc nNH4D/O9tFathSqeAKYHb0XIXW/aCRFPopgdyv+xxYAwFsW6cw0KSEtKRL0g6ivuEVOTycPSJbS lgHe9HmP0lnNSx70nbeVUnZoKq3ETU1dAD/y4rLy8sqPjMMjJJmdfqIoEn4HxGpyr3MOHLiZjaP WvTF/Hy04duUeRVxIWQfTChuvJ+pZ6cmn5sN/6pzQT4ty3Bn0a/Yk5y/beLGHcwcChMzCDh9KDb bwMWXOH0q/w== X-Google-Smtp-Source: AGHT+IFeC/Qys+/7sF45M/fkHIF2OL1t5xj5tpFJZ8FW6zvHkojyOSceKkwzXx8Kb5JbkZgkEDBZ5A== X-Received: by 2002:a05:600c:a4d:b0:43d:fa58:8377 with SMTP id 5b1f17b1804b1-440ab871ff7mr66062485e9.32.1745836567840; Mon, 28 Apr 2025 03:36:07 -0700 (PDT) Received: from davidp-xps-13.pitowers.org ([2a00:1098:3142:1f:6594:d5bc:c5ae:99b5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4408d04802fsm116243185e9.1.2025.04.28.03.36.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 03:36:07 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH 1/2] utils: raspberrypi: ctt: Fix NaNs in lens shading tables Date: Mon, 28 Apr 2025 11:36:03 +0100 Message-Id: <20250428103604.151551-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250428103604.151551-1-david.plowman@raspberrypi.com> References: <20250428103604.151551-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The problem occurs when the calculation could lead to a final row (or column) of grid squares with no pixels in them (and hence, NaNs). One specific case is a Pi 5 with an image width (or height) of 1364, so that's 682 Bayer quads. To give 32 grid squares it was calculating 22 quads per cell. However, 31 * 22 = 682 leaving nothing in the final column. The fix is to do a rounding-down division by the number of cells minus one, rather than a rounding-up division by the number of cells. This turns the corner case from one where the final row/column has no pixels to one where we don't quite cover the full image, which is how we have to handle these cases. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Acked-by: Kieran Bingham --- utils/raspberrypi/ctt/ctt_alsc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py index 1d94dfa5..f4fd09e3 100644 --- a/utils/raspberrypi/ctt/ctt_alsc.py +++ b/utils/raspberrypi/ctt/ctt_alsc.py @@ -127,11 +127,12 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12), max_gain=8.0) channels = [Img.channels[i] for i in Img.order] """ calculate size of single rectangle. - -(-(w-1)//32) is a ceiling division. w-1 is to deal robustly with the case - where w is a multiple of 32. + The divisions here must ensure the final row/column of cells has a non-zero number of + pixels. """ w, h = Img.w/2, Img.h/2 - dx, dy = int(-(-(w-1)//grid_w)), int(-(-(h-1)//grid_h)) + dx, dy = (w - 1) // (grid_w - 1), (h - 1) // (grid_h - 1) + """ average the green channels into one """