From 7b380e7003ab5ce5d22da4ba79adc12fd3231458 Mon Sep 17 00:00:00 2001 From: kdx Date: Sat, 15 Apr 2023 17:14:51 +0200 Subject: macro for tilesize --- src/main.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 665d3c8..a5f3514 100644 --- a/src/main.c +++ b/src/main.c @@ -2,14 +2,15 @@ #include "stb_image.h" #include +#define TSIZE 8 #define RGB(r, g, b) (((r) << 11) | ((g) << 5) | (b)) static void output_tile(const uint8_t *data, int x, int y, int w) { - for (int iy = 0; iy < 16; iy += 1) { + for (int iy = 0; iy < TSIZE; iy += 1) { putchar('\t'); - for (int ix = 0; ix < 16; ix += 1) { + for (int ix = 0; ix < TSIZE; ix += 1) { const int i = (ix + x + (iy + y) * w) * 3; const int v = RGB(data[i]/8, data[i+1]/4, data[i+2]/8); printf("%04x ", v); @@ -34,10 +35,10 @@ main(int argc, char **argv) return 1; } - if ((w & 15) || (h & 15)) { + if (w % TSIZE || h % TSIZE) { fprintf(stderr, "invalid dimensions %dx%d, " - "expected dimensions divisible by 16\n", - w, h); + "expected dimensions divisible by %d\n", + w, h, TSIZE); goto panic; } if (chans != 3) { @@ -47,8 +48,8 @@ main(int argc, char **argv) goto panic; } - for (int y = 0; y < h; y += 16) - for (int x = 0; x < w; x += 16) + for (int y = 0; y < h; y += TSIZE) + for (int x = 0; x < w; x += TSIZE) output_tile(data, x, y, w); stbi_image_free(data); -- cgit v1.2.3