/** *MinimalPNGencoderforgeneratingsimpleRGBAimageswithoutnativedependencies. *UsedforQRcodes,liveprobes,andotherprogrammaticimagegeneration.
*/ import { deflateSync } from "node:zlib";
const CRC_TABLE = (() => { const table = new Uint32Array(256); for (let i = 0; i < 256; i += 1) {
let c = i; for (let k = 0; k < 8; k += 1) {
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
}
table[i] = c >>> 0;
} return table;
})();
/** Compute CRC32 checksum for a buffer (used in PNG chunk encoding). */
export function crc32(buf: Buffer): number {
let crc = 0xffffffff; for (let i = 0; i < buf.length; i += 1) {
crc = CRC_TABLE[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
} return (crc ^ 0xffffffff) >>> 0;
}
/** Create a PNG chunk with type, data, and CRC. */
export function pngChunk(type: string, data: Buffer): Buffer { const typeBuf = Buffer.from(type, "ascii"); const len = Buffer.alloc(4);
len.writeUInt32BE(data.length, 0); const crc = crc32(Buffer.concat([typeBuf, data])); const crcBuf = Buffer.alloc(4);
crcBuf.writeUInt32BE(crc, 0); return Buffer.concat([len, typeBuf, data, crcBuf]);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.