MCPcopy
hub / github.com/processing/p5.js / getIndexedFrame

Function getIndexedFrame

src/image/loading_displaying.js:431–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429 // key collisions.
430 const paletteCache = {};
431 const getIndexedFrame = frame => {
432 const length = frame.length / 4;
433 const index = new Uint8Array(length);
434 for (let i = 0; i < length; i++) {
435 const key =
436 (frame[i * 4] << 24) |
437 (frame[i * 4 + 1] << 16) |
438 (frame[i * 4 + 2] << 8) |
439 frame[i * 4 + 3];
440 if (paletteCache[key] === undefined) {
441 paletteCache[key] = nearestColorIndex(
442 globalPalette,
443 frame.slice(i * 4, (i + 1) * 4)
444 );
445 }
446 index[i] = paletteCache[key];
447 }
448 return index;
449 };
450
451 // the way we designed the palette means we always take the last index for transparency
452 const transparentIndex = globalPalette.length - 1;

Callers 1

loadingDisplayingFunction · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected