MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / noisePng

Function noisePng

packages/agent-core/test/tools/image-compress.test.ts:65–77  ·  view source on GitHub ↗

High-entropy image whose PNG barely compresses — used to force the ladder.

(width: number, height: number, alpha = false)

Source from the content-addressed store, hash-verified

63
64/** High-entropy image whose PNG barely compresses — used to force the ladder. */
65async 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
79async function decodeAlpha(bytes: Uint8Array): Promise<boolean> {
80 const image = await Jimp.fromBuffer(Buffer.from(bytes));

Callers 1

Calls 1

getBufferMethod · 0.80

Tested by

no test coverage detected