From patchwork Tue Mar 4 23:12:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 22923 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 B5C95C32DD for ; Tue, 4 Mar 2025 23:13:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BE8E68822; Wed, 5 Mar 2025 00:13:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="r/s3Za8x"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9D36868779 for ; Wed, 5 Mar 2025 00:13:26 +0100 (CET) Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DCB18BF; Wed, 5 Mar 2025 00:11:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741129914; bh=M4g1KD9fiAFPc9xaV9pfUdioKxsL21IDwnRxjN/imlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r/s3Za8x94pjet9VVb+CPXBRRJucvRoYXkqrVL486dZ5n6V4Lnp5Y9PIF5v0RoMIt Zlm73CDL3qG8rB/i0y3hOrhtlQx9HnpaRRGPhQseCW9zUHveuxpIMPP8xvCnZxa+qg sRh0kbtXthQ3wmhuC/Lw++oqQRXc9Ozw06vK2VhU= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH 2/3] libtuning: Gradient: Correct Linear distribution Date: Tue, 4 Mar 2025 23:12:53 +0000 Message-Id: <20250304231254.10588-3-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250304231254.10588-1-dan.scally@ideasonboard.com> References: <20250304231254.10588-1-dan.scally@ideasonboard.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 Linear distributor attempts to distribute pixels into sectors of even size. Where the image width doesn't allow this it attempts to create all but one sector of full size, and allows the caller to choose to have the stunted sector at the front or the back. The implicit assumption is that domain == (sector_size * (n_sectors - 1)) + remainder which does not necessarily hold true. For example with 32 sectors and a domain of 648 the calculated sector size will be 21 pixels, which leads to 31 * 21 = 651 which is larger than the domain size. Correct the issue by checking if there's more one stunted sector to be filled. If there is, rather than following the remainder hint for distribution place one of the stunted sectors at the front and one at the back. Signed-off-by: Daniel Scally --- utils/tuning/libtuning/gradient.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/utils/tuning/libtuning/gradient.py b/utils/tuning/libtuning/gradient.py index b643f502..bb2edef2 100644 --- a/utils/tuning/libtuning/gradient.py +++ b/utils/tuning/libtuning/gradient.py @@ -55,17 +55,23 @@ class Linear(Gradient): size = math.ceil(size) rem = domain % size - output_sectors = [int(size)] * (sectors - 1) + n_full_sectors = math.floor(domain / size) + output_sectors = [int(size)] * n_full_sectors if self.remainder == lt.Remainder.Float: size = domain / sectors output_sectors = [size] * sectors - elif self.remainder == lt.Remainder.DistributeFront: + elif ((sectors - n_full_sectors) == 1): + if self.remainder == lt.Remainder.DistributeFront: + output_sectors.append(int(rem)) + elif self.remainder == lt.Remainder.DistributeBack: + output_sectors.insert(0, int(rem)) + else: + raise ValueError + else: + rem = rem / 2 output_sectors.append(int(rem)) - elif self.remainder == lt.Remainder.DistributeBack: output_sectors.insert(0, int(rem)) - else: - raise ValueError return output_sectors