Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp33018imm; Tue, 17 Jul 2018 20:04:53 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfGYIujpG5+bSxuieVJwBlq7y2VT4KMNGNsyEDSY9kUhJrfMzWUtPFNPd4KrdIbwvAX70F0 X-Received: by 2002:a63:d309:: with SMTP id b9-v6mr3983254pgg.163.1531883093026; Tue, 17 Jul 2018 20:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531883092; cv=none; d=google.com; s=arc-20160816; b=zV/7GEi/8u26xbgvLdiNnWUIFrSxZ7tDl9c63Ph89Vjo615hNMKDh8NEbYF+/aFTMW RSPk/eI5VTrNNWO2yXCeqrw2McY6F/M1UAq6/cd1EO8QRjYT36jJHx9MBPzoI1t2BTc7 7o7B5xhRldwST0Ay2Irj8KZhmavYJ3djpHt74ctQ1lOuzuk/sgOeAYErElC2nmnN2ewf s+LXrFVsB+zsXDe4DpT5bAy8G/0I6UzEa21IGmbrI3HH4oHaDvGxWbSa5Q2fD75EVVRY GPF67QobslHmV1d9vv6WCabvVBuJ21xCFNiGk01Inxg7PtDeLUA9rvYgeau6PRpVISkt v9iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=iKl4FP6X3trjv0ysRs/HOuP2JbuqqWJyOMIZ6McdKPE=; b=kSxBif5RzE9Ogi5mZ5oq7j6MlQA6Q7VtFgzBvwGvGkKtO9uKX9gVGvWN7IPwzDGH5j QWfqxGt9Zk1X4HaCaQWa1ivzvvojZ7mNphSiY9SWRSaNXdNOE6nqamotYQwTG+3PLJJX hi/TgDmZLATts9hd1JGj88dsJWdydYuQ9QLGvhQe2hR2ZrJkwBill5CmVUHa0PcsZu8L zK6q9MHr2h2f3cQo0e5a+f4i9MjiIhRPcEknjf7u/8yo+2k0nxvipPxWdLyoO51kSFIB ZHuwJ0K+u/Y5SePyDjmqV48RSRWit0i4EveuvRDna5q0XBuSLODtEgxsXD7Ijo3RXvY4 UAiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z33-v6si2192501plb.380.2018.07.17.20.04.38; Tue, 17 Jul 2018 20:04:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731720AbeGRDjh (ORCPT + 99 others); Tue, 17 Jul 2018 23:39:37 -0400 Received: from tartarus.angband.pl ([89.206.35.136]:37804 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731567AbeGRDj0 (ORCPT ); Tue, 17 Jul 2018 23:39:26 -0400 Received: from 89-71-158-145.dynamic.chello.pl ([89.71.158.145] helo=umbar.angband.pl) by tartarus.angband.pl with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ffckZ-0007zP-KD; Wed, 18 Jul 2018 05:03:41 +0200 Received: from kilobyte by umbar.angband.pl with local (Exim 4.91) (envelope-from ) id 1ffckZ-0000AW-AE; Wed, 18 Jul 2018 05:03:35 +0200 From: Adam Borowski To: Greg Kroah-Hartman , Jiri Slaby , linux-console@vger.kernel.org, Bartlomiej Zolnierkiewicz , linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Adam Borowski Date: Wed, 18 Jul 2018 05:03:27 +0200 Message-Id: <20180718030327.579-6-kilobyte@angband.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180718030327.579-1-kilobyte@angband.pl> References: <20180718030152.kdq53mwpdfusvwl5@angband.pl> <20180718030327.579-1-kilobyte@angband.pl> X-SA-Exim-Connect-IP: 89.71.158.145 X-SA-Exim-Mail-From: kilobyte@angband.pl X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tartarus X-Spam-Level: X-Spam-Status: No, score=-2.9 required=8.0 tests=ALL_TRUSTED=-1,BAYES_00=-1.9, TVD_RCVD_IP=0.001 autolearn=ham autolearn_force=no languages=ro en ca Subject: [PATCH 6/6] vt: support bright backgrounds for \e[48m if unblinking X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on tartarus.angband.pl) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This improves schemes used by fancy new programs. For example, it lets bright powerline segments match, and fixes images shown by catimg being striped to the point of unreadability. Handling of 8-color backgrounds uses stripped 16-color value instead of a dedicated formula; this works worse for dark and better for bright inputs. Signed-off-by: Adam Borowski --- drivers/tty/vt/vt.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index c777f4c91df0..7fcb0ff2dccf 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1555,7 +1555,7 @@ static void rgb_from_256(int i, struct rgb *c) c->r = c->g = c->b = i * 10 - 2312; } -static void rgb_foreground(struct vc_data *vc, const struct rgb *c) +static u8 rgb_to_16(const struct rgb *c) { u8 hue = 0, max = max3(c->r, c->g, c->b); @@ -1566,22 +1566,12 @@ static void rgb_foreground(struct vc_data *vc, const struct rgb *c) if (c->b > max / 2 + 32) hue |= 1; - if (hue == 7 && max <= 0x70) { - hue = 0; - vc->vc_intensity = 2; - } else if (max > 0xc0) - vc->vc_intensity = 2; + if (hue == 7 && max <= 0x70) + return 8; + if (max > 0xc0) + return hue | 8; else - vc->vc_intensity = 1; - - vc->vc_color = (vc->vc_color & 0xf0) | hue; -} - -static void rgb_background(struct vc_data *vc, const struct rgb *c) -{ - /* For backgrounds, err on the dark side. */ - vc->vc_color = (vc->vc_color & 0x0f) - | (c->r&0x80) >> 1 | (c->g&0x80) >> 2 | (c->b&0x80) >> 3; + return hue; } /* @@ -1593,10 +1583,10 @@ static void rgb_background(struct vc_data *vc, const struct rgb *c) * Subcommands 3 (CMY) and 4 (CMYK) are so insane there's no point in * supporting them. */ -static int vc_t416_color(struct vc_data *vc, int i, - void(*set_color)(struct vc_data *vc, const struct rgb *c)) +static int vc_t416_color(struct vc_data *vc, int i, int bgshift) { struct rgb c; + u8 v; i++; if (i > vc->vc_npar) @@ -1615,7 +1605,13 @@ static int vc_t416_color(struct vc_data *vc, int i, } else return i; - set_color(vc, &c); + v = rgb_to_16(&c); + + vc->vc_color = (vc->vc_color & (0xf0 >> bgshift)) | v << bgshift; + if (!bgshift) + vc->vc_intensity = (v & 8 >> 4) + 1; + else if (vc->vc_unblinking) + vc->vc_blink = v & 8 >> 4; return i; } @@ -1695,10 +1691,10 @@ static void csi_m(struct vc_data *vc) vc->vc_reverse = 0; break; case 38: - i = vc_t416_color(vc, i, rgb_foreground); + i = vc_t416_color(vc, i, 0); break; case 48: - i = vc_t416_color(vc, i, rgb_background); + i = vc_t416_color(vc, i, 4); break; case 39: vc->vc_color = (vc->vc_def_color & 0x0f) | -- 2.18.0