MCPcopy Create free account
hub / github.com/melonjs/melonJS / readPixel

Function readPixel

packages/melonjs/tests/aseprite-parser.spec.js:258–269  ·  view source on GitHub ↗
(bitmap, x, y)

Source from the content-addressed store, hash-verified

256
257// read a single RGBA pixel from an ImageBitmap or canvas at (x,y)
258function readPixel(bitmap, x, y) {
259 const canvas =
260 typeof OffscreenCanvas !== "undefined"
261 ? new OffscreenCanvas(bitmap.width, bitmap.height)
262 : Object.assign(document.createElement("canvas"), {
263 width: bitmap.width,
264 height: bitmap.height,
265 });
266 const ctx = canvas.getContext("2d");
267 ctx.drawImage(bitmap, 0, 0);
268 return Array.from(ctx.getImageData(x, y, 1, 1).data);
269}
270
271// 2×2 RGBA test pattern: TL=red, TR=green, BL=blue, BR=white
272const PATTERN_2X2 = new Uint8Array([

Callers 1

Calls 3

getContextMethod · 0.45
drawImageMethod · 0.45
getImageDataMethod · 0.45

Tested by

no test coverage detected