mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-27 17:41:40 +00:00
terminal/kitty: convert Format, Medium, Compression to lib.Enum
Convert the Transmission.Format, Transmission.Medium, and Transmission.Compression types from plain Zig enums to lib.Enum so they get a C-compatible backing type when building with c_abi. This lets the C API layer reuse the types directly instead of maintaining separate mirror enums. Move Format.bpp() to a standalone Transmission.formatBpp() function since lib.Enum types cannot have decls. In the C API layer, rename kitty_gfx to kitty_storage and command to kitty_cmd for clarity, and simplify the format/compression getters to direct assignment now that the types are shared.
This commit is contained in:
@@ -3,6 +3,7 @@ const assert = @import("../../quirks.zig").inlineAssert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
const simd = @import("../../simd/main.zig");
|
||||
const lib = @import("../lib.zig");
|
||||
|
||||
const log = std.log.scoped(.kitty_gfx);
|
||||
|
||||
@@ -394,39 +395,38 @@ pub const Transmission = struct {
|
||||
compression: Compression = .none, // o
|
||||
more_chunks: bool = false, // m
|
||||
|
||||
pub const Format = enum {
|
||||
rgb, // 24
|
||||
rgba, // 32
|
||||
png, // 100
|
||||
|
||||
pub const Format = lib.Enum(lib.target, &.{
|
||||
"rgb", // 24
|
||||
"rgba", // 32
|
||||
"png", // 100
|
||||
// The following are not supported directly via the protocol
|
||||
// but they are formats that a png may decode to that we
|
||||
// support.
|
||||
gray_alpha,
|
||||
gray,
|
||||
"gray_alpha",
|
||||
"gray",
|
||||
});
|
||||
|
||||
pub fn bpp(self: Format) u8 {
|
||||
return switch (self) {
|
||||
.gray => 1,
|
||||
.gray_alpha => 2,
|
||||
.rgb => 3,
|
||||
.rgba => 4,
|
||||
.png => unreachable, // Must be validated before
|
||||
};
|
||||
}
|
||||
};
|
||||
pub const Medium = lib.Enum(lib.target, &.{
|
||||
"direct", // d
|
||||
"file", // f
|
||||
"temporary_file", // t
|
||||
"shared_memory", // s
|
||||
});
|
||||
|
||||
pub const Medium = enum {
|
||||
direct, // d
|
||||
file, // f
|
||||
temporary_file, // t
|
||||
shared_memory, // s
|
||||
};
|
||||
pub const Compression = lib.Enum(lib.target, &.{
|
||||
"none",
|
||||
"zlib_deflate", // z
|
||||
});
|
||||
|
||||
pub const Compression = enum {
|
||||
none,
|
||||
zlib_deflate, // z
|
||||
};
|
||||
pub fn formatBpp(format: Format) u8 {
|
||||
return switch (format) {
|
||||
.gray => 1,
|
||||
.gray_alpha => 2,
|
||||
.rgb => 3,
|
||||
.rgba => 4,
|
||||
.png => unreachable, // Must be validated before
|
||||
};
|
||||
}
|
||||
|
||||
fn parse(kv: KV) !Transmission {
|
||||
var result: Transmission = .{};
|
||||
|
||||
@@ -202,8 +202,8 @@ pub const LoadingImage = struct {
|
||||
.png => stat_size,
|
||||
|
||||
// For these formats we have a size we must have.
|
||||
.gray, .gray_alpha, .rgb, .rgba => |f| size: {
|
||||
const bpp = f.bpp();
|
||||
.gray, .gray_alpha, .rgb, .rgba => size: {
|
||||
const bpp = command.Transmission.formatBpp(self.image.format);
|
||||
break :size self.image.width * self.image.height * bpp;
|
||||
},
|
||||
};
|
||||
@@ -390,7 +390,7 @@ pub const LoadingImage = struct {
|
||||
if (img.width > max_dimension or img.height > max_dimension) return error.DimensionsTooLarge;
|
||||
|
||||
// Data length must be what we expect
|
||||
const bpp = img.format.bpp();
|
||||
const bpp = command.Transmission.formatBpp(img.format);
|
||||
const expected_len = img.width * img.height * bpp;
|
||||
const actual_len = self.data.items.len;
|
||||
if (actual_len != expected_len) {
|
||||
|
||||
Reference in New Issue
Block a user