static void put_string_in_rgb_image(uint8_t *x, int w, int h, int posx, int posy, uint8_t *fg, uint8_t *bg, int kerning, struct bitmap_font *font, char *string) { int posx0 = posx; while (1) { int c = *string++; if (!c) break; if (c == '\n') { posx = posx0; posy += font->height; continue; } if (c > 0 && c < font->number_of_glyphs) { for (int i = 0; i < font->width; i++) for (int j = 0; j < font->height; j++) { int ii = posx + i; int jj = posy + j; if (get_font_bit(font, c, i, j)) put_pixel_rgb(x, w, h, ii, jj, fg); else put_pixel_rgb(x, w, h, ii, jj, bg); } } posx += font->width + kerning; } }
static void put_char_in_rgb_image(uint8_t *rgb, int w, int h, struct bitmap_font *f, int posx, int posy, uint8_t *fg, uint8_t *bg, int c) { if (c > 0 && c < f->number_of_glyphs) for (int i = 0; i < f->width; i++) for (int j = 0; j < f->height; j++) { int ii = posx + i; int jj = posy + j; if (get_font_bit(f, c, i, j)) put_pixel_rgb(rgb, w, h, ii, jj, fg); else put_pixel_rgb(rgb, w, h, ii, jj, bg); } }
// dump the terminal state into a rgb bitmap void term_bitmap(uint8_t *rgb, int w, int h, struct terminal *t) { // compute grid offsets int ox = t->font->width + t->kerning; int oy = t->font->height + t->spacing; // size consistency check if (w != ox * t->w || h != oy * t->h) fprintf(stderr, "WARNING: (%d,%d) != (%d,%d)\n", w, h, ox*t->w, oy*t->h); // clear rgb buffer for (int i = 0; i < 3 * w * h; i++) rgb[i] = 0; // draw character bitmaps for (int j = 0; j < t->h; j++) for (int i = 0; i < t->w; i++) { int c = t->letters[j * t->w + i]; int a = t->attributes[j * t->w + i]; uint8_t fg[3] = {205, 205, 205}; uint8_t bg[3] = {0, 0, 0}; put_char_in_rgb_image(rgb,w,h, t->font, i*ox,j*oy, fg,bg, c); } // draw cursor if (t->cursorx >= 0 && t->cursorx < t->w) if (t->cursory >= 0 && t->cursory < t->h) { int c0x = t->cursorx * ox; int c0y = t->cursory * oy; uint8_t cc[3] = {200, 100, 0}; for (int i = 0; i < ox; i++) { put_pixel_rgb(rgb,w,h, c0x + i, c0y , cc); put_pixel_rgb(rgb,w,h, c0x + i, c0y + oy, cc); } for (int j = 0; j < oy; j++) { put_pixel_rgb(rgb,w,h, c0x , c0y + j, cc); put_pixel_rgb(rgb,w,h, c0x + ox, c0y + j, cc); } } }