mwg API
    Preparing search index...

    Function remapPixels

    • The renderer-free core of a palette remap. In 'exact' mode (the default) a pixel is repainted only when it exactly matches one of mapping.from; every other pixel, including one close but not identical to a from colour, passes through unchanged. In 'nearest' mode every opaque pixel is repainted with the to colour of whichever from entry 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.

      Parameters

      Returns Uint8ClampedArray

      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