11 static unsigned int cd
[] = {
12 COLOR0
, COLOR1
, COLOR2
, COLOR3
,
13 COLOR4
, COLOR5
, COLOR6
, COLOR7
,
14 COLOR8
, COLOR9
, COLOR10
, COLOR11
,
15 COLOR12
, COLOR13
, COLOR14
, COLOR15
};
16 static int rows
, cols
;
22 rows
= fb_rows() / font_rows();
23 cols
= fb_cols() / font_cols();
31 #define CR(a) (((a) >> 16) & 0x0000ff)
32 #define CG(a) (((a) >> 8) & 0x0000ff)
33 #define CB(a) ((a) & 0x0000ff)
34 #define COLORMERGE(f, b, c) ((b) + (((f) - (b)) * (c) >> 8u))
36 static fbval_t
mixed_color(int fg
, int bg
, unsigned char val
)
38 unsigned int fore
= cd
[fg
], back
= cd
[bg
];
39 unsigned char r
= COLORMERGE(CR(fore
), CR(back
), val
);
40 unsigned char g
= COLORMERGE(CG(fore
), CG(back
), val
);
41 unsigned char b
= COLORMERGE(CB(fore
), CB(back
), val
);
42 return fb_color(r
, g
, b
);
45 static fbval_t
color2fb(int c
)
47 return fb_color(CR(cd
[c
]), CG(cd
[c
]), CB(cd
[c
]));
50 #define NCACHE (1 << 11)
51 static fbval_t cache
[NCACHE
* MAXDOTS
];
57 static int glyph_hash(struct glyph
*g
)
59 return (g
->c
^ (g
->fg
<< 7) ^ (g
->bg
<< 6)) & (NCACHE
- 1);
62 static fbval_t
*bitmap(int c
, short fg
, short bg
)
66 struct glyph glyph
= {0};
69 int nbits
= font_rows() * font_cols();
70 if (c
< 0 || (c
< 256 && (!isprint(c
) || isspace(c
))))
75 hash
= glyph_hash(&glyph
);
76 fbbits
= &cache
[hash
* MAXDOTS
];
77 if (!memcmp(&glyph
, &cacheid
[hash
], sizeof(glyph
)))
79 bits
= font_bitmap(c
);
82 memcpy(&cacheid
[hash
], &glyph
, sizeof(glyph
));
83 for (i
= 0; i
< nbits
; i
++)
84 fbbits
[i
] = mixed_color(fg
, bg
, bits
[i
]);
88 #define MAXFBWIDTH (1 << 12)
89 void fb_box(int sr
, int sc
, int er
, int ec
, fbval_t val
)
91 static fbval_t line
[MAXFBWIDTH
];
94 for (i
= 0; i
< cn
; i
++)
96 for (i
= sr
; i
< er
; i
++)
97 fb_set(i
, sc
, line
, cn
);
100 void pad_put(int ch
, int r
, int c
, int fg
, int bg
)
102 int sr
= font_rows() * r
;
103 int sc
= font_cols() * c
;
104 int frows
= font_rows(), fcols
= font_cols();
106 fbval_t
*bits
= bitmap(ch
, fg
, bg
);
108 fb_box(sr
, sc
, sr
+ frows
, sc
+ fcols
, color2fb(bg
));
110 for (i
= 0; i
< frows
; i
++)
111 fb_set(sr
+ i
, sc
, bits
+ (i
* fcols
), fcols
);
114 void pad_blank(int c
)
116 fb_box(0, 0, fb_rows(), fb_cols(), color2fb(c
));
119 void pad_blankrow(int r
, int bg
)
121 int sr
= r
* font_rows();
122 int er
= r
== rows
- 1 ? fb_rows() : (r
+ 1) * font_rows();
123 fb_box(sr
, 0, er
, fb_cols(), color2fb(bg
));