import { remapPixels } from '@datamoc/mw_games/two-d/render';
const pixels = new Uint8ClampedArray([255, 0, 255, 255, 10, 10, 10, 255]); // magenta, then dark grey
const out = remapPixels(pixels, { from: [0xff00ff], to: [0xff0000] }); // 'exact' by default
console.log([...out.slice(0, 4)]); // [255, 0, 0, 255] - the exact match repainted
console.log([...out.slice(4, 8)]); // [10, 10, 10, 255] - not a match, left alone
The renderer-free core of a palette remap. In
'exact'mode (the default) a pixel is repainted only when it exactly matches one ofmapping.from; every other pixel, including one close but not identical to afromcolour, passes through unchanged. In'nearest'mode every opaque pixel is repainted with thetocolour of whicheverfromentry it is nearest to in RGB space. Alpha and fully transparent pixels are always left untouched. Exported on its own so the remap logic is unit-testable without a canvas or a texture.