import { withTextureCanvas } from '@datamoc/mw_games/two-d/render';
import type { Texture2D } from '@datamoc/mw_games/two-d/render';
declare const texture: Texture2D;
// a minimal custom modifier: invert every pixel's RGB, alpha untouched
const inverted = withTextureCanvas(texture, {}, (context, width, height) => {
const { data } = context.getImageData(0, 0, width, height);
for (let i = 0; i < data.length; i += 4) {
data[i] = 255 - data[i];
data[i + 1] = 255 - data[i + 1];
data[i + 2] = 255 - data[i + 2];
}
context.putImageData({ data, width, height }, 0, 0);
});
Opens a canvas the size of
texture, draws it in, and hands the 2D context topaintto make whatever further edits it needs (a palette remap, a composited overlay, a rewritten alpha channel); the result becomes the returnedTexture. Shared by every texture-level image modifier (recolorTexturehere,~BLIT/~MASK/~BLENDinImageModifiers.ts) so each one only has to write its own pixel or compositing logic, not the canvas bookkeeping. Returnstextureunchanged if there is no usable 2D canvas.