From 1497cf19f852a5b38bc3e2f3641a81a077ba8a32 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:30:01 -0300 Subject: zstbi: upstream's main, the fork pinned before being gone: Pivok7/zstbi (zig-gamedev/zstbi PR #16, the Zig 0.17 port the manifest waited on) is deleted and a fresh checkout could not fetch it, while upstream has since ported itself (6b9bea1f); its init takes no Io and can fail, and its resize can fail, so TerminalImages.start takes the allocator alone (a start refused leaves PNGs refused, as before one) and a resize that fails is an undecodable PNG; host_io.startWorkers and tape.replayMain lose the Io they only handed on; build.zig's patch of zstbi.c applies unchanged (the file is the same); test: kitty: a PNG longer than 1280 pixels on a side is kept at 1280 (the one path through zstbi, which no case walked: a 1300-pixel one-bit PNG built in the test, its row stored); kitty-test 45 of 45; the changelog says so --- src/TerminalImages.zig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/TerminalImages.zig') diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig index c352c2a4..f8fed78e 100644 --- a/src/TerminalImages.zig +++ b/src/TerminalImages.zig @@ -123,8 +123,9 @@ const max_dim: u32 = 1280; var started = false; /// Once at startup and exit, with what the resize allocates from. -pub fn start(io: std.Io, gpa: std.mem.Allocator) void { - zstbi.init(io, gpa); +pub fn start(gpa: std.mem.Allocator) void { + // Refused only when started twice with a resize still alive: PNGs then stay refused. + zstbi.init(gpa) catch return; started = true; } pub fn stop() void { @@ -149,7 +150,7 @@ fn decodePng(gpa: std.mem.Allocator, bytes: []const u8) ghostty_vt.sys.DecodeErr if (longest <= max_dim) return .{ .width = got.width, .height = got.height, .data = got.data }; defer gpa.free(got.data); const img: zstbi.Image = .{ .data = got.data, .width = got.width, .height = got.height, .num_components = 4, .bytes_per_component = 1, .bytes_per_row = got.width * 4, .is_hdr = false }; - var scaled = img.resize(@intCast(@max(1, @as(u64, got.width) * max_dim / longest)), @intCast(@max(1, @as(u64, got.height) * max_dim / longest))); + var scaled = img.resize(@intCast(@max(1, @as(u64, got.width) * max_dim / longest)), @intCast(@max(1, @as(u64, got.height) * max_dim / longest))) catch return error.InvalidData; defer scaled.deinit(); return .{ .width = scaled.width, .height = scaled.height, .data = gpa.dupe(u8, scaled.data) catch return error.InvalidData }; } -- cgit v1.3