Skip to content

Commit 27023de

Browse files
committed
Force Bitmaps to be square for tracing, avoiding weird issues with alignment
1 parent 24b2218 commit 27023de

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

native/src/potrace.zig

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ pub const Bitmap = struct {
5151
bm: c.potrace_bitmap_t,
5252

5353
pub fn from_image(allocator: std.mem.Allocator, image: Image) !Bitmap {
54-
const dy = try Bitmap.dy_for_width(image.w);
55-
const size_in_words = dy * image.h;
54+
// For Gingerbread, it's important that the image always has the same width
55+
// and height, as non-square images seem to cause weird issues with offsets
56+
// and such.
57+
const wh = @max(image.w, image.h);
58+
59+
const dy = try Bitmap.dy_for_width(wh);
60+
const size_in_words = dy * wh;
5661

5762
var bitmap = Bitmap{ .allocator = allocator, .data = try allocator.alloc(c.potrace_word, size_in_words), .bm = c.potrace_bitmap_t{
58-
.w = @as(c_int, @intCast(image.w)),
59-
.h = @as(c_int, @intCast(image.h)),
60-
.dy = @as(c_int, @intCast(dy)),
63+
.w = @intCast(wh),
64+
.h = @intCast(wh),
65+
.dy = @intCast(dy),
6166
.map = null,
6267
} };
6368

0 commit comments

Comments
 (0)