diff options
Diffstat (limited to 'src/image.zig')
| -rw-r--r-- | src/image.zig | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/image.zig b/src/image.zig index a9f0e227..50e9649c 100644 --- a/src/image.zig +++ b/src/image.zig @@ -4,20 +4,56 @@ //! a pixel attachment the shell transmits/places (TTY: Kitty; SDL: GPU texture). const std = @import("std"); const zstbi = @import("zstbi"); -const ghostty_vt = @import("ghostty-vt"); +/// The 16-colour ANSI table below is the only thing this file ever wanted from +/// the emulator, and a build without one still renders images — see +/// `pardes.terminal_panes`. +const terminal_panes = @import("pardes.zig").terminal_panes; +const ghostty_vt = if (terminal_panes) @import("ghostty-vt") else struct {}; const pdf_enabled = @import("pardes_config").mupdf; pub const petscii = @import("petscii.zig"); /// the terminal's own 16 ANSI colors — what the `terminal` palette mode /// scores against; cells then paint as indexed colors so the real terminal /// resolves the RGB -pub fn ansiPalette() [16][3]u8 { - var p: [16][3]u8 = undefined; - for (0..16) |i| { +/// +/// These are GHOSTTY's sixteen, transcribed, because on a platform that has an +/// emulator the scoring used to read them straight out of it and a build +/// without one has to score against the identical table or render different +/// glyph art for the same photo. Note they are the base16 Tomorrow Night set, +/// NOT the xterm defaults: zig-pkg/ghostty-1.3.2-dev-5UdBCzeJ.../src/terminal/ +/// color.zig:389-405 (`Name.default`), which color.zig:8-15 copies into the +/// first sixteen entries of `color.default`. The comptime block below makes +/// the emulator prove that, so the transcription cannot rot in silence. +const ansi_default = [16][3]u8{ + .{ 0x1D, 0x1F, 0x21 }, // black + .{ 0xCC, 0x66, 0x66 }, // red + .{ 0xB5, 0xBD, 0x68 }, // green + .{ 0xF0, 0xC6, 0x74 }, // yellow + .{ 0x81, 0xA2, 0xBE }, // blue + .{ 0xB2, 0x94, 0xBB }, // magenta + .{ 0x8A, 0xBE, 0xB7 }, // cyan + .{ 0xC5, 0xC8, 0xC6 }, // white + .{ 0x66, 0x66, 0x66 }, // bright black + .{ 0xD5, 0x4E, 0x53 }, // bright red + .{ 0xB9, 0xCA, 0x4A }, // bright green + .{ 0xE7, 0xC5, 0x47 }, // bright yellow + .{ 0x7A, 0xA6, 0xDA }, // bright blue + .{ 0xC3, 0x97, 0xD8 }, // bright magenta + .{ 0x70, 0xC0, 0xB1 }, // bright cyan + .{ 0xEA, 0xEA, 0xEA }, // bright white +}; + +comptime { + if (terminal_panes) for (ansi_default, 0..) |rgb, i| { const c = ghostty_vt.color.default[i]; - p[i] = .{ c.r, c.g, c.b }; - } - return p; + if (rgb[0] != c.r or rgb[1] != c.g or rgb[2] != c.b) @compileError( + "src/image.zig ansi_default has drifted from ghostty's color.default", + ); + }; +} + +pub fn ansiPalette() [16][3]u8 { + return ansi_default; } /// cap the longest side before keeping/transmitting: a pane is at most a |
