(width, height, rgba)
| 227 | } |
| 228 | |
| 229 | function 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 | |
| 250 | function glyphFor(char) { |
| 251 | return LABEL_FONT[char] || LABEL_FONT["?"]; |
no test coverage detected