Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/bb_ep_gfx.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1141,20 +1141,29 @@ int bbepWriteStringCustom(FASTEPDSTATE *pBBEP, const void *pFont, int x, int y,
}
tw = w;
if (pBBEP->anti_alias) { // draw half-size anti-aliased characters
const uint8_t grayColors[4] = {0xf, 0xc, 0x6, 0};
const uint8_t grayColorPalette[4] = {0xf, 0xc, 0x6, 0};
const uint8_t invertedGrayColorPalette[4] = {0, 0x6, 0xc, 0xf};
const uint8_t *grayColors = iBG == BBEP_BLACK ? invertedGrayColorPalette : grayColorPalette; // invert the gray table if we're on a black background
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these 3 const declarations could be moved outside of the while loop on line 1072 as iBG stays unchanged

Kept it as is but happy to make the change if you want

Copy link
Copy Markdown
Owner

@bitbank2 bitbank2 Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an improvement. The const values appearing in the main loop has no effect on how the code is generated. Const are kept in a different memory segment. The compiler makes them go out of scope, but they don't get generated/removed each time the code is called. I'll test this shortly and let you know.

int iLineSize = (tw+7)/8;
memset(u8Cache, 0, iLineSize*2); // start with 2 lines of white (gray table is inverted)
for (ty=dy; ty<end_y+1 && ty+1 < height; ty++) {
uint8_t u8, u8Count, u8Color;
g5_decode_line(&g5dec, &u8Cache[(ty & 1) * iLineSize]);
if (w & 7) {
u8Cache[(ty & 1) * iLineSize + iLineSize - 1] &= u8EndMask;
}
if (ty & 1 && ty/2 >= 0) {
Scale2Gray(u8Cache, iLineSize, iLineSize); // convert a pair of lines
s = u8Cache;
u8 = *s++; // grab first byte
u8Count = 4;
for (tx=x+x_off; tx<x+x_off+tw && tx < width; tx+=2) {
u8Color = grayColors[u8>>6];
(*pBBEP->pfnSetPixelFast)(pBBEP, tx/2, ty/2, u8Color);
if (u8Color != iBG) {
// draw the pixel if it's not transparent
// avoid overlapping the previous character's pixels if the font is Italic for example
(*pBBEP->pfnSetPixelFast)(pBBEP, tx/2, ty/2, u8Color);
}
u8 <<= 2;
u8Count--;
if (u8Count == 0) {
Expand Down