From 888d289641be21bd50fa56851ca78eb925e2e710 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Wed, 17 Jul 2019 20:46:07 -0400 Subject: font_render(): Actually address bits in font --- diff --git a/src/font.c b/src/font.c index 76510a6..3958891 100644 --- a/src/font.c +++ b/src/font.c @@ -21,6 +21,7 @@ #include "font.h" +#include #include #include @@ -28,9 +29,12 @@ #include #include "image.h" +#define BIT_TO_BYTE(i) ((i) / CHAR_BIT) +#define BITS_TO_BYTES(i) BIT_TO_BYTE((i) + CHAR_BIT - 1) +#define BIT_BYTE_SHIFT(i) (CHAR_BIT - 1 - ((i) % CHAR_BIT)) #define FONT_H(f) ((size_t) (f)->desc.height) #define FONT_W(f) ((size_t) (f)->desc.width) -#define CHAR_PIXEL(f, c, x, y) (((((c) * FONT_H(f)) + (y)) * FONT_W(f)) + (x)) +#define FONT_W_BYTES(f) BITS_TO_BYTES(FONT_W(f)) struct font { const struct font_desc desc; @@ -76,14 +80,19 @@ void font_render(struct font *font, png_const_colorp fg, png_const_colorp bg, char ch, png_bytepp rows, int row, int col) { - size_t y; - size_t r; - size_t x; - size_t c; + size_t y; + size_t r; + size_t x; + size_t c; + size_t byte; + unsigned char font_ch; for (y = 0, r = row * FONT_H(font); y < FONT_H(font); ++y, ++r) { for (x = 0, c = col * FONT_W(font); x < FONT_W(font); ++x, ++c){ - if (CHAR_PIXEL(font, ch, x, y)) { + byte = ((ch * FONT_H(font)) + y) * FONT_W_BYTES(font) + + BIT_TO_BYTE(x); + font_ch = font->desc.data[byte]; + if ((font_ch >> (BIT_BYTE_SHIFT(x))) & 0x01) { rows[r][c * IMAGE_PIXEL_SIZE + 0] = fg->red; rows[r][c * IMAGE_PIXEL_SIZE + 1] = fg->green; rows[r][c * IMAGE_PIXEL_SIZE + 2] = fg->blue; -- cgit v0.9.1