From 6d4156322682919c86d922131c2f658e0b67da65 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Sat, 8 Apr 2023 17:31:10 -0700 Subject: [PATCH] new -flip arg to rotate 180 degrees Fixes #4 --- src/main.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.zig b/src/main.zig index f754a7d..0d6bb76 100644 --- a/src/main.zig +++ b/src/main.zig @@ -38,6 +38,7 @@ fn usage(args: [][]u8) !void { const Options = struct { background_filename: [:0]u8, device_file: [:0]u8, + flip: bool, }; pub fn main() !void { defer deinit(); @@ -88,6 +89,10 @@ pub fn main() !void { var pixels: [display.WIDTH * display.HEIGHT]u8 = undefined; try convertImage(opts.background_filename, &pixels, noTextForLine); try addTextToImage(alloc, &pixels, &lines); + if (opts.flip) { + try stdout.print("Flipping\n", .{}); + flipImage(&pixels); + } try bw.flush(); // We should take the linux device file here, then inspect for ttyUSB vs @@ -126,6 +131,10 @@ fn processArgs(args: [][:0]u8, line_array: *[display.LINES]*const [:0]u8) !Optio var is_filename = false; var line_number: ?usize = null; for (args[1..], 1..) |arg, i| { + if (std.mem.eql(u8, "-flip", arg)) { + opts.flip = true; + continue; + } if (std.mem.eql(u8, "-bg", arg)) { is_filename = true; continue; @@ -162,6 +171,15 @@ fn areDigits(bytes: []u8) bool { } return true; } +fn flipImage(pixels: *[display.WIDTH * display.HEIGHT]u8) void { + for (pixels[0..(display.WIDTH * display.HEIGHT / 2)], 0..) |_, i| { + const dest_pixel = pixels[pixels.len - 1 - i]; + const src_pixel = pixels[i]; + + pixels[pixels.len - 1 - i] = src_pixel; + pixels[i] = dest_pixel; + } +} fn addTextToImage(allocator: std.mem.Allocator, pixels: *[display.WIDTH * display.HEIGHT]u8, data: []*[]u8) !void { var maybe_font_data = try getFontData(allocator, DEFAULT_FONT);