shithub: atlas

Download patch

ref: 9273e8bdb036058c8deba9c0495f2aab765fd835
parent: 3971ccb2be32e517f6932bc88f6876d7881ff63f
author: Sigrid Haflínudóttir <[email protected]>
date: Mon Jan 6 04:23:36 EST 2020

keep w/h increments to a minimum

--- a/atlas.c
+++ b/atlas.c
@@ -105,7 +105,7 @@
 	stbrp_node *nodes;
 	Memimage **im, *b;
 	stbrp_context ctx;
-	int i, w, h, n, fd, chan;
+	int i, w, h, n, fd, chan, delta;
 	u32int backcolor;
 
 	o = nil;
@@ -148,6 +148,7 @@
 	im = calloc(argc, sizeof(*im));
 	rects = calloc(argc, sizeof(*rects));
 	w = h = n = 0;
+	delta = 99999;
 	for (i = 0; i < argc; i++) {
 		if ((im[i] = load(argv[i])) == nil)
 			sysfatal("%s: %r", argv[i]);
@@ -160,6 +161,10 @@
 			w = rects[i].w;
 		if (h < rects[i].h)
 			h = rects[i].h;
+		if (delta > w)
+			delta = w;
+		if (delta > h)
+			delta = h;
 		n += rects[i].w;
 	}
 	nodes = calloc(n, sizeof(*nodes));
@@ -167,8 +172,8 @@
 		stbrp_init_target(&ctx, w, h, nodes, n);
 		if (stbrp_pack_rects(&ctx, rects, argc) == 1)
 			break;
-		w += 32;
-		h += 32;
+		w += delta;
+		h += delta;
 	}
 
 	if ((fd = o == nil ? open("/dev/null", OWRITE) : create(o, OWRITE, 0664)) < 0)