MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / encodePng

Function encodePng

source code/utils/ansiToPng.ts:309–336  ·  view source on GitHub ↗

* Encode an RGBA pixel buffer as PNG. Minimal encoder: 8-bit depth, * color type 6 (RGBA), filter 0 (none) on every scanline, single IDAT.

(px: Uint8Array, width: number, height: number)

Source from the content-addressed store, hash-verified

307 * color type 6 (RGBA), filter 0 (none) on every scanline, single IDAT.
308 */
309function encodePng(px: Uint8Array, width: number, height: number): Buffer {
310 // IHDR
311 const ihdr = Buffer.alloc(13)
312 ihdr.writeUInt32BE(width, 0)
313 ihdr.writeUInt32BE(height, 4)
314 ihdr[8] = 8 // bit depth
315 ihdr[9] = 6 // color type: RGBA
316 ihdr[10] = 0 // compression: deflate
317 ihdr[11] = 0 // filter method
318 ihdr[12] = 0 // interlace: none
319
320 // IDAT: each scanline prefixed with filter byte 0.
321 const stride = width * 4
322 const raw = Buffer.alloc(height * (stride + 1))
323 for (let y = 0; y < height; y++) {
324 const dst = y * (stride + 1)
325 raw[dst] = 0
326 raw.set(px.subarray(y * stride, (y + 1) * stride), dst + 1)
327 }
328 const idat = deflateSync(raw)
329
330 return Buffer.concat([
331 PNG_SIG,
332 chunk('IHDR', ihdr),
333 chunk('IDAT', idat),
334 chunk('IEND', new Uint8Array(0)),
335 ])
336}

Callers 1

ansiToPngFunction · 0.85

Calls 2

chunkFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected