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 if (sizeof(fbval_t
) != FBM_BPP(fb_mode())) {
23 fprintf(stderr
, "pad_init: fbval_t doesn't match fb depth\n");
27 rows
= fb_rows() / font_rows();
28 cols
= fb_cols() / font_cols();
37 #define CR(a) (((a) >> 16) & 0x0000ff)
38 #define CG(a) (((a) >> 8) & 0x0000ff)
39 #define CB(a) ((a) & 0x0000ff)
40 #define COLORMERGE(f, b, c) ((b) + (((f) - (b)) * (c) >> 8u))
42 static unsigned mixed_color(int fg
, int bg
, unsigned char val
)
44 unsigned int fore
= cd
[fg
], back
= cd
[bg
];
45 unsigned char r
= COLORMERGE(CR(fore
), CR(back
), val
);
46 unsigned char g
= COLORMERGE(CG(fore
), CG(back
), val
);
47 unsigned char b
= COLORMERGE(CB(fore
), CB(back
), val
);
48 return FB_VAL(r
, g
, b
);
51 static unsigned color2fb(int c
)
53 return FB_VAL(CR(cd
[c
]), CG(cd
[c
]), CB(cd
[c
]));
56 #define NCACHE (1 << 11)
57 static fbval_t cache
[NCACHE
* MAXDOTS
];
63 static int glyph_hash(struct glyph
*g
)
65 return (g
->c
^ (g
->fg
<< 7) ^ (g
->bg
<< 6)) & (NCACHE
- 1);
68 static fbval_t
*bitmap(int c
, short fg
, short bg
)
72 struct glyph glyph
= {0};
75 int nbits
= font_rows() * font_cols();
76 if (c
< 0 || (c
< 256 && (!isprint(c
) || isspace(c
))))
81 hash
= glyph_hash(&glyph
);
82 fbbits
= &cache
[hash
* MAXDOTS
];
83 if (!memcmp(&glyph
, &cacheid
[hash
], sizeof(glyph
)))
85 bits
= font_bitmap(c
);
88 memcpy(&cacheid
[hash
], &glyph
, sizeof(glyph
));
89 for (i
= 0; i
< nbits
; i
++)
90 fbbits
[i
] = mixed_color(fg
, bg
, bits
[i
]);
94 #define MAXFBWIDTH (1 << 12)
95 static void fb_box(int sr
, int sc
, int er
, int ec
, fbval_t val
)
97 static fbval_t line
[MAXFBWIDTH
];
100 for (i
= 0; i
< cn
; i
++)
102 for (i
= sr
; i
< er
; i
++)
103 fb_set(i
, sc
, line
, cn
);
106 void pad_put(int ch
, int r
, int c
, int fg
, int bg
)
108 int sr
= font_rows() * r
;
109 int sc
= font_cols() * c
;
110 int frows
= font_rows(), fcols
= font_cols();
112 fbval_t
*bits
= bitmap(ch
, fg
, bg
);
114 fb_box(sr
, sc
, sr
+ frows
, sc
+ fcols
, color2fb(bg
));
116 for (i
= 0; i
< frows
; i
++)
117 fb_set(sr
+ i
, sc
, bits
+ (i
* fcols
), fcols
);
120 void pad_blank(int c
)
122 fb_box(0, 0, fb_rows(), fb_cols(), color2fb(c
));
125 void pad_blankrow(int r
, int bg
)
127 int sr
= r
* font_rows();
128 int er
= r
== rows
- 1 ? fb_rows() : (r
+ 1) * font_rows();
129 fb_box(sr
, 0, er
, fb_cols(), color2fb(bg
));