{"id":22923,"url":"https://patchwork.libcamera.org/api/patches/22923/?format=json","web_url":"https://patchwork.libcamera.org/patch/22923/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250304231254.10588-3-dan.scally@ideasonboard.com>","date":"2025-03-04T23:12:53","name":"[2/3] libtuning: Gradient: Correct Linear distribution","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a5510890d6e8afdef0adb11ca11dd410274e8e8e","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/?format=json","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22923/mbox/","series":[{"id":5045,"url":"https://patchwork.libcamera.org/api/series/5045/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5045","date":"2025-03-04T23:12:51","name":"Add Mali-C55 Tuning Script","version":1,"mbox":"https://patchwork.libcamera.org/series/5045/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22923/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22923/checks/","tags":{},"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 B5C95C32DD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  4 Mar 2025 23:13:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8BE8E68822;\n\tWed,  5 Mar 2025 00:13:30 +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 9D36868779\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Mar 2025 00:13:26 +0100 (CET)","from mail.ideasonboard.com\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DCB18BF;\n\tWed,  5 Mar 2025 00:11:54 +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=\"r/s3Za8x\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1741129914;\n\tbh=M4g1KD9fiAFPc9xaV9pfUdioKxsL21IDwnRxjN/imlk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=r/s3Za8x94pjet9VVb+CPXBRRJucvRoYXkqrVL486dZ5n6V4Lnp5Y9PIF5v0RoMIt\n\tZlm73CDL3qG8rB/i0y3hOrhtlQx9HnpaRRGPhQseCW9zUHveuxpIMPP8xvCnZxa+qg\n\tsRh0kbtXthQ3wmhuC/Lw++oqQRXc9Ozw06vK2VhU=","From":"Daniel Scally <dan.scally@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Daniel Scally <dan.scally@ideasonboard.com>","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","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>"},"content":"The Linear distributor attempts to distribute pixels into sectors\nof even size. Where the image width doesn't allow this it attempts\nto create all but one sector of full size, and allows the caller\nto choose to have the stunted sector at the front or the back. The\nimplicit assumption is that\n\n\tdomain == (sector_size * (n_sectors - 1)) + remainder\n\nwhich does not necessarily hold true. For example with 32 sectors and\na domain of 648 the calculated sector size will be 21 pixels, which\nleads to 31 * 21 = 651 which is larger than the domain size.\n\nCorrect the issue by checking if there's more one stunted sector to\nbe filled. If there is, rather than following the remainder hint for\ndistribution place one of the stunted sectors at the front and one at\nthe back.\n\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\n utils/tuning/libtuning/gradient.py | 16 +++++++++++-----\n 1 file changed, 11 insertions(+), 5 deletions(-)","diff":"diff --git a/utils/tuning/libtuning/gradient.py b/utils/tuning/libtuning/gradient.py\nindex b643f502..bb2edef2 100644\n--- a/utils/tuning/libtuning/gradient.py\n+++ b/utils/tuning/libtuning/gradient.py\n@@ -55,17 +55,23 @@ class Linear(Gradient):\n \n         size = math.ceil(size)\n         rem = domain % size\n-        output_sectors = [int(size)] * (sectors - 1)\n+        n_full_sectors = math.floor(domain / size)\n+        output_sectors = [int(size)] * n_full_sectors\n \n         if self.remainder == lt.Remainder.Float:\n             size = domain / sectors\n             output_sectors = [size] * sectors\n-        elif self.remainder == lt.Remainder.DistributeFront:\n+        elif ((sectors - n_full_sectors) == 1):\n+            if self.remainder == lt.Remainder.DistributeFront:\n+                output_sectors.append(int(rem))\n+            elif self.remainder == lt.Remainder.DistributeBack:\n+                output_sectors.insert(0, int(rem))\n+            else:\n+                raise ValueError\n+        else:\n+            rem = rem / 2\n             output_sectors.append(int(rem))\n-        elif self.remainder == lt.Remainder.DistributeBack:\n             output_sectors.insert(0, int(rem))\n-        else:\n-            raise ValueError\n \n         return output_sectors\n \n","prefixes":["2/3"]}