From 86db30785c9310ba5e7f3c7634ea70d0c61df37c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 20 Aug 2026 20:41:57 -0700 Subject: [PATCH] pkg/wuffs: fix gray+alpha to RGBA swizzle failing for all inputs The gaToRgba swizzle requested a YA_PREMUL source pixel format from the wuffs pixel swizzler, but wuffs does not support YA_PREMUL as a swizzle source. As a result, gaToRgba returned error.WuffsError for every input. The path can't happen in Ghostty GUI today since our PNG decoding always produces RGBA, but it is possible via libghostty that submit grey+alpha directly. --- pkg/wuffs/src/swizzle.zig | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/wuffs/src/swizzle.zig b/pkg/wuffs/src/swizzle.zig index 9e7ffa5cb..c1e64b91c 100644 --- a/pkg/wuffs/src/swizzle.zig +++ b/pkg/wuffs/src/swizzle.zig @@ -16,11 +16,15 @@ pub fn gToRgba(alloc: Allocator, src: []const u8) Error![]u8 { } pub fn gaToRgba(alloc: Allocator, src: []const u8) Error![]u8 { + // Wuffs doesn't support YA_PREMUL as a swizzle source. The nonpremul + // pair produces the same bytes (r=g=b=y, a=a, no alpha math), which + // is what we want: alpha semantics are preserved as-is, matching the + // other conversions here. return swizzle( alloc, src, - c.WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL, - c.WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL, + c.WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL, + c.WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL, ); } @@ -51,6 +55,16 @@ pub fn bgraToRgba(alloc: Allocator, src: []const u8) Error![]u8 { ); } +test "gaToRgba" { + const rgba = try gaToRgba(std.testing.allocator, &.{ 7, 100, 8, 200 }); + defer std.testing.allocator.free(rgba); + + try std.testing.expectEqualSlices(u8, &.{ + 7, 7, 7, 100, + 8, 8, 8, 200, + }, rgba); +} + fn swizzle( alloc: Allocator, src: []const u8,