MCPcopy Create free account
hub / github.com/TomClive/SeeDance2Stitcher / encodePng

Function encodePng

server.js:229–248  ·  view source on GitHub ↗
(width, height, rgba)

Source from the content-addressed store, hash-verified

227}
228
229function encodePng(width, height, rgba) {
230 const ihdr = Buffer.alloc(13);
231 ihdr.writeUInt32BE(width, 0);
232 ihdr.writeUInt32BE(height, 4);
233 ihdr[8] = 8;
234 ihdr[9] = 6;
235 const scanlineLength = width * 4 + 1;
236 const scanlines = Buffer.alloc(scanlineLength * height);
237 for (let y = 0; y < height; y += 1) {
238 const sourceStart = y * width * 4;
239 const targetStart = y * scanlineLength + 1;
240 rgba.copy(scanlines, targetStart, sourceStart, sourceStart + width * 4);
241 }
242 return Buffer.concat([
243 Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
244 pngChunk("IHDR", ihdr),
245 pngChunk("IDAT", zlib.deflateSync(scanlines)),
246 pngChunk("IEND")
247 ]);
248}
249
250function glyphFor(char) {
251 return LABEL_FONT[char] || LABEL_FONT["?"];

Callers 1

writeLabelImageFunction · 0.85

Calls 1

pngChunkFunction · 0.85

Tested by

no test coverage detected