From 80c8e750762984f0996bad8aa594288c5a16b92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Wed, 23 Jun 2021 17:39:44 +0200 Subject: [PATCH] chr2img: shorten writebmp, explain bitmasks --- src/chr2img.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/chr2img.c b/src/chr2img.c index 322cb4d..22e7b48 100644 --- a/src/chr2img.c +++ b/src/chr2img.c @@ -93,9 +93,10 @@ static int writebmp(int w, int h, u32int *p) { /* clang-format off */ + int sz = 14 + 40 + 4*4 + 4*w*h; u8int hd[14+40+4*4] = { 'B', 'M', - 0, 0, 0, 0, /* file size */ + sz, sz>>8, sz>>16, sz>>24, /* file size */ 0, 0, 0, 0, 14+40+4*4, 0, 0, 0, /* pixel data offset */ @@ -110,20 +111,13 @@ writebmp(int w, int h, u32int *p) 0, 0, 0, 0, /* dummy ver ppm */ 0, 0, 0, 0, /* dummy num of colors */ 0, 0, 0, 0, /* dummy important colors */ - 0, 0, 0, 0xff, - 0, 0, 0xff, 0, - 0, 0xff, 0, 0, - 0xff, 0, 0, 0, + 0, 0, 0, 0xff, /* R mask */ + 0, 0, 0xff, 0, /* G mask */ + 0, 0xff, 0, 0, /* B mask */ + 0xff, 0, 0, 0, /* A mask */ }; - int sz; /* clang-format on */ - sz = 14 + 40 + 4 * 4 + 4 * w * h; - hd[2] = sz; - hd[3] = sz >> 8; - hd[4] = sz >> 16; - hd[5] = sz >> 24; - write(1, hd, sizeof(hd)); while(h-- >= 0) write(1, p + w * h, 4 * w);