From 5ad01f6a3a13bf9fad2ff5915ac42a6c2fcc8e94 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 30 Apr 2024 09:02:16 -0500 Subject: [PATCH] image: fix base64 and example --- examples/image.zig | 10 ++++++---- src/Vaxis.zig | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/image.zig b/examples/image.zig index 3a4abfd..acce241 100644 --- a/examples/image.zig +++ b/examples/image.zig @@ -18,11 +18,13 @@ pub fn main() !void { } const alloc = gpa.allocator(); - var vx = try vaxis.init(Event, .{}); + var vx = try vaxis.init(alloc, .{}); defer vx.deinit(alloc); - try vx.startReadThread(); - defer vx.stopReadThread(); + var loop: vaxis.Loop(Event) = .{ .vaxis = &vx }; + + try loop.run(); + defer loop.stop(); try vx.enterAltScreen(); @@ -38,7 +40,7 @@ pub fn main() !void { var n: usize = 0; while (true) { - const event = vx.nextEvent(); + const event = loop.nextEvent(); switch (event) { .key_press => |key| { if (key.matches('c', .{ .ctrl = true })) { diff --git a/src/Vaxis.zig b/src/Vaxis.zig index 6623416..56296f6 100644 --- a/src/Vaxis.zig +++ b/src/Vaxis.zig @@ -1,6 +1,6 @@ const std = @import("std"); const atomic = std.atomic; -const base64 = std.base64; +const base64Encoder = std.base64.standard.Encoder; const zigimg = @import("zigimg"); const Cell = @import("Cell.zig"); @@ -580,8 +580,8 @@ pub fn loadImage( const png_buf = try alloc.alloc(u8, img.imageByteSize()); defer alloc.free(png_buf); const png = try img.writeToMemory(png_buf, .{ .png = .{} }); - const b64_buf = try alloc.alloc(u8, base64.calcSize(png.len)); - const encoded = base64.encode(b64_buf, png); + const b64_buf = try alloc.alloc(u8, base64Encoder.calcSize(png.len)); + const encoded = base64Encoder.encode(b64_buf, png); defer alloc.free(b64_buf); const id = self.next_img_id;