Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand img_putc to support 2bpp fonts #21

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions main/display/lispif_disp_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1646,9 +1646,11 @@ static void img_putc(image_buffer_t *img, int x, int y, int fg, int bg, uint8_t
uint8_t w = font_data[0];
uint8_t h = font_data[1];
uint8_t char_num = font_data[2];
int bytes_per_char = (w * h) / 8;

if ((w * h) % 8 != 0) {
uint8_t bits_per_pixel = font_data[3];

int pixels_per_byte = 8 / bits_per_pixel;
int bytes_per_char = (w * h) / pixels_per_byte;
if ((w * h) % pixels_per_byte != 0) {
bytes_per_char += 1;
}

Expand All @@ -1662,14 +1664,25 @@ static void img_putc(image_buffer_t *img, int x, int y, int fg, int bg, uint8_t
return;
}

for (int i = 0; i < w * h; i++) {
uint8_t byte = font_data[4 + bytes_per_char * ch + (i / 8)];
uint8_t bit_pos = i % 8;
uint8_t bit = byte & (1 << bit_pos);
if (bit || bg >= 0) {
if (bits_per_pixel == 2) {
for (int i = 0; i < w * h; i++) {
uint8_t byte = font_data[4 + bytes_per_char * ch + (i / 4)];
uint8_t bit_pos = i % pixels_per_byte;
uint8_t pixel_value = (byte >> (bit_pos * 2)) & 0x03;
int x0 = i % w;
int y0 = i / w;
putpixel(img, x + x0, y + y0, bit ? fg : bg);
putpixel(img, x + x0, y + y0, pixel_value);
}
} else {
for (int i = 0; i < w * h; i++) {
uint8_t byte = font_data[4 + bytes_per_char * ch + (i / 8)];
uint8_t bit_pos = i % 8;
uint8_t bit = byte & (1 << bit_pos);
if (bit || bg >= 0) {
int x0 = i % w;
int y0 = i / w;
putpixel(img, x + x0, y + y0, bit ? fg : bg);
}
}
}
}
Expand Down