(bitmap, x, y)
| 256 | |
| 257 | // read a single RGBA pixel from an ImageBitmap or canvas at (x,y) |
| 258 | function 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 |
| 272 | const PATTERN_2X2 = new Uint8Array([ |
no test coverage detected