NetDeck: transparent color-key dither for the freeze tint
- stampImage16_P(): PROGMEM 16bpp stamp with color-key transparency (ND_TRANS16 pixels leave the destination untouched) — TFT_eSprite has no transparent pushImage variant, so it composites via drawPixel on both backends (sprite RAM on device, host framebuffer in the emulator) - shim: pgm_read_byte/word/dword macros (flash is memory-mapped on host and ESP32 alike) - pattern: 2px checker of black dots + transparent cells — half-visible dither, map/units stay readable underneath - E2E now proves the transparency itself: wall pixels survive under transparent cells, dots render black, key color never rendered
This commit is contained in:
+34
-15
@@ -1264,28 +1264,47 @@ static void renderCursor()
|
||||
}
|
||||
}
|
||||
|
||||
// 8x8 stamp for the tactical-freeze tint: 2px checkerboard of black and a
|
||||
// dark teal (the map stays readable underneath). RGB565 has no alpha, so a
|
||||
// dither is the way to "tint" — same trick the old scanlines used.
|
||||
// Transparency key for 16bpp stamps: RGB565 has no alpha channel, so a
|
||||
// stamped pixel equal to this key leaves the destination pixel untouched
|
||||
// (color-key transparency). Chosen outside the nd_layout.h palette so it
|
||||
// can never collide with real drawing colors.
|
||||
#define ND_TRANS16 0x1F1F
|
||||
|
||||
// 8x8 dither stamp for the tactical-freeze tint: 2px checkerboard — black
|
||||
// dots are drawn, transparent cells let the frozen game view show through.
|
||||
// Half coverage dims the map without hiding it.
|
||||
static const uint16_t PROGMEM checkered8x8[64] = {
|
||||
0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F,
|
||||
0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F,
|
||||
0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000,
|
||||
0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F,
|
||||
0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F,
|
||||
0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000,
|
||||
0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16,
|
||||
0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16,
|
||||
ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000,
|
||||
ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16,
|
||||
0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16,
|
||||
ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000,
|
||||
ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000,
|
||||
};
|
||||
|
||||
// Stamp a PROGMEM 16bpp image with color-key transparency. TFT_eSprite has no
|
||||
// transparent pushImage() variant (only pushSprite() to the TFT does), so the
|
||||
// composite is done pixel by pixel via drawPixel(); on the emulator the same
|
||||
// call writes the host framebuffer. Clipping is drawPixel's job on both.
|
||||
static void stampImage16_P(int x, int y, int w, int h,
|
||||
const uint16_t *data, uint16_t transp)
|
||||
{
|
||||
for (int j = 0; j < h; j++) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
uint16_t c = pgm_read_word(&data[j * w + i]);
|
||||
if (c != transp) GFXP->drawPixel(x + i, y + j, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void renderFreezeTint()
|
||||
{
|
||||
// Stamp the checkered 8x8 pattern across the view. pushImage() exists on
|
||||
// BOTH backends: device = TFT_eSprite::pushImage (blits into the fb
|
||||
// sprite RAM), emulator = the shim blit into the host framebuffer.
|
||||
// Stamp the dithered, transparent-keyed 8x8 pattern across the view
|
||||
for (int by = 0; by < nd::VIEW_H; by += 8) {
|
||||
for (int bx = 0; bx < nd::VIEW_W; bx += 8) {
|
||||
GFXP->pushImage(bx, by, 8, 8, checkered8x8);
|
||||
stampImage16_P(bx, by, 8, 8, checkered8x8, ND_TRANS16);
|
||||
}
|
||||
}
|
||||
GFXP->setTextDatum(TR_DATUM);
|
||||
|
||||
Reference in New Issue
Block a user