PNG images: a file's bytes decoded into a surface.
png reads every colour type and bit depth the format has, the tRNS
chunk, the five row filters and interlaced files. The surface holds
straight alpha, as the file does. A 16-bit sample keeps its high byte.
Colour management chunks are not read: the samples go to the surface as
they are.
The decoder is strict. A file gives every pixel it names or is refused: one cut short, one whose CRC or checksum does not match, one whose data is shorter or longer than its image.
| Name | Signature |
|---|---|
| png | png(data, opts) -> surface, err |
png(
data,opts) ->surface,err
Decode a PNG file's bytes into a surface
data is the whole file. The surface is the image's size, and canvas:blit,
gfx.sprite and gfx.sheet take it as a source.
opts.max_bytes bounds the surface: an image whose width * height * 4
is over it is refused before anything is allocated, on the header alone.
It is 256 MiB when left out. An image over 32767 pixels a side is refused
whatever the bound, since no surface is that large.
Nil and an error for bytes that are no PNG, and for a PNG the decoder refuses.