High-entropy image whose PNG barely compresses — used to force the ladder.
(width: number, height: number, alpha = false)
| 63 | |
| 64 | /** High-entropy image whose PNG barely compresses — used to force the ladder. */ |
| 65 | async function noisePng(width: number, height: number, alpha = false): Promise<Uint8Array> { |
| 66 | const image = new Jimp({ width, height, color: 0x000000ff }); |
| 67 | const data = image.bitmap.data; |
| 68 | for (let i = 0; i < data.length; i += 4) { |
| 69 | // Deterministic pseudo-random bytes (no Math.random for stable fixtures). |
| 70 | // Distinct multipliers per channel keep entropy high so PNG barely shrinks. |
| 71 | data[i] = (i * 2_654_435_761) & 0xff; |
| 72 | data[i + 1] = (i * 40_503) & 0xff; |
| 73 | data[i + 2] = (i * 12_289) & 0xff; |
| 74 | data[i + 3] = alpha ? (i * 7 + 17) & 0xff : 0xff; |
| 75 | } |
| 76 | return new Uint8Array(await image.getBuffer('image/png')); |
| 77 | } |
| 78 | |
| 79 | async function decodeAlpha(bytes: Uint8Array): Promise<boolean> { |
| 80 | const image = await Jimp.fromBuffer(Buffer.from(bytes)); |
no test coverage detected