MCPcopy
hub / github.com/donmccurdy/glTF-Transform / PNGImageUtils

Class PNGImageUtils

packages/core/src/utils/image-utils.ts:56–83  ·  view source on GitHub ↗

* PNG image support. * * PNG signature: 'PNG\r\n\x1a\n' * PNG image header chunk name: 'IHDR'

Source from the content-addressed store, hash-verified

54 * PNG image header chunk name: 'IHDR'
55 */
56class PNGImageUtils implements ImageUtilsFormat {
57 // Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
58 static PNG_FRIED_CHUNK_NAME = 'CgBI';
59 match(array: Uint8Array): boolean {
60 return (
61 array.length >= 8 &&
62 array[0] === 0x89 &&
63 array[1] === 0x50 &&
64 array[2] === 0x4e &&
65 array[3] === 0x47 &&
66 array[4] === 0x0d &&
67 array[5] === 0x0a &&
68 array[6] === 0x1a &&
69 array[7] === 0x0a
70 );
71 }
72 getSize(array: Uint8Array): vec2 {
73 const view = new DataView(array.buffer, array.byteOffset);
74 const magic = BufferUtils.decodeText(array.slice(12, 16));
75 if (magic === PNGImageUtils.PNG_FRIED_CHUNK_NAME) {
76 return [view.getUint32(32, false), view.getUint32(36, false)];
77 }
78 return [view.getUint32(16, false), view.getUint32(20, false)];
79 }
80 getChannels(_buffer: Uint8Array): number {
81 return 4;
82 }
83}
84
85/**
86 * *Common utilities for working with image data.*

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected