commit 80c8e750762984f0996bad8aa594288c5a16b92b
parent 62d809147bdcd0cf3c3a4ac076553876c0565adb
Author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
Date: Wed, 23 Jun 2021 17:39:44 +0200
chr2img: shorten writebmp, explain bitmasks
Diffstat:
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git 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);