From 74750fbd49aa14c3de72f0c8574dc25a7e1aa579 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Sun, 29 Sep 2024 21:47:26 -0600 Subject: [PATCH] font/Atlas: add dump method to dump to ppm --- src/font/Atlas.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/font/Atlas.zig b/src/font/Atlas.zig index 6cb546af3..938946655 100644 --- a/src/font/Atlas.zig +++ b/src/font/Atlas.zig @@ -297,6 +297,29 @@ pub fn clear(self: *Atlas) void { self.nodes.appendAssumeCapacity(.{ .x = 1, .y = 1, .width = self.size - 2 }); } +/// Dump the atlas as a PPM to a writer, for debug purposes. +/// Only supports grayscale and rgb atlases. +pub fn dump(self: Atlas, writer: anytype) !void { + try writer.print( + \\P{c} + \\{d} {d} + \\255 + \\ + , .{ + @as(u8, switch (self.format) { + .grayscale => '5', + .rgb => '6', + else => { + log.err("Unsupported format for dump: {}", .{ self.format }); + @panic("Cannot dump this atlas format."); + } + }), + self.size, + self.size, + }); + try writer.writeAll(self.data); +} + /// The wasm-compatible API. This lacks documentation unless the API differs /// from the standard Zig API. To learn what a function does, just look one /// level deeper to what Zig function is called and read the documentation there.