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:
Dejvino
2026-11-14 15:33:25 +01:00
parent 83ec0217f4
commit cd688b8abe
3 changed files with 45 additions and 21 deletions
+3
View File
@@ -12,6 +12,9 @@
// Host flash is memory-mapped, so flash-resident data needs no special read // Host flash is memory-mapped, so flash-resident data needs no special read
// macro (same as on ESP32; real AVR pgm_read is not used by our sketches). // macro (same as on ESP32; real AVR pgm_read is not used by our sketches).
#define PROGMEM #define PROGMEM
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
#include <cstdint> #include <cstdint>
#include <cstddef> #include <cstddef>
+8 -6
View File
@@ -106,6 +106,7 @@ TEST(e2e/boot_and_controls)
schedule(2.2, 'p'); // -> Network view schedule(2.2, 'p'); // -> Network view
schedule(2.6, ' '); // freeze OFF schedule(2.6, ' '); // freeze OFF
schedule(3.0, 'r'); // reset (re-pauses) schedule(3.0, 'r'); // reset (re-pauses)
schedule(3.4, 'p'); // back to Cameras (full map)
test::serialClear(); test::serialClear();
EXPECT(pumpFor(4.5)); // run the inputs through loop() EXPECT(pumpFor(4.5)); // run the inputs through loop()
EXPECT(test::serialHas("[key] view -> NETWORK")); EXPECT(test::serialHas("[key] view -> NETWORK"));
@@ -114,12 +115,13 @@ TEST(e2e/boot_and_controls)
// HUD separator rendered across the top of the HUD bar // HUD separator rendered across the top of the HUD bar
EXPECT(test::pixelIs565(160, nd::HUD_Y, nd::C_BORDER)); EXPECT(test::pixelIs565(160, nd::HUD_Y, nd::C_BORDER));
// paused -> checkered freeze tint: 2px checker of black + dark teal // paused -> dithered freeze tint with color-key transparency:
// P(x,y): black when ((x>>1)+(y>>1)) is even // black dots where ((x>>1)+(y>>1)) is even, map shows through elsewhere
EXPECT(test::pixelIs565(50, 0, 0x1F1F)); // (25+0) odd -> teal EXPECT(test::pixelIs565(50, 2, 0x0000)); // dither dot drawn
EXPECT(test::pixelIs565(50, 2, 0x0000)); // (25+1) even -> black EXPECT(test::pixelIs565(52, 0, 0x0000)); // dither dot drawn
EXPECT(test::pixelIs565(52, 0, 0x0000)); // (26+0) even -> black EXPECT(test::pixelIs565(50, 0, nd::C_WALL)); // transparent: wall pixel
EXPECT(!test::pixelIs565(52, 0, 0x1F1F)); EXPECT(test::pixelIs565(50, 4, nd::C_WALL)); // survives untouched
EXPECT(!test::pixelIs565(50, 0, 0x1F1F)); // key color never rendered
} }
TEST(e2e/network_journey) TEST(e2e/network_journey)
+34 -15
View File
@@ -1264,28 +1264,47 @@ static void renderCursor()
} }
} }
// 8x8 stamp for the tactical-freeze tint: 2px checkerboard of black and a // Transparency key for 16bpp stamps: RGB565 has no alpha channel, so a
// dark teal (the map stays readable underneath). RGB565 has no alpha, so a // stamped pixel equal to this key leaves the destination pixel untouched
// dither is the way to "tint" — same trick the old scanlines used. // (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] = { static const uint16_t PROGMEM checkered8x8[64] = {
0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16,
0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16,
0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000,
0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000,
0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16,
0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16,
0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000, ND_TRANS16, ND_TRANS16, 0x0000, 0x0000,
0x1F1F, 0x1F1F, 0x0000, 0x0000, 0x1F1F, 0x1F1F, 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() static void renderFreezeTint()
{ {
// Stamp the checkered 8x8 pattern across the view. pushImage() exists on // Stamp the dithered, transparent-keyed 8x8 pattern across the view
// BOTH backends: device = TFT_eSprite::pushImage (blits into the fb
// sprite RAM), emulator = the shim blit into the host framebuffer.
for (int by = 0; by < nd::VIEW_H; by += 8) { for (int by = 0; by < nd::VIEW_H; by += 8) {
for (int bx = 0; bx < nd::VIEW_W; bx += 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); GFXP->setTextDatum(TR_DATUM);