Re: [hackers] [st][PATCH] Fix truecolor being slightly inaccurate

From: Viktor Grigorov <vlg_AT_tutamail.com>
Date: Mon, 7 Mar 2022 13:38:24 +0100 (CET)

I get #ffffff as well.

Mar 6, 2022, 15:07 by yyt16384_AT_gmail.com:

> The displayed color in truecolor mode is sometimes darker than
> requested. The inaccuracy can be verified with the following example,
> which should paint a white block but instead produces color #fefefe.
>
> printf '\e[38;2;255;255;255m\u2588\u2588\u2588\n'
>
> The truecolor code uses 8-bit color values (0 to 0xff), while X uses
> 16-bit color values (0 to 0xffff). Existing code multiplies the value by
> 256 to make the conversion, but this is incorrect, as it maps 0xff to
> 0xff00, not 0xffff. This patch multiplies the value by 257 instead,
> which is the correct formula (0xff * 257 == 0xffff).
> ---
> x.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/x.c b/x.c
> index cd96575..f012539 100644
> --- a/x.c
> +++ b/x.c
> _AT_@ -69,9 +69,9 @@ static void ttysend(const Arg *);
>
> /* macros */
> #define IS_SET(flag) ((win.mode & (flag)) != 0)
> -#define TRUERED(x) (((x) & 0xff0000) >> 8)
> -#define TRUEGREEN(x) (((x) & 0xff00))
> -#define TRUEBLUE(x) (((x) & 0xff) << 8)
> +#define TRUERED(x) ((((x) & 0xff0000) >> 16) * 257)
> +#define TRUEGREEN(x) ((((x) & 0xff00) >> 8) * 257)
> +#define TRUEBLUE(x) ((((x) & 0xff)) * 257)
>
> typedef XftDraw *Draw;
> typedef XftColor Color;
> --
> 2.35.0
>
Received on Mon Mar 07 2022 - 13:38:24 CET

This archive was generated by hypermail 2.3.0 : Mon Mar 07 2022 - 13:48:38 CET