MCPcopy Create free account
hub / github.com/cifertech/DisplayKit / rgba_to_rgb565_row

Function rgba_to_rgb565_row

server/icon_export.py:42–57  ·  view source on GitHub ↗

Same alpha rule as app.js imageDataToRgb565 (alpha < 16 → background).

(
    rgba: bytes, w: int, h: int, bg: tuple[int, int, int]
)

Source from the content-addressed store, hash-verified

40
41
42def rgba_to_rgb565_row(
43 rgba: bytes, w: int, h: int, bg: tuple[int, int, int]
44) -> list[int]:
45 """Same alpha rule as app.js imageDataToRgb565 (alpha < 16 → background)."""
46 out: list[int] = []
47 bg_r, bg_g, bg_b = bg
48 for p in range(w * h):
49 i = p * 4
50 r, g, b, a = rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]
51 if a < 16:
52 r, g, b = bg_r, bg_g, bg_b
53 r5 = (r >> 3) & 0x1F
54 g6 = (g >> 2) & 0x3F
55 b5 = (b >> 3) & 0x1F
56 out.append((r5 << 11) | (g6 << 5) | b5)
57 return out
58
59
60def rgba_to_mono_xbm(rgba: bytes, w: int, h: int) -> bytes:

Callers 1

export_iconsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected