summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/font.c21
1 files changed, 15 insertions, 6 deletions
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 <limits.h>
#include <string.h>
#include <png.h>
@@ -28,9 +29,12 @@
#include <linux/font.h>
#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;