Something went wrong. Try again.
A sans-I/O Zig library that reads and writes DEC sixel graphics as z2d surfaces.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! Writes each test picture through the encoder, for `tools/oracle.py check`//! to read back with libsixel: `NAME.six`, and beside it `NAME.rgba`, the//! picture it was written from, with straight alpha.//!//! Run as part of `zig build oracle`, which passes the directory to write to.
const std = @import("std");const Io = std.Io;const sixel = @import("sixel");const z2d = @import("z2d");const pictures = @import("pictures");
pub fn main(init: std.process.Init) !void { const io = init.io; const gpa = init.gpa; const args = try init.minimal.args.toSlice(init.arena.allocator()); if (args.len != 2) return error.Usage;
var dir = try Io.Dir.cwd().createDirPathOpen(io, args[1], .{}); defer dir.close(io);
const list = try pictures.all(io, gpa); defer pictures.free(gpa, list); for (list) |pic| { if (!pic.oracle) continue; const name = try std.fmt.allocPrint(gpa, "{s}.six", .{pic.name}); defer gpa.free(name); const bytes = try sixel.encodeAlloc(gpa, &pic.surface, pic.options); defer gpa.free(bytes); try dir.writeFile(io, .{ .sub_path = name, .data = bytes });
const w: u32 = @intCast(pic.surface.getWidth()); const h: u32 = @intCast(pic.surface.getHeight()); var raw: std.ArrayList(u8) = .empty; defer raw.deinit(gpa); try raw.appendSlice(gpa, std.mem.asBytes(&std.mem.nativeToLittle(u32, w))); try raw.appendSlice(gpa, std.mem.asBytes(&std.mem.nativeToLittle(u32, h))); for (0..h) |y| { for (0..w) |x| { const px = z2d.pixel.RGBA.fromPixel(pic.surface.getPixel(@intCast(x), @intCast(y)).?).demultiply(); try raw.appendSlice(gpa, &.{ px.r, px.g, px.b, px.a }); } } const raw_name = try std.fmt.allocPrint(gpa, "{s}.rgba", .{pic.name}); defer gpa.free(raw_name); try dir.writeFile(io, .{ .sub_path = raw_name, .data = raw.items }); }}