From patchwork Fri Feb 2 06:55:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 195636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp250661dyc; Thu, 1 Feb 2024 22:56:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IENTCAvSU5NDl48E+Fn6GbuCOt3u7wrlDNoEIfWFzATEaEAWrj6mQUvWuv3ayPoVdtTpRQP X-Received: by 2002:a05:620a:22d4:b0:785:478c:ece4 with SMTP id o20-20020a05620a22d400b00785478cece4mr3544386qki.12.1706857009528; Thu, 01 Feb 2024 22:56:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706857009; cv=pass; d=google.com; s=arc-20160816; b=vFoapHj1F5smfQoc8FP6Sy/TdqkKKU8zU6BIT5KLYtWE+uvazzgKkuyhuzZAHLz7AS rbxNxJ0NvkpxO5OjAMBOP/XAV2odUWODBmFJdrBM5g3xKpcrPGoztPrcT/pFLcLwv1+Z 1/MI9i94B0JNvA+ZUM+q9SVClS9QsxjKLYeLaGgWMvkQ3meo83EaEGARzzccI8hSLH7S CrOUSaw2ARQ10JDToRCYuXv7fYt3spp7ckqnsIWC53Sc6xOSTFri4tYTl08y/zlqPekt zTU2b0OvtggDVHq2KyWeE1r4vZvUG++1F6YZcJgpI2sbKlT7LKrRhoh/59GVsCHBWQrk cKGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MtjDizjvjNbFzs5T5EQjvevt0au3cLaYl/EYLWd/EN8=; fh=rU71d9K/uvEk3hGJybyKWTu1IJodyo7AcL1MG7Yz7MA=; b=kssL91rDR8YGEKtvmP7LJhknbPyHPrD+wW6XSDS+8iRcU7VosnBkT+W4NmtiOQEyqe ctUaySJ6YhyCm5x/2j2rnFqoSgIX/vAKAQ7taRyDWYM8qVDUx6y4+hiHVcj7TyhfLoJw NqNY8i1UrvRLGpvyZc18xtHyPMjn3lYVSM3QI5MvjZWMCvkJNKa2KMErfBl5rScPOQrm jJevjqiPPrbQvyECKCptFbkDVV1mXQRE0HYpiVli/C0vFwJUe+F9Xf1makPmVp8KpM6w ByXNYcOrmO3UxDuERLl5alVoigkhQDD5iHWbygc3vDUXzEhrxQrEUm7eKGUnpNpqEWyr DHpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JFgEKrM5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49316-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49316-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUPtgb46ndRdnSG4aMp6H9hdWMVDTgT8/0XM1054u2AYePpduOh1CFzwXJtutbcTyKKLRowEt9pdo9Ly0XV04fdNBFZiw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id po2-20020a05620a384200b007854e0786d0si1332543qkn.648.2024.02.01.22.56.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 22:56:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49316-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JFgEKrM5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49316-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49316-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 414471C21FBA for ; Fri, 2 Feb 2024 06:56:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 609AE17C60; Fri, 2 Feb 2024 06:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JFgEKrM5" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEFD317755; Fri, 2 Feb 2024 06:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706856973; cv=none; b=lXvyu0cAw/xxDKKwHzf07VmWxNQWTg3qq4gUUNWou13Iw/d9CZVqpJMSVOei2lAC3jHrAONXoZvlXfP0lPuwOiVqCpohYu7zZfiJk6gKtSAwx9fpqdjMis0P8xCgmOK00gTkavIkVU/gMXIsIvghaj1OG6jkGcSO+6mb7F49nFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706856973; c=relaxed/simple; bh=zh855z9zkcp82mqscxhofAUAlll2wwDk2/8ndqNudGY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MTKWp91PtU062uDAQloOj43r8LFdxUjzFzi3MzmL6gQcWZ0KqkVq2irigxTshr+K23BMM90DPpBbv90oTHzQ5lH4thbQjGKHcsbg3Rkfa/qgGNuyTeaY7Yd+jX9VGBbYDVRrBE7wVyy35p+OXifXAP9yqrcDnw/RaBYp6RbCUAM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JFgEKrM5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7240BC433C7; Fri, 2 Feb 2024 06:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706856973; bh=zh855z9zkcp82mqscxhofAUAlll2wwDk2/8ndqNudGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JFgEKrM5wTITV5azZ2L6F8afa5eFIYHYdLzpw31YAcYR868VOQ4TDnFbC4fhj2Jmx RfQZ1Hvihyw6XGtCweIMchTGuv+VATe4pmExZ/TxBAUMC70k61HOAVSYYXY9+hpuX2 3nw+vzq4CDMssgtsWrwNqwnUj8TQouzM+NtS8yJJsMdOPG1FwKtJJsgybizSX35u2F 4F5RPgzaYT4+JKrrCZWxUNgkNUTfRTvrYISst3cJ3VLNoJ6nY/iAH+vTf4EA8Etgqg AV3Zpcw/Z9ux2H0JpmqvmSO4/oSCv0HQtpNkVZQEcfuG+eE9SwbTQmPnPqtrMHrXy9 qetFvHcDPPMeg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 01/22] tty: vt: make rgb_from_256() slighly more comprehensible Date: Fri, 2 Feb 2024 07:55:47 +0100 Message-ID: <20240202065608.14019-2-jirislaby@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202065608.14019-1-jirislaby@kernel.org> References: <20240202065608.14019-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789769295462505559 X-GMAIL-MSGID: 1789769295462505559 * make the parameter unsigned, as it is expected to be unsigned, * make the computation easier to follow -- step-by-step, and * don't use 85 / 2 which is only a reduced form of 255 / 6 (by a factor 3). Unlike the former, the latter can be understood. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/vt/vt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 65cd40cac96b..7d42f148559a 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1588,7 +1588,7 @@ static void default_attr(struct vc_data *vc) struct rgb { u8 r; u8 g; u8 b; }; -static void rgb_from_256(int i, struct rgb *c) +static void rgb_from_256(unsigned int i, struct rgb *c) { if (i < 8) { /* Standard colours. */ c->r = i&1 ? 0xaa : 0x00; @@ -1599,9 +1599,12 @@ static void rgb_from_256(int i, struct rgb *c) c->g = i&2 ? 0xff : 0x55; c->b = i&4 ? 0xff : 0x55; } else if (i < 232) { /* 6x6x6 colour cube. */ - c->r = (i - 16) / 36 * 85 / 2; - c->g = (i - 16) / 6 % 6 * 85 / 2; - c->b = (i - 16) % 6 * 85 / 2; + i -= 16; + c->b = i % 6 * 255 / 6; + i /= 6; + c->g = i % 6 * 255 / 6; + i /= 6; + c->r = i * 255 / 6; } else /* Grayscale ramp. */ c->r = c->g = c->b = i * 10 - 2312; }