summaryrefslogtreecommitdiff
path: root/addons/image
diff options
context:
space:
mode:
Diffstat (limited to 'addons/image')
-rw-r--r--addons/image/image.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/addons/image/image.zig b/addons/image/image.zig
index f2303433..48135458 100644
--- a/addons/image/image.zig
+++ b/addons/image/image.zig
@@ -137,3 +137,19 @@ test "a job decodes a picture to its size and pixels, and one past max_dim is sc
try std.testing.expectEqual(8 + 1280 * 4, wide.len);
try std.testing.expect(Image.jobRun("not a picture", arena.allocator()) == null);
}
+
+test "a top-down BMP (its height negative in its header) opens at its size, as any picture" {
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ // 2x2, 24 bits, biHeight -2: rows top first, each 6 bytes and 2 of padding.
+ const bmp = "BM" ++ "\x46\x00\x00\x00" ++ "\x00\x00\x00\x00" ++ "\x36\x00\x00\x00" ++
+ "\x28\x00\x00\x00" ++ "\x02\x00\x00\x00" ++ "\xfe\xff\xff\xff" ++ "\x01\x00" ++ "\x18\x00" ++
+ "\x00\x00\x00\x00" ++ "\x10\x00\x00\x00" ++ "\x13\x0b\x00\x00" ++ "\x13\x0b\x00\x00" ++ "\x00\x00\x00\x00" ++ "\x00\x00\x00\x00" ++
+ "\x00\x00\xff\x00\xff\x00\x00\x00" ++ "\xff\x00\x00\xff\xff\xff\x00\x00";
+ try std.testing.expectEqual([2]u32{ 2, 2 }, info(bmp).?);
+ const got = Image.jobRun(bmp, arena.allocator()).?;
+ try std.testing.expectEqual(8 + 2 * 2 * 4, got.len);
+ try std.testing.expectEqual(2, std.mem.readInt(u32, got[4..8], .little));
+ // Its first pixel is the top row's first: red (BGR 00 00 ff).
+ try std.testing.expectEqualSlices(u8, &.{ 0xff, 0, 0, 0xff }, got[8..12]);
+}