At least: font code generator, exchange code support for color 128x128
This commit is contained in:
@@ -93,6 +93,12 @@ void DisplayDriver::set_bit(uint32_t x, uint32_t y, uint8_t val)
|
||||
set_dirty(y);
|
||||
}
|
||||
|
||||
uint8_t DisplayDriver::get_bit(uint32_t x, uint32_t y)
|
||||
{
|
||||
struct display_line &line = m_buffer.lines[y];
|
||||
return (line.data[x >> 3] >> (x & 7)) & 1;
|
||||
}
|
||||
|
||||
void DisplayDriver::set_byte(uint32_t x, uint32_t y, uint8_t val)
|
||||
{
|
||||
// if (x >= DISPLAY_WIDTH || y >= DISPLAY_HEIGHT) {
|
||||
@@ -114,7 +120,7 @@ void DisplayDriver::set_byte(uint32_t x, uint32_t y, uint8_t val)
|
||||
#define R4(n) R2(n), R2(n + 2*16), R2(n + 1*16), R2(n + 3*16)
|
||||
#define R6(n) R4(n), R4(n + 2*4 ), R4(n + 1*4 ), R4(n + 3*4 )
|
||||
|
||||
static const unsigned char BitReverseTable256[256] =
|
||||
static constexpr unsigned char BitReverseTable256[256] =
|
||||
{
|
||||
R6(0), R6(2), R6(1), R6(3)
|
||||
};
|
||||
@@ -129,11 +135,11 @@ unsigned char ReverseBitsLookupTable(unsigned char v)
|
||||
* (obviously) requires that everything is aligned correctly.
|
||||
*/
|
||||
|
||||
void DisplayDriver::clear_glyph_aligned(uint32_t x_off, uint32_t y_off, const struct font *, const struct glyph *g)
|
||||
void DisplayDriver::clear_glyph_aligned(uint32_t x_off, uint32_t y_off, const struct font *f, const struct glyph *g)
|
||||
{
|
||||
for (uint32_t y = y_off; y < y_off + g->rows && y < DISPLAY_HEIGHT; y++) {
|
||||
for (uint32_t y = y_off; y < y_off + f->height + g->top && y < DISPLAY_HEIGHT; y++) {
|
||||
uint8_t *start = (uint8_t *) &m_buffer.lines[y].data[(x_off) >> 3];
|
||||
uint8_t *end = (uint8_t *) &m_buffer.lines[y].data[(x_off + g->advance) >> 3];
|
||||
uint8_t *end = (uint8_t *) &m_buffer.lines[y].data[(x_off + f->width) >> 3];
|
||||
memset(start, 0xFF, end - start);
|
||||
}
|
||||
}
|
||||
@@ -180,18 +186,18 @@ void DisplayDriver::clear_glyph_unaligned(uint32_t x_off, uint32_t y_off, const
|
||||
{
|
||||
int16_t x = 0;
|
||||
if (x & 7) {
|
||||
while ((x & 7) && x < g->advance) {
|
||||
while ((x & 7) && x < font->width) {
|
||||
// TODO: use a switch on (x & 7) instead?
|
||||
for (int16_t y = 0; y < g->rows && y < (int16_t) DISPLAY_HEIGHT; y++) {
|
||||
set_bit(x_off + x, y_off + y + font->size - g->top, 0);
|
||||
for (int16_t y = 0; y < font->height && y < (int16_t) DISPLAY_HEIGHT; y++) {
|
||||
set_bit(x_off + x, y_off + y + font->height - g->top, 0);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
while (g->advance - x > 0) {
|
||||
for (int16_t y = 0; y < g->rows && y < (int16_t) DISPLAY_HEIGHT; y++) {
|
||||
set_bit(x_off + x, y_off + y + font->size - g->top, 0);
|
||||
while (font->width - x > 0) {
|
||||
for (int16_t y = 0; y < font->height && y < (int16_t) DISPLAY_HEIGHT; y++) {
|
||||
set_bit(x_off + x, y_off + y + font->height - g->top, 0);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
@@ -199,26 +205,31 @@ void DisplayDriver::clear_glyph_unaligned(uint32_t x_off, uint32_t y_off, const
|
||||
}
|
||||
|
||||
|
||||
void DisplayDriver::write_glyph_unaligned(uint32_t x_off, uint32_t y_off, const struct font *font, const struct glyph *g)
|
||||
void DisplayDriver::write_glyph_unaligned(uint32_t x_off, uint32_t y_off, const struct font *f, const struct glyph *g)
|
||||
{
|
||||
int byte_cols = g->cols / 8;
|
||||
if (g->cols & 7) {
|
||||
byte_cols++;
|
||||
}
|
||||
|
||||
for (size_t x = 0; x < g->cols && x < DISPLAY_WIDTH; x++) {
|
||||
for (size_t y = 0; y < g->rows && y < DISPLAY_HEIGHT; y++) {
|
||||
int byte_cols = g->width_bytes;
|
||||
|
||||
for (size_t x = 0; x < g->width && x + x_off + g->left < DISPLAY_WIDTH; x++) {
|
||||
for (size_t y = 0; y < g->height && y_off + y + f->height - g->top < DISPLAY_HEIGHT; y++) {
|
||||
int byte_x = x / 8;
|
||||
int byte_y = y;
|
||||
uint8_t bit = (g->bitmap[byte_y * byte_cols + byte_x] >> (7 - (x & 7))) & 1;
|
||||
set_bit(g->left + x_off + x,
|
||||
y_off + y + font->size - g->top,
|
||||
y_off + y + f->height - g->top,
|
||||
bit);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DisplayDriver::draw_hline(uint32_t x, uint32_t y, uint32_t width)
|
||||
{
|
||||
for (uint32_t i = 0; i < width; i += 8) {
|
||||
set_byte(x + i, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// void DisplayDriver::write_glyph_unaligned2(int *x_off, int y_off, const struct font *font, const struct glyph *g)
|
||||
// {
|
||||
// int byte_cols = g->cols / 8;
|
||||
@@ -242,20 +253,17 @@ void DisplayDriver::write_glyph_unaligned(uint32_t x_off, uint32_t y_off, const
|
||||
* requires that everything is aligned correctly.
|
||||
*/
|
||||
void DisplayDriver::write_glyph_aligned(uint32_t x_off, uint32_t y_off,
|
||||
const struct font *font, const struct glyph *g)
|
||||
const struct font *, const struct glyph *g)
|
||||
{
|
||||
int byte_cols = g->cols / 8;
|
||||
if (g->cols & 7) {
|
||||
byte_cols++;
|
||||
}
|
||||
int byte_cols = g->width_bytes;
|
||||
|
||||
|
||||
for (size_t x = 0; x < g->cols; x += 8) {
|
||||
for (size_t y = 0, byte_y = 0; y < g->rows && y < DISPLAY_HEIGHT; y++, byte_y += byte_cols) {
|
||||
for (size_t x = 0; x < g->width; x += 8) {
|
||||
for (size_t y = 0, byte_y = 0; y < g->height && y < DISPLAY_HEIGHT; y++, byte_y += byte_cols) {
|
||||
int byte_x = x / 8;
|
||||
uint8_t byte = g->bitmap[byte_y + byte_x];
|
||||
set_byte(g->left + x_off + x,
|
||||
y_off + y + font->size - g->top,
|
||||
y_off + y + g->height - g->top,
|
||||
~ReverseBitsLookupTable(byte));
|
||||
}
|
||||
}
|
||||
@@ -268,28 +276,22 @@ void DisplayDriver::char_at(uint32_t *x_off, uint32_t y_off, char c, const struc
|
||||
return;
|
||||
}
|
||||
|
||||
if (*x_off + g->left + g->cols >= DISPLAY_WIDTH) {
|
||||
if (*x_off + font->width >= DISPLAY_WIDTH) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(*x_off & 7) && !((*x_off + g->advance) & 7)) {
|
||||
if (!(*x_off & 7) && !(font->width & 7)) {
|
||||
clear_glyph_aligned(*x_off, y_off, font, g);
|
||||
} else {
|
||||
clear_glyph_unaligned(*x_off, y_off, font, g);
|
||||
}
|
||||
|
||||
// FIXME: REALLY DO THIS!
|
||||
// Check the right glyph boundary (g->left + g->cols)
|
||||
if (!((*x_off + g->left) & 7)) {
|
||||
write_glyph_aligned(*x_off, y_off, font, g);
|
||||
} else {
|
||||
write_glyph_unaligned(*x_off, y_off, font, g);
|
||||
}
|
||||
write_glyph_unaligned(*x_off, y_off, font, g);
|
||||
|
||||
m_dirty_line_min = MIN(m_dirty_line_min, y_off);
|
||||
m_dirty_line_max = MAX(m_dirty_line_max, y_off + g->rows);
|
||||
m_dirty_line_max = MAX(m_dirty_line_max, y_off + g->height);
|
||||
m_is_dirty = true;
|
||||
*x_off += g->advance;
|
||||
*x_off += font->width;
|
||||
}
|
||||
|
||||
void DisplayDriver::string_at(uint32_t *x_off, uint32_t y_off, const char *string, const struct font *font)
|
||||
@@ -301,12 +303,15 @@ void DisplayDriver::string_at(uint32_t *x_off, uint32_t y_off, const char *strin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DisplayDriver::refresh()
|
||||
{
|
||||
if (!m_is_dirty) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
uint8_t *start = (uint8_t *) &m_buffer.lines[m_dirty_line_min];
|
||||
// Data size
|
||||
size_t size = sizeof(m_buffer.lines[0]) * (m_dirty_line_max - m_dirty_line_min + 1);
|
||||
@@ -330,25 +335,7 @@ void DisplayDriver::clear()
|
||||
//TODO: put me somewhere fonty
|
||||
const struct glyph *DisplayDriver::glyph_for_char(const struct font *font, char c)
|
||||
{
|
||||
std::size_t low = 0;
|
||||
std::size_t high = font->count - 1;
|
||||
|
||||
while (low <= high) {
|
||||
std::size_t mid = (high - low) / 2;
|
||||
mid += low;
|
||||
|
||||
const struct glyph *g = font->glyphs[mid];
|
||||
if (g->glyph == c) {
|
||||
return g;
|
||||
}
|
||||
|
||||
if (g->glyph > c) {
|
||||
high = mid - 1;
|
||||
} else {
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return font->glyphs[(size_t) c];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user