From 01db040717b3f6179d2f7644d7f175466d10f994 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Mon, 3 Aug 2026 12:08:28 +0100 Subject: [PATCH] Correct SIXEL HLS colour conversion Use the DEC hue origin and channel order, and round percentage and HLS conversions to the nearest byte value. --- image-sixel.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/image-sixel.c b/image-sixel.c index 577ba51a1..e2ab71307 100644 --- a/image-sixel.c +++ b/image-sixel.c @@ -429,9 +429,9 @@ sixel_colour_to_rgb(u_int colour, u_char *r, u_char *g, u_char *b) double h, l, s, p, q; if (type == 2) { - *r = ((colour >> 16) & 0x1ff) * 255 / 100; - *g = ((colour >> 8) & 0xff) * 255 / 100; - *b = (colour & 0xff) * 255 / 100; + *r = (((colour >> 16) & 0xff) * 255 + 50) / 100; + *g = (((colour >> 8) & 0xff) * 255 + 50) / 100; + *b = ((colour & 0xff) * 255 + 50) / 100; return; } if (type != 1) { @@ -443,14 +443,15 @@ sixel_colour_to_rgb(u_int colour, u_char *r, u_char *g, u_char *b) l = ((colour >> 8) & 0xff) / 100.0; s = (colour & 0xff) / 100.0; if (s == 0) { - *r = *g = *b = l * 255; + *r = *g = *b = l * 255 + 0.5; return; } q = l < 0.5 ? l * (1 + s) : l + s - l * s; p = 2 * l - q; - *r = sixel_hue(p, q, h + 1.0 / 3) * 255; - *g = sixel_hue(p, q, h) * 255; - *b = sixel_hue(p, q, h - 1.0 / 3) * 255; + /* SIXEL HLS has blue at 0, red at 120 and green at 240 degrees. */ + *r = sixel_hue(p, q, h) * 255 + 0.5; + *g = sixel_hue(p, q, h - 1.0 / 3) * 255 + 0.5; + *b = sixel_hue(p, q, h + 1.0 / 3) * 255 + 0.5; } /* Convert decoded SIXEL data into the protocol-neutral immutable image. */