MCPcopy Index your code
hub / github.com/cifertech/DisplayKit / imageDataToRgb565

Function imageDataToRgb565

app.js:2693–2708  ·  view source on GitHub ↗
(data, w, h, bgHex)

Source from the content-addressed store, hash-verified

2691}
2692
2693function imageDataToRgb565(data, w, h, bgHex) {
2694 const rgb565 = new Array(w * h);
2695 const bg = hexToRgb(bgHex || "#000000") || { r: 0, g: 0, b: 0 };
2696 for (let i = 0, p = 0; i < data.length; i += 4, p++) {
2697 const a = data[i + 3];
2698 // No alpha on TFT pushImage; blend with current background for preview + export
2699 const r = a < 16 ? bg.r : data[i];
2700 const g = a < 16 ? bg.g : data[i + 1];
2701 const b = a < 16 ? bg.b : data[i + 2];
2702 const r5 = (r >> 3) & 0x1f;
2703 const g6 = (g >> 2) & 0x3f;
2704 const b5 = (b >> 3) & 0x1f;
2705 rgb565[p] = (r5 << 11) | (g6 << 5) | b5;
2706 }
2707 return rgb565;
2708}
2709
2710function buildMonoBitmapFromImageData(imageData, w, h, alphaThreshold = 16, lumaThreshold = 0.35) {
2711 // U8g2 drawXBMP expects XBM bit order: LSB first within each byte, row-major.

Callers 1

loadPngToRgb565Function · 0.85

Calls 1

hexToRgbFunction · 0.85

Tested by

no test coverage detected