12 static unsigned int cd
[] = {
13 COLOR0
, COLOR1
, COLOR2
, COLOR3
,
14 COLOR4
, COLOR5
, COLOR6
, COLOR7
,
15 COLOR8
, COLOR9
, COLOR10
, COLOR11
,
16 COLOR12
, COLOR13
, COLOR14
, COLOR15
};
17 static int rows
, cols
;
23 rows
= fb_rows() / font_rows();
24 cols
= fb_cols() / font_cols();
32 #define CR(a) (((a) >> 16) & 0x0000ff)
33 #define CG(a) (((a) >> 8) & 0x0000ff)
34 #define CB(a) ((a) & 0x0000ff)
35 #define COLORMERGE(f, b, c) ((b) + (((f) - (b)) * (c) >> 8u))
37 static fbval_t
mixed_color(int fg
, int bg
, unsigned char val
)
39 unsigned int fore
= cd
[fg
], back
= cd
[bg
];
40 unsigned char r
= COLORMERGE(CR(fore
), CR(back
), val
);
41 unsigned char g
= COLORMERGE(CG(fore
), CG(back
), val
);
42 unsigned char b
= COLORMERGE(CB(fore
), CB(back
), val
);
43 return fb_color(r
, g
, b
);
46 static fbval_t
color2fb(int c
)
48 return fb_color(CR(cd
[c
]), CG(cd
[c
]), CB(cd
[c
]));
51 #define NCACHE ((1 << 11) - 1)
52 static fbval_t cache
[NCACHE
* MAXDOTS
];
58 static int glyph_hash(struct glyph
*g
)
60 return (g
->c
| (((g
->fg
+ 1) ^ g
->bg
) << 7)) % NCACHE
;
63 static fbval_t
*bitmap(int c
, short fg
, short bg
)
67 struct glyph glyph
= {0};
70 int nbits
= font_rows() * font_cols();
71 if (c
< 0 || (c
< 256 && (!isprint(c
) || isspace(c
))))
76 hash
= glyph_hash(&glyph
);
77 fbbits
= &cache
[hash
* MAXDOTS
];
78 if (!memcmp(&glyph
, &cacheid
[hash
], sizeof(glyph
)))
80 bits
= font_bitmap(c
);
83 memcpy(&cacheid
[hash
], &glyph
, sizeof(glyph
));
84 for (i
= 0; i
< nbits
; i
++)
85 fbbits
[i
] = mixed_color(fg
, bg
, bits
[i
]);
89 void pad_put(int ch
, int r
, int c
, int fg
, int bg
)
91 int sr
= font_rows() * r
;
92 int sc
= font_cols() * c
;
93 int frows
= font_rows(), fcols
= font_cols();
95 fbval_t
*bits
= bitmap(ch
, fg
, bg
);
97 fb_box(sr
, sc
, sr
+ frows
, sc
+ fcols
, color2fb(bg
));
99 for (i
= 0; i
< frows
; i
++)
100 fb_set(sr
+ i
, sc
, bits
+ (i
* fcols
), fcols
);
103 void pad_blank(int c
)
105 fb_box(0, 0, fb_rows(), fb_cols(), color2fb(c
));
108 void pad_blankrow(int r
, int bg
)
110 int sr
= r
* font_rows();
111 int er
= r
== rows
- 1 ? fb_rows() : (r
+ 1) * font_rows();
112 fb_box(sr
, 0, er
, fb_cols(), color2fb(bg
));