// Rôle : génère de vraies images bitmap unies, seul format accepté par les outils d'image. import { Buffer } from "node:buffer"; import { crc32, deflateSync } from "node:zlib"; function chunk(type, data) { const length = Buffer.alloc(4); length.writeUInt32BE(data.length); const body = Buffer.concat([Buffer.from(type, "latin1"), data]); const checksum = Buffer.alloc(4); checksum.writeUInt32BE(crc32(body)); return Buffer.concat([length, body, checksum]); } export function solidPngDataUrl([red, green, blue], width = 640, height = 360) { const header = Buffer.alloc(13); header.writeUInt32BE(width, 0); header.writeUInt32BE(height, 4); header.set([8, 2, 0, 0, 0], 8); const row = Buffer.alloc(1 + width * 3); for (let x = 0; x < width; x += 1) row.set([red, green, blue], 1 + x * 3); const png = Buffer.concat([ Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", header), chunk("IDAT", deflateSync(Buffer.concat(Array.from({ length: height }, () => row)))), chunk("IEND", Buffer.alloc(0)) ]); return `data:image/png;base64,${png.toString("base64")}`; }