static void init_font(rgui_handle_t *rgui, const uint8_t *font_bmp_buf) { uint8_t *font = (uint8_t *) calloc(1, FONT_OFFSET(256)); rgui->alloc_font = true; for (unsigned i = 0; i < 256; i++) { unsigned y = i / 16; unsigned x = i % 16; copy_glyph(&font[FONT_OFFSET(i)], font_bmp_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x)); } rgui->font = font; }
static void char_to_texture(bm_renderer_t *handle, uint8_t letter, unsigned atlas_x, unsigned atlas_y) { unsigned y, x; uint8_t *target = handle->atlas.buffer + atlas_x + atlas_y * handle->atlas.width; for (y = 0; y < FONT_HEIGHT; y++) { for (x = 0; x < FONT_WIDTH; x++) { unsigned xo, yo; unsigned font_pixel = x + y * FONT_WIDTH; uint8_t rem = 1 << (font_pixel & 7); unsigned offset = font_pixel >> 3; uint8_t col = (bitmap_bin[FONT_OFFSET(letter) + offset] & rem) ? 0xff : 0; uint8_t *dst = target; dst += x * handle->scale_factor; dst += y * handle->scale_factor * handle->atlas.width; for (yo = 0; yo < handle->scale_factor; yo++) for (xo = 0; xo < handle->scale_factor; xo++) dst[xo + yo * handle->atlas.width] = col; } } handle->atlas.dirty = true; }