Skip to content

Commit 467960e

Browse files
jractravisg
authored andcommitted
[lib][gfx] Add mono 1bpp support
[lib][font] Use mono 1bpp byte-span drawing, where available - Adds 1bpp rendering function, and accompanying implementations of putpixel, copyrect, fillrect. - libgfx now calls arch_clean_cache_range() conditionally, to avoid crashes on architectures lacking cache support. - Includes changes made by scripts/codestyle
1 parent 9ffd430 commit 467960e

File tree

3 files changed

+462
-113
lines changed

3 files changed

+462
-113
lines changed

lib/font/font.c

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* @ingroup graphics
1717
*/
1818

19-
#include <lk/debug.h>
20-
#include <lib/gfx.h>
2119
#include <lib/font.h>
20+
#include <lib/gfx.h>
21+
#include <lk/debug.h>
2222

2323
#include "font.h"
2424

@@ -28,19 +28,47 @@
2828
* @ingroup graphics
2929
*/
3030
void font_draw_char(gfx_surface *surface, unsigned char c, int x, int y, uint32_t color) {
31-
uint i,j;
31+
uint i, j;
3232
uint line;
3333

34-
// draw this char into a buffer
34+
// 1bpp batched per-byte, for performance boost
35+
if (surface->format == GFX_FORMAT_MONO_1 && surface->spanmono1) {
36+
uint32_t c1 = surface->translate_color ? surface->translate_color(color) : color;
37+
gfx_span_op op = (c1 != 0) ? GFX_SPAN_SET : GFX_SPAN_CLR;
38+
39+
for (i = 0; i < FONT_Y; i++) {
40+
line = FONT[(c * FONT_Y) + i];
41+
42+
for (j = 0; j < FONT_X;) {
43+
if ((line & 0x1) == 0) {
44+
line >>= 1;
45+
j++;
46+
continue;
47+
}
48+
49+
uint start = j;
50+
do {
51+
line >>= 1;
52+
j++;
53+
} while (j < FONT_X && (line & 0x1));
54+
55+
surface->spanmono1(surface, (x + start), (y + i), (j - start), op);
56+
}
57+
}
58+
59+
gfx_flush_rows(surface, y, (y + FONT_Y));
60+
return;
61+
}
62+
63+
// Per-pixel default
3564
for (i = 0; i < FONT_Y; i++) {
36-
line = FONT[c * FONT_Y + i];
65+
line = FONT[(c * FONT_Y) + i];
3766
for (j = 0; j < FONT_X; j++) {
38-
if (line & 0x1)
39-
gfx_putpixel(surface, x + j, y + i, color);
67+
if (line & 0x1) {
68+
gfx_putpixel(surface, (x + j), (y + i), color);
69+
}
4070
line = line >> 1;
4171
}
4272
}
43-
gfx_flush_rows(surface, y, y + FONT_Y);
73+
gfx_flush_rows(surface, y, (y + FONT_Y));
4474
}
45-
46-

0 commit comments

Comments
 (0)