From bb2b80459f71ccb2270c4eeec9d9e767cbccf49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Alonso?= <242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:55:41 +0100 Subject: [PATCH] fix(graphics): ignore a sixel colour with a component over 100 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #845 Signed-off-by: Álvaro Alonso <242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com> --- CHANGELOG.md | 5 +++++ crates/termlens/src/graphics.rs | 28 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 710021d..08cfc7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,11 @@ reads that marker. ### Fixed +- A sixel colour definition with an RGB component over 100, as an encoder + that writes 0-255 values gives, is ignored and the register keeps its + colour, as xterm does. Each component was clamped to 100 and applied, + so the image decoded in colours xterm never shows. (#845) + - Both published crates, `termlens` and `termlens-cli`, ship `LICENSE-MIT` and `LICENSE-APACHE`. They are `MIT OR Apache-2.0`, and both licences ask for their text in every copy, but the texts sat only at the repository diff --git a/crates/termlens/src/graphics.rs b/crates/termlens/src/graphics.rs index d0f90f1..bc7b4d1 100644 --- a/crates/termlens/src/graphics.rs +++ b/crates/termlens/src/graphics.rs @@ -823,7 +823,8 @@ fn decode_sixel(data: &[u8], background: Option<(u32, u32)>) -> Result u8 { // Sixel colour components are percentages, and the rounding has to - // match what a terminal does or every assertion lands one off. + // match what a terminal does or every assertion lands one off. A + // definition with a component over 100 never gets here. ((value.min(100) * 255 + 50) / 100) as u8 } fn rgb([r, g, b]: [u32; 3]) -> [u8; 4] { @@ -894,7 +895,13 @@ fn decode_sixel(data: &[u8], background: Option<(u32, u32)>) -> Result = (0..bitmap.width()) + .map(|x| bitmap.pixel(x, 0).unwrap()) + .collect(); + assert_eq!(top, [[0, 0, 255, 255]; 3]); + // 100 itself is in range. + let bitmap = sixel_payload(b"#1;2;100;0;0#1~").decode().expect("decodes"); + assert_eq!(bitmap.pixel(0, 0), Some([255, 0, 0, 255])); + } + #[test] fn the_debug_rendering_stays_short_enough_for_a_log() { let payload = kitty_payload(b"a=T,f=32,o=z,s=954,v=133,i=7,c=106,r=7", &[b'A'; 4096]);