Decodes a PNG to the nearest pixel format: GRAY8, GRAY_ALPHA8, RGB8 or RGBA8. Palettes are expanded to RGB8 (RGBA8 with a tRNS chunk), a tRNS colour key on gray or RGB adds alpha, and 1, 2 and 4-bit gray is scaled to 8 bits. 16-bit samples keep their high byte (truncation). Adam7 interlacing is supported. Gamma, colour profiles and other ancillary chunks are ignored, and of an animated PNG only the default image is decoded. Chunk CRCs are checked for the critical chunks and tRNS.
decode_png :: (
data: [] u8,
max_pixels: s64 = DEFAULT_MAX_PIXELS
) -> (image: Image, ok: bool, error: string)
Decodes a PNG to the nearest pixel format: GRAY8, GRAY_ALPHA8, RGB8 or RGBA8. Palettes are expanded to RGB8 (RGBA8 with a tRNS chunk), a tRNS colour key on gray or RGB adds alpha, and 1, 2 and 4-bit gray is scaled to 8 bits. 16-bit samples keep their high byte (truncation). Adam7 interlacing is supported. Gamma, colour profiles and other ancillary chunks are ignored, and of an animated PNG only the default image is decoded. Chunk CRCs are checked for the critical chunks and tRNS.
Parameters
- data: [] u8
- max_pixels: s64
Returns
- image: Image
- ok: bool
- error: string