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

Function rgb565ToDataUrl

app.js:903–929  ·  view source on GitHub ↗
(w, h, rgb565)

Source from the content-addressed store, hash-verified

901}
902
903function rgb565ToDataUrl(w, h, rgb565) {
904 const canvas = document.createElement("canvas");
905 canvas.width = w;
906 canvas.height = h;
907 const ctx = canvas.getContext("2d");
908 const img = ctx.createImageData(w, h);
909 const d = img.data;
910
911 const total = Math.min(rgb565.length, w * h);
912 for (let p = 0; p < total; p++) {
913 const v = rgb565[p] & 0xffff;
914 const r5 = (v >> 11) & 0x1f;
915 const g6 = (v >> 5) & 0x3f;
916 const b5 = v & 0x1f;
917 const r = (r5 << 3) | (r5 >> 2);
918 const g = (g6 << 2) | (g6 >> 4);
919 const b = (b5 << 3) | (b5 >> 2);
920 const i = p * 4;
921 d[i] = r;
922 d[i + 1] = g;
923 d[i + 2] = b;
924 d[i + 3] = 255;
925 }
926
927 ctx.putImageData(img, 0, 0);
928 return canvas.toDataURL("image/png");
929}
930
931function importRgb565ImageToDisplayKit({ symbol, w, h, rgb565 }) {
932 if (!Array.isArray(rgb565) || !rgb565.length) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected