diff --git a/src/imb.zig b/src/imb.zig index 12e83be..b08502b 100644 --- a/src/imb.zig +++ b/src/imb.zig @@ -188,7 +188,29 @@ fn generateChecksum(data: [13]u8) u16 { return checksum; } -fn decode(bars: [65]BarType) Error!BarcodeResult { +fn flipBarcode(bars: [65]BarType) [65]BarType { + var flipped: [65]BarType = undefined; + + var i: u8 = 65; + + for (bars) |bar| { + i -= 1; + + flipped[i] = switch (bar) { + .ascending => .descending, + .descending => .ascending, + else => bar, + }; + } + + return flipped; +} + +pub fn decode(bars: [65]BarType) Error!BarcodeResult { + return tryDecode(bars) catch tryDecode(flipBarcode(bars)); +} + +fn tryDecode(bars: [65]BarType) Error!BarcodeResult { var characters = [_]u13{0} ** 10; for (bars, 0..) |bar, i| { diff --git a/web/imb.wasm b/web/imb.wasm index cba5bfe..ab31d91 100755 Binary files a/web/imb.wasm and b/web/imb.wasm differ