MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / decodePng

Function decodePng

packages/engine/src/utils/alphaBlit.ts:159–182  ·  view source on GitHub ↗
(buf: Buffer)

Source from the content-addressed store, hash-verified

157 * Returns a Uint8Array of width*height*4 bytes in RGBA order.
158 */
159export function decodePng(buf: Buffer): { width: number; height: number; data: Uint8Array } {
160 const { width, height, bitDepth, colorType, rawPixels } = decodePngRaw(buf, "decodePng");
161
162 if (bitDepth !== 8) {
163 throw new Error(`decodePng: unsupported bit depth ${bitDepth} (expected 8)`);
164 }
165
166 const output = new Uint8Array(width * height * 4);
167
168 if (colorType === 6) {
169 // RGBA — copy directly
170 output.set(rawPixels);
171 } else {
172 // RGB → RGBA: set alpha to 255
173 for (let i = 0; i < width * height; i++) {
174 output[i * 4 + 0] = rawPixels[i * 3 + 0] ?? 0;
175 output[i * 4 + 1] = rawPixels[i * 3 + 1] ?? 0;
176 output[i * 4 + 2] = rawPixels[i * 3 + 2] ?? 0;
177 output[i * 4 + 3] = 255;
178 }
179 }
180
181 return { width, height, data: output };
182}
183
184// ── 16-bit PNG decoder ────────────────────────────────────────────────────────
185

Callers 5

runWebmCheckFunction · 0.90
runPngSequenceCheckFunction · 0.90
compositeHdrFrameFunction · 0.90
captureSceneIntoBufferFunction · 0.90
alphaBlit.test.tsFile · 0.85

Calls 2

decodePngRawFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected